Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
grid_birmingham_fluidized_bed.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#include <deal.II/grid/grid_tools.h>
8
9template <int dim, int spacedim>
11 const std::string &grid_arguments)
12{
13 if constexpr (!(dim == 3 && spacedim == 3))
14 {
15 AssertThrow(
16 false,
17 ExcMessage(
18 "The Birmingham fluidized bed mesh is only supported in 3D space with 3D elements."));
19 return;
20 }
21
22 this->grid_arguments = grid_arguments;
23
24 AssertThrow(grid_arguments.find(';') == std::string::npos,
25 ExcMessage("The Birmingham fluidized bed grid arguments must be "
26 "separated by colons (:), not semicolons (;)."));
27
28 // Parse optional enable_chimney flag (defaults to true)
29 const std::vector<std::string> arguments =
30 Utilities::split_string_list(grid_arguments, ':');
31
32 this->enable_chimney = !(arguments.size() > 0 && arguments[0] == "false");
33
34 // Parse optional inlet_offset (defaults to 0.0)
35 this->inlet_offset = (arguments.size() > 1) ? std::stod(arguments[1]) : 0.0;
36}
37
38
39template <>
40void
41GridBirminghamFluidizedBed<3, 3>::make_grid(Triangulation<3, 3> &triangulation)
42{
43 const double r_small = 0.154 / 2;
44 const double r_large = 0.254 / 2;
45 const double half_len_bot = 0.924 / 2;
46 const double half_len_cone = 0.285 / 2;
47 const double half_len_top = 0.5 / 2;
48 const double chimney_length = 0.1;
49 const unsigned int n_chimney_refinements = 1;
50 const unsigned int n_axial_bot = 10;
51 const unsigned int n_axial_top = 5;
52 const unsigned int n_axial_chimney = 2;
53 const double tol = 1e-10;
54
55 // ---- 1. Build the cylindrical geometry ----
56
57 // Bottom cylinder (small radius), shifted to [-inlet_offset, 2*half_len_bot].
58 // The offset extends the cylinder into negative x while keeping x = 0 at
59 // the original start of the geometry.
60 const double extended_half_len_bot = half_len_bot + inlet_offset / 2.0;
61 const unsigned int n_axial_bot_total =
62 std::max(1u,
63 static_cast<unsigned int>(
64 std::round(n_axial_bot * (2.0 * half_len_bot + inlet_offset) /
65 (2.0 * half_len_bot))));
66
67 Triangulation<3> tria_bottom;
68 GridGenerator::subdivided_cylinder(tria_bottom,
69 n_axial_bot_total,
70 r_small,
71 extended_half_len_bot);
72 GridTools::shift(Point<3>(half_len_bot - inlet_offset / 2.0, 0, 0),
73 tria_bottom);
74
75 // Truncated cone from r_small to r_large,
76 // shifted to [2*half_len_bot, 2*half_len_bot + 2*half_len_cone]
77 Triangulation<3> tria_cone;
78 GridGenerator::truncated_cone(tria_cone, r_small, r_large, half_len_cone);
79 GridTools::shift(Point<3>(2.0 * half_len_bot + half_len_cone, 0, 0),
80 tria_cone);
81
82 // Top cylinder (large radius),
83 // shifted to [2*half_len_bot + 2*half_len_cone, ...]
84 Triangulation<3> tria_top;
85 GridGenerator::subdivided_cylinder(tria_top,
86 n_axial_top,
87 r_large,
88 half_len_top);
89 GridTools::shift(
90 Point<3>(2.0 * half_len_bot + 2.0 * half_len_cone + half_len_top, 0, 0),
91 tria_top);
92
93 // Length of the cylindrical section (before chimney)
94 const double base_length =
95 2.0 * (half_len_bot + half_len_cone + half_len_top);
96
97 // Merge bottom + cone + top
98 Triangulation<3> tria_temp1;
99 GridGenerator::merge_triangulations(tria_bottom, tria_cone, tria_temp1);
100 Triangulation<3> tria_merged;
101 GridGenerator::merge_triangulations(tria_temp1, tria_top, tria_merged);
102
103 if (enable_chimney)
104 {
105 // ---- 2. Attach manifolds and refine ----
106
107 // Assign manifold IDs to curved surfaces before refining so that new
108 // vertices are placed on the cylindrical/conical surface.
109 for (const auto &cell : tria_merged.active_cell_iterators())
110 {
111 cell->set_manifold_id(0);
112 for (unsigned int f = 0; f < GeometryInfo<3>::faces_per_cell; ++f)
113 {
114 if (!cell->face(f)->at_boundary())
115 continue;
116
117 bool is_end_cap = true;
118 for (unsigned int v = 0; v < GeometryInfo<3>::vertices_per_face;
119 ++v)
120 {
121 const double x = cell->face(f)->vertex(v)[0];
122 if (std::abs(x + inlet_offset) > tol &&
123 std::abs(x - base_length) > tol)
124 {
125 is_end_cap = false;
126 break;
127 }
128 }
129 if (!is_end_cap)
130 {
131 cell->face(f)->set_manifold_id(1);
132 for (unsigned int l = 0; l < GeometryInfo<3>::lines_per_face;
133 ++l)
134 cell->face(f)->line(l)->set_manifold_id(1);
135 }
136 }
137 }
138
139 tria_merged.set_manifold(1, CylindricalManifold<3>(0));
140 tria_merged.set_manifold(0, FlatManifold<3>());
141
142 tria_merged.refine_global(n_chimney_refinements);
143
144 // ---- 3. Flatten the refined mesh ----
145
146 // flatten_triangulation turns every active cell of the refined mesh
147 // into a coarse cell, so the result can be merged with the chimney.
148 Triangulation<3> tria_flat;
149 GridGenerator::flatten_triangulation(tria_merged, tria_flat);
150
151 // ---- 4. Find an off-center face on the top end cap ----
152
153 // Target point in the first shell ring, offset in the +z direction.
154 const Point<3> chimney_target(base_length, 0.0, r_large / 2.0);
155
156 double best_dist_sq = r_large * r_large + 1.0;
157 std::array<Point<3>, 4> best_face_vertices;
158
159 for (const auto &cell : tria_flat.active_cell_iterators())
160 for (unsigned int f = 0; f < GeometryInfo<3>::faces_per_cell; ++f)
161 {
162 if (!cell->face(f)->at_boundary())
163 continue;
164 const auto &face = cell->face(f);
165
166 // Only consider faces on the top end cap (x ≈ base_length)
167 bool on_top_cap = true;
168 for (unsigned int v = 0; v < GeometryInfo<3>::vertices_per_face;
169 ++v)
170 if (std::abs(face->vertex(v)[0] - base_length) > tol)
171 {
172 on_top_cap = false;
173 break;
174 }
175 if (!on_top_cap)
176 continue;
177
178 const Point<3> center = face->center();
179 const double dist_sq = (center - chimney_target).norm_square();
180
181 if (dist_sq < best_dist_sq)
182 {
183 best_dist_sq = dist_sq;
184 for (unsigned int v = 0; v < 4; ++v)
185 best_face_vertices[v] = face->vertex(v);
186 }
187 }
188
189 AssertThrow(best_dist_sq < r_large * r_large,
190 ExcMessage(
191 "Could not find a suitable face on the top end cap "
192 "for the chimney placement."));
193
194 // ---- 5. Build the chimney triangulation ----
195
196 // Sort the four face vertices into (y, z) quadrants relative to the
197 // face center so that the hex vertex ordering
198 // (index = x_bit + 2*y_bit + 4*z_bit) is satisfied.
199 Point<3> face_center;
200 for (const auto &p : best_face_vertices)
201 face_center += p;
202 face_center /= 4.0;
203
204 std::array<Point<3>, 4> sorted_fv;
205 for (const auto &p : best_face_vertices)
206 {
207 unsigned int idx = 0;
208 if (p[1] > face_center[1])
209 idx += 1; // high y -> y_bit = 1
210 if (p[2] > face_center[2])
211 idx += 2; // high z -> z_bit = 1
212 sorted_fv[idx] = p;
213 }
214
215 // Create chimney vertices: (n_axial_chimney + 1) layers of 4
216 // vertices, each layer extruded along the x-axis.
217 const unsigned int n_layers = n_axial_chimney;
218 std::vector<Point<3>> chimney_vertices(4 * (n_layers + 1));
219 for (unsigned int layer = 0; layer <= n_layers; ++layer)
220 {
221 const double dx = chimney_length * layer / n_layers;
222 for (unsigned int v = 0; v < 4; ++v)
223 {
224 chimney_vertices[layer * 4 + v] = sorted_fv[v];
225 chimney_vertices[layer * 4 + v][0] += dx;
226 }
227 }
228
229 // Create chimney hex cells. Each cell spans one layer; the vertex
230 // layout follows deal.II convention
231 // (index = x_bit + 2*y_bit + 4*z_bit).
232 std::vector<CellData<3>> chimney_cells(n_layers);
233 for (unsigned int layer = 0; layer < n_layers; ++layer)
234 {
235 const unsigned int L = layer * 4; // left layer base index
236 const unsigned int R = (layer + 1) * 4; // right layer base index
237 chimney_cells[layer].vertices = {L + 0,
238 R + 0, // hex 0, 1
239 L + 1,
240 R + 1, // hex 2, 3
241 L + 2,
242 R + 2, // hex 4, 5
243 L + 3,
244 R + 3}; // hex 6, 7
245 }
246
247 Triangulation<3> tria_chimney;
248 tria_chimney.create_triangulation(chimney_vertices,
249 chimney_cells,
250 SubCellData());
251
252 // ---- 6. Final merge ----
253
254 GridGenerator::merge_triangulations(tria_flat,
255 tria_chimney,
256 triangulation);
257
258 // ---- 7. Reassign manifold and boundary IDs ----
259
260 // Faces with all vertices at x >= base_length are chimney walls or
261 // the annular top wall; they stay flat. The inlet end cap (x ≈ 0) is
262 // also flat. All other non-end-cap faces are curved and receive
263 // manifold_id 1 (CylindricalManifold).
264 const double total_length = base_length + chimney_length;
265
266 for (const auto &cell : triangulation.active_cell_iterators())
267 {
268 cell->set_manifold_id(0);
269 for (unsigned int f = 0; f < GeometryInfo<3>::faces_per_cell; ++f)
270 {
271 if (!cell->face(f)->at_boundary())
272 continue;
273
274 bool is_inlet = true;
275 bool is_outlet = true;
276 bool at_or_beyond_base = true;
277
278 for (unsigned int v = 0; v < GeometryInfo<3>::vertices_per_face;
279 ++v)
280 {
281 const double x = cell->face(f)->vertex(v)[0];
282 if (std::abs(x + inlet_offset) > tol)
283 is_inlet = false;
284 if (std::abs(x - total_length) > tol)
285 is_outlet = false;
286 if (x < base_length - tol)
287 at_or_beyond_base = false;
288 }
289
290 if (is_inlet)
291 {
292 cell->face(f)->set_boundary_id(1);
293 }
294 else if (is_outlet)
295 {
296 cell->face(f)->set_boundary_id(2);
297 }
298 else if (at_or_beyond_base)
299 {
300 // Chimney lateral walls or annular top wall around the
301 // chimney opening. These are flat surfaces.
302 cell->face(f)->set_boundary_id(0);
303 }
304 else
305 {
306 // Curved lateral surfaces of cylinders and cone
307 cell->face(f)->set_manifold_id(1);
308 for (unsigned int l = 0; l < GeometryInfo<3>::lines_per_face;
309 ++l)
310 cell->face(f)->line(l)->set_manifold_id(1);
311 cell->face(f)->set_boundary_id(0);
312 }
313 }
314 }
315
316 triangulation.set_manifold(1, CylindricalManifold<3>(0));
317 triangulation.set_manifold(0, FlatManifold<3>());
318 }
319 else
320 {
321 // ---- No chimney: simple cylindrical geometry ----
322
323 triangulation.copy_triangulation(tria_merged);
324
325 for (const auto &cell : triangulation.active_cell_iterators())
326 {
327 cell->set_manifold_id(0);
328 for (unsigned int f = 0; f < GeometryInfo<3>::faces_per_cell; ++f)
329 {
330 if (!cell->face(f)->at_boundary())
331 continue;
332
333 bool is_end_cap = true;
334 for (unsigned int v = 0; v < GeometryInfo<3>::vertices_per_face;
335 ++v)
336 {
337 const double x = cell->face(f)->vertex(v)[0];
338 if (std::abs(x + inlet_offset) > tol &&
339 std::abs(x - base_length) > tol)
340 {
341 is_end_cap = false;
342 break;
343 }
344 }
345
346 if (!is_end_cap)
347 {
348 cell->face(f)->set_manifold_id(1);
349 for (unsigned int l = 0; l < GeometryInfo<3>::lines_per_face;
350 ++l)
351 cell->face(f)->line(l)->set_manifold_id(1);
352 cell->face(f)->set_boundary_id(0);
353 }
354 else
355 {
356 const double x = cell->face(f)->center()[0];
357 if (std::abs(x + inlet_offset) < tol)
358 cell->face(f)->set_boundary_id(1);
359 else
360 cell->face(f)->set_boundary_id(2);
361 }
362 }
363 }
364
365 triangulation.set_manifold(1, CylindricalManifold<3>(0));
366 triangulation.set_manifold(0, FlatManifold<3>());
367 }
368}
369
370// Fallback make_grid definition for unsupported template parameters. This
371// provides a linker-visible symbol and a clear runtime error when the
372// class is instantiated for dim/spacedim combinations that are not
373// specialized above.
374template <int dim, int spacedim>
375void
377 Triangulation<dim, spacedim> & /*triangulation*/)
378{
379 AssertThrow(
380 false,
381 ExcMessage(
382 "GridBirminghamFluidizedBed is only implemented for dim = 3 and spacedim = 3."));
383}
384
385// Explicit template instantiations
Generates a 3D mesh for the Birmingham fluidized bed geometry.
GridBirminghamFluidizedBed(const std::string &grid_arguments)
Constructor that parses grid parameters from a colon-separated string.
double inlet_offset
Length by which the bottom cylinder extends into negative x.
std::string grid_arguments
Arguments used to generate the grid.
void make_grid(Triangulation< dim, spacedim > &triangulation)
Generate the Birmingham fluidized bed mesh.
bool enable_chimney
Flag used to indicate if the chimney is added or not to the mesh.