-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into arr/shallow_water_cartesian_topography
- Loading branch information
Showing
18 changed files
with
1,023 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
examples/elixir_shallowwater_quad_icosahedron_shell_advection.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
|
||
using OrdinaryDiffEq | ||
using Trixi | ||
using TrixiAtmo | ||
|
||
# To run a convergence test, we have two options: | ||
# 1. Use the p4est variable initial_refinement_level to refine the grid: | ||
# - To do this, line 46 ("initial_refinement_level = 0") must NOT be a comment | ||
# - Call convergence_test("../examples/elixir_shallowwater_quad_icosahedron_shell_advection.jl", 4, initial_refinement_level = 0) | ||
# - NOT OPTIMAL: Good convergence the first iterations, but then it stagnates. Reason: The geometry does not improve with refinement. | ||
# 2. Use the variable trees_per_face_dimension of P4estMeshQuadIcosahedron2D | ||
# - To do this, line 46 ("initial_refinement_level = 0") MUST BE commented/removed | ||
# - Call convergence_test("../examples/elixir_shallowwater_quad_icosahedron_shell_advection.jl", 4, cells_per_dimension = (1,1)) | ||
# - OPTIMAL convergence of polydeg + 1. Reason: The geometry improves with refinement. | ||
|
||
############################################################################### | ||
# semidiscretization of the linear advection equation | ||
initial_condition = initial_condition_gaussian | ||
polydeg = 3 | ||
cells_per_dimension = (2, 2) | ||
|
||
# We use the ShallowWaterEquations3D equations structure but modify the rhs! function to | ||
# convert it to a variable-coefficient advection equation | ||
equations = ShallowWaterEquations3D(gravity_constant = 0.0) | ||
|
||
# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux | ||
solver = DGSEM(polydeg = polydeg, surface_flux = flux_lax_friedrichs) | ||
|
||
# Source term function to transform the Euler equations into a linear advection equation with variable advection velocity | ||
function source_terms_convert_to_linear_advection(u, du, x, t, | ||
equations::ShallowWaterEquations3D, | ||
normal_direction) | ||
v1 = u[2] / u[1] | ||
v2 = u[3] / u[1] | ||
v3 = u[4] / u[1] | ||
|
||
s2 = du[1] * v1 - du[2] | ||
s3 = du[1] * v2 - du[3] | ||
s4 = du[1] * v3 - du[4] | ||
|
||
return SVector(0.0, s2, s3, s4, 0.0) | ||
end | ||
|
||
# Create a 2D quad-based icosahedral mesh the size of the Earth | ||
mesh = P4estMeshQuadIcosahedron2D(cells_per_dimension[1], EARTH_RADIUS, | ||
#initial_refinement_level = 0, | ||
polydeg = polydeg) | ||
|
||
# Convert initial condition given in terms of zonal and meridional velocity components to | ||
# one given in terms of Cartesian momentum components | ||
initial_condition_transformed = transform_to_cartesian(initial_condition, equations) | ||
|
||
# A semidiscretization collects data structures and functions for the spatial discretization | ||
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_transformed, solver, | ||
source_terms = source_terms_convert_to_linear_advection) | ||
|
||
############################################################################### | ||
# ODE solvers, callbacks etc. | ||
|
||
ode = semidiscretize(semi, (0.0, 12 * SECONDS_PER_DAY)) | ||
|
||
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup | ||
# and resets the timers | ||
summary_callback = SummaryCallback() | ||
|
||
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results | ||
analysis_callback = AnalysisCallback(semi, interval = 100, | ||
save_analysis = true, | ||
extra_analysis_errors = (:conservation_error,)) | ||
|
||
# The SaveSolutionCallback allows to save the solution to a file in regular intervals | ||
save_solution = SaveSolutionCallback(interval = 100, | ||
solution_variables = cons2prim) | ||
|
||
# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step | ||
stepsize_callback = StepsizeCallback(cfl = 0.7) | ||
|
||
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver | ||
callbacks = CallbackSet(summary_callback, analysis_callback, save_solution, | ||
stepsize_callback) | ||
|
||
############################################################################### | ||
# run the simulation | ||
|
||
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks | ||
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false), | ||
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback | ||
save_everystep = false, callback = callbacks); | ||
|
||
# Print the timer summary | ||
summary_callback() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
include("analysis_covariant.jl") | ||
include("save_solution_covariant.jl") | ||
include("stepsize_dg2d.jl") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Convert to another set of variables using a solution_variables function that depends on | ||
# auxiliary variables | ||
function convert_variables(u, solution_variables, mesh::P4estMesh{2}, | ||
equations, dg, cache) | ||
(; aux_node_vars) = cache.auxiliary_variables | ||
|
||
# Extract the number of solution variables to be output | ||
# (may be different than the number of conservative variables) | ||
n_vars = length(solution_variables(Trixi.get_node_vars(u, equations, dg, 1, 1, 1), | ||
get_node_aux_vars(aux_node_vars, equations, dg, 1, 1, | ||
1), equations)) | ||
# Allocate storage for output | ||
data = Array{eltype(u)}(undef, n_vars, nnodes(dg), nnodes(dg), nelements(dg, cache)) | ||
|
||
# Loop over all nodes and convert variables, passing in auxiliary variables | ||
Trixi.@threaded for element in eachelement(dg, cache) | ||
for j in eachnode(dg), i in eachnode(dg) | ||
u_node = Trixi.get_node_vars(u, equations, dg, i, j, element) | ||
aux_node = get_node_aux_vars(aux_node_vars, equations, dg, i, j, element) | ||
u_node_converted = solution_variables(u_node, aux_node, equations) | ||
for v in 1:n_vars | ||
data[v, i, j, element] = u_node_converted[v] | ||
end | ||
end | ||
end | ||
return data | ||
end | ||
|
||
# Specialized save_solution_file method that supports a solution_variables function which | ||
# depends on auxiliary variables. The conversion must be defined as solution_variables(u, | ||
# aux_vars, equations), and an additional method must be defined as solution_variables(u, | ||
# equations) = u, such that no conversion is done when auxiliary variables are not provided. | ||
function Trixi.save_solution_file(u_ode, t, dt, iter, | ||
semi::SemidiscretizationHyperbolic{<:Trixi.AbstractMesh, | ||
<:AbstractCovariantEquations}, | ||
solution_callback, | ||
element_variables = Dict{Symbol, Any}(), | ||
node_variables = Dict{Symbol, Any}(); | ||
system = "") | ||
mesh, equations, solver, cache = Trixi.mesh_equations_solver_cache(semi) | ||
u = Trixi.wrap_array_native(u_ode, semi) | ||
|
||
# Perform the variable conversion at each node | ||
data = convert_variables(u, solution_callback.solution_variables, mesh, equations, | ||
solver, cache) | ||
|
||
# Call the existing Trixi.save_solution_file, which will use solution_variables(u, | ||
# equations). Since the variables are already converted above, we therefore require | ||
# solution_variables(u, equations) = u. | ||
Trixi.save_solution_file(data, t, dt, iter, mesh, equations, solver, cache, | ||
solution_callback, element_variables, | ||
node_variables, system = system) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export P4estMeshCubedSphere2D | ||
include("p4est_cubed_sphere.jl") | ||
include("p4est_icosahedron_quads.jl") |
Oops, something went wrong.