Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
grid_uniform_channel_with_meshed_cylinder.h
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
4#ifndef lethe_grid_uniform_channel_with_meshed_cylinder_h
5#define lethe_grid_uniform_channel_with_meshed_cylinder_h
6
7#include <deal.II/base/utilities.h>
8
9#include <deal.II/grid/grid_tools.h>
10#include <deal.II/grid/manifold_lib.h>
11
12#include <sstream>
13
14using namespace dealii;
15
16/**
17 * @brief Generates a rectangular channel mesh with a meshed cylinder
18 * obstacle. By default, this geometry defines two material IDs. The
19 * obstacle is assigned the material_id = 1 and the remaining domain is
20 * assigned material_id = 0. The obstacle can be optionally removed by setting @p mesh_obstacle to false, in which case the entire domain is assigned material_id = 0.
21 *
22 * The mesh consists of three concentric regions around the cylinder:
23 * -# An inner balanced disk of radius @p inner_radius (hyper_ball_balanced).
24 * -# A transition shell between @p inner_radius and @p outer_radius, whose
25 * diagonal vertices are adjusted to form a square.
26 * -# Rectangular padding regions that fill the gap between the transition
27 * square and the channel boundary defined by @p bottom_left / @p top_right.
28 *
29 * The number of subdivisions in each padding direction (bottom, top, left,
30 * right) can be controlled independently. In 3D, the 2D cross-section is
31 * extruded along the z-axis with a configurable height and number of slices.
32 * The slices refer to the number of layers in the z direction, so the total
33 * number of cells in the z direction will be n_slices - 1. It follows that the
34 * minimum number of slices is 2, which corresponds to a single layer of cells
35 * in the z direction. Note that it is always assumed that the channel bottom is
36 * at z=0 and the channel top is at z=height.
37 *
38 * The manifold objects attached for proper mesh refinement are:
39 * - PolarManifold (2D) or CylindricalManifold (3D) on the inner cylinder
40 * boundary faces (manifold_id = 1).
41 * - TransfiniteInterpolationManifold on the remaining domain (manifold_id = 0).
42 */
43template <int dim, int spacedim>
45{
46public:
47 /**
48 * @brief Constructor that parses geometry parameters from a colon-separated
49 * string.
50 *
51 * @param[in] grid_arguments A colon-separated string with the following
52 * fields (coordinates are comma-separated):
53 *
54 * | # | Field | Format | Required | Description |
55 * |----|--------------|------------|----------|----------------------------------------------------|
56 * | 0 | bottom_left | x,y | yes | Bottom-left corner of the channel before extrusion |
57 * | 1 | top_right | x,y | yes | Top-right corner of the channel before extrusion |
58 * | 2 | center | x,y | yes | Center of the cylinder |
59 * | 3 | inner_radius | double | yes | Radius of the cylinder |
60 * | 4 | outer_radius | double | yes | Radius of the transition region |
61 * | 5 | pad_bottom | int | no | N cells below the transition (default: 0) |
62 * | 6 | pad_top | int | no | N cells above the transition (default: 0) |
63 * | 7 | pad_left | int | no | N cells left of the transition (default: 0) |
64 * | 8 | pad_right | int | no | N cells right of the transition (default: 0) |
65 * | 9 | height | double | no | Extrusion height in z, 3D only (default: 1.0) |
66 * | 10 | n_slices | int | no | Number of z-layers, 3D only (default and min: 2) |
67 * | 11 | use_transfinite_region | true/false | no | Use transfinite interpolation (default: false) |
68 * | 12 | mesh_obstacle| true/false | no | Keep obstacle meshed (default: false) |
69 * | 13 | colorize | true/false | no | Assign distinct boundary IDs (default: false) |
70 *
71 * Example: @code "0,0 : 10,2 : 5,1 : 0.1 : 0.3 : 2 : 2 : 5 : 5 : 2. : 2 :
72 * true : true : true"
73 * @endcode
74 *
75 * When @p colorize is true and @p mesh_obstacle is true, boundary IDs follow
76 * the subdivided_hyper_rectangle convention: 0 (-x), 1 (+x), 2 (-y), 3 (+y).
77 * In 3D, the extruded bottom (z=0) gets id 4 and top (z=height) gets id 5.
78 * When @p mesh_obstacle is false, boundary id 0 is used for the obstacle
79 * boundary, and the channel boundaries are 1 (-x), 2 (+x), 3 (-y), 4 (+y).
80 * In 3D, the extruded bottom (z=0) gets id 5 and top (z=height) gets id 6.
81 */
82 GridUniformChannelWithMeshedCylinder(const std::string &grid_arguments);
83
84 /**
85 * @brief Generate the 2D or 3D channel mesh with a meshed cylinder and attach
86 * manifold objects for proper mesh refinement.
87 *
88 * For 2D: Delegates geometry construction to generate_2d_channel_mesh(), then
89 * attaches:
90 * - PolarManifold on the inner-cylinder boundary faces (manifold_id = 1).
91 * - TransfiniteInterpolationManifold on the remaining domain (manifold_id =
92 * 0).
93 * The boundary IDs are assigned following the subdivided_hyper_rectangle
94 * convention when colorize is enabled: 0 (-x), 1 (+x), 2 (-y), 3 (+y). When
95 * mesh_obstacle is false, boundary id 0 is used for the obstacle boundary
96 * and the channel boundaries are 1 (-x), 2 (+x), 3 (-y), 4 (+y).
97 *
98 * For 3D: Delegates geometry construction to generate_2d_channel_mesh(), then
99 * extrudes the mesh along the z-axis and attaches:
100 * - CylindricalManifold on the cylinder surface (manifold_id = 1).
101 * - TransfiniteInterpolationManifold on the remaining domain (manifold_id =
102 * 0). The lateral boundary IDs are inherited from the 2D mesh when colorize
103 * is enabled. When mesh_obstacle is true, the extruded bottom (z = 0) gets
104 * boundary_id = 4 and the top (z = height) gets boundary_id = 5. When
105 * mesh_obstacle is false, the extruded bottom (z = 0) gets boundary_id = 5
106 * and the top (z = height) gets boundary_id = 6.
107 *
108 * @param[out] triangulation The triangulation to fill with the channel mesh.
109 */
110 void
111 make_grid(Triangulation<dim, spacedim> &triangulation);
112
113private:
114 /**
115 * @brief Generate the 2D channel mesh geometry with a meshed cylinder.
116 *
117 * This private helper creates the composite 2D triangulation by merging:
118 * - A balanced disk of radius @p inner_radius (the cylinder cross-section).
119 * - A hyper_shell transition region with squared diagonal vertices between
120 * @p inner_radius and @p outer_radius.
121 * - Up to 8 rectangular padding sub-meshes filling the gap between the
122 * transition square and the channel boundary.
123 *
124 * Manifold integer IDs are assigned (0 = TFI, 1 = polar) but no manifold
125 * objects are attached — the caller must do that after this function returns.
126 *
127 * If @p colorize is true, boundary IDs are set following the
128 * subdivided_hyper_rectangle convention: 0 (-x), 1 (+x), 2 (-y), 3 (+y). When
129 * mesh_obstacle is false, boundary id 0 is used for the obstacle boundary and
130 * the channel boundaries are 1 (-x), 2 (+x), 3 (-y), 4 (+y).
131 *
132 * @param[out] triangulation The triangulation to fill.
133 * @param[in] bottom_left Bottom-left corner of the channel.
134 * @param[in] top_right Top-right corner of the channel.
135 * @param[in] center Center of the cylinder.
136 * @param[in] inner_radius Radius of the inner cylinder.
137 * @param[in] outer_radius Radius of the transition region.
138 * @param[in] pad_bottom Number of subdivisions in the bottom padding.
139 * @param[in] pad_top Number of subdivisions in the top padding.
140 * @param[in] pad_left Number of subdivisions in the left padding.
141 * @param[in] pad_right Number of subdivisions in the right padding.
142 * @param[in] colorize Whether to assign distinct boundary IDs.
143 */
144 void
145 generate_2d_channel_mesh(Triangulation<2> &triangulation,
146 const Point<2> &bottom_left,
147 const Point<2> &top_right,
148 const Point<2> &center,
149 const double inner_radius,
150 const double outer_radius,
151 const unsigned int pad_bottom,
152 const unsigned int pad_top,
153 const unsigned int pad_left,
154 const unsigned int pad_right,
155 const bool colorize);
157 /// Point that define the bottom-left of the channel in the xy-plane.
158 Point<dim> bottom_left;
159 /// Point that define the top-right of the channel in the xy-plane.
160 Point<dim> top_right;
161 /// Point that define the center of the cylinder in the xy-plane.
162 Point<dim> center;
163 /// Radius of the cylinder.
165 /// Radius of the transition region between the cylinder and the channel.
166 double outer_radius;
167 /// Number of additional cells to be added to pad the channel from center -
168 /// inner_radius - outer_radius to the channel bottom boundary (-y direction).
169 unsigned int pad_bottom;
170 /// Number of additional cells to be added to pad the channel from center +
171 /// inner_radius + outer_radius to the channel top boundary (+y direction).
172 unsigned int pad_top;
173 /// Number of additional cells to be added to pad the channel from center -
174 /// inner_radius - outer_radius to the channel left boundary (-x direction).
175 unsigned int pad_left;
176 /// Number of additional cells to be added to pad the channel from center +
177 /// inner_radius + outer_radius to the channel right boundary (+x direction).
178 unsigned int pad_right;
179 /// Extrusion height in the z direction, 3D only.
180 double height;
181 /// Number of layers in the z direction, 3D only. Minimum is 2, which
182 /// corresponds to a single layer of cells in the z direction.
183 unsigned int n_slices;
184 /// Whether to use transfinite interpolation for the transition region between
185 /// the cylinder and the channel.
187 /// Whether to keep the obstacle mesh (false removes the cylinder cells from
188 /// the cylinder).
189 bool mesh_obstacle;
190 /// Whether to assign distinct boundary IDs to the channel boundaries
191 /// following the subdivided_hyper_rectangle convention.
192 bool colorize;
193};
194
195
196
197#endif
void make_grid(Triangulation< dim, spacedim > &triangulation)
Generate the 2D or 3D channel mesh with a meshed cylinder and attach manifold objects for proper mesh...
Point< dim > center
Point that define the center of the cylinder in the xy-plane.
Point< dim > top_right
Point that define the top-right of the channel in the xy-plane.
Point< dim > bottom_left
Point that define the bottom-left of the channel in the xy-plane.
double outer_radius
Radius of the transition region between the cylinder and the channel.
GridUniformChannelWithMeshedCylinder(const std::string &grid_arguments)
Constructor that parses geometry parameters from a colon-separated string.
void generate_2d_channel_mesh(Triangulation< 2 > &triangulation, const Point< 2 > &bottom_left, const Point< 2 > &top_right, const Point< 2 > &center, const double inner_radius, const double outer_radius, const unsigned int pad_bottom, const unsigned int pad_top, const unsigned int pad_left, const unsigned int pad_right, const bool colorize)
Generate the 2D channel mesh geometry with a meshed cylinder.
double height
Extrusion height in the z direction, 3D only.