-
Notifications
You must be signed in to change notification settings - Fork 114
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
DGMulti
support for curved meshes and parabolic terms
#1400
Merged
jlchan
merged 41 commits into
trixi-framework:main
from
jlchan:jc/curved_parabolic_dgmulti
Apr 28, 2023
+699
−104
Merged
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
26afcbe
factor volume integral out of calc_gradient! and calc_divergence!
jlchan 2f5732f
add "!" for consistency
jlchan 20df8de
minor cleanup
jlchan e689a72
remove inv_h from penalty(...)
jlchan 616cf57
Merge remote-tracking branch 'origin/main' into jc/curved_parabolic_d…
jlchan 8b914de
generalized invert_jacobian
jlchan 9d90992
remove "prolong2interfaces"
jlchan 4b032ec
switch to "strong-weak" formulation
jlchan 5a2384e
precompute divergence interp matrix
jlchan a6931ae
specialize differentiation matrices for Gradient vs Divergence
jlchan 6d3cd0d
remove some @unpacks
jlchan d51d4e8
Merge branch 'main' into jc/curved_parabolic_dgmulti
jlchan 2f13473
update parabolic tests
jlchan 09554f1
fix test again
jlchan 99706c7
fix test again
jlchan e14f3ce
define md earlier
jlchan e1f1d01
use SVector for consistency/efficiency
jlchan 0c2e7ac
add curved gradient volume integral
jlchan dc78c5a
add curved "invert_jacobian_gradient!"
jlchan 387b6e4
add curved divergence volume integral
jlchan dd216da
add curved convergence elixir
jlchan 2db366a
add curved test
jlchan bfbbb73
add 3D test
jlchan 0288aaf
Merge branch 'main' into jc/curved_parabolic_dgmulti
jlchan 0ce8202
add invJ comment for affine elements
jlchan faefe3f
NDIMS -> ndims(mesh)
jlchan 14a45a5
comments
jlchan 0463178
remove outdated TODO
jlchan f31adb9
more comments
jlchan f78abbe
remove outdated TODOs
jlchan 22f4691
remove broadcasts to reduce allocations
jlchan 5681534
add timers to rhs_parabolic
jlchan 398be9a
Update src/solvers/dgmulti/dg_parabolic.jl
jlchan 774a2f3
Merge branch 'main' into jc/curved_parabolic_dgmulti
jlchan 68522b2
remove unused variable
jlchan adc0fde
replace extra curved elixirs with "trixi_include" calls
jlchan d1a42f2
revert removal of "inv_h" in `penalty`
jlchan 02c7fe9
Revert "replace extra curved elixirs with "trixi_include" calls"
jlchan 5ce9eef
add comments
jlchan a8c0933
remove inv_h from penalty formula
jlchan a58580e
Merge branch 'main' into jc/curved_parabolic_dgmulti
jlchan 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
There are no files selected for viewing
214 changes: 214 additions & 0 deletions
214
examples/dgmulti_2d/elixir_navierstokes_convergence_curved.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,214 @@ | ||
using OrdinaryDiffEq | ||
using Trixi | ||
|
||
############################################################################### | ||
# semidiscretization of the ideal compressible Navier-Stokes equations | ||
|
||
prandtl_number() = 0.72 | ||
mu() = 0.01 | ||
|
||
equations = CompressibleEulerEquations2D(1.4) | ||
# Note: If you change the Navier-Stokes parameters here, also change them in the initial condition | ||
# I really do not like this structure but it should work for now | ||
equations_parabolic = CompressibleNavierStokesDiffusion2D(equations, mu=mu(), Prandtl=prandtl_number(), | ||
gradient_variables=GradientVariablesPrimitive()) | ||
|
||
# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux | ||
dg = DGMulti(polydeg = 3, element_type = Tri(), approximation_type = Polynomial(), | ||
surface_integral = SurfaceIntegralWeakForm(flux_lax_friedrichs), | ||
volume_integral = VolumeIntegralWeakForm()) | ||
|
||
top_bottom(x, tol=50*eps()) = abs(abs(x[2]) - 1) < tol | ||
is_on_boundary = Dict(:top_bottom => top_bottom) | ||
|
||
function mapping(xi, eta) | ||
x = xi + 0.1 * sin(pi * xi) * sin(pi * eta) | ||
y = eta + 0.1 * sin(pi * xi) * sin(pi * eta) | ||
return SVector(x, y) | ||
end | ||
cells_per_dimension = (16, 16) | ||
mesh = DGMultiMesh(dg, cells_per_dimension, mapping; periodicity=(true, false), is_on_boundary) | ||
|
||
# This initial condition is taken from `examples/dgmulti_2d/elixir_navierstokes_convergence.jl` | ||
|
||
# Note: the initial condition cannot be specialized to `CompressibleNavierStokesDiffusion2D` | ||
# since it is called by both the parabolic solver (which passes in `CompressibleNavierStokesDiffusion2D`) | ||
# and by the initial condition (which passes in `CompressibleEulerEquations2D`). | ||
# This convergence test setup was originally derived by Andrew Winters (@andrewwinters5000) | ||
function initial_condition_navier_stokes_convergence_test(x, t, equations) | ||
# Amplitude and shift | ||
A = 0.5 | ||
c = 2.0 | ||
|
||
# convenience values for trig. functions | ||
pi_x = pi * x[1] | ||
pi_y = pi * x[2] | ||
pi_t = pi * t | ||
|
||
rho = c + A * sin(pi_x) * cos(pi_y) * cos(pi_t) | ||
v1 = sin(pi_x) * log(x[2] + 2.0) * (1.0 - exp(-A * (x[2] - 1.0)) ) * cos(pi_t) | ||
v2 = v1 | ||
p = rho^2 | ||
|
||
return prim2cons(SVector(rho, v1, v2, p), equations) | ||
end | ||
|
||
@inline function source_terms_navier_stokes_convergence_test(u, x, t, equations) | ||
y = x[2] | ||
|
||
# TODO: parabolic | ||
# we currently need to hardcode these parameters until we fix the "combined equation" issue | ||
# see also https://github.com/trixi-framework/Trixi.jl/pull/1160 | ||
inv_gamma_minus_one = inv(equations.gamma - 1) | ||
Pr = prandtl_number() | ||
mu_ = mu() | ||
|
||
# Same settings as in `initial_condition` | ||
# Amplitude and shift | ||
A = 0.5 | ||
c = 2.0 | ||
|
||
# convenience values for trig. functions | ||
pi_x = pi * x[1] | ||
pi_y = pi * x[2] | ||
pi_t = pi * t | ||
|
||
# compute the manufactured solution and all necessary derivatives | ||
rho = c + A * sin(pi_x) * cos(pi_y) * cos(pi_t) | ||
rho_t = -pi * A * sin(pi_x) * cos(pi_y) * sin(pi_t) | ||
rho_x = pi * A * cos(pi_x) * cos(pi_y) * cos(pi_t) | ||
rho_y = -pi * A * sin(pi_x) * sin(pi_y) * cos(pi_t) | ||
rho_xx = -pi * pi * A * sin(pi_x) * cos(pi_y) * cos(pi_t) | ||
rho_yy = -pi * pi * A * sin(pi_x) * cos(pi_y) * cos(pi_t) | ||
|
||
v1 = sin(pi_x) * log(y + 2.0) * (1.0 - exp(-A * (y - 1.0))) * cos(pi_t) | ||
v1_t = -pi * sin(pi_x) * log(y + 2.0) * (1.0 - exp(-A * (y - 1.0))) * sin(pi_t) | ||
v1_x = pi * cos(pi_x) * log(y + 2.0) * (1.0 - exp(-A * (y - 1.0))) * cos(pi_t) | ||
v1_y = sin(pi_x) * (A * log(y + 2.0) * exp(-A * (y - 1.0)) + (1.0 - exp(-A * (y - 1.0))) / (y + 2.0)) * cos(pi_t) | ||
v1_xx = -pi * pi * sin(pi_x) * log(y + 2.0) * (1.0 - exp(-A * (y - 1.0))) * cos(pi_t) | ||
v1_xy = pi * cos(pi_x) * (A * log(y + 2.0) * exp(-A * (y - 1.0)) + (1.0 - exp(-A * (y - 1.0))) / (y + 2.0)) * cos(pi_t) | ||
v1_yy = (sin(pi_x) * ( 2.0 * A * exp(-A * (y - 1.0)) / (y + 2.0) | ||
- A * A * log(y + 2.0) * exp(-A * (y - 1.0)) | ||
- (1.0 - exp(-A * (y - 1.0))) / ((y + 2.0) * (y + 2.0))) * cos(pi_t)) | ||
v2 = v1 | ||
v2_t = v1_t | ||
v2_x = v1_x | ||
v2_y = v1_y | ||
v2_xx = v1_xx | ||
v2_xy = v1_xy | ||
v2_yy = v1_yy | ||
|
||
p = rho * rho | ||
p_t = 2.0 * rho * rho_t | ||
p_x = 2.0 * rho * rho_x | ||
p_y = 2.0 * rho * rho_y | ||
p_xx = 2.0 * rho * rho_xx + 2.0 * rho_x * rho_x | ||
p_yy = 2.0 * rho * rho_yy + 2.0 * rho_y * rho_y | ||
|
||
# Note this simplifies slightly because the ansatz assumes that v1 = v2 | ||
E = p * inv_gamma_minus_one + 0.5 * rho * (v1^2 + v2^2) | ||
E_t = p_t * inv_gamma_minus_one + rho_t * v1^2 + 2.0 * rho * v1 * v1_t | ||
E_x = p_x * inv_gamma_minus_one + rho_x * v1^2 + 2.0 * rho * v1 * v1_x | ||
E_y = p_y * inv_gamma_minus_one + rho_y * v1^2 + 2.0 * rho * v1 * v1_y | ||
|
||
# Some convenience constants | ||
T_const = equations.gamma * inv_gamma_minus_one / Pr | ||
inv_rho_cubed = 1.0 / (rho^3) | ||
|
||
# compute the source terms | ||
# density equation | ||
du1 = rho_t + rho_x * v1 + rho * v1_x + rho_y * v2 + rho * v2_y | ||
|
||
# x-momentum equation | ||
du2 = ( rho_t * v1 + rho * v1_t + p_x + rho_x * v1^2 | ||
+ 2.0 * rho * v1 * v1_x | ||
+ rho_y * v1 * v2 | ||
+ rho * v1_y * v2 | ||
+ rho * v1 * v2_y | ||
# stress tensor from x-direction | ||
- 4.0 / 3.0 * v1_xx * mu_ | ||
+ 2.0 / 3.0 * v2_xy * mu_ | ||
- v1_yy * mu_ | ||
- v2_xy * mu_ ) | ||
# y-momentum equation | ||
du3 = ( rho_t * v2 + rho * v2_t + p_y + rho_x * v1 * v2 | ||
+ rho * v1_x * v2 | ||
+ rho * v1 * v2_x | ||
+ rho_y * v2^2 | ||
+ 2.0 * rho * v2 * v2_y | ||
# stress tensor from y-direction | ||
- v1_xy * mu_ | ||
- v2_xx * mu_ | ||
- 4.0 / 3.0 * v2_yy * mu_ | ||
+ 2.0 / 3.0 * v1_xy * mu_ ) | ||
# total energy equation | ||
du4 = ( E_t + v1_x * (E + p) + v1 * (E_x + p_x) | ||
+ v2_y * (E + p) + v2 * (E_y + p_y) | ||
# stress tensor and temperature gradient terms from x-direction | ||
- 4.0 / 3.0 * v1_xx * v1 * mu_ | ||
+ 2.0 / 3.0 * v2_xy * v1 * mu_ | ||
- 4.0 / 3.0 * v1_x * v1_x * mu_ | ||
+ 2.0 / 3.0 * v2_y * v1_x * mu_ | ||
- v1_xy * v2 * mu_ | ||
- v2_xx * v2 * mu_ | ||
- v1_y * v2_x * mu_ | ||
- v2_x * v2_x * mu_ | ||
- T_const * inv_rho_cubed * ( p_xx * rho * rho | ||
- 2.0 * p_x * rho * rho_x | ||
+ 2.0 * p * rho_x * rho_x | ||
- p * rho * rho_xx ) * mu_ | ||
# stress tensor and temperature gradient terms from y-direction | ||
- v1_yy * v1 * mu_ | ||
- v2_xy * v1 * mu_ | ||
- v1_y * v1_y * mu_ | ||
- v2_x * v1_y * mu_ | ||
- 4.0 / 3.0 * v2_yy * v2 * mu_ | ||
+ 2.0 / 3.0 * v1_xy * v2 * mu_ | ||
- 4.0 / 3.0 * v2_y * v2_y * mu_ | ||
+ 2.0 / 3.0 * v1_x * v2_y * mu_ | ||
- T_const * inv_rho_cubed * ( p_yy * rho * rho | ||
- 2.0 * p_y * rho * rho_y | ||
+ 2.0 * p * rho_y * rho_y | ||
- p * rho * rho_yy ) * mu_ ) | ||
|
||
return SVector(du1, du2, du3, du4) | ||
end | ||
|
||
initial_condition = initial_condition_navier_stokes_convergence_test | ||
|
||
# BC types | ||
velocity_bc_top_bottom = NoSlip((x, t, equations) -> initial_condition_navier_stokes_convergence_test(x, t, equations)[2:3]) | ||
ranocha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
heat_bc_top_bottom = Adiabatic((x, t, equations) -> 0.0) | ||
boundary_condition_top_bottom = BoundaryConditionNavierStokesWall(velocity_bc_top_bottom, heat_bc_top_bottom) | ||
|
||
# define inviscid boundary conditions | ||
boundary_conditions = (; :top_bottom => boundary_condition_slip_wall) | ||
|
||
# define viscous boundary conditions | ||
boundary_conditions_parabolic = (; :top_bottom => boundary_condition_top_bottom) | ||
|
||
semi = SemidiscretizationHyperbolicParabolic(mesh, (equations, equations_parabolic), initial_condition, dg; | ||
boundary_conditions=(boundary_conditions, boundary_conditions_parabolic), | ||
source_terms=source_terms_navier_stokes_convergence_test) | ||
|
||
|
||
############################################################################### | ||
# ODE solvers, callbacks etc. | ||
|
||
# Create ODE problem with time span `tspan` | ||
tspan = (0.0, 0.5) | ||
ode = semidiscretize(semi, tspan) | ||
|
||
summary_callback = SummaryCallback() | ||
alive_callback = AliveCallback(alive_interval=10) | ||
analysis_interval = 100 | ||
analysis_callback = AnalysisCallback(semi, interval=analysis_interval, uEltype=real(dg)) | ||
callbacks = CallbackSet(summary_callback, alive_callback) | ||
|
||
############################################################################### | ||
# run the simulation | ||
|
||
time_int_tol = 1e-8 | ||
sol = solve(ode, RDPK3SpFSAL49(); abstol=time_int_tol, reltol=time_int_tol, | ||
ode_default_options()..., callback=callbacks) | ||
summary_callback() # print the timer summary |
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.
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.
I just assume you copied this setup and did not review it properly (same in 3D).
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.
Is this referring to the type-unstable (indexing) comment above?
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.
No - to the actual formulas of the manufactured solution
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.
It's the exact same as the setup for
elixir_navierstokes_convergence.jl
. I can add a comment mentioning this?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.
Alternatively, I could just run
elixir_navierstokes_convergence.jl
and pass a new mesh throughtrixi_include
instead of creating new elixirs.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.
Nevermind, using
trixi_include
didn't work. I added some comments noting the origin of the manufactured solution.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.
Alternatively... shouldn't we add the NSE convergence test to the
CompressibleNSEDiffusionXD
types? IIRC, we do have a similar function for most other equation systems. Or was there an issue with that why this didn't work/why this is super awkward?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.
It's fine from my side to keep it as it is - I just wanted to say that I didn't want to read it 😅
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.
@sloede we could. The only potential issue I see is that the source and initial condition require functions
mu()
andprandtl_number()
to be defined (see https://github.com/jlchan/Trixi.jl/blob/a8c0933bd0077c45372c3937c40fce772e348886/examples/dgmulti_2d/elixir_navierstokes_convergence.jl#L56-L57). These functions are necessary due to the fact that initial conditions cannot specialize on only one equation type, since they are called both withequations::CompressibleEulerEquations2D
andequations::CompressibleNavierStokesDiffusion2D
in different places.To me, moving the NSE convergence test functions out of the elixir makes these implicit requirements even less clear.
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.
Good point. Let's keep them as they are, please.