Skip to content
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

WIP: Add FV method for T8codeMesh #1844

Draft
wants to merge 52 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
38ebc81
Add first working first order FV method on T8codeMesh (periodic bound…
bennibolm Feb 13, 2024
3c75fb9
Add simple routine to create `cmesh`s by hand
bennibolm Feb 13, 2024
2a7f417
fmt
bennibolm Feb 13, 2024
f59dc75
Fix bug in visualization
bennibolm Feb 13, 2024
398ed0d
Relocate function to adapt to "normal" structure
bennibolm Feb 13, 2024
1c5a941
Add tests
bennibolm Feb 13, 2024
67a25da
Rename Interface Container
bennibolm Feb 13, 2024
2d51511
Activate tests; clean up
bennibolm Feb 14, 2024
173e4b9
Merge branch 'main' into t8codemesh-fv
bennibolm Feb 20, 2024
3f09f80
Remove comments in elixirs [skip ci]
bennibolm Feb 20, 2024
3abe300
Change dispatch from T8codeMesh to FV
bennibolm Feb 20, 2024
f4511e7
Remove not-needed lines of code
bennibolm Feb 20, 2024
22527bd
Add comment; correct dispatch
bennibolm Feb 20, 2024
f0d939d
Outsource interface flux
bennibolm Feb 27, 2024
9f9a917
Add prolong2boundaries
bennibolm Feb 27, 2024
beeb833
Add non periodic elixir and flux calculation
bennibolm Feb 27, 2024
dbc5dc8
fmt
bennibolm Feb 27, 2024
76b0945
Clean up RealT and uEltype
bennibolm Feb 27, 2024
fde260d
Fix bug for simulations with mpi by using simple version of `fill_mes…
bennibolm Feb 29, 2024
765b828
remove show routine
bennibolm Feb 29, 2024
3b74f39
Move other boundary calculations to new function
bennibolm Feb 29, 2024
4710d38
Add MPI tests
bennibolm Feb 29, 2024
62b47bb
Move calculation of interface data to `fill_mesh_info_fv!`
bennibolm Feb 29, 2024
bb2138a
Update comment
bennibolm Feb 29, 2024
721b7f8
Remove elements from init routines for interfaces and boundaries
bennibolm Feb 29, 2024
dde4453
Remove not-needed code
bennibolm Mar 4, 2024
cc84c73
fmt
bennibolm Mar 4, 2024
72573f8
Change structure of element container to structure-of-arrays style
bennibolm Mar 4, 2024
4b0bc4f
Reduce unnecessary allocations
bennibolm Mar 4, 2024
78750e6
Rename routines
bennibolm Mar 4, 2024
0f7dde7
Merge branch 'main' into t8codemesh-fv
bennibolm Apr 8, 2024
2cc5e9d
Add RealT to solver
bennibolm Apr 8, 2024
75eba41
Fix dual faces
bennibolm Apr 16, 2024
d7d042d
Add first working version with linear reconstruction
bennibolm Apr 17, 2024
7cdd83e
fmt
bennibolm Apr 17, 2024
bc91a50
Fix bug
bennibolm Apr 18, 2024
6c585ce
Some changes
bennibolm Apr 22, 2024
c332a01
Add usage of gradient to `prolong2boundaries` [skip ci]
bennibolm Apr 24, 2024
5460e31
Clean up cmesh routines
bennibolm Apr 24, 2024
fa85580
Add simple reconstruction stencil
bennibolm Apr 24, 2024
aa48583
fmt [skip ci]
bennibolm Apr 24, 2024
641d8cf
Simpify code
bennibolm Apr 24, 2024
08f2418
Calc reconstruction distance in init_stencil; adapt distance for pori…
bennibolm Apr 24, 2024
874dc47
Adapt mpi test; fmt
bennibolm Apr 24, 2024
faf9709
Add source terms; Euler source term elixir; tests
bennibolm Apr 24, 2024
e92b875
fmt
bennibolm Apr 24, 2024
94ad70f
Change order of tests
bennibolm Apr 25, 2024
f72d20f
Merge branch 'main' into t8codemesh-fv
bennibolm Apr 30, 2024
b5c463c
Adapt structure of communication data to allow parallel 2order fv
bennibolm May 6, 2024
357ac9d
Remove 2order extended stencil from parallel tests
bennibolm May 6, 2024
c643295
Merge branch 'main' into t8codemesh-fv
bennibolm May 7, 2024
0b233f6
Fix bug; Change default in one elixir
bennibolm Jun 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ jobs:
- p4est_part2
- t8code_part1
- t8code_part2
- t8code_fv
- unstructured_dgmulti
- parabolic
- paper_self_gravitating_gas_dynamics
Expand Down
43 changes: 43 additions & 0 deletions examples/t8code_2d_fv/elixir_advection_basic.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using OrdinaryDiffEq
using Trixi

advection_velocity = (0.2, -0.7)
equations = LinearScalarAdvectionEquation2D(advection_velocity)

initial_condition = initial_condition_convergence_test

solver = FV(surface_flux = flux_lax_friedrichs)

mesh_function = Trixi.cmesh_new_periodic_hybrid
# mesh_function = Trixi.cmesh_new_periodic_quad
# mesh_function = Trixi.cmesh_new_periodic_tri
cmesh = mesh_function(Trixi.mpi_comm())
mesh = T8codeMesh(cmesh, solver,
initial_refinement_level = 3)

semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver)

ode = semidiscretize(semi, (0.0, 1.0));

summary_callback = SummaryCallback()

analysis_interval = 100
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)

alive_callback = AliveCallback(analysis_interval = analysis_interval)

save_solution = SaveSolutionCallback(interval = 1,
solution_variables = cons2prim)

stepsize_callback = StepsizeCallback(cfl = 0.5)

callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback,
stepsize_callback, save_solution)

###############################################################################
# run the simulation

sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = 5.0e-2, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
summary_callback()
42 changes: 42 additions & 0 deletions examples/t8code_2d_fv/elixir_advection_gauss.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using OrdinaryDiffEq
using Trixi

####################################################

advection_velocity = (0.2, -0.7)
equations = LinearScalarAdvectionEquation2D(advection_velocity)

initial_condition = initial_condition_gauss

solver = FV(surface_flux = flux_lax_friedrichs)

initial_refinement_level = 4
cmesh = Trixi.cmesh_new_periodic_hybrid(Trixi.mpi_comm())
mesh = T8codeMesh(cmesh, solver, initial_refinement_level = initial_refinement_level)

semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver)

ode = semidiscretize(semi, (0.0, 20.0));

summary_callback = SummaryCallback()

analysis_interval = 100
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)

alive_callback = AliveCallback(analysis_interval = analysis_interval)

save_solution = SaveSolutionCallback(interval = 10,
solution_variables = cons2prim)

stepsize_callback = StepsizeCallback(cfl = 0.5)

callbacks = CallbackSet(summary_callback, save_solution, analysis_callback, alive_callback,
stepsize_callback)

###############################################################################
# run the simulation

sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),#Euler(),
dt = 5.0e-2, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
summary_callback()
59 changes: 59 additions & 0 deletions examples/t8code_2d_fv/elixir_euler_blast_wave.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using OrdinaryDiffEq
using Trixi

####################################################

equations = CompressibleEulerEquations2D(1.4)

function initial_condition_blast_wave(x, t, equations::CompressibleEulerEquations2D)
# Modified From Hennemann & Gassner JCP paper 2020 (Sec. 6.3) -> "medium blast wave"
# Set up polar coordinates
inicenter = SVector(0.0, 0.0)
x_norm = x[1] - inicenter[1]
y_norm = x[2] - inicenter[2]
r = sqrt(x_norm^2 + y_norm^2)
phi = atan(y_norm, x_norm)
sin_phi, cos_phi = sincos(phi)

# Calculate primitive variables
rho = r > 0.5 ? 1.0 : 1.1691
v1 = r > 0.5 ? 0.0 : 0.1882 * cos_phi
v2 = r > 0.5 ? 0.0 : 0.1882 * sin_phi
p = r > 0.5 ? 1.0E-3 : 1.245

return prim2cons(SVector(rho, v1, v2, p), equations)
end
initial_condition = initial_condition_blast_wave

solver = FV(surface_flux = flux_lax_friedrichs)

initial_refinement_level = 4
cmesh = Trixi.cmesh_new_periodic_hybrid2(Trixi.mpi_comm())
mesh = T8codeMesh(cmesh, solver, initial_refinement_level = initial_refinement_level)

semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver)

ode = semidiscretize(semi, (0.0, 2.0));

summary_callback = SummaryCallback()

analysis_interval = 100
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)

alive_callback = AliveCallback(analysis_interval = analysis_interval)

save_solution = SaveSolutionCallback(interval = 10,
solution_variables = cons2prim)

stepsize_callback = StepsizeCallback(cfl = 0.5)

callbacks = CallbackSet(summary_callback, save_solution, analysis_callback, alive_callback,
stepsize_callback)

###############################################################################
# run the simulation

sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = 5.0e-2, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
summary_callback()
74 changes: 74 additions & 0 deletions examples/t8code_2d_fv/elixir_euler_kelvin_helmholtz_instability.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using OrdinaryDiffEq
using Trixi

###############################################################################
# semidiscretization of the compressible Euler equations
gamma = 1.4
equations = CompressibleEulerEquations2D(gamma)

"""
initial_condition_kelvin_helmholtz_instability(x, t, equations::CompressibleEulerEquations2D)

A version of the classical Kelvin-Helmholtz instability based on
- Andrés M. Rueda-Ramírez, Gregor J. Gassner (2021)
A Subcell Finite Volume Positivity-Preserving Limiter for DGSEM Discretizations
of the Euler Equations
[arXiv: 2102.06017](https://arxiv.org/abs/2102.06017)
"""
function initial_condition_kelvin_helmholtz_instability(x, t,
equations::CompressibleEulerEquations2D)
# change discontinuity to tanh
# typical resolution 128^2, 256^2
# domain size is [-1,+1]^2
slope = 15
amplitude = 0.02
B = tanh(slope * x[2] + 7.5) - tanh(slope * x[2] - 7.5)
rho = 0.5 + 0.75 * B
v1 = 0.5 * (B - 1)
v2 = 0.1 * sin(2 * pi * x[1])
p = 1.0
return prim2cons(SVector(rho, v1, v2, p), equations)
end
initial_condition = initial_condition_kelvin_helmholtz_instability

solver = FV(surface_flux = flux_lax_friedrichs)

initial_refinement_level = 4
# mesh_function = Trixi.cmesh_new_periodic_hybrid
# mesh_function = Trixi.cmesh_new_periodic_quad
# mesh_function = Trixi.cmesh_new_periodic_tri
mesh_function = Trixi.cmesh_new_periodic_tri2
cmesh = mesh_function(Trixi.mpi_comm())
mesh = T8codeMesh(cmesh, solver, initial_refinement_level = initial_refinement_level)

semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver)

tspan = (0.0, 3.7)
ode = semidiscretize(semi, tspan)

summary_callback = SummaryCallback()

analysis_interval = 100
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)

alive_callback = AliveCallback(analysis_interval = analysis_interval)

save_solution = SaveSolutionCallback(interval = 40,
save_initial_solution = true,
save_final_solution = true,
solution_variables = cons2prim)

stepsize_callback = StepsizeCallback(cfl = 0.9)

callbacks = CallbackSet(summary_callback,
analysis_callback, alive_callback,
save_solution,
stepsize_callback)

###############################################################################
# run the simulation

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);
summary_callback() # print the timer summary
2 changes: 2 additions & 0 deletions src/Trixi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ export DG,
export VolumeIntegralSubcellLimiting, BoundsCheckCallback,
SubcellLimiterIDP, SubcellLimiterIDPCorrection

export FV

export nelements, nnodes, nvariables,
eachelement, eachnode, eachvariable

Expand Down
47 changes: 45 additions & 2 deletions src/callbacks_step/analysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ or `extra_analysis_errors = (:conservation_error,)`.
If you want to omit the computation (to safe compute-time) of the [`default_analysis_errors`](@ref), specify
`analysis_errors = Symbol[]`.
Note: `default_analysis_errors` are `:l2_error` and `:linf_error` for all equations.
If you want to compute `extra_analysis_errors` such as `:conservation_error` solely, i.e.,
without `:l2_error, :linf_error` you need to specify
If you want to compute `extra_analysis_errors` such as `:conservation_error` solely, i.e.,
without `:l2_error, :linf_error` you need to specify
`analysis_errors = [:conservation_error]` instead of `extra_analysis_errors = [:conservation_error]`.

Further scalar functions `func` in `extra_analysis_integrals` are applied to the numerical
Expand Down Expand Up @@ -141,6 +141,49 @@ function AnalysisCallback(mesh, equations::AbstractEquations, solver, cache;
initialize = initialize!)
end

function AnalysisCallback(mesh, equations::AbstractEquations, solver::FV, cache;
interval = 0,
save_analysis = false,
output_directory = "out",
analysis_filename = "analysis.dat",
extra_analysis_errors = Symbol[],
analysis_errors = union(default_analysis_errors(equations),
extra_analysis_errors),
extra_analysis_integrals = (),
analysis_integrals = union(default_analysis_integrals(equations),
extra_analysis_integrals),
RealT = real(solver),
uEltype = eltype(cache.elements[1]), # TODO: this routine is equal to the existing one except this default type here.
bennibolm marked this conversation as resolved.
Show resolved Hide resolved
kwargs...)
# Decide when the callback is activated.
# With error-based step size control, some steps can be rejected. Thus,
# `integrator.iter >= integrator.stats.naccept`
# (total #steps) (#accepted steps)
# We need to check the number of accepted steps since callbacks are not
# activated after a rejected step.
condition = (u, t, integrator) -> interval > 0 &&
((integrator.stats.naccept % interval == 0 &&
!(integrator.stats.naccept == 0 && integrator.iter > 0)) ||
isfinished(integrator))

analyzer = SolutionAnalyzer(solver; kwargs...)
cache_analysis = create_cache_analysis(analyzer, mesh, equations, solver, cache,
RealT, uEltype)

analysis_callback = AnalysisCallback(0.0, 0.0, 0, 0.0,
interval, save_analysis, output_directory,
analysis_filename,
analyzer,
analysis_errors, Tuple(analysis_integrals),
SVector(ntuple(_ -> zero(uEltype),
Val(nvariables(equations)))),
cache_analysis)

DiscreteCallback(condition, analysis_callback,
save_positions = (false, false),
initialize = initialize!)
end

# This method gets called from OrdinaryDiffEq's `solve(...)`
function initialize!(cb::DiscreteCallback{Condition, Affect!}, u_ode, t,
integrator) where {Condition, Affect! <: AnalysisCallback}
Expand Down