Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
grids.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2020-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#ifndef lethe_grids_h
5#define lethe_grids_h
6
7#include <core/manifolds.h>
8#include <core/parameters.h>
10
11#include <deal.II/distributed/tria_base.h>
12
13using namespace dealii;
14
15/**
16 * @brief Attaches a grid to a triangulation using mesh parameters
17 *
18 * @param[in,out] triangulation The triangulation to which a grid is attached
19 *
20 * @param[in] mesh_parameters The mesh parameters used to decide what type of
21 * mesh or primitive is used
22 */
23template <int dim, int spacedim = dim>
24void
26 Triangulation<dim, spacedim> &triangulation,
27 const Parameters::Mesh<dim, spacedim> &mesh_parameters);
28
29/**
30 * @brief Modifies the triangulation to set up its periodic boundary conditions
31 *
32 * The periodic boundary information is the part of the boundary conditions that
33 * is shared by the CFD and the DEM solvers, so this function is used by both.
34 *
35 * @param[in,out] triangulation The triangulation to which a grid is attached
36 *
37 * @param[in] periodic_boundaries The periodic boundary pairs and their
38 * direction of periodicity. This is used to set up the periodicity of the
39 * domain
40 */
41template <int dim, int spacedim = dim>
42void
44 parallel::DistributedTriangulationBase<dim, spacedim> &triangulation,
45 const Parameters::PeriodicBoundaries &periodic_boundaries);
46
47/**
48 * @brief Completely sets up a mesh and its manifolds.
49 *
50 * This function reads and constructs a mesh according to the given mesh
51 * parameters, sets up manifolds on boundaries, and applies boundary conditions.
52 * It is intended for distributed triangulations.
53 *
54 * @tparam dim The topological dimension of the mesh.
55 * @tparam spacedim The embedding space dimension (default = dim).
56 * @param[in,out] triangulation The triangulation to which the grid will
57 * be attached.
58 * @param[in] mesh_parameters Parameters defining the mesh or primitive
59 * to use.
60 * @param[in] manifolds_parameters Information about the manifolds attached
61 * to boundaries.
62 * @param[in] restart Flag indicating whether this is a
63 * restart.
64 * @param[in] periodic_boundaries The periodic boundary pairs and their
65 * direction of periodicity, used to set up the periodicity of the domain.
66 */
67template <int dim, int spacedim = dim>
68void
70 parallel::DistributedTriangulationBase<dim, spacedim> &triangulation,
71 const Parameters::Mesh<dim, spacedim> &mesh_parameters,
72 const Parameters::Manifolds &manifolds_parameters,
73 bool restart,
74 const Parameters::PeriodicBoundaries &periodic_boundaries);
75
76/**
77 * @brief Completely sets up a mesh and its manifolds for rotor-stator domains.
78 *
79 * The `triangulation` initially contains the stator
80 * triangulation, which is later replaced by the merged rotor-stator
81 * triangulation.
82 *
83 * @tparam dim The topological dimension of the mesh.
84 * @tparam spacedim The embedding space dimension (default = dim).
85 * @param[in,out] triangulation The triangulation to which the grid will
86 * be attached.
87 * @param[in] mesh_parameters Parameters defining the mesh or primitive
88 * to use.
89 * @param[in] manifolds_parameters Information about the manifolds attached
90 * to boundaries.
91 * @param[in] restart Flag indicating whether this is a
92 * restart.
93 * @param[in] periodic_boundaries The periodic boundary pairs and their
94 * direction of periodicity, used to set up the periodicity of the domain.
95 * @param[in] mortar_parameters Parameters controlling the mortar method,
96 * including rotor mesh info.
97 */
98template <int dim, int spacedim = dim>
99void
101 parallel::DistributedTriangulationBase<dim, spacedim> &triangulation,
102 const Parameters::Mesh<dim, spacedim> &mesh_parameters,
103 const Parameters::Manifolds &manifolds_parameters,
104 bool restart,
105 const Parameters::PeriodicBoundaries &periodic_boundaries,
106 const Parameters::Mortar<dim> &mortar_parameters);
107
108/**
109 * @brief Refine a mesh around specific boundary ids
110 *
111 * @param[in] n_refinement The number of times the boundary should be refined
112 *
113 * @param[in] boundary_ids The boundary ids for which the cells should be
114 * refined
115 *
116 * @param[in, out] triangulation The triangulation on which refinement must be
117 * carried out
118 *
119 */
120template <int dim, int spacedim = dim>
121void
123 const std::vector<int> &boundary_ids,
124 const unsigned int n_refinement,
125 parallel::DistributedTriangulationBase<dim, spacedim> &triangulation)
126{
127 // For the amount of refinements required
128 for (unsigned int r = 0; r < n_refinement; ++r)
129 {
130 // Loop over the cells and flag all cells which are within the list of
131 // boundary ids
132 for (const auto &cell : triangulation.active_cell_iterators())
133 {
134 if (cell->is_locally_owned())
135 {
136 for (const auto f : cell->face_indices())
137
138 {
139 if (cell->face(f)->at_boundary())
140 {
141 if (std::find(boundary_ids.begin(),
142 boundary_ids.end(),
143 cell->face(f)->boundary_id()) !=
144 boundary_ids.end())
145 {
146 cell->set_refine_flag();
147 }
148 }
149 }
150 }
151 }
152 triangulation.execute_coarsening_and_refinement();
153 }
154}
155
156/**
157 * @brief Build the triangulation which delimits a mesh refinement box
158 *
159 * The box is described by a full set of mesh parameters, so any mesh type
160 * supported by attach_grid_to_triangulation() can be used to delimit a
161 * refinement region. The initial refinement of the box mesh is applied here, so
162 * the resulting triangulation is ready to be used to flag cells.
163 *
164 * @param[in] box_mesh_parameters The mesh parameters describing the box
165 *
166 * @param[in,out] box_triangulation The triangulation which will hold the box
167 * mesh
168 */
169template <int dim, int spacedim = dim>
170void
172 const Parameters::Mesh<dim, spacedim> &box_mesh_parameters,
173 Triangulation<dim, spacedim> &box_triangulation);
174
175/**
176 * @brief Apply scaling, rotation and translation to the mesh in the listed
177 * order.
178 *
179 * @tparam dim An integer that denotes the dimensionality of the geometry.
180 * @tparam spacedim An integer that denotes the dimension of the space occupied
181 * by the embedded geometry.
182 *
183 * @param[in] mesh_parameters Parameters of the mesh.
184 * @param[in, out] triangulation Triangulation object on which the mesh
185 * transformations are applied.
186 */
187template <int dim, int spacedim = dim>
188void
190 const Parameters::Mesh<dim, spacedim> &mesh_parameters,
191 Triangulation<dim, spacedim> &triangulation);
192
193#endif
Manifolds - This class manages attaching manifolds to faces when a manual attachment is required (for...
Definition manifolds.h:25
Mesh - Parameters that control mesh reading and mesh generation.
void read_mesh_and_manifolds_for_stator_and_rotor(parallel::DistributedTriangulationBase< dim, spacedim > &triangulation, const Parameters::Mesh< dim, spacedim > &mesh_parameters, const Parameters::Manifolds &manifolds_parameters, bool restart, const Parameters::PeriodicBoundaries &periodic_boundaries, const Parameters::Mortar< dim > &mortar_parameters)
Completely sets up a mesh and its manifolds for rotor-stator domains.
Definition grids.cc:501
void setup_periodic_boundary_conditions(parallel::DistributedTriangulationBase< dim, spacedim > &triangulation, const Parameters::PeriodicBoundaries &periodic_boundaries)
Modifies the triangulation to set up its periodic boundary conditions.
Definition grids.cc:367
void apply_mesh_transformation(const Parameters::Mesh< dim, spacedim > &mesh_parameters, Triangulation< dim, spacedim > &triangulation)
Apply scaling, rotation and translation to the mesh in the listed order.
Definition grids.cc:728
void attach_grid_to_triangulation(Triangulation< dim, spacedim > &triangulation, const Parameters::Mesh< dim, spacedim > &mesh_parameters)
Attaches a grid to a triangulation using mesh parameters.
Definition grids.cc:96
void refine_triangulation_at_boundaries(const std::vector< int > &boundary_ids, const unsigned int n_refinement, parallel::DistributedTriangulationBase< dim, spacedim > &triangulation)
Refine a mesh around specific boundary ids.
Definition grids.h:122
void build_refinement_box_triangulation(const Parameters::Mesh< dim, spacedim > &box_mesh_parameters, Triangulation< dim, spacedim > &box_triangulation)
Build the triangulation which delimits a mesh refinement box.
Definition grids.cc:712
void read_mesh_and_manifolds(parallel::DistributedTriangulationBase< dim, spacedim > &triangulation, const Parameters::Mesh< dim, spacedim > &mesh_parameters, const Parameters::Manifolds &manifolds_parameters, bool restart, const Parameters::PeriodicBoundaries &periodic_boundaries)
Completely sets up a mesh and its manifolds.
Definition grids.cc:447
std::map< dealii::types::boundary_id, PeriodicBoundary > PeriodicBoundaries
The periodic boundary pairs of a simulation, keyed by the principal (first) boundary id of each pair.
Mortar - Defines parameters used to construct mortar elements.