Skip to content

Commit

Permalink
Added parameters to p4est mesh struct.
Browse files Browse the repository at this point in the history
Added preliminary coupling methods for p4est meshes.
  • Loading branch information
SimonCan committed Mar 19, 2024
1 parent 2dfde7f commit 5aaee81
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/meshes/p4est_mesh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ mutable struct P4estMesh{NDIMS, RealT <: Real, IsParallel, P, Ghost, NDIMSP2, NN
current_filename::String
unsaved_changes::Bool
p4est_partition_allow_for_coarsening::Bool
coordinates_min::SVector{NDIMS, RealT}
coordinates_max::SVector{NDIMS, RealT}
trees_per_dimension::SVector{NDIMS, Int}

function P4estMesh{NDIMS}(p4est, tree_node_coordinates, nodes, boundary_names,
current_filename, unsaved_changes,
p4est_partition_allow_for_coarsening) where {NDIMS}
p4est_partition_allow_for_coarsening,
coordinates_min, coordinates_max, trees_per_dimension) where {NDIMS}
if NDIMS == 2
@assert p4est isa Ptr{p4est_t}
elseif NDIMS == 3
Expand Down Expand Up @@ -57,7 +61,10 @@ mutable struct P4estMesh{NDIMS, RealT <: Real, IsParallel, P, Ghost, NDIMSP2, NN
boundary_names,
current_filename,
unsaved_changes,
p4est_partition_allow_for_coarsening)
p4est_partition_allow_for_coarsening,
coordinates_min,
coordinates_max,
trees_per_dimension)

# Destroy `p4est` structs when the mesh is garbage collected
finalizer(destroy_mesh, mesh)
Expand Down Expand Up @@ -215,7 +222,8 @@ function P4estMesh(trees_per_dimension; polydeg,

return P4estMesh{NDIMS}(p4est, tree_node_coordinates, nodes,
boundary_names, "", unsaved_changes,
p4est_partition_allow_for_coarsening)
p4est_partition_allow_for_coarsening,
coordinates_min, coordinates_max, trees_per_dimension)
end

# 2D version
Expand Down
71 changes: 71 additions & 0 deletions src/semidiscretization/semidiscretization_coupled.jl
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ end
# In 2D
function allocate_coupled_boundary_condition(boundary_condition::BoundaryConditionCoupled{2},
direction, mesh, equations, dg::DGSEM)
@autoinfiltrate
if direction in (1, 2)
cell_size = size(mesh, 2)
else
Expand All @@ -479,6 +480,48 @@ function allocate_coupled_boundary_condition(boundary_condition::BoundaryConditi
cell_size)
end

# In 2D
function allocate_coupled_boundary_condition(boundary_condition::BoundaryConditionCoupled{2
},
direction, mesh::P4estMesh, equations, dg::DGSEM)
@autoinfiltrate
if direction in (1, 2)
cell_size = size(mesh, 2)
# Negative and positive y.
else
cell_size = size(mesh, 1)
end

uEltype = eltype(boundary_condition)
boundary_condition.u_boundary = Array{uEltype, 3}(undef, nvariables(equations),
nnodes(dg),
cell_size)
end

# In 2D for a p4est mesh.
function allocate_coupled_boundary_condition(boundary_condition::BoundaryConditionCoupled{2
},
direction, mesh::P4estMesh, equations, dg::DGSEM)
# Negative x.
if direction == 1
cell_size = sum(mesh.tree_node_coordinates[1, 1, 1, :] .== minimum(mesh.tree_node_coordinates[1, 1, 1, :]))
# Positive x.
elseif direction == 2
cell_size = sum(mesh.tree_node_coordinates[1, 1, 1, :] .== maximum(mesh.tree_node_coordinates[1, 1, 1, :]))
# Negative y.
elseif direction == 3
cell_size = sum(mesh.tree_node_coordinates[2, 1, 1, :] .== minimum(mesh.tree_node_coordinates[2, 1, 1, :]))
# Positive y.
else
cell_size = sum(mesh.tree_node_coordinates[2, 1, 1, :] .== maximum(mesh.tree_node_coordinates[2, 1, 1, :]))
end

uEltype = eltype(boundary_condition)
boundary_condition.u_boundary = Array{uEltype, 3}(undef, nvariables(equations),
nnodes(dg),
cell_size)
end

# Don't do anything for other BCs than BoundaryConditionCoupled
function copy_to_coupled_boundary!(boundary_condition, u_ode, semi_coupled, semi)
return nothing
Expand Down Expand Up @@ -535,6 +578,26 @@ function copy_to_coupled_boundary!(boundary_condition::BoundaryConditionCoupled{
cells = axes(mesh_other, 1)
end

if mesh isa P4estMesh
linear_indices = LinearIndices((mesh.trees_per_dimension[1], mesh.trees_per_dimension[2]))
else
linear_indices = LinearIndices(size(mesh))
end

if mesh isa P4estMesh
if other_orientation == 1
cells = mesh.trees_per_dimension[2]
else # other_orientation == 2
cells = mesh.trees_per_dimension[1]
end
else
if other_orientation == 1
cells = axes(mesh, 2)
else # other_orientation == 2
cells = axes(mesh, 1)
end
end

# Copy solution data to the coupled boundary using "delayed indexing" with
# a start value and a step size to get the correct face and orientation.
node_index_range = eachnode(solver_other)
Expand All @@ -543,10 +606,18 @@ function copy_to_coupled_boundary!(boundary_condition::BoundaryConditionCoupled{

i_cell_start, i_cell_step = index_to_start_step_2d(indices[1], axes(mesh_other, 1))
j_cell_start, j_cell_step = index_to_start_step_2d(indices[2], axes(mesh_other, 2))
if mesh isa P4estMesh
i_cell_start, i_cell_step = index_to_start_step_2d(indices[1], mesh.trees_per_dimension[1])
j_cell_start, j_cell_step = index_to_start_step_2d(indices[2], mesh.trees_per_dimension[2])
else
i_cell_start, i_cell_step = index_to_start_step_2d(indices[1], axes(mesh, 1))
j_cell_start, j_cell_step = index_to_start_step_2d(indices[2], axes(mesh, 2))
end

i_cell = i_cell_start
j_cell = j_cell_start

# @autoinfiltrate
for cell in cells
i_node = i_node_start
j_node = j_node_start
Expand Down

0 comments on commit 5aaee81

Please sign in to comment.