-
Notifications
You must be signed in to change notification settings - Fork 134
User defined RHS Splitting for IMEX #2518
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
Open
MarcoArtiano
wants to merge
76
commits into
trixi-framework:main
Choose a base branch
from
MarcoArtiano:ma/rhs_splitting
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+551
−1
Open
Changes from 18 commits
Commits
Show all changes
76 commits
Select commit
Hold shift + click to select a range
409872d
add user defined rhs splitting
MarcoArtiano b4fe4ea
testing some IMEX schemes
MarcoArtiano 7dd83d2
clean up
MarcoArtiano b3e5641
Merge branch 'trixi-framework:main' into ma/rhs_splitting
MarcoArtiano 279b971
format
MarcoArtiano 3e278a0
add hacky fix for amr
MarcoArtiano 59b07d4
format
MarcoArtiano f1c759c
Merge branch 'main' into ma/rhs_splitting
MarcoArtiano 185b6e0
Merge branch 'main' into ma/rhs_splitting
MarcoArtiano 0d1ddb6
Merge branch 'main' into ma/rhs_splitting
MarcoArtiano 92c575d
better splitting
MarcoArtiano 96f91de
add tests
MarcoArtiano 2cad29b
Merge branch 'main' into ma/rhs_splitting
MarcoArtiano 7b8707c
rm old elixir
MarcoArtiano 9900953
Delete examples/p4est_2d_dgsem/elixir_euler_imex_inertia_gravity_wave…
MarcoArtiano 13b6145
using ADTypes
MarcoArtiano 36e3c70
make rhs call compatible for testing allocations
MarcoArtiano d45ea6e
increase coverage
MarcoArtiano ce8ed43
change 1,2 to stiff and nonstiff
MarcoArtiano 5f8544e
add comments and fmt
MarcoArtiano 6851b99
Merge branch 'main' into ma/rhs_splitting
MarcoArtiano e8a8723
add comments, fix docs
MarcoArtiano d61febc
merge
MarcoArtiano 2ebd1e2
add comments and fix docs
MarcoArtiano 730627b
Merge branch 'main' into ma/rhs_splitting
MarcoArtiano 0c7dbd0
Merge branch 'main' into ma/rhs_splitting
MarcoArtiano 5e98dc4
Update examples/p4est_2d_dgsem/elixir_euler_imex_warm_bubble.jl
DanielDoehring 9d3c0ef
Update examples/p4est_2d_dgsem/elixir_euler_imex_warm_bubble.jl
DanielDoehring cf70c7e
Update examples/p4est_2d_dgsem/elixir_euler_imex_warm_bubble.jl
DanielDoehring 5ade557
Apply suggestions from code review
DanielDoehring 1282ad1
Update examples/p4est_2d_dgsem/elixir_euler_imex_warm_bubble.jl
DanielDoehring 944a9c7
Apply suggestions from code review
MarcoArtiano 20bc000
Update src/semidiscretization/semidiscretization_split.jl
DanielDoehring 3d7a69d
add other suggestions
MarcoArtiano 04b7280
Update src/semidiscretization/semidiscretization_split.jl
DanielDoehring 17087b2
fmt
MarcoArtiano 26ee4e8
Apply suggestions from code review
MarcoArtiano e91dafc
Merge branch 'main' into ma/rhs_splitting
MarcoArtiano 8840a63
Apply suggestions from code review
MarcoArtiano 8843e92
Merge branch 'main' into ma/rhs_splitting
MarcoArtiano 0b3fb29
fix indentation, tuple of solvers and fix test values
MarcoArtiano 5132d0e
move definition of dt, reduce output
MarcoArtiano 7500872
add ndims for plotting
MarcoArtiano 9e89ce2
Merge branch 'main' into ma/rhs_splitting
MarcoArtiano 810ce3e
add comment on bc's and test unit
MarcoArtiano 3bda497
change time integration method and update test values
MarcoArtiano a762002
change to KenCarp4 and update test values
MarcoArtiano 5daa12a
fix tests
MarcoArtiano ae0ab07
Merge branch 'main' into ma/rhs_splitting
MarcoArtiano 164b906
Merge branch 'main' into ma/rhs_splitting
MarcoArtiano 639123e
update elixir and test
MarcoArtiano 5c72392
Merge branch 'ma/rhs_splitting' of github.com:MarcoArtiano/Trixi.jl i…
MarcoArtiano a4b6dcd
Merge branch 'main' into ma/rhs_splitting
MarcoArtiano 730b17b
fix tests
MarcoArtiano e66028c
add news entry
MarcoArtiano 9d1e25a
Merge branch 'main' into ma/rhs_splitting
MarcoArtiano 35c0b79
fix test
MarcoArtiano a984d5e
Merge branch 'main' into ma/rhs_splitting
MarcoArtiano 0638544
Merge branch 'main' into ma/rhs_splitting
MarcoArtiano 81e42ad
Merge branch 'main' into ma/rhs_splitting
MarcoArtiano 8e518a5
reduce boilerplate
MarcoArtiano c22d818
Merge branch 'main' into ma/rhs_splitting
MarcoArtiano 115dc30
Merge branch 'main' into ma/rhs_splitting
MarcoArtiano 96aacf6
Merge branch 'main' into ma/rhs_splitting
MarcoArtiano 6680552
Merge branch 'main' into ma/rhs_splitting
MarcoArtiano 6c9eaca
Merge branch 'main' into ma/rhs_splitting
MarcoArtiano d8a5b43
Merge branch 'main' into ma/rhs_splitting
MarcoArtiano 6113fbe
Apply suggestions from code review
DanielDoehring 804019f
Update src/semidiscretization/semidiscretization_split.jl
DanielDoehring be0fc6d
Update src/semidiscretization/semidiscretization_split.jl
DanielDoehring daba7ff
Apply suggestions from code review
DanielDoehring 031ad24
Merge branch 'main' into ma/rhs_splitting
DanielDoehring 840c573
Apply suggestions from code review
DanielDoehring c4ba68b
Update src/semidiscretization/semidiscretization_split.jl
DanielDoehring 119faea
Update src/semidiscretization/semidiscretization_split.jl
DanielDoehring de1d471
Update src/semidiscretization/semidiscretization_split.jl
DanielDoehring File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
212 changes: 212 additions & 0 deletions
212
examples/p4est_2d_dgsem/elixir_euler_imex_warm_bubble.jl
This file contains hidden or 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,212 @@ | ||
| using Trixi | ||
| using OrdinaryDiffEqBDF | ||
ranocha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| using ADTypes ## This is needed to force 'autodiff = AutoFiniteDiff()' in the ODE solver. | ||
DanielDoehring marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| function initial_condition_warm_bubble(x, t, equations::CompressibleEulerEquations2D) | ||
| g = 9.81 | ||
| c_p = 1004.0 | ||
| c_v = 717.0 | ||
|
|
||
| # center of perturbation | ||
| center_x = 10000.0 | ||
| center_z = 2000.0 | ||
| # radius of perturbation | ||
| radius = 2000.0 | ||
| # distance of current x to center of perturbation | ||
| r = sqrt((x[1] - center_x)^2 + (x[2] - center_z)^2) | ||
|
|
||
| # perturbation in potential temperature | ||
| potential_temperature_ref = 300.0 | ||
| potential_temperature_perturbation = 0.0 | ||
| if r <= radius | ||
| potential_temperature_perturbation = 2 * cospi(0.5 * r / radius)^2 | ||
| end | ||
| potential_temperature = potential_temperature_ref + potential_temperature_perturbation | ||
|
|
||
| # Exner pressure, solves hydrostatic equation for x[2] | ||
| exner = 1 - g / (c_p * potential_temperature) * x[2] | ||
|
|
||
| # pressure | ||
| p_0 = 100_000.0 # reference pressure | ||
| R = c_p - c_v # gas constant (dry air) | ||
| p = p_0 * exner^(c_p / R) | ||
|
|
||
| # temperature | ||
| T = potential_temperature * exner | ||
|
|
||
| # density | ||
| rho = p / (R * T) | ||
|
|
||
| v1 = 20.0 | ||
| v2 = 0.0 | ||
| return prim2cons(SVector(rho, v1, v2, p), equations) | ||
| end | ||
|
|
||
| @inline function flux_lmars_fast(u_ll, u_rr, normal_direction::AbstractVector, | ||
| equations::CompressibleEulerEquations2D) | ||
| a = 340.0 | ||
| # Unpack left and right state | ||
| rho_ll, v1_ll, v2_ll, p_ll = cons2prim(u_ll, equations) | ||
| rho_rr, v1_rr, v2_rr, p_rr = cons2prim(u_rr, equations) | ||
|
|
||
| v_ll = v1_ll * normal_direction[1] + v2_ll * normal_direction[2] | ||
| v_rr = v1_rr * normal_direction[1] + v2_rr * normal_direction[2] | ||
|
|
||
| norm_ = Trixi.norm(normal_direction) | ||
|
|
||
| rho = 0.5f0 * (rho_ll + rho_rr) | ||
|
|
||
| p_interface = 0.5f0 * (p_ll + p_rr) - 0.5f0 * a * rho * (v_rr - v_ll) / norm_ | ||
| v_interface = 0.5f0 * (v_ll + v_rr) - 1 / (2 * a * rho) * (p_rr - p_ll) * norm_ | ||
|
|
||
| if (v_interface > 0) | ||
| f4 = p_ll * v_interface | ||
| else | ||
| f4 = p_rr * v_interface | ||
| end | ||
|
|
||
| return SVector(zero(eltype(u_ll)), | ||
| p_interface * normal_direction[1], | ||
| p_interface * normal_direction[2], | ||
| f4) | ||
| end | ||
|
|
||
| @inline function flux_lmars_slow(u_ll, u_rr, normal_direction::AbstractVector, | ||
| equations::CompressibleEulerEquations2D) | ||
| a = 340.0 | ||
| # Unpack left and right state | ||
| rho_ll, v1_ll, v2_ll, p_ll = cons2prim(u_ll, equations) | ||
| rho_rr, v1_rr, v2_rr, p_rr = cons2prim(u_rr, equations) | ||
|
|
||
| v_ll = v1_ll * normal_direction[1] + v2_ll * normal_direction[2] | ||
| v_rr = v1_rr * normal_direction[1] + v2_rr * normal_direction[2] | ||
|
|
||
| norm_ = Trixi.norm(normal_direction) | ||
|
|
||
| rho = 0.5f0 * (rho_ll + rho_rr) | ||
|
|
||
| p_interface = 0.5f0 * (p_ll + p_rr) - 0.5f0 * a * rho * (v_rr - v_ll) / norm_ | ||
| v_interface = 0.5f0 * (v_ll + v_rr) - 1 / (2 * a * rho) * (p_rr - p_ll) * norm_ | ||
|
|
||
| if (v_interface > 0) | ||
| f1, f2, f3, f4 = u_ll * v_interface | ||
| else | ||
| f1, f2, f3, f4 = u_rr * v_interface | ||
| end | ||
|
|
||
| return SVector(f1, | ||
| f2, | ||
| f3, | ||
| f4) | ||
DanielDoehring marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| end | ||
|
|
||
| @inline function flux_kennedy_gruber_slow(u_ll, u_rr, normal_direction::AbstractVector, | ||
| equations::CompressibleEulerEquations2D) | ||
| # Unpack left and right state | ||
| rho_e_ll = last(u_ll) | ||
| rho_e_rr = last(u_rr) | ||
| rho_ll, v1_ll, v2_ll, p_ll = cons2prim(u_ll, equations) | ||
| rho_rr, v1_rr, v2_rr, p_rr = cons2prim(u_rr, equations) | ||
|
|
||
| # Average each factor of products in flux | ||
| rho_avg = 0.5f0 * (rho_ll + rho_rr) | ||
| v1_avg = 0.5f0 * (v1_ll + v1_rr) | ||
| v2_avg = 0.5f0 * (v2_ll + v2_rr) | ||
| v_dot_n_avg = v1_avg * normal_direction[1] + v2_avg * normal_direction[2] | ||
| p_avg = 0.5f0 * (p_ll + p_rr) | ||
| e_avg = 0.5f0 * (rho_e_ll / rho_ll + rho_e_rr / rho_rr) | ||
|
|
||
| v_dot_n_avg_horizontal = v1_avg * normal_direction[1] | ||
| # Calculate fluxes depending on normal_direction | ||
| f1 = rho_avg * v_dot_n_avg | ||
| f2 = f1 * v1_avg | ||
| f3 = f1 * v2_avg | ||
| f4 = f1 * e_avg | ||
|
|
||
| return SVector(f1, f2, f3, f4) | ||
| end | ||
|
|
||
| @inline function flux_kennedy_gruber_fast(u_ll, u_rr, normal_direction::AbstractVector, | ||
| equations::CompressibleEulerEquations2D) | ||
| # Unpack left and right state | ||
| rho_e_ll = last(u_ll) | ||
| rho_e_rr = last(u_rr) | ||
| rho_ll, v1_ll, v2_ll, p_ll = cons2prim(u_ll, equations) | ||
| rho_rr, v1_rr, v2_rr, p_rr = cons2prim(u_rr, equations) | ||
|
|
||
| # Average each factor of products in flux | ||
| v1_avg = 0.5f0 * (v1_ll + v1_rr) | ||
| v2_avg = 0.5f0 * (v2_ll + v2_rr) | ||
| v_dot_n_avg = v1_avg * normal_direction[1] + v2_avg * normal_direction[2] | ||
| p_avg = 0.5f0 * (p_ll + p_rr) | ||
|
|
||
| # Calculate fluxes depending on normal_direction | ||
| f2 = p_avg * normal_direction[1] | ||
| f3 = p_avg * normal_direction[2] | ||
| f4 = p_avg * v_dot_n_avg | ||
|
|
||
| return SVector(zero(eltype(u_ll)), f2, f3, f4) | ||
| end | ||
|
|
||
| @inline function source_terms_gravity(u, x, t, equations::CompressibleEulerEquations2D) | ||
| g = 9.81 | ||
| rho, _, rho_v2, _ = u | ||
| return SVector(zero(eltype(u)), zero(eltype(u)), -g * rho, -g * rho_v2) | ||
| end | ||
|
|
||
| equations = CompressibleEulerEquations2D(1004 / 717) | ||
DanielDoehring marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| polydeg = 2 | ||
| basis = LobattoLegendreBasis(polydeg) | ||
ranocha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| volume_integral_explicit = VolumeIntegralFluxDifferencing(flux_kennedy_gruber_slow) | ||
| solver_explicit = DGSEM(basis, flux_lmars_slow, volume_integral_explicit) | ||
|
|
||
| volume_integral_implicit = VolumeIntegralFluxDifferencing(flux_kennedy_gruber_fast) | ||
| solver_implicit = DGSEM(basis, flux_lmars_fast, volume_integral_implicit) | ||
|
|
||
| coordinates_min = (0.0, 0.0) | ||
| coordinates_max = (20_000.0, 10_000.0) | ||
|
|
||
| trees_per_dimension = (16, 8) | ||
|
|
||
| mesh = P4estMesh(trees_per_dimension, polydeg = polydeg, | ||
MarcoArtiano marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| coordinates_min = coordinates_min, coordinates_max = coordinates_max, | ||
| periodicity = (true, false), initial_refinement_level = 0) | ||
|
|
||
| boundary_conditions = Dict(:y_neg => boundary_condition_slip_wall, | ||
| :y_pos => boundary_condition_slip_wall) | ||
|
|
||
| initial_condition = initial_condition_warm_bubble | ||
|
|
||
| semi = SemidiscretizationHyperbolicSplit(mesh, | ||
| (equations, equations), | ||
| initial_condition, | ||
| solver_implicit, | ||
| solver_explicit; | ||
DanielDoehring marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| boundary_conditions = (boundary_conditions, | ||
| boundary_conditions), | ||
| source_terms = (nothing, source_terms_gravity),) | ||
| dt = 0.5 | ||
| tspan = (0.0, 1000.0) | ||
| ode = semidiscretize(semi, tspan) | ||
|
|
||
| summary_callback = SummaryCallback() | ||
|
|
||
| # The AnalysisCallback allows to analyse the solution in regular intervals and prints the results | ||
| analysis_callback = AnalysisCallback(semi, interval = 1) | ||
MarcoArtiano marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # The SaveSolutionCallback allows to save the solution to a file in regular intervals | ||
| save_solution = SaveSolutionCallback(interval = 100, solution_variables = cons2prim) | ||
|
|
||
| # 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) | ||
|
|
||
| ############################################################################### | ||
| # run the simulation | ||
| # OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks | ||
| sol = solve(ode, | ||
| SBDF2(autodiff = AutoFiniteDiff()); | ||
| dt = dt, # solve needs some value here but it will be overwritten by the stepsize_callback | ||
DanielDoehring marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| save_everystep = false, | ||
DanielDoehring marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| callback = callbacks,); | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.