Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
grid_uniform_channel_with_meshed_square_prism.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_square_prism_h
5#define lethe_grid_uniform_channel_with_meshed_square_prism_h
6
7#include <deal.II/base/point.h>
8#include <deal.II/base/utilities.h>
9
10#include <deal.II/grid/tria.h>
11
12#include <cmath>
13#include <sstream>
14
15using namespace dealii;
16
17/**
18 * @brief Generates a rectangular channel mesh with a meshed square obstacle
19 * in 2D (extruded to a square prism in 3D). By default, this geometry defines
20 * two material IDs. The obstacle is assigned the material_id = 1 and the
21 * remaining domain is assigned material_id = 0.
22 *
23 * The mesh consists of three nested regions around the obstacle center:
24 * - An inner square of half-side @p inner_half_side (material_id = 1).
25 * - A transition ring between @p inner_half_side and @p outer_half_side.
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 */
39template <int dim, int spacedim>
41{
42public:
43 /**
44 * @brief Constructor that parses geometry parameters from a colon-separated
45 * string.
46 *
47 * @param[in] grid_arguments A colon-separated string with the following
48 * fields (coordinates are comma-separated):
49 *
50 * | # | Field | Format | Required | Description |
51 * |----|-----------------|------------|----------|----------------------------------------------------------------------|
52 * | 0 | bottom_left | x,y | yes | Bottom-left corner of the channel before extrusion |
53 * | 1 | top_right | x,y | yes | Top-right corner of the channel before extrusion |
54 * | 2 | center | x,y | yes | Center of the square obstacle |
55 * | 3 | inner_half_side | double | yes | Half-side of the inner square obstacle |
56 * | 4 | outer_half_side | double | yes | Half-side of the outer transition square |
57 * | 5 | rotation_deg | double | no | In-plane rotation (degrees) applied to the inner region (default: 0) |
58 * | 6 | pad_bottom | int | no | N cells below the transition (default: 0) |
59 * | 7 | pad_top | int | no | N cells above the transition (default: 0) |
60 * | 8 | pad_left | int | no | N cells left of the transition (default: 0) |
61 * | 9 | pad_right | int | no | N cells right of the transition (default: 0) |
62 * | 10 | height | double | no | Extrusion height in z, 3D only (default: 1.0) |
63 * | 11 | n_slices | int | no | Number of z-layers, 3D only (default and min: 2) |
64 * | 12 | mesh_obstacle | true/false | no | Whether to mesh the inner square obstacle (default: false) |
65 * | 13 | colorize | true/false | no | Assign distinct boundary IDs (default: false) |
66 *
67 * Example: @code "0,0 : 10,2 : 5,1 : 0.1 : 0.3 : 15 : 2 : 2 : 5 : 5 : 2. : 2
68 * : false: true "
69 * @endcode
70 *
71 * When @p colorize is true, boundary IDs follow the
72 * subdivided_hyper_rectangle convention: 0 (-x), 1 (+x), 2 (-y), 3 (+y).
73 * In 3D, the extruded bottom (z=0) gets id 4 and top (z=height) gets id 5.
74 */
75 GridUniformChannelWithMeshedSquarePrism(const std::string &grid_arguments);
76
77 /**
78 * @brief Generate the 2D/3D channel mesh with a meshed square obstacle.
79 *
80 * For 2D: Delegates geometry construction to generate_2d_channel_mesh().
81 * The boundary IDs are assigned following the subdivided_hyper_rectangle
82 * convention when colorize is enabled: 0 (-x), 1 (+x), 2 (-y), 3 (+y).
83 *
84 * For 3D: Delegates geometry construction to generate_2d_channel_mesh(), then
85 * extrudes the mesh along the z-axis and attaches the new boundary IDs. The
86 * lateral boundary IDs are inherited from the 2D mesh when colorize is
87 * enabled. The extruded bottom (z = 0) gets boundary_id = 4 and the top (z =
88 * height) gets boundary_id = 5.
89 *
90 * @param[out] triangulation The triangulation to fill with the channel mesh.
91 */
92 void
93 make_grid(Triangulation<dim, spacedim> &triangulation);
94
95private:
96 /**
97 * @brief Generate the 2D channel mesh geometry with a meshed square obstacle.
98 *
99 * This private helper creates the composite 2D triangulation by merging:
100 * - A modified hyper_ball_balanced from deal.ii so the inner vertex are
101 * placed to form the inner square of half-side @p inner_half_side and the
102 * outer vertices are placed to form the outer square of half-side
103 * @p outer_half_side. When rotated, the inner vertices are rotated by
104 * @p inner_rotation_angle while only half of the outer vertices are rotated
105 * and projected to the closest point on the outer square. The other half
106 * are attached to the outer square corners. The choice of which outer
107 * vertices are rotated and which are attached to the corners is made on a
108 * closest-angle basis to minimize the distortion of the transition cells.
109 * - Up to 8 rectangular padding sub-meshes filling the gap between the
110 * transition square and the channel boundary. Those are set up in a way
111 * that their vertices line up with the vertices projected from the
112 * transition region to avoid the need of introducing new vertices when
113 * merging the triangulations.
114 *
115 * Material IDs are assigned as follows: 1 for the inner obstacle and 0 for
116 * the rest of the channel.
117 *
118 * If @p colorize is true, boundary IDs are set following the
119 * subdivided_hyper_rectangle convention: 0 (-x), 1 (+x), 2 (-y), 3 (+y).
120 *
121 * @param[out] triangulation The triangulation to fill.
122 * @param[in] bottom_left Bottom-left corner of the channel.
123 * @param[in] top_right Top-right corner of the channel.
124 * @param[in] center Center of the square obstacle.
125 * @param[in] inner_half_side Half-side of the inner square obstacle.
126 * @param[in] outer_half_side Half-side of the outer transition square.
127 * @param[in] inner_rotation_angle In-plane rotation angle in degrees.
128 * @param[in] pad_bottom Number of subdivisions in the bottom padding.
129 * @param[in] pad_top Number of subdivisions in the top padding.
130 * @param[in] pad_left Number of subdivisions in the left padding.
131 * @param[in] pad_right Number of subdivisions in the right padding.
132 * @param[in] mesh_obstacle Whether to mesh the inner square obstacle or
133 * leave it as a hole.
134 * @param[in] colorize Whether to assign distinct boundary IDs.
135 */
136 void
137 generate_2d_channel_mesh(Triangulation<2> &triangulation,
138 const Point<2> &bottom_left,
139 const Point<2> &top_right,
140 const Point<2> &center,
141 const double inner_half_side,
142 const double outer_half_side,
143 const double inner_rotation_angle,
144 const unsigned int pad_bottom,
145 const unsigned int pad_top,
146 const unsigned int pad_left,
147 const unsigned int pad_right,
148 const bool colorize);
150 /// Point that define the bottom-left of the channel in the xy-plane.
151 Point<dim> bottom_left;
152 /// Point that define the top-right of the channel in the xy-plane.
153 Point<dim> top_right;
154 /// Point that define the center of the obstacle in the xy-plane.
155 Point<dim> center;
156 /// Half-side of the inner square obstacle.
158 /// Half-side of the outer transition square.
160 /// In-plane rotation angle in radians applied to the inner mesh pattern.
162 /// Number of additional cells to be added to pad the channel from center -
163 /// inner_half_side - outer_half_side to the channel bottom boundary (-y
164 /// direction).
165 unsigned int pad_bottom;
166 /// Number of additional cells to be added to pad the channel from center +
167 /// inner_half_side + outer_half_side to the channel top boundary (+y
168 /// direction).
169 unsigned int pad_top;
170 /// Number of additional cells to be added to pad the channel from center -
171 /// inner_half_side - outer_half_side to the channel left boundary (-x
172 /// direction).
173 unsigned int pad_left;
174 /// Number of additional cells to be added to pad the channel from center +
175 /// inner_half_side + outer_half_side to the channel right boundary (+x
176 /// direction).
177 unsigned int pad_right;
178 /// Extrusion height in the z direction, 3D only.
179 double height;
180 /// Number of layers in the z direction, 3D only. Minimum is 2, which
181 /// corresponds to a single layer of cells in the z direction.
182 unsigned int n_slices;
183 /// Whether to mesh the inner square obstacle or leave it as a hole.
184 bool mesh_obstacle;
185 /// Whether to assign distinct boundary IDs to the channel boundaries
186 /// following the subdivided_hyper_rectangle convention.
187 bool colorize;
188};
189
190
191
192#endif
double inner_rotation_angle
In-plane rotation angle in radians applied to the inner mesh pattern.
double outer_half_side
Half-side of the outer transition square.
double inner_half_side
Half-side of the inner square obstacle.
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_half_side, const double outer_half_side, const double inner_rotation_angle, 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 square obstacle.
Point< dim > bottom_left
Point that define the bottom-left of the channel in the xy-plane.
double height
Extrusion height in the z direction, 3D only.
Point< dim > top_right
Point that define the top-right of the channel in the xy-plane.
void make_grid(Triangulation< dim, spacedim > &triangulation)
Generate the 2D/3D channel mesh with a meshed square obstacle.
bool mesh_obstacle
Whether to mesh the inner square obstacle or leave it as a hole.
GridUniformChannelWithMeshedSquarePrism(const std::string &grid_arguments)
Constructor that parses geometry parameters from a colon-separated string.
Point< dim > center
Point that define the center of the obstacle in the xy-plane.