Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
grid_fichera_oven.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
5
6#include <deal.II/grid/grid_generator.h>
7
8template <int dim, int spacedim>
10 const std::string &grid_arguments)
11{
12 if constexpr (dim != 3 || spacedim != 3)
13 {
14 AssertThrow(
15 false,
16 ExcMessage(
17 "The Fichera oven mesh is only supported in 3D space with 3D elements."));
18 return;
19 }
20
21 this->grid_arguments = grid_arguments;
22 const std::vector<std::string> arguments =
23 Utilities::split_string_list(grid_arguments, ':');
24
25 if (arguments.size() < 2)
26 {
27 AssertThrow(false,
28 ExcMessage(
29 "The Fichera oven grid requires at least 2 arguments: "
30 "(bottom_left : top_right [: colorize]). "
31 "Points are given as x,y,z and colorize as true/false."));
32 }
33
34 // Parse bottom_left point
35 std::stringstream bottom_left_stream(arguments[0]);
36 std::vector<double> bottom_left_coords;
37 std::string coord_str;
38 while (getline(bottom_left_stream, coord_str, ','))
39 bottom_left_coords.push_back(std::stod(coord_str));
40
41 AssertThrow(bottom_left_coords.size() == static_cast<unsigned int>(dim),
42 ExcMessage("The bottom_left point must have exactly " +
43 std::to_string(dim) + " coordinates (x,y,z format)."));
44
45 this->bottom_left = Point<dim>(bottom_left_coords[0],
46 bottom_left_coords[1],
47 bottom_left_coords[2]);
48
49 // Parse top_right point
50 std::stringstream top_right_stream(arguments[1]);
51 std::vector<double> top_right_coords;
52 while (getline(top_right_stream, coord_str, ','))
53 top_right_coords.push_back(std::stod(coord_str));
54
55 AssertThrow(top_right_coords.size() == static_cast<unsigned int>(dim),
56 ExcMessage("The top_right point must have exactly " +
57 std::to_string(dim) + " coordinates (x,y,z format)."));
58 this->top_right =
59 Point<dim>(top_right_coords[0], top_right_coords[1], top_right_coords[2]);
60
61 // Parse optional colorize flag (defaults to false)
62 this->colorize =
63 (arguments.size() > 2 && arguments[2] == "true") ? true : false;
64}
65
66
67template <>
68void
69GridFicheraOven<3, 3>::make_grid(Triangulation<3, 3> &triangulation)
70{
71 // Create the initial 2x2x3 subdivided rectangle to be carved
72 Triangulation<3> bulk_tria;
73 std::vector<unsigned int> repetitions = {2, 2, 3};
74 GridGenerator::subdivided_hyper_rectangle(bulk_tria,
75 repetitions,
77 top_right);
78
79 // Compute the dimensions of the box for later use in cell removal
80 const Tensor<1, 3> dimensions = top_right - bottom_left;
81
82 // Remove cells to create the staircase geometry
83 std::set<Triangulation<3>::active_cell_iterator> cells_to_remove;
84 for (const auto &cell : bulk_tria.active_cell_iterators())
85 {
86 const Point<3> cell_center = cell->center();
87
88 // Remove cells in the (+x, +y) quadrant above z > 1/3 height
89 if ((cell_center[0] > dimensions[0] / 2) &&
90 (cell_center[1] > dimensions[1] / 2) &&
91 (cell_center[2] > dimensions[2] / 3))
92 {
93 cells_to_remove.insert(cell);
94 }
95 // Remove cells in the (+x, -y) above z > 2/3 height
96 if ((cell_center[0] > dimensions[0] / 2) &&
97 (cell_center[1] < dimensions[1] / 2) &&
98 (cell_center[2] > 2. * dimensions[2] / 3))
99 {
100 cells_to_remove.insert(cell);
101 }
102 // Remove cells in the (-x, +y) above z > 2/3 height
103 if ((cell_center[0] < dimensions[0] / 2) &&
104 (cell_center[1] > dimensions[1] / 2) &&
105 (cell_center[2] > 2. * dimensions[2] / 3))
106 {
107 cells_to_remove.insert(cell);
108 }
109 }
110
111 // Create the oven
112 GridGenerator::create_triangulation_with_removed_cells(bulk_tria,
113 cells_to_remove,
114 triangulation);
115
116 // Colorize the inlet. For this geometry, the top face of the remaining
117 // staircase (z = top_right[2]) is chosen as the inlet and assigned
118 // boundary_id = 1 for the waveguide problem the Fichera oven is used for; all
119 // other faces keep the default boundary_id = 0. The top face is identified by
120 // checking if the z-coordinate of the face center is close to top_right[2].
121 if (colorize)
122 {
123 for (const auto &face : triangulation.active_face_iterators())
124 if (face->at_boundary())
125 {
126 const Point<3> face_center = face->center();
127 if (std::abs(face_center[2] - dimensions[2]) < 1e-12)
128 face->set_boundary_id(1);
129 }
130 }
131}
132
133// Fallback make_grid definition for unsupported template parameters. This
134// provides a linker-visible symbol and a clear runtime error when the
135// class is instantiated for dim/spacedim combinations that are not
136// specialized above.
137template <int dim, int spacedim>
138void
140 Triangulation<dim, spacedim> & /*triangulation*/)
141{
142 AssertThrow(
143 false,
144 ExcMessage(
145 "GridFicheraOven is only supported for dim = 3 ,spacedim = 3 specializations."));
146}
147
148// Explicit template instantiations
149template class GridFicheraOven<2, 2>;
150template class GridFicheraOven<2, 3>;
151template class GridFicheraOven<3, 3>;
Generates a 3D Fichera oven mesh by removing cells from a subdivided hyper-rectangle.
Point< dim > bottom_left
GridFicheraOven(const std::string &grid_arguments)
Constructor that parses geometry parameters from a colon-separated string.
std::string grid_arguments
void make_grid(Triangulation< dim, spacedim > &triangulation)
Generate the Fichera oven mesh by removing cells from a subdivided hyper-rectangle.
Point< dim > top_right