-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tree Mesh 2D Dirichlet #1251
Tree Mesh 2D Dirichlet #1251
Conversation
Co-authored-by: Andrew Winters <andrew.ross.winters@liu.se>
Co-authored-by: Andrew Winters <andrew.ross.winters@liu.se>
Co-authored-by: Andrew Winters <andrew.ross.winters@liu.se>
Co-authored-by: Andrew Winters <andrew.ross.winters@liu.se>
Co-authored-by: Andrew Winters <andrew.ross.winters@liu.se>
Co-authored-by: Andrew Winters <andrew.ross.winters@liu.se>
Co-authored-by: Andrew Winters <andrew.ross.winters@liu.se>
Co-authored-by: Andrew Winters <andrew.ross.winters@liu.se>
Co-authored-by: Andrew Winters <andrew.ross.winters@liu.se>
Co-authored-by: Andrew Winters <andrew.ross.winters@liu.se>
Co-authored-by: Andrew Winters <andrew.ross.winters@liu.se>
Co-authored-by: Andrew Winters <andrew.ross.winters@liu.se>
Co-authored-by: Andrew Winters <andrew.ross.winters@liu.se>
Co-authored-by: Andrew Winters <andrew.ross.winters@liu.se>
Co-authored-by: Andrew Winters <andrew.ross.winters@liu.se>
Co-authored-by: Andrew Winters <andrew.ross.winters@liu.se>
Co-authored-by: Andrew Winters <andrew.ross.winters@liu.se>
Co-authored-by: Andrew Winters <andrew.ross.winters@liu.se>
Co-authored-by: Andrew Winters <andrew.ross.winters@liu.se>
Co-authored-by: Andrew Winters <andrew.ross.winters@liu.se>
Co-authored-by: Andrew Winters <andrew.ross.winters@liu.se>
Co-authored-by: Andrew Winters <andrew.ross.winters@liu.se>
Yes, it only calls on the surface flux. I thought this is intended, as the inital slip wall consition also only calls on the surface flux? I also dir a simulation with a discontinuous bottom topography. This is the underlying code using LinearAlgebra
using Plots
using OrdinaryDiffEq
using Trixi
###############################################################################
# semidiscretization of the shallow water equations with a discontinuous
# bottom topography function
equations = ShallowWaterEquations2D(gravity_constant=1.0, H0=7.0)
# An initial condition with constant total water height and zero velocities to test well-balancedness.
# Note, this routine is used to compute errors in the analysis callback but the initialization is
# overwritten by `initial_condition_discontinuous_well_balancedness` below.
function initial_condition_well_balancedness(x, t, equations::ShallowWaterEquations2D)
inicenter = SVector(0.0, 0.0)
x_norm = x - inicenter
r = norm(x_norm)
# Calculate primitive variables
H = r < 0.1 ? 9.0 : 7.0
v1 = 0.0
v2 = 0.0
# bottom topography taken from Pond.control in [HOHQMesh](https://github.com/trixi-framework/HOHQMesh)
x1, x2 = x
b = ( 1.5 / exp( 0.5 * ((x1 - 1.0)^2 + (x2 - 1.0)^2) )
+ 0.75 / exp( 0.5 * ((x1 + 1.0)^2 + (x2 + 1.0)^2) ) )
return prim2cons(SVector(H, v1, v2, b), equations)
end
initial_condition = initial_condition_well_balancedness
boundary_condition = boundary_condition_slip_wall
###############################################################################
# Get the DG approximation space
volume_flux = (flux_wintermeyer_etal, flux_nonconservative_wintermeyer_etal)
surface_flux = (flux_fjordholm_etal, flux_nonconservative_fjordholm_etal)
solver = DGSEM(polydeg=4, surface_flux=surface_flux,
volume_integral=VolumeIntegralFluxDifferencing(volume_flux))
###############################################################################
# Get the TreeMesh and setup a periodic mesh
coordinates_min = (-1.0, -1.0)
coordinates_max = ( 1.0, 1.0)
mesh = TreeMesh(coordinates_min, coordinates_max,
initial_refinement_level=2,
n_cells_max=10_000,
periodicity = false)
# Create the semi discretization object
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver;
boundary_conditions = boundary_condition)
###############################################################################
# ODE solver
tspan = (0.0, 1.0)
ode = semidiscretize(semi, tspan)
###############################################################################
# Workaround to set a discontinuous bottom topography and initial condition for debugging and testing.
# alternative version of the initial conditinon used to setup a truly discontinuous
# bottom topography function for this academic testcase of well-balancedness.
# The errors from the analysis callback are not important but the error for this lake at rest test case
# `∑|H0-(h+b)|` should be around machine roundoff
# In contrast to the usual signature of initial conditions, this one get passed the
# `element_id` explicitly. In particular, this initial conditions works as intended
# only for the TreeMesh2D with initial_refinement_level=2.
function initial_condition_discontinuous_well_balancedness(x, t, element_id, equations::ShallowWaterEquations2D)
inicenter = SVector(0.0, 0.0)
x_norm = x - inicenter
r = norm(x_norm)
# Calculate primitive variables
H = r < 0.1 ? 9.0 : 7.0
v1 = 0.0
v2 = 0.0
x1, x2 = x
b = ( 1.5 / exp( 0.5 * ((x1 - 1.0)^2 + (x2 - 1.0)^2) )
+ 0.75 / exp( 0.5 * ((x1 + 1.0)^2 + (x2 + 1.0)^2) ) )
# Setup a discontinuous bottom topography using the element id number
if element_id == 7
b = 2.0 + 0.5 * sin(2.0 * pi * x[1]) + 0.5 * cos(2.0 * pi * x[2])
end
return prim2cons(SVector(H, v1, v2, b), equations)
end
# point to the data we want to augment
u = Trixi.wrap_array(ode.u0, semi)
# reset the initial condition
for element in eachelement(semi.solver, semi.cache)
for j in eachnode(semi.solver), i in eachnode(semi.solver)
x_node = Trixi.get_node_coords(semi.cache.elements.node_coordinates, equations, semi.solver, i, j, element)
u_node = initial_condition_discontinuous_well_balancedness(x_node, first(tspan), element, equations)
Trixi.set_node_vars!(u, u_node, equations, semi.solver, i, j, element)
end
end
###############################################################################
# run the simulation
sol = solve(ode, RDPK3SpFSAL49(), abstol=1.0e-8, reltol=1.0e-8, save_everystep=true);
pyplot()
animation = @animate for k= 1:5:700
pd = PlotData2D(sol.u[k], semi)
wireframe(pd["H"])
surface!(pd["b"], zlim=(0,10), camera = (30,20), title="t=$(k-1)")
end
gif(animation, "dam_break_2d.gif", fps=10) |
Yeah, this is consistent with how the wall BC is set for the other mesh types with the shallow water equations. The last example run you provided looks good. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation of the wall BC for TreeMesh
looks good now. Is there a corresponding test that was added?
Not yet. What are you thinking of? |
I added a well balanced test which is analogue to The original elixir had the lake at rest error at the end of the simulation of |
I also added another elixir julia> convergence_test("examples\\tree_2d_dgsem\\elixir_shallowwater_source_terms_dirichlet.jl", 4) I get the following error message ERROR: UndefVarError: result not defined
Stacktrace:
[1] find_assignment(expr::Expr, destination::Symbol)
@ Trixi C:\Users\maxbe\Repos\maxbertrand1996\Trixi.jl\src\auxiliary\special_elixirs.jl:219
[2] extract_initial_resolution(elixir::String, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ Trixi C:\Users\maxbe\Repos\maxbertrand1996\Trixi.jl\src\auxiliary\special_elixirs.jl:239
[3] convergence_test(mod::Module, elixir::String, iterations::Int64; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ Trixi C:\Users\maxbe\Repos\maxbertrand1996\Trixi.jl\src\auxiliary\special_elixirs.jl:62
[4] convergence_test
@ C:\Users\maxbe\Repos\maxbertrand1996\Trixi.jl\src\auxiliary\special_elixirs.jl:56 [inlined]
[5] #convergence_test#1157
@ C:\Users\maxbe\Repos\maxbertrand1996\Trixi.jl\src\auxiliary\special_elixirs.jl:142 [inlined]
[6] convergence_test(elixir::String, iterations::Int64)
@ Trixi C:\Users\maxbe\Repos\maxbertrand1996\Trixi.jl\src\auxiliary\special_elixirs.jl:142
[7] top-level scope
@ REPL[14]:1
caused by: UndefVarError: result not defined
Stacktrace:
[1] find_assignment(expr::Expr, destination::Symbol)
@ Trixi C:\Users\maxbe\Repos\maxbertrand1996\Trixi.jl\src\auxiliary\special_elixirs.jl:219
[2] extract_initial_resolution(elixir::String, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ Trixi C:\Users\maxbe\Repos\maxbertrand1996\Trixi.jl\src\auxiliary\special_elixirs.jl:229
[3] convergence_test(mod::Module, elixir::String, iterations::Int64; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ Trixi C:\Users\maxbe\Repos\maxbertrand1996\Trixi.jl\src\auxiliary\special_elixirs.jl:62
[4] convergence_test
@ C:\Users\maxbe\Repos\maxbertrand1996\Trixi.jl\src\auxiliary\special_elixirs.jl:56 [inlined]
[5] #convergence_test#1157
@ C:\Users\maxbe\Repos\maxbertrand1996\Trixi.jl\src\auxiliary\special_elixirs.jl:142 [inlined]
[6] convergence_test(elixir::String, iterations::Int64)
@ Trixi C:\Users\maxbe\Repos\maxbertrand1996\Trixi.jl\src\auxiliary\special_elixirs.jl:142
[7] top-level scope
@ REPL[14]:1 Does anybody of you know what might be causing this? |
You need to add a carriage return to the end of the new |
😳 Uh. Is this a known (and fixable) issue in the implementation of |
Not sure how easy it is to fix. I played around with the code for about twenty minutes until I noticed that without this carriage return the command $(Expr(:incomplete, "incomplete: \"begin\" at none:1 requires end")) because the |
Should be fixed by #1280 |
Yes, the change from #1280 fixes this newline issue |
Thanks a lot, the
The results are even better than for
I also added the example elixirs to |
I get shown that there are still changes requested for this PR, but I do not see what needs to be addressed. |
@andrewwinters5000 requested changes before, so he needs to approve the new version to clear the old status and allow merging this PR. |
Yes, I will review everything today. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new tests and feature look good. I just left one last request to see if we can simplify the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the confusion about the nonconservative flux. The suggested simplifications should work and shrink the code.
Co-authored-by: Andrew Winters <andrew.ross.winters@liu.se>
I hope now everything is fine |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, everything looks fine now. This can merge once the tests all pass.
src/solvers/dgsem_tree/dg_2d.jl
did not yet consider non periodic boundary conditions, if the underlying equation has non conservative terms.This has been added using a similar logic as in
src/solvers/dgsem_tree/dg_1d.jl