]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/MEDLoader/CrackAlgo.hxx
Salome HOME
feat: new crackAlong method
[tools/medcoupling.git] / src / MEDLoader / CrackAlgo.hxx
1 // Copyright (C) 2007-2024  CEA, EDF
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email :
18 // webmaster.salome@opencascade.com
19 //
20 // Author : Aymeric SONOLET (CEA/DES)
21
22 #ifndef SRC_MEDLOADER_CRACKALGO_HXX_
23 #define SRC_MEDLOADER_CRACKALGO_HXX_
24
25 #include <unordered_map>
26 #include <vector>
27 #include <memory>
28 #include <string>
29 #include <map>
30 #include <unordered_set>
31 #include <utility>
32
33 #include <MCType.hxx>
34
35 namespace MEDCoupling {
36
37 class MEDFileUMesh;
38 class DataArrayIdType;
39 class MEDCouplingUMesh;
40
41 class CrackAlgo {
42  public:
43      using Set = std::unordered_set<mcIdType>;
44      using Map = std::unordered_map<mcIdType, mcIdType>;
45      using Graph = std::unordered_map<mcIdType, Set>;
46      using Map2Set = std::unordered_map<mcIdType, Set>;
47      using Map2Map = std::unordered_map<mcIdType, Map>;
48
49      CrackAlgo() {}
50      ~CrackAlgo() {}
51      static Map2Map
52      Compute(MEDFileUMesh* mm, const std::string& grp_name, bool grpMustBeFullyDup = true);
53
54     static void
55     OpenCrack(
56         MEDFileUMesh * mf,
57         const Map2Map & cellOld2NewNode,
58         const double & factor = 0.9);
59
60  private:
61      /* Find connected components using a node to node graph.
62       */
63      static std::vector<std::shared_ptr<std::vector<mcIdType>>>
64      FindConnectedComponents(
65          const Graph& graph);
66
67      /* Depth First Search function to find connected components.
68       */
69      static void Dfs(
70          const Graph& graph,
71          const mcIdType &node,
72          const std::size_t &componentId,
73          std::map<mcIdType, bool>& visited,
74          std::map<mcIdType, std::size_t>& componentMap);
75
76      /* Converts DataArrayIdType to Set.
77       *
78       * Usefull for doing multiple search in the Set efficiently.
79       */
80      static Set
81      DataArrayToSet(
82          const DataArrayIdType &da);
83
84     static DataArrayIdType *
85     SetToDataArray(
86         const Set& s);
87
88      static Set
89      GetCellsTouchingNodesToDup(
90          const MEDCouplingUMesh * mf,
91          const DataArrayIdType * n2cIdx,
92          const DataArrayIdType * n2c,
93          const DataArrayIdType * f2dup);
94
95      static Map2Set
96      GetNode2CellMap(
97          const MEDCouplingUMesh * mf,
98          const DataArrayIdType * n2cIdx,
99          const DataArrayIdType * n2c,
100          const DataArrayIdType * f2dup);
101
102      /* Building the cell to cell graph.
103       *
104       * This graph concerns only cells touching nodes touching faces to duplicate.
105       * The connection between cells sharing a face to dup is cut in this graph.
106       */
107      static Graph
108      BuildCutC2CGraph(
109          const DataArrayIdType * c2fIdx,
110          const DataArrayIdType * c2f,
111          const DataArrayIdType * f2cIdx,
112          const DataArrayIdType * f2c,
113          const Set & cTouchingN_dup,
114          const DataArrayIdType * f2dup);
115
116      static Map2Map
117      CreateNewNodesInTopLevelMesh(
118          const Map2Set & n2c_dup,
119          const Graph & c2c,
120          MEDCouplingUMesh * m0);
121
122      static void
123      AddMissingElementsOnLevelM1AndChangeConnectivity(
124          const DataArrayIdType * f2cIdx,
125          const DataArrayIdType * f2c,
126          const DataArrayIdType * f2dupIdInM1,
127          const DataArrayIdType * f2dupIdInMf,
128          const Map2Map & cellOld2NewNode,
129          MEDCouplingUMesh * m1,
130          bool grpMustBeFullyDup = true);
131
132     /* Create new family array for level -1, which is the extended copy of the
133      * original as new elements are appended. Caller owns newFamily DAI.
134      * Supposes that the elements to duplicate are all duplicated and appended
135      * in the order at the end of mf.
136      */
137     static DataArrayIdType *
138     CopyAndCompleteFamilyArrAtLevelM1(
139         const MEDFileUMesh * mm,
140         const MEDCouplingUMesh * mf,
141         const DataArrayIdType * f2dup);
142
143     static DataArrayIdType *
144     CopyFamilyArrAtLev0(const MEDFileUMesh * mm);
145
146     /* Manage node families.
147      *
148      * Extend the family size inplace and set new nodes family to their
149      * predecessor.
150      */
151     static void
152     CompleteFamilyArrAtNodeLevel(
153         const Map2Set& addedNodes,
154         MEDFileUMesh * mm);
155
156     /* Aggregate CellOld2NewNodes into oldNode to newNodes.
157      */
158     static Map2Set
159     BuildMap2Set(
160         const Map2Map& cellOld2NewNode);
161
162     /* Remomves cells from crackingMesh which are part of m skin.
163      *
164      * Returns a new MEDCouplingUMesh. User is responsible to delete it.
165      */
166     static MEDCouplingUMesh *
167     CleanM1Mesh(
168         const MEDCouplingUMesh & m,
169         const MEDCouplingUMesh & crackingMesh);
170
171     static std::pair<DataArrayIdType*, DataArrayIdType*>
172     GetFacesInM1TouchingDuplicatedNodes(
173         const Map2Set & n2c_dup,
174         const DataArrayIdType * f2dupIdInM1,
175         const MEDCouplingUMesh & mf,
176         const MEDCouplingUMesh & m1);
177
178     static DataArrayIdType *
179     GetFacesToDupInM1(
180         const MEDCouplingUMesh & crackMesh,
181         const MEDCouplingUMesh & m1);
182
183     static void
184     ChangeConnectivityOfM1Elements(
185         const DataArrayIdType * f2changeIdInM1,
186         const DataArrayIdType * f2changeIdInMf,
187         const Map2Map & cellOld2New,
188         const DataArrayIdType * f2cIdx,
189         const DataArrayIdType * f2c,
190         MEDCouplingUMesh * m1);
191 };
192 }  // namespace MEDCoupling
193 #endif  // SRC_MEDLOADER_CRACKALGO_HXX_