Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
manifolds.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_manifolds_h
5#define lethe_manifolds_h
6
7#include <core/utilities.h>
8
9#include <deal.II/base/parameter_handler.h>
10
11#include <deal.II/distributed/tria_base.h>
12
13#include <deal.II/numerics/data_postprocessor.h>
14
15using namespace dealii;
16
17namespace Parameters
18{
19 /**
20 * @brief Manifolds - This class manages attaching manifolds to
21 * faces when a manual attachment is required (for example if the mesh
22 * is coming from a GMSH file)
23 */
25 {
26 public:
35
36 // IDs of boundaries to which the manifold will be applied. Each manifold
37 // will be stored with its corresponding boundary ID
38 std::vector<unsigned int> ids;
39
40 // List of boundary type for each number
41 std::vector<ManifoldType> types;
42
43 // Vector containing strings describing the user inserted geometrical
44 // characteristics of the manifolds
45 std::vector<std::string> manifold_point;
46 std::vector<std::string> manifold_direction;
47
48 // File names for cad manifolds
49 std::vector<std::string> cad_files;
50
51 // Scale factors applied to the cad manifolds when they are read
52 std::vector<double> cad_scale_factors;
53
54 // Number of manifolds subsections. Each manifold description (i.e., type
55 // and geometric characteristics) can be associated to more than one
56 // boundary ID. Hence, the total number of individual manifolds should be
57 // accessed through the size of the manifold description vectors (e.g.,
58 // `ids`).
60
61 void
62 parse_boundary(const ParameterHandler &prm);
63
64 /**
65 * @brief Declare the default parameters for one manifold subsection.
66 *
67 * @param[in,out] prm Parameter handler object.
68 * @param[in] i_bc Index of the manifold subsection.
69 */
70 static void
71 declareDefaultEntry(ParameterHandler &prm, unsigned int i_bc);
72
73 /**
74 * @brief Declare the manifold parameters.
75 *
76 * @param[in,out] prm Parameter handler object.
77 * @param[in] subsection_max_size Maximum number of manifold subsections to
78 * declare.
79 */
80 void
81 declare_parameters(ParameterHandler &prm, unsigned int subsection_max_size);
82
83 /**
84 * @brief Parse the manifold parameters.
85 *
86 * @param[in] prm Parameter handler object.
87 */
88 void
89 parse_parameters(ParameterHandler &prm);
90 };
91} // namespace Parameters
92
93/**
94 * @brief BoundaryPostprocessor Post-processor class used to attach the boundary
95 * id to the faces when outputting the surfaces within the domain.
96 */
97template <int dim>
98class BoundaryPostprocessor : public DataPostprocessorScalar<dim>
99{
100public:
102 : DataPostprocessorScalar<dim>("boundary_id", update_quadrature_points)
103 {}
104 virtual void
106 const DataPostprocessorInputs::Vector<dim> &input_data,
107 std::vector<Vector<double>> &computed_quantities) const override
108 {
109 auto current_cell = input_data.template get_cell<dim>();
110
111 for (unsigned int p = 0; p < input_data.evaluation_points.size(); ++p)
112 {
113 unsigned int boundary_id = 0;
114 double min_distance = DBL_MAX;
115
116 for (const auto face : current_cell->face_indices())
117 {
118 if (current_cell->face(face)->at_boundary())
119 {
120 for (const auto vertex :
121 current_cell->face(face)->vertex_indices())
122 {
123 double distance = input_data.evaluation_points[p].distance(
124 current_cell->face(face)->vertex(vertex));
125 if (distance < min_distance)
126 {
127 min_distance = distance;
128
129 boundary_id = current_cell->face(face)->boundary_id();
130 }
131 }
132 }
133 }
134 computed_quantities[p][0] = boundary_id;
135 }
136 };
137
138 virtual void
140 const DataPostprocessorInputs::Scalar<dim> &input_data,
141 std::vector<Vector<double>> &computed_quantities) const override
142 {
143 auto current_cell = input_data.template get_cell<dim>();
144
145 for (unsigned int p = 0; p < input_data.evaluation_points.size(); ++p)
146 {
147 unsigned int boundary_id = 0;
148 double min_distance = DBL_MAX;
149
150 for (const auto face : current_cell->face_indices())
151 {
152 if (current_cell->face(face)->at_boundary())
153 {
154 for (const auto vertex :
155 current_cell->face(face)->vertex_indices())
156 {
157 double distance = input_data.evaluation_points[p].distance(
158 current_cell->face(face)->vertex(vertex));
159 if (distance < min_distance)
160 {
161 min_distance = distance;
162
163 boundary_id = current_cell->face(face)->boundary_id();
164 }
165 }
166 }
167 }
168 computed_quantities[p][0] = boundary_id;
169 }
170 }
171};
172
173
174/**
175 * @brief Attaches manifold to boundaries of the triangulation
176 *
177 * @param triangulation The triangulation to manifolds are attached
178 *
179 * @param manifolds The information about the type of manifolds attached to the faces
180 */
181template <int dim, int spacedim = dim>
182void
184 parallel::DistributedTriangulationBase<dim, spacedim> &triangulation,
185 const Parameters::Manifolds manifolds);
186
187/**
188 * @brief Attaches CAD manifolds using IGES or STEP files to boundaries of the
189 * triangulation. This function attaches a CAD manifold to the faces of a
190 * triangulation. Note that this only works in 3D.
191 *
192 * @param triangulation The triangulation to manifolds are attached
193 *
194 * @param cad_name Filename of the cad file
195 *
196 * @param manifold_id Identifier of the manifold
197 *
198 * @param cad_type Type of the CAD file (ManifoldType::iges or
199 * ManifoldType::step)
200 *
201 * @param cad_scale_factor Scale factor applied to the CAD geometry once read.
202 * OpenCASCADE reads CAD files in millimeters, hence 1e-3 yields meters.
203 */
204void
205attach_cad_to_manifold(parallel::DistributedTriangulationBase<2> &triangulation,
206 const std::string &cad_name,
207 const unsigned int manifold_id,
209 const double cad_scale_factor);
210
211void
213 parallel::DistributedTriangulationBase<2, 3> &triangulation,
214 const std::string &cad_name,
215 const unsigned int manifold_id,
217 const double cad_scale_factor);
218
219void
220attach_cad_to_manifold(parallel::DistributedTriangulationBase<3> &triangulation,
221 const std::string &cad_name,
222 const unsigned int manifold_id,
224 const double cad_scale_factor);
225
226
227
228#endif
virtual void evaluate_vector_field(const DataPostprocessorInputs::Vector< dim > &input_data, std::vector< Vector< double > > &computed_quantities) const override
Definition manifolds.h:105
virtual void evaluate_scalar_field(const DataPostprocessorInputs::Scalar< dim > &input_data, std::vector< Vector< double > > &computed_quantities) const override
Definition manifolds.h:139
Manifolds - This class manages attaching manifolds to faces when a manual attachment is required (for...
Definition manifolds.h:25
void parse_boundary(const ParameterHandler &prm)
Definition manifolds.cc:52
void declare_parameters(ParameterHandler &prm, unsigned int subsection_max_size)
Declare the manifold parameters.
Definition manifolds.cc:71
std::vector< unsigned int > ids
Definition manifolds.h:38
std::vector< std::string > cad_files
Definition manifolds.h:49
static void declareDefaultEntry(ParameterHandler &prm, unsigned int i_bc)
Declare the default parameters for one manifold subsection.
Definition manifolds.cc:17
std::vector< ManifoldType > types
Definition manifolds.h:41
std::vector< std::string > manifold_direction
Definition manifolds.h:46
unsigned int number_of_manifolds_subsections
Definition manifolds.h:59
std::vector< double > cad_scale_factors
Definition manifolds.h:52
std::vector< std::string > manifold_point
Definition manifolds.h:45
void parse_parameters(ParameterHandler &prm)
Parse the manifold parameters.
Definition manifolds.cc:91
void attach_cad_to_manifold(parallel::DistributedTriangulationBase< 2 > &triangulation, const std::string &cad_name, const unsigned int manifold_id, const Parameters::Manifolds::ManifoldType cad_type, const double cad_scale_factor)
Attaches CAD manifolds using IGES or STEP files to boundaries of the triangulation....
Definition manifolds.cc:168
void attach_manifolds_to_triangulation(parallel::DistributedTriangulationBase< dim, spacedim > &triangulation, const Parameters::Manifolds manifolds)
Attaches manifold to boundaries of the triangulation.
Definition manifolds.cc:110