v0.16.3
Loading...
Searching...
No Matches
CgalCrackGrowth.hpp
Go to the documentation of this file.
1/** \file CgalCrackGrowth.hpp
2 * \brief Crack growth one step at a time on two bit levels, on top of
3 * CGALInterface. Not included by MoFEM.hpp.
4 */
5#ifndef __CGAL_CRACK_GROWTH_HPP__
6#define __CGAL_CRACK_GROWTH_HPP__
7
8#include "CGALInterface.hpp"
9#include <functional>
10#include <unordered_map>
11
12namespace MoFEM {
13
14/** Crack growth by steps. A step joins the front to the existing crack,
15 * closes a gap whose closing face is missing, or extends one front edge.
16 * A closure or an extension publishes the mesh on the other bit level, fills
17 * notches, retires the old level and swaps the two levels. The caller
18 * chooses the extension direction of a front edge and the order in which
19 * front edges are tried. One rank. See
20 * doc/development/cgal_crack_extension_algorithm.md.
21 */
23 /// A front edge by the sorted GLOBAL_IDs of its vertices; stable when
24 /// levels are swapped and retired entities are deleted.
25 using Pair = std::array<int, 2>;
26 /// Extension direction of a front edge, given the crack faces.
27 using Direction = std::function<MoFEMErrorCode(
28 EntityHandle edge, const Range &crack, std::array<double, 3> &direction)>;
29
30 struct Settings {
32 bool join = true; ///< Close gaps globally, then join, before advancing.
33 bool fill = true; ///< Fill notches after a closure or an extension.
34 /// Largest angle tolerance, degrees. When no listed front edge extends,
35 /// the tolerance doubles up to it; at or below the set tolerance, none.
36 double angleMaxDegrees = 45;
37 };
38
39 enum class Kind { None, Join, Closure, Extension };
40
41 /** What a step did. */
42 struct Step {
44 /// Join: the CGALTools::CrackJoinFace category of each face.
45 std::vector<int> joinCategories;
46 Pair edge{0, 0}; ///< Front edge of closure, extension or ordered join.
47 double opening = 0; ///< Closure: uncracked angle of the corner, radians.
49 std::size_t closures = 0; ///< Faces closing corners in the same step.
50 std::size_t filled = 0; ///< Notch faces filled after it.
51 double toleranceDegrees = 0; ///< Extension: the angle tolerance used.
52 int extended = -1; ///< Index selected by extend or advanceOrdered.
53 std::vector<int> dropped; ///< Extension: listed edges not on the front.
54 std::vector<Pair> addedEdges; ///< Closure, extension: edges of new faces.
55 };
56
57 /** crack_set holds the crack faces on source; constraints are protected
58 * as in CGALInterface::CrackExtension::extendCrack. */
59 CgalCrackGrowth(MoFEM::Interface &m_field, EntityHandle crack_set,
61 const Range &constraints, const Settings &settings);
62
63 /// The level holding the current mesh.
64 BitRefLevel level() const { return sourceBit; }
65 const Settings &settings() const { return options; }
66
68 /** Crack edges with one crack face that are not on the body skin. */
69 MoFEMErrorCode frontEdges(const Range &crack, Range &front) const;
70 Pair edgeIds(EntityHandle edge) const;
71 /** Uncracked opening at a front node: 2 pi minus the sum of the angles of
72 * its crack faces. A node on the body skin, or without exactly two front
73 * edges, is neutral (pi). */
74 MoFEMErrorCode opening(EntityHandle node, const Range &crack,
75 const Range &front, double &value) const;
76
77 /** Close a feasible gap anywhere on the front before joining anywhere.
78 * Sharpness orders edges within each phase. Missing faces are recovered by
79 * flips; neither phase moves vertices. None when joining is disabled or
80 * no gap or join is admissible. */
81 MoFEMErrorCode join(const Direction &direction, Step &step);
82
83 /** Try flip-only advances on the whole list over the allowed tolerance
84 * range, then allow vertex movement. Within a pass, preserve FIFO edge and
85 * tolerance order. This method omits the separate global gap/join passes. */
86 MoFEMErrorCode extend(const std::vector<Pair> &edges,
87 const Direction &direction, Step &step);
88
89 /** Global gap closure, then global joining, then flip-only advance,
90 * then vertex movement. Supplied edge priority is respected within each
91 * phase; each edge exhausts its allowed tolerance range before the next.
92 * Flips may recover both missing gap and joining faces. */
93 MoFEMErrorCode advanceOrdered(const std::vector<Pair> &edges,
94 const Direction &direction, Step &step);
95
96private:
98 EntityHandle crackSet;
102
103 /// Skin and vertex IDs of the current level, refreshed when it changes.
104 mutable bool levelChanged = true;
106 mutable std::unordered_map<int, EntityHandle> vertexById;
108
109 /// Front edges whose gap closure failed. An entry is forgotten when a
110 /// step changes the mesh or the crack near it, see forgetClosuresNear.
111 std::set<Pair> failedClosures;
113 /** Global gap-closure pass followed by joining, ordered by edges within
114 * each operation. Both passes can recover missing faces by flips. */
115 MoFEMErrorCode closeAndJoin(const std::vector<Pair> &edges,
116 const Direction &direction, Step &step);
117 /** Forget failed closures within twice the ring limit of the nodes of
118 * faces: a closure search changes cells within the ring limit of its
119 * edge, so a change there may make it possible. */
121
122 /** The current front edge of pair, or zero. */
123 MoFEMErrorCode resolve(const Pair &pair, const Range &front,
124 EntityHandle &edge) const;
125 /** The current front edge of edges[i], or zero. An edge no longer on the
126 * front is marked in dropped and recorded in step.dropped once. */
127 MoFEMErrorCode resolveListed(const std::vector<Pair> &edges, std::size_t i,
128 const Range &front, std::vector<char> &dropped,
129 Step &step, EntityHandle &edge);
130
132 return mField.getInterface<CGALInterface>()->getCrackExtension();
133 }
134 /** Settings of the advance phases: flips alone first, then, when moves
135 * are allowed, the move classes only. */
136 std::vector<CGALTools::CrackExtensionSettings> advancePhases() const;
137 /** Double tolerance up to Settings::angleMaxDegrees; false when it is
138 * already there or relaxation is disabled. */
139 bool widenTolerance(double &tolerance) const;
140 /** Close a gap at, or extend, one front edge; on success publish, fill,
141 * retire and swap levels, and describe it in step. */
142 MoFEMErrorCode change(Kind operation, const Pair &pair, EntityHandle edge,
143 const Range &crack, const Direction &direction,
145 bool &changed, Step &step);
146};
147
148} // namespace MoFEM
149
150#endif // __CGAL_CRACK_GROWTH_HPP__
Range crackFaces
std::vector< std::array< EntityHandle, 3 > > faces
Sorted keys.
Local MOAB point-set and CGAL Delaunay mesh transfer.
std::vector< int > source
FaceSet crack
double tolerance
Radians.
FTensor::Index< 'i', SPACE_DIM > i
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition Types.hpp:40
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
CGALTools::CrackExtensionSettings extension
bool join
Close gaps globally, then join, before advancing.
std::vector< Pair > addedEdges
Closure, extension: edges of new faces.
CGALTools::CrackExtensionCandidate candidate
Closure, extension.
std::vector< int > dropped
Extension: listed edges not on the front.
int extended
Index selected by extend or advanceOrdered.
double toleranceDegrees
Extension: the angle tolerance used.
std::vector< int > joinCategories
Join: the CGALTools::CrackJoinFace category of each face.
double opening
Closure: uncracked angle of the corner, radians.
std::size_t closures
Faces closing corners in the same step.
Pair edge
Front edge of closure, extension or ordered join.
std::size_t filled
Notch faces filled after it.
std::unordered_map< int, EntityHandle > vertexById
bool widenTolerance(double &tolerance) const
MoFEMErrorCode forgetClosuresNear(const Range &faces)
std::set< Pair > failedGapJoins
BitRefLevel level() const
The level holding the current mesh.
MoFEMErrorCode join(const Direction &direction, Step &step)
MoFEM::Interface & mField
std::set< Pair > failedJoins
MoFEMErrorCode refreshLevel() const
std::set< Pair > failedClosures
MoFEMErrorCode resolveListed(const std::vector< Pair > &edges, std::size_t i, const Range &front, std::vector< char > &dropped, Step &step, EntityHandle &edge)
std::function< MoFEMErrorCode(EntityHandle edge, const Range &crack, std::array< double, 3 > &direction)> Direction
Extension direction of a front edge, given the crack faces.
MoFEMErrorCode extend(const std::vector< Pair > &edges, const Direction &direction, Step &step)
bool levelChanged
Skin and vertex IDs of the current level, refreshed when it changes.
MoFEMErrorCode frontEdges(const Range &crack, Range &front) const
const Settings & settings() const
MoFEMErrorCode resolve(const Pair &pair, const Range &front, EntityHandle &edge) const
Pair edgeIds(EntityHandle edge) const
MoFEMErrorCode opening(EntityHandle node, const Range &crack, const Range &front, double &value) const
std::array< int, 2 > Pair
std::vector< CGALTools::CrackExtensionSettings > advancePhases() const
MoFEMErrorCode change(Kind operation, const Pair &pair, EntityHandle edge, const Range &crack, const Direction &direction, const CGALTools::CrackExtensionSettings &settings, bool &changed, Step &step)
CGALInterface::CrackExtension & crackExtension() const
MoFEMErrorCode closeAndJoin(const std::vector< Pair > &edges, const Direction &direction, Step &step)
MoFEMErrorCode advanceOrdered(const std::vector< Pair > &edges, const Direction &direction, Step &step)
Deprecated interface functions.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.