Skip to content

Commit e6496e2

Browse files
vincmarksJoshuaLampertDanielDoehringranocha
authored
Default BC functions for P4est , Tree and Structured meshes (#2515)
* new paragraph: Boundary conditions * new paragraph: Boundary conditions * additional functions for default choice of boundary conditions * added the default condition functions in Trixi * added the tree mesh default boundary condition * add boundary condition paragraph * some reformulaition * added the boundary_condition_default_tree funtions to trixi * Update src/solvers/dgsem_unstructured/sort_boundary_conditions.jl Co-authored-by: Joshua Lampert <[email protected]> * Update docs/src/meshes/tree_mesh.md Co-authored-by: Joshua Lampert <[email protected]> * Update src/solvers/dgsem_unstructured/sort_boundary_conditions.jl Co-authored-by: Joshua Lampert <[email protected]> * Update src/solvers/dgsem_unstructured/sort_boundary_conditions.jl Co-authored-by: Joshua Lampert <[email protected]> * Update src/solvers/dgsem_unstructured/sort_boundary_conditions.jl Co-authored-by: Joshua Lampert <[email protected]> * Update src/solvers/dgsem_unstructured/sort_boundary_conditions.jl Co-authored-by: Joshua Lampert <[email protected]> * Update src/solvers/dgsem_unstructured/sort_boundary_conditions.jl Co-authored-by: Joshua Lampert <[email protected]> * Update src/solvers/dgsem_unstructured/sort_boundary_conditions.jl Co-authored-by: Joshua Lampert <[email protected]> * Update src/solvers/dgsem_unstructured/sort_boundary_conditions.jl Co-authored-by: Joshua Lampert <[email protected]> * Update src/solvers/dgsem_unstructured/sort_boundary_conditions.jl Co-authored-by: Joshua Lampert <[email protected]> * Update src/solvers/dgsem_unstructured/sort_boundary_conditions.jl Co-authored-by: Joshua Lampert <[email protected]> * Update src/solvers/dgsem_unstructured/sort_boundary_conditions.jl Co-authored-by: Joshua Lampert <[email protected]> * Update src/solvers/dgsem_unstructured/sort_boundary_conditions.jl Co-authored-by: Joshua Lampert <[email protected]> * Update src/solvers/dgsem_unstructured/sort_boundary_conditions.jl Co-authored-by: Joshua Lampert <[email protected]> * Update src/solvers/dgsem_unstructured/sort_boundary_conditions.jl Co-authored-by: Joshua Lampert <[email protected]> * Apply suggestions from code review Co-authored-by: Joshua Lampert <[email protected]> * added reference files to get an impression of the new function: boundary_condition_default(mesh, boundary_condition) * adding examples for the boundary_condition_default(mesh, boundary_condition) function * included the default_boundary_conditions.jl file and the boundary_condition_default function * create a new file (default_boundary_conditions.jl)for the boundary_condition_default(mesh, boundary_condition) function instead of writing it in the sort_boundary_conditions.jl file * fixed typo: named tuples instead of dicitonaries * delete unnecessary functions * only use boundary_condition_default function * formatting * Syncen with Trixi.jl * Apply suggestions from code review Co-authored-by: Hendrik Ranocha <[email protected]> * using the function ``boundary_condition_default `` * fixed typo * using the function boundary_condition_default * not using the function boundary_condition_default here * changed the file where the function `boundary_condition_default(mesh, boundary_condition)` is used in the examples/tree_3d_dgsem folder * Apply suggestions from code review Co-authored-by: Hendrik Ranocha <[email protected]> * Apply suggestions from code review Co-authored-by: Joshua Lampert <[email protected]> * using `mesh` as an argument in the docstrings * format * changing the file name to boundary_condition_default.jl * Apply suggestions from code review Co-authored-by: Daniel Doehring <[email protected]> --------- Co-authored-by: Joshua Lampert <[email protected]> Co-authored-by: Daniel Doehring <[email protected]> Co-authored-by: Hendrik Ranocha <[email protected]>
1 parent 82efbc7 commit e6496e2

14 files changed

+307
-62
lines changed

docs/src/meshes/p4est_mesh.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,3 +939,7 @@ rebalance_solver!(u0, mesh, equations, dg, cache, old_global_first_quadrant)
939939
reinitialize_boundaries!(semi.boundary_conditions, cache) # Needs to be called after `rebalance_solver!`
940940
```
941941
This code could then be placed in the [`resize!`](https://github.com/trixi-framework/Trixi.jl/blob/eaeb04113523500ed831e3ab459694f12f7a49ea/src/time_integration/methods_2N.jl#L251-L255) function of a corresponding multirate integrator to ensure load-balancing for simulations involving AMR.
942+
943+
### Boundary conditions
944+
For [`P4estMesh`](@ref)es, boundary conditions are defined and stored in [dictionaries](https://docs.julialang.org/en/v1/base/collections/#Base.Dict) (see, for example, `examples/p4est_2d_dgsem/elixir_advection_diffusion_nonperiodic_amr.jl`).
945+
If you want to apply the same boundary condition to all faces of the mesh, you can use the `boundary_condition_default(mesh, boundary_condition)` function, as demonstrated in `examples/p4est_2d_dgsem/elixir_advection_diffusion_nonperiodic_amr.jl` and `examples/p4est_3d_dgsem/elixir_euler_source_terms_nonperiodic.jl`.

docs/src/meshes/structured_mesh.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ such as the compressible Euler equations can use [`FluxRotated`](@ref) to
1111
wrap numerical fluxes implemented only for Cartesian meshes. This simplifies
1212
the re-use of existing functionality for the [`TreeMesh`](@ref) but is usually
1313
less efficient, cf. [PR #550](https://github.com/trixi-framework/Trixi.jl/pull/550).
14+
15+
### Boundary conditions
16+
For [`StructuredMesh`](@ref)es, boundary conditions are defined and stored in [named tuples](https://docs.julialang.org/en/v1/manual/functions/#Named-Tuples) (see, for example, `examples/structured_1d_dgsem/elixir_euler_source_terms_nonperiodic.jl`).
17+
If you want to apply the same boundary condition to all faces of the mesh, you can use the `boundary_condition_default(mesh, boundary_condition)` function, as demonstrated in `examples/structured_1d_dgsem/elixir_euler_source_terms_nonperiodic.jl`, `examples/structured_2d_dgsem/elixir_euler_rayleigh_taylor_instability.jl` and `examples/structured_3d_dgsem/elixir_euler_source_terms_nonperiodic_curved.jl`.

docs/src/meshes/tree_mesh.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ It is limited to hypercube domains (that is, lines in 1D, squares in 2D and cube
99
Due to its Cartesian nature, (numerical) fluxes need to implement methods
1010
dispatching on the `orientation::Integer` as described in the
1111
[conventions](@ref conventions).
12+
13+
14+
### Boundary conditions
15+
For [`TreeMesh`](@ref)es, boundary conditions are defined and stored in [named tuples](https://docs.julialang.org/en/v1/manual/functions/#Named-Tuples) (see, for example, `examples/tree_1d_dgsem/elixir_euler_source_terms_nonperiodic.jl`).
16+
If you want to apply the same boundary condition to all faces of the mesh, you can use the `boundary_condition_default(mesh, boundary_condition)` function, as demonstrated in `examples/tree_1d_dgsem/elixir_euler_source_terms_nonperiodic.jl`, `examples/tree_2d_dgsem/elixir_euler_source_terms_nonperiodic.jl` and `examples/tree_3d_dgsem/elixir_advection_extended.jl`.

examples/p4est_2d_dgsem/elixir_advection_diffusion_nonperiodic_amr.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,14 @@ boundary_conditions = Dict(:x_neg => BoundaryConditionDirichlet(initial_conditio
4545
:y_pos => BoundaryConditionDirichlet(initial_condition),
4646
:x_pos => boundary_condition_do_nothing)
4747

48-
boundary_conditions_parabolic = Dict(:x_neg => BoundaryConditionDirichlet(initial_condition),
49-
:x_pos => BoundaryConditionDirichlet(initial_condition),
50-
:y_neg => BoundaryConditionDirichlet(initial_condition),
51-
:y_pos => BoundaryConditionDirichlet(initial_condition))
48+
# Assign a single boundary condition to all boundaries
49+
boundary_condition = BoundaryConditionDirichlet(initial_condition)
50+
boundary_conditions_parabolic = boundary_condition_default(mesh, boundary_condition)
51+
# Alternatively, you can use
52+
# boundary_conditions_parabolic = Dict(:x_neg => BoundaryConditionDirichlet(initial_condition),
53+
# :x_pos => BoundaryConditionDirichlet(initial_condition),
54+
# :y_neg => BoundaryConditionDirichlet(initial_condition),
55+
# :y_pos => BoundaryConditionDirichlet(initial_condition))
5256

5357
# A semidiscretization collects data structures and functions for the spatial discretization
5458
semi = SemidiscretizationHyperbolicParabolic(mesh,

examples/p4est_3d_dgsem/elixir_euler_source_terms_nonperiodic.jl

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ equations = CompressibleEulerEquations3D(1.4)
88

99
initial_condition = initial_condition_convergence_test
1010

11-
boundary_condition = BoundaryConditionDirichlet(initial_condition)
12-
boundary_conditions = Dict(:x_neg => boundary_condition,
13-
:x_pos => boundary_condition,
14-
:y_neg => boundary_condition,
15-
:y_pos => boundary_condition,
16-
:z_neg => boundary_condition,
17-
:z_pos => boundary_condition)
18-
1911
# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of
2012
# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.
2113
# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.
@@ -35,6 +27,17 @@ mesh = P4estMesh(trees_per_dimension, polydeg = 1,
3527
coordinates_min = coordinates_min, coordinates_max = coordinates_max,
3628
periodicity = false, initial_refinement_level = 1)
3729

30+
# Assign a single boundary condition to all boundaries
31+
boundary_condition = BoundaryConditionDirichlet(initial_condition)
32+
boundary_conditions = boundary_condition_default(mesh, boundary_condition)
33+
# Alternatively, you can use
34+
# boundary_conditions = Dict(:x_neg => boundary_condition,
35+
# :x_pos => boundary_condition,
36+
# :y_neg => boundary_condition,
37+
# :y_pos => boundary_condition,
38+
# :z_neg => boundary_condition,
39+
# :z_pos => boundary_condition)
40+
3841
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
3942
source_terms = source_terms_convergence_test,
4043
boundary_conditions = boundary_conditions)

examples/structured_1d_dgsem/elixir_euler_source_terms_nonperiodic.jl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@ initial_condition = initial_condition_convergence_test
1010

1111
source_terms = source_terms_convergence_test
1212

13-
# you can either use a single function to impose the BCs weakly in all
14-
# 1*ndims == 2 directions or you can pass a tuple containing BCs for
15-
# each direction
16-
boundary_condition = BoundaryConditionDirichlet(initial_condition)
17-
boundary_conditions = (x_neg = boundary_condition,
18-
x_pos = boundary_condition)
19-
2013
# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of
2114
# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.
2215
# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.
@@ -30,6 +23,16 @@ f1() = SVector(0.0)
3023
f2() = SVector(2.0)
3124
mesh = StructuredMesh((16,), (f1, f2), periodicity = false)
3225

26+
# you can either use a single function to impose the BCs weakly in all
27+
# 2*ndims == 2 directions or you can pass a tuple containing BCs for
28+
# each direction
29+
# Assign a single boundary condition to all boundaries
30+
boundary_condition = BoundaryConditionDirichlet(initial_condition)
31+
boundary_conditions = boundary_condition_default(mesh, boundary_condition)
32+
# Alternatively, you can use
33+
# boundary_conditions = (x_neg = boundary_condition,
34+
# x_pos = boundary_condition)
35+
3336
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
3437
source_terms = source_terms,
3538
boundary_conditions = boundary_conditions)

examples/structured_2d_dgsem/elixir_euler_rayleigh_taylor_instability.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,14 @@ cells_per_dimension = (num_elements_per_dimension, num_elements_per_dimension *
7171
mesh = StructuredMesh(cells_per_dimension, mapping, periodicity = false)
7272

7373
initial_condition = initial_condition_rayleigh_taylor_instability
74-
boundary_conditions = (x_neg = boundary_condition_slip_wall,
75-
x_pos = boundary_condition_slip_wall,
76-
y_neg = boundary_condition_slip_wall,
77-
y_pos = boundary_condition_slip_wall)
74+
75+
# Assign a single boundary condition to all boundaries
76+
boundary_conditions = boundary_condition_default(mesh, boundary_condition_slip_wall)
77+
# Alternatively, you can use
78+
# boundary_conditions = (x_neg = boundary_condition_slip_wall,
79+
# x_pos = boundary_condition_slip_wall,
80+
# y_neg = boundary_condition_slip_wall,
81+
# y_pos = boundary_condition_slip_wall)
7882

7983
# # Alternative setup: left/right periodic BCs and Dirichlet BCs on the top/bottom.
8084
# boundary_conditions = (

examples/structured_3d_dgsem/elixir_euler_source_terms_nonperiodic_curved.jl

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@ equations = CompressibleEulerEquations3D(1.4)
88

99
initial_condition = initial_condition_convergence_test
1010

11-
# you can either use a single function to impose the BCs weakly in all
12-
# 2*ndims == 4 directions or you can pass a tuple containing BCs for each direction
13-
boundary_condition = BoundaryConditionDirichlet(initial_condition)
14-
boundary_conditions = (x_neg = boundary_condition,
15-
x_pos = boundary_condition,
16-
y_neg = boundary_condition,
17-
y_pos = boundary_condition,
18-
z_neg = boundary_condition,
19-
z_pos = boundary_condition)
20-
2111
# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of
2212
# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.
2313
# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.
@@ -57,6 +47,19 @@ end
5747
cells_per_dimension = (4, 4, 4)
5848
mesh = StructuredMesh(cells_per_dimension, mapping, periodicity = false)
5949

50+
# you can either use a single function to impose the BCs weakly in all
51+
# 2*ndims == 6 directions or you can pass a tuple containing BCs for each direction
52+
# Assign a single boundary condition to all boundaries
53+
boundary_condition = BoundaryConditionDirichlet(initial_condition)
54+
boundary_conditions = boundary_condition_default(mesh, boundary_condition)
55+
# Alternatively, you can use
56+
# boundary_conditions = (x_neg = boundary_condition,
57+
# x_pos = boundary_condition,
58+
# y_neg = boundary_condition,
59+
# y_pos = boundary_condition,
60+
# z_neg = boundary_condition,
61+
# z_pos = boundary_condition)
62+
6063
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
6164
source_terms = source_terms_convergence_test,
6265
boundary_conditions = boundary_conditions)

examples/tree_1d_dgsem/elixir_euler_source_terms_nonperiodic.jl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ equations = CompressibleEulerEquations1D(1.4)
88

99
initial_condition = initial_condition_convergence_test
1010

11-
# you can either use a single function to impose the BCs weakly in all
12-
# 1*ndims == 2 directions or you can pass a tuple containing BCs for
13-
# each direction
14-
boundary_condition = BoundaryConditionDirichlet(initial_condition)
15-
boundary_conditions = (x_neg = boundary_condition,
16-
x_pos = boundary_condition)
17-
1811
# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of
1912
# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.
2013
# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.
@@ -31,6 +24,16 @@ mesh = TreeMesh(coordinates_min, coordinates_max,
3124
n_cells_max = 10_000,
3225
periodicity = false)
3326

27+
# you can either use a single function to impose the BCs weakly in all
28+
# 2*ndims == 2 directions or you can pass a tuple containing BCs for
29+
# each direction
30+
# Assign a single boundary condition to all boundaries
31+
boundary_condition = BoundaryConditionDirichlet(initial_condition)
32+
boundary_conditions = boundary_condition_default(mesh, boundary_condition)
33+
# Alternatively, you can use
34+
# boundary_conditions = (x_neg = boundary_condition,
35+
# x_pos = boundary_condition)
36+
3437
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
3538
source_terms = source_terms_convergence_test,
3639
boundary_conditions = boundary_conditions)

examples/tree_2d_dgsem/elixir_euler_source_terms_nonperiodic.jl

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ equations = CompressibleEulerEquations2D(1.4)
88

99
initial_condition = initial_condition_convergence_test
1010

11-
# you can either use a single function to impose the BCs weakly in all
12-
# 2*ndims == 4 directions or you can pass a tuple containing BCs for each direction
13-
boundary_condition = BoundaryConditionDirichlet(initial_condition)
14-
boundary_conditions = (x_neg = boundary_condition,
15-
x_pos = boundary_condition,
16-
y_neg = boundary_condition,
17-
y_pos = boundary_condition)
18-
1911
# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of
2012
# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.
2113
# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.
@@ -32,6 +24,17 @@ mesh = TreeMesh(coordinates_min, coordinates_max,
3224
n_cells_max = 10_000,
3325
periodicity = false)
3426

27+
# you can either use a single function to impose the BCs weakly in all
28+
# 2*ndims == 4 directions or you can pass a tuple containing BCs for each direction
29+
# Assign a single boundary condition to all boundaries
30+
boundary_condition = BoundaryConditionDirichlet(initial_condition)
31+
boundary_conditions = boundary_condition_default(mesh, boundary_condition)
32+
# Alternatively, you can use
33+
# boundary_conditions = (x_neg = boundary_condition,
34+
# x_pos = boundary_condition,
35+
# y_neg = boundary_condition,
36+
# y_pos = boundary_condition)
37+
3538
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
3639
source_terms = source_terms_convergence_test,
3740
boundary_conditions = boundary_conditions)

0 commit comments

Comments
 (0)