1 // Copyright (C) 2007-2024 CEA, EDF
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.
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.
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
17 // See http://www.salome-platform.org/ or email :
18 // webmaster.salome@opencascade.com
20 // Author : Aymeric SONOLET (CEA/DES)
22 #ifndef SRC_MEDLOADER_CRACKALGO_HXX_
23 #define SRC_MEDLOADER_CRACKALGO_HXX_
25 #include <unordered_map>
30 #include <unordered_set>
35 namespace MEDCoupling {
38 class DataArrayIdType;
39 class MEDCouplingUMesh;
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>;
52 Compute(MEDFileUMesh* mm, const std::string& grp_name, bool grpMustBeFullyDup = true);
57 const Map2Map & cellOld2NewNode,
58 const double & factor = 0.9);
61 /* Find connected components using a node to node graph.
63 static std::vector<std::shared_ptr<std::vector<mcIdType>>>
64 FindConnectedComponents(
67 /* Depth First Search function to find connected components.
72 const std::size_t &componentId,
73 std::map<mcIdType, bool>& visited,
74 std::map<mcIdType, std::size_t>& componentMap);
76 /* Converts DataArrayIdType to Set.
78 * Usefull for doing multiple search in the Set efficiently.
82 const DataArrayIdType &da);
84 static DataArrayIdType *
89 GetCellsTouchingNodesToDup(
90 const MEDCouplingUMesh * mf,
91 const DataArrayIdType * n2cIdx,
92 const DataArrayIdType * n2c,
93 const DataArrayIdType * f2dup);
97 const MEDCouplingUMesh * mf,
98 const DataArrayIdType * n2cIdx,
99 const DataArrayIdType * n2c,
100 const DataArrayIdType * f2dup);
102 /* Building the cell to cell graph.
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.
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);
117 CreateNewNodesInTopLevelMesh(
118 const Map2Set & n2c_dup,
120 MEDCouplingUMesh * m0);
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);
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.
137 static DataArrayIdType *
138 CopyAndCompleteFamilyArrAtLevelM1(
139 const MEDFileUMesh * mm,
140 const MEDCouplingUMesh * mf,
141 const DataArrayIdType * f2dup);
143 static DataArrayIdType *
144 CopyFamilyArrAtLev0(const MEDFileUMesh * mm);
146 /* Manage node families.
148 * Extend the family size inplace and set new nodes family to their
152 CompleteFamilyArrAtNodeLevel(
153 const Map2Set& addedNodes,
156 /* Aggregate CellOld2NewNodes into oldNode to newNodes.
160 const Map2Map& cellOld2NewNode);
162 /* Remomves cells from crackingMesh which are part of m skin.
164 * Returns a new MEDCouplingUMesh. User is responsible to delete it.
166 static MEDCouplingUMesh *
168 const MEDCouplingUMesh & m,
169 const MEDCouplingUMesh & crackingMesh);
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);
178 static DataArrayIdType *
180 const MEDCouplingUMesh & crackMesh,
181 const MEDCouplingUMesh & m1);
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);
192 } // namespace MEDCoupling
193 #endif // SRC_MEDLOADER_CRACKALGO_HXX_