Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
manifolds.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2019-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#include <core/manifolds.h>
5#include <core/utilities.h>
6
7#include <deal.II/base/point.h>
8
9#include <deal.II/grid/manifold_lib.h>
10
11#include <deal.II/opencascade/manifold_lib.h>
12#include <deal.II/opencascade/utilities.h>
13
14namespace Parameters
15{
16 void
17 Manifolds::declareDefaultEntry(ParameterHandler &prm, const unsigned int i_bc)
18 {
20 "type",
22 "Type of manifold description.");
23
24 prm.declare_entry(
25 "id",
26 Utilities::int_to_string(i_bc, 2),
27 Patterns::List(Patterns::Integer()),
28 "IDs of boundaries to which the manifold will be applied");
29
30 prm.declare_entry("cad file",
31 "none",
32 Patterns::FileName(),
33 "CAD file name (IGES or STEP)");
34 prm.declare_entry(
35 "cad scale factor",
36 "1e-3",
37 Patterns::Double(),
38 "Scale factor applied to the CAD file once read. OpenCASCADE reads CAD "
39 "files in millimeters, so the default (1e-3) yields meters");
40 prm.declare_entry(
41 "point coordinates",
42 "0,0,0",
43 Patterns::List(Patterns::Double()),
44 "Point coordinates describing the spherical or cylindrical manifold");
45 prm.declare_entry("direction vector",
46 "0,1,0",
47 Patterns::List(Patterns::Double()),
48 "Central axis describing the cylindrical manifold");
49 }
50
51 void
52 Manifolds::parse_boundary(const ParameterHandler &prm)
53 {
54 // Parse the list of boundary IDs for the current manifold type
55 std::vector<unsigned int> ids_current =
57
58 for (const unsigned int id : ids_current)
59 {
60 this->types.emplace_back(string_to_enum<ManifoldType>(prm.get("type")));
61 this->ids.emplace_back(id);
62 this->manifold_point.emplace_back(prm.get("point coordinates"));
63 this->manifold_direction.emplace_back(prm.get("direction vector"));
64 this->cad_files.emplace_back(prm.get("cad file"));
65 this->cad_scale_factors.emplace_back(
66 prm.get_double("cad scale factor"));
67 }
68 }
69
70 void
71 Manifolds::declare_parameters(ParameterHandler &prm,
72 unsigned int subsection_max_size)
73 {
74 prm.enter_subsection("manifolds");
75 {
76 prm.declare_entry("number",
77 "0",
78 Patterns::Integer(),
79 "Number of manifolds");
80 for (unsigned int i = 0; i < subsection_max_size; i++)
81 {
82 prm.enter_subsection("manifold " + Utilities::int_to_string(i));
83 declareDefaultEntry(prm, i);
84 prm.leave_subsection();
85 }
86 }
87 prm.leave_subsection();
88 }
89
90 void
91 Manifolds::parse_parameters(ParameterHandler &prm)
92 {
93 prm.enter_subsection("manifolds");
94 {
95 this->number_of_manifolds_subsections = prm.get_integer("number");
96
97 for (unsigned int i = 0; i < this->number_of_manifolds_subsections; i++)
98 {
99 prm.enter_subsection("manifold " + Utilities::int_to_string(i));
100 parse_boundary(prm);
101 prm.leave_subsection();
102 }
103 }
104 prm.leave_subsection();
105 }
106} // namespace Parameters
107
108template <int dim, int spacedim>
109void
111 parallel::DistributedTriangulationBase<dim, spacedim> &triangulation,
112 Parameters::Manifolds manifolds)
113{
114 for (unsigned int i = 0; i < manifolds.types.size(); ++i)
115 {
117 {
118 // Create a point using the parameter file input
119 Point<spacedim> circle_center(
121
122 SphericalManifold<dim, spacedim> manifold_description(circle_center);
123 triangulation.set_manifold(manifolds.ids[i], manifold_description);
124 }
125 else if (manifolds.types[i] ==
127 {
128 if constexpr (spacedim == 3)
129 {
130 // Create a point using the parameter file input
131 Point<spacedim> point_on_axis(
133
134 // Create a tensor representing the direction of the length of the
135 // cylinder
136 Tensor<1, spacedim> cylinder_axis(
138 manifolds.manifold_direction[i]));
139
140 CylindricalManifold<dim, spacedim> manifold_description(
141 cylinder_axis, point_on_axis);
142 triangulation.set_manifold(manifolds.ids[i],
143 manifold_description);
144 }
145 else
146 throw std::runtime_error(
147 "Cylindrical manifolds are not supported in 2D");
148 }
149 else if (manifolds.types[i] ==
152 {
153 attach_cad_to_manifold(triangulation,
154 manifolds.cad_files[i],
155 manifolds.ids[i],
156 manifolds.types[i],
157 manifolds.cad_scale_factors[i]);
158 }
159 else if (manifolds.types[i] == Parameters::Manifolds::ManifoldType::none)
160 {
161 }
162 else
163 throw std::runtime_error("Unsupported manifolds type");
164 }
165}
166
167void
168attach_cad_to_manifold(parallel::DistributedTriangulationBase<2> &,
169 const std::string &,
170 const unsigned int,
172 const double)
173{
174 throw std::runtime_error("CAD manifolds are not supported in 2D");
175}
176
177void
178attach_cad_to_manifold(parallel::DistributedTriangulationBase<2, 3> &,
179 const std::string &,
180 const unsigned int,
182 const double)
183{
184 throw std::runtime_error("CAD manifolds are not supported in 2D/3D");
185}
186
187#ifdef DEAL_II_WITH_OPENCASCADE
188void
189attach_cad_to_manifold(parallel::DistributedTriangulationBase<3> &triangulation,
190 const std::string &cad_name,
191 const unsigned int manifold_id,
193 const double cad_scale_factor)
194{
195 TopoDS_Shape cad_surface =
197 OpenCASCADE::read_STEP(cad_name, cad_scale_factor) :
198 OpenCASCADE::read_IGES(cad_name, cad_scale_factor);
199
200 // Enforce manifold over boundary ID
201 for (const auto &cell : triangulation.active_cell_iterators())
202 {
203 for (const auto &face : cell->face_iterators())
204 {
205 if (face->boundary_id() == manifold_id)
206 {
207 face->set_all_manifold_ids(manifold_id);
208 }
209 }
210 }
211
212 // Define tolerance for interpretation of CAD file
213 const double tolerance = OpenCASCADE::get_shape_tolerance(cad_surface) * 5;
214
215 // OpenCASCADE::NormalProjectionManifold<3,3> normal_projector(
216 // cad_surface, tolerance);
217 OpenCASCADE::NormalToMeshProjectionManifold<3, 3> normal_projector(
218 cad_surface, tolerance);
219
220 triangulation.set_manifold(manifold_id, normal_projector);
221}
222#else
223void
224attach_cad_to_manifold(parallel::DistributedTriangulationBase<3> &,
225 const std::string &,
226 const unsigned int,
228 const double)
229{
230 throw std::runtime_error(
231 "CAD manifolds require DEAL_II to be compiled with OPENCASCADE");
232}
233#endif // DEAL_II_WITH_OPENCASCADE
234
235
236template void
238 parallel::DistributedTriangulationBase<2> &triangulation,
239 Parameters::Manifolds manifolds);
240
241template void
243 parallel::DistributedTriangulationBase<3> &triangulation,
244 Parameters::Manifolds manifolds);
245
246template void
248 parallel::DistributedTriangulationBase<2, 3> &triangulation,
249 Parameters::Manifolds manifolds);
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
Tensor< 1, spacedim > value_string_to_tensor(const std::string &value_string)
Return the tensor corresponding to the value_string. If the dimension correspondence of the value_str...
Definition utilities.h:956
std::vector< T > convert_string_to_vector(const ParameterHandler &prm, const std::string &entry_string)
Return the vector of size N of entry @entry_string. If the entry is specified in the ....
Definition utilities.h:1330
EnumType string_to_enum(const std::string &name)
Return the enumerator whose identifier is name, e.g. to parse the value of a parameter entry into its...
Definition utilities.h:734
void declare_enum_entry(ParameterHandler &prm, const std::string &entry_name, const EnumType default_value, const std::string &description, const DeprecatedEnumNames< EnumType > &deprecated_names={}, const std::vector< EnumType > &allowed_values={})
Declare a parameter entry whose value is an enumerator. The default value, the accepted values and th...
Definition utilities.h:888
void attach_manifolds_to_triangulation(parallel::DistributedTriangulationBase< dim, spacedim > &triangulation, Parameters::Manifolds manifolds)
Attaches manifold to boundaries of the triangulation.
Definition manifolds.cc:110
void attach_cad_to_manifold(parallel::DistributedTriangulationBase< 2 > &, const std::string &, const unsigned int, const Parameters::Manifolds::ManifoldType, const double)
Attaches CAD manifolds using IGES or STEP files to boundaries of the triangulation....
Definition manifolds.cc:168