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

First-order Finite Volume Method organized with t8code #1627

Closed
wants to merge 55 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
0dc2e35
First try
bennibolm Jun 28, 2023
765afd4
Next changes
bennibolm Jun 29, 2023
0c34277
Changes
bennibolm Jun 30, 2023
a26bdd8
Next step
bennibolm Jul 4, 2023
dab1d5b
Fix init of semi, mesh, ...
bennibolm Jul 12, 2023
14e350a
Add other meshes
bennibolm Jul 13, 2023
d68c743
Formatting code
bennibolm Jul 14, 2023
ad8fa2f
Fix vertices
bennibolm Jul 14, 2023
8d64f5d
Use OrdinaryDiffEq
bennibolm Jul 14, 2023
f3d5d64
Use SaveSolutionCallback
bennibolm Jul 17, 2023
ca0c8d3
Implement AnalysisCallback
bennibolm Jul 17, 2023
162f438
Use StepsizeCallback
bennibolm Jul 17, 2023
c564d80
Generalize structs; add euler blast elixir
bennibolm Jul 18, 2023
ae2d95c
Restructure elixirs
bennibolm Jul 18, 2023
569d3d7
Use existing mpi routines
bennibolm Jul 18, 2023
212123b
Fix mpi_ranks()
bennibolm Jul 18, 2023
c55e02f
Rename solver
bennibolm Jul 19, 2023
fa9ba28
Automate calc of max_number_faces
bennibolm Jul 19, 2023
038dea0
Add face_midpoints
bennibolm Jul 19, 2023
422dee9
Adapt elixir
bennibolm Jul 24, 2023
fe1d67a
Adapt mesh size
bennibolm Jul 24, 2023
b0e37f0
Clean up
bennibolm Jul 26, 2023
6be3fa7
Save allocs
bennibolm Jul 26, 2023
3f7e67b
Add neighbor_faces and first implementation of second order
bennibolm Jul 27, 2023
cf1088a
Fix linear reconstruction
bennibolm Jul 28, 2023
4dbb28f
Revise slope calculation
bennibolm Jul 28, 2023
89c6f3a
Implement slope for systems
bennibolm Jul 28, 2023
8222925
Use function get_variable_wrapped
bennibolm Jul 31, 2023
1c4ce38
Revise get_variable_wrapped; other stuff
bennibolm Aug 2, 2023
0dd25ad
Fix evaluation of edge values
bennibolm Aug 2, 2023
c120873
Reduce allocations
bennibolm Aug 3, 2023
ed18bca
Add slope data to vtk_data
bennibolm Aug 9, 2023
a20b235
Fix problem wirh length of slopes at t=0
bennibolm Aug 10, 2023
b7e635d
Reduce allocations
bennibolm Aug 10, 2023
e427e27
Add KHI elixir
bennibolm Aug 18, 2023
d6f1b6f
Adapt dispatch
bennibolm Sep 6, 2023
1b91c64
Implement InterfaceContainer
bennibolm Sep 6, 2023
05898e4
Relocate forest initialization
bennibolm Sep 6, 2023
6ca50bd
Relocate mesh construction
bennibolm Sep 7, 2023
a199c7d
Add reconstruction option as comment
bennibolm Sep 7, 2023
b5a6419
First order FV
bennibolm Sep 7, 2023
b1e3b58
Remove slope
bennibolm Sep 7, 2023
763403b
Rename `T8codeMesh` to `T8codeFVMesh`
bennibolm Oct 30, 2023
6b9f68c
Rename file
bennibolm Oct 30, 2023
b2f9054
Merge branch 'main' into t8codemesh-tests
bennibolm Oct 30, 2023
bc4278d
Format
bennibolm Oct 30, 2023
b519dc9
Fix bugs
bennibolm Oct 30, 2023
6c92fdf
Merge branch 'main' into t8codemesh-tests
bennibolm Nov 28, 2023
ca5b2db
Rename mesh
bennibolm Jan 8, 2024
f1e2e2c
Merge branch 'main' into t8codemesh-FV-1order
bennibolm Jan 8, 2024
beb1435
Fix FV elixirs
bennibolm Jan 8, 2024
51c5d25
Merge branch 't8codemesh-tests' into t8codemesh-FV-1order
bennibolm Jan 8, 2024
ee713ee
Merge branch 'main' into t8codemesh-FV-1order
bennibolm Jan 19, 2024
c1465b7
Rearrange routines
bennibolm Jan 19, 2024
824b4e2
Merge branch 'main' into t8codemesh-FV-1order
bennibolm Feb 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions examples/t8code_2d_fv/elixir_advection_basic.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env julia
# Has to be at least Julia v1.9.0.

