Debian Codegraph @

include/deal.II/opencascade/manifold_lib.h

raw
1 // ------------------------------------------------------------------------
2 //
3 // SPDX-License-Identifier: LGPL-2.1-or-later
4 // Copyright (C) 2014 - 2024 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // Part of the source code is dual licensed under Apache-2.0 WITH
9 // LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10 // governing the source code and code contributions can be found in
11 // LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12 //
13 // ------------------------------------------------------------------------
14
15
16 #ifndef dealii_occ_manifold_lib_h
17 #define dealii_occ_manifold_lib_h
18
19 #include <deal.II/base/config.h>
20
21 #ifdef DEAL_II_WITH_OPENCASCADE
22
23 # include <deal.II/grid/manifold.h>
24
25 # include <deal.II/opencascade/utilities.h>
26
27 // opencascade needs "HAVE_CONFIG_H" to be exported...
28 # define HAVE_CONFIG_H
29 # include <Adaptor3d_Curve.hxx>
30 # if !DEAL_II_OPENCASCADE_VERSION_GTE(7, 6, 0)
31 # include <Adaptor3d_HCurve.hxx>
32 # endif
33 # include <BRepAdaptor_Curve.hxx>
34 # undef HAVE_CONFIG_H
35
36 DEAL_II_NAMESPACE_OPEN
37
38 /**
39 * @addtogroup OpenCASCADE
40 * @{
41 */
42
43 namespace OpenCASCADE
44 {
45 /**
46 * A Manifold object based on OpenCASCADE TopoDS_Shape where new points are
47 * first computed by averaging the surrounding points in the same way as
48 * FlatManifold does, and are then projected in the normal direction using
49 * OpenCASCADE utilities.
50 *
51 * This class makes no assumptions on the shape you pass to it, and the
52 * topological dimension of the Manifold is inferred from the TopoDS_Shape
53 * itself. In debug mode there is a sanity check to make sure that the
54 * surrounding points (the ones used in project_to_manifold()) actually live
55 * on the Manifold, i.e., calling OpenCASCADE::closest_point() on those
56 * points leaves them untouched. If this is not the case, an
57 * ExcPointNotOnManifold is thrown.
58 *
59 * This could happen, for example, if you are trying to use a shape of type
60 * TopoDS_Edge when projecting on a face. In this case, the vertices of the
61 * face would be collapsed to the edge, and your surrounding points would
62 * not be lying on the given shape, raising an exception.
63 */
64 template <int dim, int spacedim>
65 class NormalProjectionManifold : public FlatManifold<dim, spacedim>
66 {
67 public:
68 /**
69 * The standard constructor takes a generic TopoDS_Shape @p sh, and a
70 * tolerance used to compute distances internally.
71 *
72 * The TopoDS_Shape can be arbitrary, i.e., a collection of shapes, faces,
73 * edges or a single face or edge.
74 */
75 NormalProjectionManifold(const TopoDS_Shape &sh,
76 const double tolerance = 1e-7);
77
78 /**
79 * Clone the current Manifold.
80 */
81 virtual std::unique_ptr<Manifold<dim, spacedim>>
82 clone() const override;
83
84 /**
85 * Perform the actual projection onto the manifold. This function, in
86 * debug mode, checks that each of the @p surrounding_points is within
87 * tolerance from the given TopoDS_Shape. If this is not the case, an
88 * exception is thrown.
89 *
90 * The projected point is computed using OpenCASCADE normal projection
91 * algorithms.
92 */
93 virtual Point<spacedim>
94 project_to_manifold(
95 const ArrayView<const Point<spacedim>> &surrounding_points,
96 const Point<spacedim> &candidate) const override;
97
98
99 protected:
100 /**
101 * The topological shape which is used internally to project points. You
102 * can construct such a shape by calling the OpenCASCADE::read_IGES()
103 * function, which will create a TopoDS_Shape with the geometry contained
104 * in the IGES file.
105 */
106 const TopoDS_Shape sh;
107
108 /**
109 * Relative tolerance used by this class to compute distances.
110 */
111 const double tolerance;
112 };
113
114 /**
115 * A Manifold object based on OpenCASCADE TopoDS_Shape where new points are
116 * first computed by averaging the surrounding points in the same way as
117 * FlatManifold does, and then projecting them onto the manifold along the
118 * direction specified at construction time using OpenCASCADE utilities.
119 *
120 * This class makes no assumptions on the shape you pass to it, and the
121 * topological dimension of the Manifold is inferred from the TopoDS_Shape
122 * itself. In debug mode there is a sanity check to make sure that the
123 * surrounding points (the ones used in project_to_manifold()) actually live
124 * on the Manifold, i.e., calling OpenCASCADE::closest_point() on those
125 * points leaves them untouched. If this is not the case, an
126 * ExcPointNotOnManifold is thrown.
127 *
128 * Notice that this type of Manifold descriptor may fail to give results if
129 * the triangulation to be refined is close to the boundary of the given
130 * TopoDS_Shape, or when the direction you use at construction time does not
131 * intersect the shape. An exception is thrown when this happens.
132 */
133 template <int dim, int spacedim>
134 class DirectionalProjectionManifold : public FlatManifold<dim, spacedim>
135 {
136 public:
137 /**
138 * Construct a Manifold object which will project points on the
139 * TopoDS_Shape @p sh, along the given @p direction.
140 */
141 DirectionalProjectionManifold(const TopoDS_Shape &sh,
142 const Tensor<1, spacedim> &direction,
143 const double tolerance = 1e-7);
144
145 /**
146 * Clone the current Manifold.
147 */
148 virtual std::unique_ptr<Manifold<dim, spacedim>>
149 clone() const override;
150
151 /**
152 * Perform the actual projection onto the manifold. This function, in
153 * debug mode, checks that each of the @p surrounding_points is within
154 * tolerance from the given TopoDS_Shape. If this is not the case, an
155 * exception is thrown.
156 *
157 * The projected point is computed using OpenCASCADE directional
158 * projection algorithms.
159 */
160 virtual Point<spacedim>
161 project_to_manifold(
162 const ArrayView<const Point<spacedim>> &surrounding_points,
163 const Point<spacedim> &candidate) const override;
164
165 protected:
166 /**
167 * The topological shape which is used internally to project points. You
168 * can construct such a shape by calling the OpenCASCADE::read_IGES()
169 * function, which will create a TopoDS_Shape with the geometry contained
170 * in the IGES file.
171 */
172 const TopoDS_Shape sh;
173
174 /**
175 * Direction used to project new points on the shape.
176 */
177 const Tensor<1, spacedim> direction;
178
179 /**
180 * Relative tolerance used by this class to compute distances.
181 */
182 const double tolerance;
183 };
184
185
186 /**
187 * A Manifold object based on OpenCASCADE TopoDS_Shape where new points are
188 * first computed by averaging the surrounding points in the same way as
189 * FlatManifold does, and then projecting them using OpenCASCADE utilities
190 * onto the manifold along a direction which is an estimation of the
191 * surrounding points (hence mesh cell) normal.
192 *
193 * The direction normal to the mesh is particularly useful because it is the
194 * direction in which the mesh is missing nodes. For instance, during the
195 * refinement of a cell a new node is initially created around the
196 * baricenter of the cell. This location somehow ensures a uniform distance
197 * from the nodes of the old cell. Projecting such cell baricenter onto the
198 * CAD surface in the direction normal to the original cell will then retain
199 * uniform distance from the points of the original cell. Of course, at the
200 * stage of mesh generation, no dof handler nor finite element are defined,
201 * and such direction has to be estimated. For the case in which 8
202 * surrounding points are present, 4 different triangles are identified with
203 * the points assigned, and the normals of such triangles are averaged to
204 * obtain the approximation of the normal to the cell.
205 *
206 * The case in which 2 surrounding points are present (i.e.:a cell edge is
207 * being refined) is of course more tricky. The average of the CAD surface
208 * normals at the 2 surrounding points is first computed, and then projected
209 * onto the plane normal to the segment linking the surrounding points. This
210 * again is an attempt to have the new point with equal distance with
211 * respect to the surrounding points
212 *
213 * This class only operates with CAD faces and makes the assumption that the
214 * shape you pass to it contains at least one face. If that is not the case,
215 * an Exception is thrown. In debug mode there is a sanity check to make
216 * sure that the surrounding points (the ones used in project_to_manifold())
217 * actually live on the Manifold, i.e., calling OpenCASCADE::closest_point()
218 * on those points leaves them untouched. If this is not the case, an
219 * ExcPointNotOnManifold is thrown.
220 *
221 *
222 * Notice that this type of Manifold descriptor may fail to give results if
223 * the triangulation to be refined is close to the boundary of the given
224 * TopoDS_Shape, or when the normal direction estimated from the surrounding
225 * points does not intersect the shape. An exception is thrown when this
226 * happens.
227 */
228 template <int dim, int spacedim>
229 class NormalToMeshProjectionManifold : public FlatManifold<dim, spacedim>
230 {
231 public:
232 /**
233 * Construct a Manifold object which will project points on the
234 * TopoDS_Shape @p sh, along a direction which is approximately normal to
235 * the mesh cell.
236 */
237 NormalToMeshProjectionManifold(const TopoDS_Shape &sh,
238 const double tolerance = 1e-7);
239
240 /**
241 * Clone the current Manifold.
242 */
243 virtual std::unique_ptr<Manifold<dim, spacedim>>
244 clone() const override;
245
246 /**
247 * Perform the actual projection onto the manifold. This function, in
248 * debug mode, checks that each of the @p surrounding_points is within
249 * tolerance from the given TopoDS_Shape. If this is not the case, an
250 * exception is thrown.
251 */
252 virtual Point<spacedim>
253 project_to_manifold(
254 const ArrayView<const Point<spacedim>> &surrounding_points,
255 const Point<spacedim> &candidate) const override;
256
257 protected:
258 /**
259 * The topological shape which is used internally to project points. You
260 * can construct such a shape by calling the OpenCASCADE::read_IGES()
261 * function, which will create a TopoDS_Shape with the geometry contained
262 * in the IGES file.
263 */
264 const TopoDS_Shape sh;
265
266 /**
267 * Relative tolerance used by this class to compute distances.
268 */
269 const double tolerance;
270 };
271
272 /**
273 * A Manifold object based on OpenCASCADE TopoDS_Shape objects which have
274 * topological dimension equal to one (TopoDS_Edge or TopoDS_Wire) where new
275 * points are located at the arclength average of the surrounding points. If
276 * the given TopoDS_Shape can be casted to a periodic (closed) curve, then
277 * this information is used internally to set the periodicity of the base
278 * ChartManifold class.
279 *
280 * This class can only work on TopoDS_Edge or TopoDS_Wire objects, and it
281 * only makes sense when spacedim is three. If you use an object of
282 * topological dimension different from one, an exception is throw.
283 *
284 * In debug mode there is an additional sanity check to make sure that the
285 * surrounding points actually live on the Manifold, i.e., calling
286 * OpenCASCADE::closest_point() on those points leaves them untouched. If
287 * this is not the case, an ExcPointNotOnManifold is thrown.
288 */
289 template <int dim, int spacedim>
290 class ArclengthProjectionLineManifold : public ChartManifold<dim, spacedim, 1>
291 {
292 public:
293 /**
294 * Default constructor with a TopoDS_Edge.
295 */
296 ArclengthProjectionLineManifold(const TopoDS_Shape &sh,
297 const double tolerance = 1e-7);
298
299 /**
300 * Clone the current Manifold.
301 */
302 virtual std::unique_ptr<Manifold<dim, spacedim>>
303 clone() const override;
304
305 /**
306 * Given a point on real space, find its arclength parameter. Throws an
307 * error in debug mode, if the point is not on the TopoDS_Edge given at
308 * construction time.
309 */
310 virtual Point<1>
311 pull_back(const Point<spacedim> &space_point) const override;
312
313 /**
314 * Given an arclength parameter, find its image in real space.
315 */
316 virtual Point<spacedim>
317 push_forward(const Point<1> &chart_point) const override;
318
319 protected:
320 /**
321 * The actual shape used to build this object.
322 */
323 const TopoDS_Shape sh;
324
325 /**
326 * A Curve adaptor. This is the one which is used in the computations, and
327 * it points to the right one above.
328 */
329 # if DEAL_II_OPENCASCADE_VERSION_GTE(7, 6, 0)
330 Handle_Adaptor3d_Curve curve;
331 # else
332 Handle_Adaptor3d_HCurve curve;
333 # endif
334
335 /**
336 * Relative tolerance used in all internal computations.
337 */
338 const double tolerance;
339
340 /**
341 * The total length of the curve. This is also used as a period if the
342 * edge is periodic.
343 */
344 const double length;
345 };
346
347 /**
348 * Manifold description for the face of a CAD imported using OpenCASCADE.
349 *
350 * @ingroup manifold
351 */
352 template <int dim, int spacedim>
353 class NURBSPatchManifold : public ChartManifold<dim, spacedim, 2>
354 {
355 public:
356 /**
357 * The constructor takes an OpenCASCADE TopoDS_Face @p face and an optional
358 * @p tolerance. This class uses the interval OpenCASCADE variables u, v
359 * to describe the manifold.
360 */
361 NURBSPatchManifold(const TopoDS_Face &face, const double tolerance = 1e-7);
362
363 /**
364 * Clone the current Manifold.
365 */
366 virtual std::unique_ptr<Manifold<dim, spacedim>>
367 clone() const override;
368
369 /**
370 * Pull back the given point from the Euclidean space. Will return the uv
371 * coordinates associated with the point @p space_point.
372 */
373 virtual Point<2>
374 pull_back(const Point<spacedim> &space_point) const override;
375
376 /**
377 * Given a @p chart_point in the uv coordinate system, this method returns the
378 * Euclidean coordinates associated.
379 */
380 virtual Point<spacedim>
381 push_forward(const Point<2> &chart_point) const override;
382
383 /**
384 * Given a point in the spacedim dimensional Euclidean space, this
385 * method returns the derivatives of the function $F$ that maps from
386 * the uv coordinate system to the Euclidean coordinate
387 * system. In other words, it is a matrix of size
388 * $\text{spacedim}\times\text{chartdim}$.
389 *
390 * This function is used in the computations required by the
391 * get_tangent_vector() function.
392 *
393 * Refer to the general documentation of this class for more information.
394 */
395 virtual DerivativeForm<1, 2, spacedim>
396 push_forward_gradient(const Point<2> &chart_point) const override;
397
398 protected:
399 /**
400 * Return a tuple representing the minimum and maximum values of u
401 * and v. Precisely, it returns (u_min, u_max, v_min, v_max)
402 */
403 std::tuple<double, double, double, double>
404 get_uv_bounds() const;
405
406 /**
407 * An OpenCASCADE TopoDS_Face @p face given by the CAD.
408 */
409 TopoDS_Face face;
410
411 /**
412 * Tolerance used by OpenCASCADE to identify points in each
413 * operation.
414 */
415 double tolerance;
416 };
417
418 } // namespace OpenCASCADE
419
420 /** @} */
421
422 DEAL_II_NAMESPACE_CLOSE
423
424
425 #else
426
427 // Make sure the scripts that create the C++20 module input files have
428 // something to latch on if the preprocessor #ifdef above would
429 // otherwise lead to an empty content of the file.
430 DEAL_II_NAMESPACE_OPEN
431 DEAL_II_NAMESPACE_CLOSE
432
433 #endif // DEAL_II_WITH_OPENCASCADE
434 #endif // dealii_occ_manifold_lib_h