forked from trixi-framework/Trixi.jl
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 3d support for FV using T8codeMesh (#130)
* Add first version of 3d support * Complete 3d support * Add 3d elixirs and tests * Adapt name in elixir * Reduce initial refinement level of one test * Simplify NDIMS=3 * Add 3d mpi tests * Remove initial_condition from rhs; fmt * Fix parameter in `x_trans_periodic_3d` * Remove comment * Some last changes * fmt
- Loading branch information
Showing
18 changed files
with
1,151 additions
and
181 deletions.
There are no files selected for viewing
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
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
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
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,96 @@ | ||
using OrdinaryDiffEq | ||
using Trixi | ||
using T8code | ||
|
||
advection_velocity = (0.2, -0.7, 0.5) | ||
equations = LinearScalarAdvectionEquation3D(advection_velocity) | ||
|
||
initial_condition = initial_condition_convergence_test | ||
|
||
solver = FV(order = 2, extended_reconstruction_stencil = false, | ||
surface_flux = flux_lax_friedrichs) | ||
|
||
# Option 1: coordinates | ||
# For all problems see the 2D file... | ||
coordinates_min = (0.0, 0.0, 0.0) # minimum coordinates (min(x), min(y), min(z)) | ||
coordinates_max = (8.0, 8.0, 8.0) # maximum coordinates (max(x), max(y), max(z)) | ||
|
||
mapping_coordinates = Trixi.coordinates2mapping(coordinates_min, coordinates_max) | ||
|
||
# Option 3: classic mapping | ||
function mapping(xi, eta, zeta) | ||
x = 4 * (xi + 1) | ||
y = 4 * (eta + 1) | ||
z = 4 * (zeta + 1) | ||
|
||
return SVector(x, y, z) | ||
end | ||
|
||
function trixi_t8_mapping(cmesh, gtreeid, ref_coords, num_coords, out_coords, | ||
tree_data, user_data) | ||
ltreeid = t8_cmesh_get_local_id(cmesh, gtreeid) | ||
eclass = t8_cmesh_get_tree_class(cmesh, ltreeid) | ||
T8code.t8_geom_compute_linear_geometry(eclass, tree_data, | ||
ref_coords, num_coords, out_coords) | ||
|
||
for i in 1:num_coords | ||
offset_3d = 3 * (i - 1) + 1 | ||
|
||
xi = unsafe_load(out_coords, offset_3d) | ||
eta = unsafe_load(out_coords, offset_3d + 1) | ||
zeta = unsafe_load(out_coords, offset_3d + 2) | ||
# xyz = mapping_coordinates(xi, eta, zeta) | ||
xyz = mapping(xi, eta, zeta) | ||
|
||
unsafe_store!(out_coords, xyz[1], offset_3d) | ||
unsafe_store!(out_coords, xyz[2], offset_3d + 1) | ||
unsafe_store!(out_coords, xyz[3], offset_3d + 2) | ||
end | ||
|
||
return nothing | ||
end | ||
|
||
function trixi_t8_mapping_c() | ||
@cfunction($trixi_t8_mapping, Cvoid, | ||
(t8_cmesh_t, t8_gloidx_t, Ptr{Cdouble}, Csize_t, | ||
Ptr{Cdouble}, Ptr{Cvoid}, Ptr{Cvoid})) | ||
end | ||
|
||
trees_per_dimension = (2, 2, 2) | ||
|
||
eclass = T8_ECLASS_HEX | ||
mesh = T8codeMesh(trees_per_dimension, eclass; | ||
mapping = trixi_t8_mapping_c(), | ||
# Plan is to use either | ||
# coordinates_max = coordinates_max, coordinates_min = coordinates_min, | ||
# or at least | ||
# mapping = mapping, | ||
initial_refinement_level = 5) | ||
|
||
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver) | ||
|
||
tspan = (0.0, 1.0) | ||
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 = 10, | ||
solution_variables = cons2prim) | ||
|
||
stepsize_callback = StepsizeCallback(cfl = 0.9) | ||
|
||
callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback, | ||
stepsize_callback, save_solution) | ||
|
||
############################################################################### | ||
# 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() |
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,42 @@ | ||
using OrdinaryDiffEq | ||
using Trixi | ||
|
||
advection_velocity = (0.2, -0.7, 0.5) | ||
equations = LinearScalarAdvectionEquation3D(advection_velocity) | ||
|
||
initial_condition = initial_condition_convergence_test | ||
|
||
solver = FV(order = 2, extended_reconstruction_stencil = false, | ||
surface_flux = flux_lax_friedrichs) | ||
|
||
# TODO: There are no other cmesh functions implemented yet in 3d. | ||
cmesh = Trixi.cmesh_new_quad_3d(periodicity = (true, true, true)) | ||
mesh = T8codeMesh(cmesh, solver, | ||
initial_refinement_level = 4) | ||
|
||
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.9) | ||
|
||
callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback, | ||
stepsize_callback, save_solution) | ||
|
||
############################################################################### | ||
# 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() |
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,47 @@ | ||
using OrdinaryDiffEq | ||
using Trixi | ||
|
||
#################################################### | ||
|
||
advection_velocity = (0.2, -0.7, 0.5) | ||
equations = LinearScalarAdvectionEquation3D(advection_velocity) | ||
|
||
initial_condition = initial_condition_gauss | ||
|
||
solver = FV(order = 2, surface_flux = flux_lax_friedrichs) | ||
|
||
initial_refinement_level = 4 | ||
|
||
# TODO: There are no other cmesh functions implemented yet in 3d. | ||
cmesh = Trixi.cmesh_new_quad_3d(coordinates_min = (-5.0, -5.0, -5.0), | ||
coordinates_max = (5.0, 5.0, 5.0), | ||
periodicity = (true, true, true)) | ||
mesh = T8codeMesh(cmesh, solver, initial_refinement_level = initial_refinement_level) | ||
|
||
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver) | ||
|
||
tspan = (0.0, 5.0) | ||
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 = 10, | ||
solution_variables = cons2prim) | ||
|
||
stepsize_callback = StepsizeCallback(cfl = 0.7) | ||
|
||
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() |
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,53 @@ | ||
using OrdinaryDiffEq | ||
using Trixi | ||
|
||
############################################################################### | ||
# Semidiscretization of the linear advection equation. | ||
|
||
advection_velocity = (0.2, -0.7, 0.5) | ||
equations = LinearScalarAdvectionEquation3D(advection_velocity) | ||
|
||
initial_condition = initial_condition_convergence_test | ||
|
||
boundary_condition = BoundaryConditionDirichlet(initial_condition) | ||
boundary_conditions = Dict(:all => boundary_condition) | ||
# Problem: T8codeMesh interface with parameter cmesh cannot distinguish between boundaries | ||
# boundary_conditions = Dict(:x_neg => boundary_condition, | ||
# :x_pos => boundary_condition, | ||
# :y_neg => boundary_condition_periodic, | ||
# :y_pos => boundary_condition_periodic) | ||
|
||
solver = FV(order = 2, surface_flux = flux_lax_friedrichs) | ||
|
||
# TODO: When using mesh construction as in elixir_advection_basic.jl boundary Symbol :all is not defined | ||
initial_refinement_level = 5 | ||
cmesh = Trixi.cmesh_new_quad_3d(periodicity = (false, false, false)) | ||
mesh = T8codeMesh(cmesh, solver, initial_refinement_level = initial_refinement_level) | ||
|
||
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver, | ||
boundary_conditions = boundary_conditions) | ||
|
||
############################################################################### | ||
# ODE solvers, callbacks etc. | ||
|
||
tspan = (0.0, 1.0) | ||
ode = semidiscretize(semi, tspan) | ||
|
||
summary_callback = SummaryCallback() | ||
|
||
analysis_interval = 100 | ||
analysis_callback = AnalysisCallback(semi, interval = analysis_interval) | ||
alive_callback = AliveCallback(analysis_interval = analysis_interval) | ||
|
||
stepsize_callback = StepsizeCallback(cfl = 0.8) | ||
|
||
callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback, | ||
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() |
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,51 @@ | ||
|
||
using OrdinaryDiffEq | ||
using Trixi | ||
|
||
equations = CompressibleEulerEquations3D(1.4) | ||
|
||
initial_condition = initial_condition_convergence_test | ||
|
||
# boundary_condition = BoundaryConditionDirichlet(initial_condition) | ||
# boundary_conditions = Dict(:all => boundary_condition) | ||
|
||
source_terms = source_terms_convergence_test | ||
|
||
solver = FV(order = 2, extended_reconstruction_stencil = false, | ||
surface_flux = flux_lax_friedrichs) | ||
|
||
# TODO: There are no other cmesh functions implemented yet in 3d. | ||
cmesh = Trixi.cmesh_new_quad_3d(periodicity = (true, true, true)) | ||
mesh = T8codeMesh(cmesh, solver, | ||
initial_refinement_level = 3) | ||
|
||
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver, | ||
source_terms = source_terms) | ||
# boundary_conditions = boundary_conditions) | ||
|
||
tspan = (0.0, 2.0) | ||
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 = 100, | ||
save_initial_solution = true, | ||
save_final_solution = true, | ||
solution_variables = cons2prim) | ||
|
||
stepsize_callback = StepsizeCallback(cfl = 0.8) | ||
|
||
callbacks = CallbackSet(summary_callback, | ||
analysis_callback, alive_callback, | ||
save_solution, | ||
stepsize_callback) | ||
|
||
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 |
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
Oops, something went wrong.