# Running in parallel:
# ${JULIA_DEPOT_PATH}/.julia/bin/mpiexecjl --project=. -n 3 julia hybrid-t8code-mesh.jl
#
# More information: https://juliaparallel.org/MPI.jl/stable/usage/
using OrdinaryDiffEq
using Trixi

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

initial_condition = initial_condition_convergence_test

solver = FV(order = 1, surface_flux = flux_lax_friedrichs)

coordinates_min = (-1.0, -1.0) # minimum coordinates (min(x), min(y))
coordinates_max = (1.0, 1.0) # maximum coordinates (max(x), max(y))

trees_per_dimension = (8, 8)

mesh = T8codeMesh(trees_per_dimension, polydeg = 3,
coordinates_min = coordinates_min, coordinates_max = coordinates_max,
initial_refinement_level = 1)

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, 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()
49 changes: 49 additions & 0 deletions examples/t8code_2d_fv/elixir_advection_convergence.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env julia
# Has to be at least Julia v1.9.0.

# Running in parallel:
# ${JULIA_DEPOT_PATH}/.julia/bin/mpiexecjl --project=. -n 3 julia hybrid-t8code-mesh.jl
#
# More information: https://juliaparallel.org/MPI.jl/stable/usage/
using OrdinaryDiffEq
using Trixi

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

initial_condition = initial_condition_convergence_test

solver = FV(order = 1, 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 = T8codeFVMesh{2}(mesh_function, initial_refinement_level)

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, 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()
48 changes: 48 additions & 0 deletions examples/t8code_2d_fv/elixir_advection_gauss.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env julia
# Has to be at least Julia v1.9.0.

# Running in parallel:
# ${JULIA_DEPOT_PATH}/.julia/bin/mpiexecjl --project=. -n 3 julia hybrid-t8code-mesh.jl
#
# More information: https://juliaparallel.org/MPI.jl/stable/usage/
using OrdinaryDiffEq
using Trixi

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

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

initial_condition = initial_condition_gauss

solver = FV(order = 1, surface_flux = flux_lax_friedrichs)

initial_refinement_level = 4
mesh = T8codeFVMesh{2}(Trixi.cmesh_new_periodic_hybrid, 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 = 1,
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()
65 changes: 65 additions & 0 deletions examples/t8code_2d_fv/elixir_euler_blast_wave_hybrid_mesh.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env julia
# Has to be at least Julia v1.9.0.

# Running in parallel:
# ${JULIA_DEPOT_PATH}/.julia/bin/mpiexecjl --project=. -n 3 julia hybrid-t8code-mesh.jl
#
# More information: https://juliaparallel.org/MPI.jl/stable/usage/
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(order = 1, surface_flux = flux_lax_friedrichs)

initial_refinement_level = 4
mesh = T8codeFVMesh{2}(Trixi.cmesh_new_periodic_hybrid2, 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()
80 changes: 80 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,80 @@
#!/usr/bin/env julia
# Has to be at least Julia v1.9.0.

# Running in parallel:
# ${JULIA_DEPOT_PATH}/.julia/bin/mpiexecjl --project=. -n 3 julia hybrid-t8code-mesh.jl
#
# More information: https://juliaparallel.org/MPI.jl/stable/usage/
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(order = 1, 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
mesh = T8codeFVMesh{2}(mesh_function, 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
4 changes: 3 additions & 1 deletion src/Trixi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export entropy, energy_total, energy_kinetic, energy_internal, energy_magnetic,
export lake_at_rest_error
export ncomponents, eachcomponent

export TreeMesh, StructuredMesh, UnstructuredMesh2D, P4estMesh, T8codeMesh
export TreeMesh, StructuredMesh, UnstructuredMesh2D, P4estMesh, T8codeMesh, T8codeFVMesh

export DG,
DGSEM, LobattoLegendreBasis,
Expand All @@ -240,6 +240,8 @@ export DG,
export VolumeIntegralSubcellLimiting, BoundsCheckCallback,
SubcellLimiterIDP, SubcellLimiterIDPCorrection

export FV

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

Expand Down
43 changes: 43 additions & 0 deletions src/callbacks_step/analysis.jl
Original file line number Diff line number Diff line change
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 = RealT,#TODO:eltype(cache.elements),
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
Loading
Loading