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

Check BCs for periodicity for periodic Tree & Structured meshes #1860

Merged
3 changes: 3 additions & 0 deletions src/meshes/tree_mesh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,8 @@ function total_volume(mesh::TreeMesh)
return mesh.tree.length_level_0^ndims(mesh)
end

isperiodic(mesh::TreeMesh) = isperiodic(mesh.tree)
isperiodic(mesh::TreeMesh, dimension) = isperiodic(mesh.tree, dimension)

include("parallel_tree_mesh.jl")
end # @muladd
122 changes: 122 additions & 0 deletions src/semidiscretization/semidiscretization_hyperbolic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ function SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver
_boundary_conditions = digest_boundary_conditions(boundary_conditions, mesh, solver,
cache)

check_periodicity_mesh_boundary_conditions(mesh, _boundary_conditions)

SemidiscretizationHyperbolic{typeof(mesh), typeof(equations),
typeof(initial_condition),
typeof(_boundary_conditions), typeof(source_terms),
Expand Down Expand Up @@ -210,6 +212,126 @@ function digest_boundary_conditions(boundary_conditions::AbstractArray, mesh, so
throw(ArgumentError("Please use a (named) tuple instead of an (abstract) array to supply multiple boundary conditions (to improve performance)."))
end

# No checks for these meshes yet available
function check_periodicity_mesh_boundary_conditions(mesh::Union{P4estMesh,
UnstructuredMesh2D,
T8CodeMesh,
DGMultiMesh},
boundary_conditions)
end

# No actions needed for periodic boundary conditions
function check_periodicity_mesh_boundary_conditions(mesh::Union{TreeMesh,
StructuredMesh},
boundary_conditions::BoundaryConditionPeriodic)
end

function check_periodicity_mesh_boundary_conditions(mesh::Union{TreeMesh{1},
StructuredMesh{1}},
boundary_conditions::NamedTuple)
@unpack x_neg, x_pos = boundary_conditions
if isperiodic(mesh, 1) &&
(x_neg != BoundaryConditionPeriodic() ||
x_pos != BoundaryConditionPeriodic())
@error "For periodic mesh non-periodic boundary conditions are supplied.
The boundary conditions will be ignored and periodic boundary conditions are used."
end
end

function check_periodicity_mesh_boundary_conditions(mesh::Union{TreeMesh{1},
StructuredMesh{1}},
boundary_conditions::NTuple{2, Any})
if isperiodic(mesh, 1) &&
DanielDoehring marked this conversation as resolved.
Show resolved Hide resolved
(boundary_conditions[1] != BoundaryConditionPeriodic() ||
boundary_conditions[2] != BoundaryConditionPeriodic())
@error "For periodic mesh non-periodic boundary conditions are supplied.
The boundary conditions will be ignored and periodic boundary conditions are used."
end
end

function check_periodicity_mesh_boundary_conditions(mesh::Union{TreeMesh{2},
StructuredMesh{2}},
boundary_conditions::NamedTuple)
@unpack x_neg, x_pos, y_neg, y_pos = boundary_conditions
if isperiodic(mesh, 1) &&
(x_neg != BoundaryConditionPeriodic() ||
x_pos != BoundaryConditionPeriodic())
@error "For periodic mesh non-periodic boundary conditions in x-direction are supplied.
The boundary conditions will be ignored and periodic boundary conditions are used."
end
if isperiodic(mesh, 2) &&
(y_neg != BoundaryConditionPeriodic() ||
y_pos != BoundaryConditionPeriodic())
@error "For periodic mesh non-periodic boundary conditions in y-direction are supplied.
The boundary conditions will be ignored and periodic boundary conditions are used."
end
end

function check_periodicity_mesh_boundary_conditions(mesh::Union{TreeMesh{2},
StructuredMesh{2}},
boundary_conditions::NTuple{4, Any})
if isperiodic(mesh, 1) &&
(boundary_conditions[1] != BoundaryConditionPeriodic() ||
boundary_conditions[2] != BoundaryConditionPeriodic())
@error "For periodic mesh non-periodic boundary conditions in x-direction are supplied.
The boundary conditions will be ignored and periodic boundary conditions are used."
end
if isperiodic(mesh, 2) &&
(boundary_conditions[3] != BoundaryConditionPeriodic() ||
boundary_conditions[4] != BoundaryConditionPeriodic())
@error "For periodic mesh non-periodic boundary conditions in y-direction are supplied.
The boundary conditions will be ignored and periodic boundary conditions are used."
end
end

function check_periodicity_mesh_boundary_conditions(mesh::Union{TreeMesh{3},
StructuredMesh{3}},
boundary_conditions::NamedTuple)
@unpack x_neg, x_pos, y_neg, y_pos, z_neg, z_pos = boundary_conditions
if isperiodic(mesh, 1) &&
(x_neg != BoundaryConditionPeriodic() ||
x_pos != BoundaryConditionPeriodic())
@error "For periodic mesh non-periodic boundary conditions in x-direction are supplied.
The boundary conditions will be ignored and periodic boundary conditions are used."
end
if isperiodic(mesh, 2) &&
(y_neg != BoundaryConditionPeriodic() ||
y_pos != BoundaryConditionPeriodic())
@error "For periodic mesh non-periodic boundary conditions in y-direction are supplied.
The boundary conditions will be ignored and periodic boundary conditions are used."
end
if isperiodic(mesh, 3) &&
(z_neg != BoundaryConditionPeriodic() ||
z_pos != BoundaryConditionPeriodic())
@error "For periodic mesh non-periodic boundary conditions in z-direction are supplied.
The boundary conditions will be ignored and periodic boundary conditions are used."
end
end

function check_periodicity_mesh_boundary_conditions(mesh::Union{TreeMesh{3},
StructuredMesh{3}},
boundary_conditions::NTuple{6, Any})
@unpack x_neg, x_pos, y_neg, y_pos, z_neg, z_pos = boundary_conditions
if isperiodic(mesh, 1) &&
(boundary_conditions[1] != BoundaryConditionPeriodic() ||
boundary_conditions[2] != BoundaryConditionPeriodic())
@error "For periodic mesh non-periodic boundary conditions in x-direction are supplied.
The boundary conditions will be ignored and periodic boundary conditions are used."
end
if isperiodic(mesh, 2) &&
(boundary_conditions[3] != BoundaryConditionPeriodic() ||
boundary_conditions[4] != BoundaryConditionPeriodic())
@error "For periodic mesh non-periodic boundary conditions in y-direction are supplied.
The boundary conditions will be ignored and periodic boundary conditions are used."
end
if isperiodic(mesh, 3) &&
(boundary_conditions[5] != BoundaryConditionPeriodic() ||
boundary_conditions[6] != BoundaryConditionPeriodic())
@error "For periodic mesh non-periodic boundary conditions in z-direction are supplied.
The boundary conditions will be ignored and periodic boundary conditions are used."
end
end

function Base.show(io::IO, semi::SemidiscretizationHyperbolic)
@nospecialize semi # reduce precompilation time

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ function SemidiscretizationHyperbolicParabolic(mesh, equations, equations_parabo
_boundary_conditions_parabolic = digest_boundary_conditions(boundary_conditions_parabolic,
mesh, solver, cache)

check_periodicity_mesh_boundary_conditions(mesh, _boundary_conditions)

cache_parabolic = (;
create_cache_parabolic(mesh, equations, equations_parabolic,
solver, solver_parabolic, RealT,
Expand Down
Loading