Skip to content

Commit

Permalink
Rearrange routines
Browse files Browse the repository at this point in the history
  • Loading branch information
bennibolm committed Jan 19, 2024
1 parent ee713ee commit c1465b7
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 25 deletions.
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()
13 changes: 0 additions & 13 deletions src/meshes/t8code_fv_mesh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,6 @@ function Base.show(io::IO, ::MIME"text/plain", mesh::T8codeFVMesh)
end
end

function create_cache(mesh::T8codeFVMesh, equations,
solver, RealT, uEltype)
elements = init_elements(mesh, RealT, uEltype)

interfaces = init_interfaces(mesh, equations, elements)

u_ = init_solution!(mesh, equations)

cache = (; elements, interfaces, u_)

return cache
end

# Write the forest as vtu and also write the element's volumes in the file.
#
# t8code supports writing element based data to vtu as long as its stored
Expand Down
27 changes: 15 additions & 12 deletions src/solvers/fv_t8code/containers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,7 @@ function Base.show(container::T8codeElementContainer)
println("neighbor_faces = ", container.neighbor_faces[1:num_faces])
end

function init_elements(mesh::T8codeFVMesh, RealT, uEltype)
# Initialize container
elements = init_elements(mesh)

# Exchange the neighboring data at MPI process boundaries.
exchange_ghost_data(mesh, elements)

return elements
end

function init_elements(mesh::T8codeFVMesh)
function init_elements(mesh::T8codeFVMesh, uEltype)
@unpack forest = mesh
# Check that the forest is a committed.
@assert(t8_forest_is_committed(forest)==1)
Expand All @@ -81,6 +71,19 @@ function init_elements(mesh::T8codeFVMesh)
num_local_elements +
num_ghost_elements)

init_elements!(elements, mesh)

# Exchange the neighboring data at MPI process boundaries.
exchange_ghost_data(mesh, elements)

return elements
end

function init_elements!(elements, mesh::T8codeFVMesh)
@unpack forest = mesh
n_dims = ndims(mesh)
@unpack max_number_faces = mesh

midpoint = Vector{Cdouble}(undef, n_dims)

face_midpoints = Matrix{Cdouble}(undef, 3, max_number_faces) # Need NDIMS=3 for t8code API. Also, consider that Julia is column major.
Expand Down Expand Up @@ -175,7 +178,7 @@ function init_elements(mesh::T8codeFVMesh)
end
end

return elements
return nothing
end

mutable struct T8codeInterfaceContainer{NDIMS, uEltype <: Real} <: AbstractContainer
Expand Down
13 changes: 13 additions & 0 deletions src/solvers/fv_t8code/fv_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ Base.summary(io::IO, solver::FV) = print(io, "FV(order=$(solver.order))")
ndofs(mesh, solver, cache)
end

function create_cache(mesh::T8codeFVMesh, equations,
solver, RealT, uEltype)
elements = init_elements(mesh, uEltype)

interfaces = init_interfaces(mesh, equations, elements)

u_ = init_solution!(mesh, equations)

cache = (; elements, interfaces, u_)

return cache
end

function compute_coefficients!(u, func, t, mesh::T8codeFVMesh, equations,
solver::FV, cache)
for element in eachelement(mesh, solver, cache)
Expand Down

0 comments on commit c1465b7

Please sign in to comment.