1 diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx
2 index 4d01f5e7..e62c5611 100755
3 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx
4 +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx
5 @@ -2497,8 +2497,6 @@ DataArrayIdType* MEDCouplingUMesh::findNodesToDuplicate(const MEDCouplingUMesh&
6 void MEDCouplingUMesh::findCellsToRenumber(const MEDCouplingUMesh& otherDimM1OnSameCoords, const mcIdType *nodeIdsToDuplicateBg, const mcIdType *nodeIdsToDuplicateEnd,
7 DataArrayIdType *& cellIdsNeededToBeRenum, DataArrayIdType *& cellIdsNotModified) const
9 - // DEBUG NOTE: in case of issue with the algorithm in this method, see Python script in resources/dev
10 - // which mimicks the C++
11 using DAInt = MCAuto<DataArrayIdType>;
12 using MCUMesh = MCAuto<MEDCouplingUMesh>;
14 @@ -2509,192 +2507,79 @@ void MEDCouplingUMesh::findCellsToRenumber(const MEDCouplingUMesh& otherDimM1OnS
15 if(otherDimM1OnSameCoords.getMeshDimension()!=getMeshDimension()-1)
16 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::findCellsToRenumber: the mesh given in other parameter must have this->getMeshDimension()-1 !");
18 + // Compute cell IDs of the mesh with cells that touch the M1 group with a least one node:
19 DAInt cellsAroundGroupLarge = getCellIdsLyingOnNodes(nodeIdsToDuplicateBg, nodeIdsToDuplicateEnd, false); // false= take cell in, even if not all nodes are in dupl
22 MCUMesh mAroundGrpLarge=static_cast<MEDCouplingUMesh *>(buildPartOfMySelf(cellsAroundGroupLarge->begin(),cellsAroundGroupLarge->end(),true));
23 + mcIdType nCellsLarge=cellsAroundGroupLarge->getNumberOfTuples();
24 DAInt descL=DataArrayIdType::New(),descIL=DataArrayIdType::New(),revDescL=DataArrayIdType::New(),revDescIL=DataArrayIdType::New();
25 MCUMesh mArGrpLargeDesc=mAroundGrpLarge->buildDescendingConnectivity(descL,descIL,revDescL,revDescIL);
26 const mcIdType *descILP=descIL->begin(), *descLP=descL->begin();
28 - // Extract now all N D cells which have a complete face in touch with the group:
29 - // 1. Identify cells of M1 group in sub-mesh mAroundGrp
30 DataArrayIdType *idsOfM1t;
31 mArGrpLargeDesc->areCellsIncludedIn(&otherDimM1OnSameCoords,2, idsOfM1t);
32 DAInt idsOfM1Large(idsOfM1t);
33 mcIdType nL = mArGrpLargeDesc->getNumberOfCells();
34 - DAInt idsStrict = DataArrayIdType::New(); idsStrict->alloc(0,1);
35 - // 2. Build map giving for each cell ID in mAroundGrp (not in mAroundGrpLarge) the corresponding cell
36 - // ID on the other side of the crack:
37 - std::map<mcIdType, mcIdType> toOtherSide, pos;
40 + // Computation of the neighbor information of the mesh WITH the crack (some neighbor links are removed):
41 + // In the neighbor information remove the connection between high dimension cells and its low level constituents which are part
42 + // of the frontier given in parameter (i.e. the cells of low dimension from the group delimiting the crack):
43 + DAInt descLTrunc = descL->deepCopy(), descILTrunc = descIL->deepCopy();
44 + DataArrayIdType::RemoveIdsFromIndexedArrays(idsOfM1Large->begin(), idsOfM1Large->end(),descLTrunc,descILTrunc);
45 + DataArrayIdType *neight=0, *neighIt=0;
46 + MEDCouplingUMesh::ComputeNeighborsOfCellsAdv(descLTrunc,descILTrunc,revDescL,revDescIL, neight, neighIt);
47 + DAInt neighL(neight), neighIL(neighIt);
49 + DAInt hitCellsLarge = DataArrayIdType::New(); hitCellsLarge->alloc(nCellsLarge,1);
50 + hitCellsLarge->fillWithValue(0); // 0 : not hit, +1: one side of the crack, -1: other side of the crack,
51 + mcIdType* hitCellsLargeP = hitCellsLarge->rwBegin();
53 + // Now loop on the faces of the M1 group and fill spread zones on either side of the crack:
54 const mcIdType *revDescILP=revDescIL->begin(), *revDescLP=revDescL->begin();
55 for(const auto& v: *idsOfM1Large)
57 - if (v >= nL) // Keep valid match only
59 + if (v >= nL) continue; // Keep valid match only - see doc of areCellsIncludedIn()
60 mcIdType idx0 = revDescILP[v];
61 - // Keep the two cells on either side of the face v of M1:
62 + // Retrieve the two cells on either side of the face v of M1:
63 mcIdType c1=revDescLP[idx0], c2=revDescLP[idx0+1];
64 - DAInt t1=idsStrict->findIdsEqual(c1), t2=idsStrict->findIdsEqual(c2);
66 - if (!t1->getNumberOfTuples())
67 - { pos[c1] = cnt++; idsStrict->pushBackSilent(c1); }
68 - if (!t2->getNumberOfTuples())
69 - { pos[c2] = cnt++; idsStrict->pushBackSilent(c2); }
71 - mcIdType k1 = pos[c1], k2=pos[c2];
72 - toOtherSide[k1] = k2;
73 - toOtherSide[k2] = k1;
76 - DAInt cellsAroundGroup = cellsAroundGroupLarge->selectByTupleId(idsStrict->begin(), idsStrict->end());
77 - MCUMesh mAroundGrp = static_cast<MEDCouplingUMesh *>(buildPartOfMySelf(cellsAroundGroup->begin(), cellsAroundGroup->end(), true));
78 - mcIdType nCells=cellsAroundGroup->getNumberOfTuples(), nCellsLarge=cellsAroundGroupLarge->getNumberOfTuples();
79 - DAInt desc=DataArrayIdType::New(),descI=DataArrayIdType::New(),revDesc=DataArrayIdType::New(),revDescI=DataArrayIdType::New();
80 - MCUMesh mArGrpDesc=mAroundGrp->buildDescendingConnectivity(desc,descI,revDesc,revDescI);
81 - DataArrayIdType *idsOfM1t2;
82 - mArGrpDesc->areCellsIncludedIn(&otherDimM1OnSameCoords,2, idsOfM1t2); // TODO can we avoid recomputation here?
83 - DAInt idsOfM1(idsOfM1t2);
85 - // Neighbor information of the mesh WITH the crack (some neighbors are removed):
86 - // In the neighbor information remove the connection between high dimension cells and its low level constituents which are part
87 - // of the frontier given in parameter (i.e. the cells of low dimension from the group delimiting the crack):
88 - DataArrayIdType::RemoveIdsFromIndexedArrays(idsOfM1->begin(), idsOfM1->end(),desc,descI);
89 - // Compute the neighbor of each cell in mAroundGrp, taking into account the broken link above. Two
90 - // cells on either side of the crack (defined by the mesh of low dimension) are not neighbor anymore.
91 - DataArrayIdType *neight=0, *neighIt=0;
92 - MEDCouplingUMesh::ComputeNeighborsOfCellsAdv(desc,descI,revDesc,revDescI, neight, neighIt);
93 - DAInt neigh(neight), neighI(neighIt);
95 - // For each initial connex part of the M1 mesh (or said differently for each independent crack):
96 - mcIdType seed=0, nIter=0;
97 - mcIdType nIterMax = nCells+1; // Safety net for the loop
98 - DAInt hitCells = DataArrayIdType::New(); hitCells->alloc(nCells,1);
99 - mcIdType* hitCellsP = hitCells->rwBegin();
100 - hitCells->fillWithValue(0); // 0 : not hit, +x: one side of the crack, -x: other side of the crack, with 'x' the index of the connex component
101 - mcIdType PING_FULL, PONG_FULL;
102 - mcIdType MAX_CP = 10000; // the choices below assume we won't have more than 10000 different connex parts ...
103 - mcIdType PING_FULL_init = 0, PING_PART = MAX_CP;
104 - mcIdType PONG_FULL_init = 0, PONG_PART = -MAX_CP;
106 - while (nIter < nIterMax)
108 - DAInt t = hitCells->findIdsEqual(0);
109 - if(!t->getNumberOfTuples())
111 - mcIdType seed = t->getIJ(0,0);
114 - PING_FULL = PING_FULL_init+cnt;
115 - PONG_FULL = PONG_FULL_init-cnt;
116 - // while the connex bits in correspondance on either side of the crack are not fully covered
117 - while(!done && nIter < nIterMax) // Start of the ping-pong
118 + std::map<mcIdType, mcIdType> toOther = {{c1, c2}, {c2, c1}};
119 + // Handle the spread zones on the two sides of the crack:
120 + for (const auto c: {c1, c2})
123 - // Identify connex zone around the seed - this zone corresponds to some cells on the other side
124 - // of the crack that might extend further away. So we will need to compute spread zone on the other side
125 - // too ... and this process can repeat, hence the "ping-pong" logic.
126 + if (hitCellsLargeP[c]) continue;
127 + // Identify connex zone around this cell - if we find a value already assigned there, use it.
129 - DAInt spreadZone = MEDCouplingUMesh::ComputeSpreadZoneGraduallyFromSeed(&seed, &seed+1, neigh,neighI, -1, dnu);
131 - for(const mcIdType& s: *spreadZone)
133 - hitCellsP[s] = PING_FULL;
134 - const auto& it = toOtherSide.find(s);
135 - if (it != toOtherSide.end())
137 - mcIdType other = it->second;
138 - if (hitCellsP[other] != PONG_FULL)
140 - // On the other side of the crack we hit a cell which was not fully covered previously by the
141 - // ComputeSpreadZone process, so we are not done yet, ComputeSreadZone will need to be applied there
143 - hitCellsP[other] = PONG_PART;
144 - // Compute next seed, i.e. a cell on the other side of the crack
151 - // we might have several disjoint PONG parts in front of a single PING connex part:
152 - DAInt idsPong = hitCells->findIdsEqual(PONG_PART);
153 - if (idsPong->getNumberOfTuples())
155 - seed = idsPong->getIJ(0,0);
158 - continue; // continue without switching side (or break if 'done' remains false)
161 + DAInt spreadZone = MEDCouplingUMesh::ComputeSpreadZoneGraduallyFromSeed(&c, &c+1, neighL,neighIL, -1, dnu);
162 + std::set<mcIdType> sv;
163 + for (const mcIdType& s: *spreadZone)
164 + if (hitCellsLargeP[s]) sv.insert(hitCellsLargeP[s]);
166 + // Strange: we find in the same spread zone a +1 and -1 !
167 + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::findCellsToRenumber: internal error #0 - conflicting values - should not happen!");
168 + // If a valid value was found, use it:
169 + mcIdType val = sv.size()==1 ? *sv.begin() : 0;
170 + // Hopefully this does not conflict with an potential value on the other side:
171 + mcIdType other = toOther[c];
172 + if (hitCellsLargeP[other])
174 - // Go to the other side
175 - std::swap(PING_FULL, PONG_FULL);
176 - std::swap(PING_PART, PONG_PART);
178 - } // while (!done ...)
179 - DAInt nonHitCells = hitCells->findIdsEqual(0);
180 - if (nonHitCells->getNumberOfTuples())
181 - seed = nonHitCells->getIJ(0,0);
184 - } // while (nIter < nIterMax ...
185 - if (nIter >= nIterMax)
186 - throw INTERP_KERNEL::Exception("MEDCouplingUMesh::findCellsToRenumber: Too many iterations - should not happen");
188 - // Now we have handled all N D cells which have a face touching the M1 group. It remains the cells
189 - // which are just touching the group by one (or several) node(s) (see for example testBuildInnerBoundaryAlongM1Group4)
190 - // All those cells are in direct contact with a cell which is either PING_FULL or PONG_FULL
191 - // So first reproject the PING/PONG info onto mAroundGrpLarge:
192 - DAInt hitCellsLarge = DataArrayIdType::New(); hitCellsLarge->alloc(nCellsLarge,1);
193 - hitCellsLarge->fillWithValue(0);
194 - mcIdType *hitCellsLargeP=hitCellsLarge->rwBegin(), tt=0;
195 - for(const auto &i: *idsStrict)
196 - { hitCellsLargeP[i] = hitCellsP[tt++]; }
197 - DAInt nonHitCells = hitCellsLarge->findIdsEqual(0);
198 - // Neighbor information in mAroundGrpLarge:
199 - DataArrayIdType *neighLt=0, *neighILt=0;
200 - MEDCouplingUMesh::ComputeNeighborsOfCellsAdv(descL,descIL,revDescL,revDescIL, neighLt, neighILt);
201 - DAInt neighL(neighLt), neighIL(neighILt);
202 - const mcIdType *neighILP=neighIL->begin(), *neighLP=neighL->begin();
203 - for(const auto& c : *nonHitCells)
205 - mcIdType cnt00 = neighILP[c];
206 - for (const mcIdType *n=neighLP+cnt00; cnt00 < neighILP[c+1]; n++, cnt00++)
208 - mcIdType neighVal = hitCellsLargeP[*n];
209 - if (neighVal != 0 && std::abs(neighVal) < MAX_CP) // (@test_T0) second part of the test to skip cells being assigned and target only cells assigned in the first part of the algo above
211 - mcIdType currVal = hitCellsLargeP[c];
212 - if (currVal != 0) // Several neighbors have a candidate number
214 - // Unfortunately in some weird cases (see testBuildInnerBoundary8) a cell in mAroundGrpLarge
215 - // might have as neighbor two conflicting spread zone ...
216 - if (currVal*neighVal < 0)
218 - // If we arrive here, the cell was already assigned a number and we found a neighbor with
219 - // a different sign ... we must swap the whole spread zone!!
220 - DAInt ids1 = hitCellsLarge->findIdsEqual(neighVal), ids1b = hitCellsLarge->findIdsEqual(-neighVal);
221 - DAInt ids2 = hitCellsLarge->findIdsEqual(MAX_CP*neighVal), ids2b = hitCellsLarge->findIdsEqual(-MAX_CP*neighVal);
222 - // A nice little lambda to multiply part of a DAInt by -1 ...
223 - auto mul_part_min1 = [hitCellsLargeP](const DAInt& ids) { for(const auto& i: *ids) hitCellsLargeP[i] *= -1; };
224 - mul_part_min1(ids1);
225 - mul_part_min1(ids1b);
226 - mul_part_min1(ids2);
227 - mul_part_min1(ids2b);
230 - else // First assignation
231 - hitCellsLargeP[c] = MAX_CP*neighVal; // Same sign, but different value to preserve PING_FULL and PONG_FULL
232 + if(val && hitCellsLargeP[other] != -val)
233 + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::findCellsToRenumber: internal error #1 - conflictint values - should not happen!");;
234 + // We do not yet have a value, but other side has one. Use it!
235 + if(!val) val = -hitCellsLargeP[other];
237 + // Cover first initialisation:
239 + // And finally, fill the current spread zone:
240 + for(const mcIdType& s: *spreadZone) hitCellsLargeP[s] = val;
243 - DAInt cellsRet1 = hitCellsLarge->findIdsInRange(1,MAX_CP*MAX_CP); // Positive spread zone number
244 - DAInt cellsRet2 = hitCellsLarge->findIdsInRange(-MAX_CP*MAX_CP, 0); // Negative spread zone number
246 + DAInt cellsRet1 = hitCellsLarge->findIdsEqual(1);
247 + DAInt cellsRet2 = hitCellsLarge->findIdsEqual(-1);
249 if (cellsRet1->getNumberOfTuples() + cellsRet2->getNumberOfTuples() != cellsAroundGroupLarge->getNumberOfTuples())
250 - throw INTERP_KERNEL::Exception("MEDCouplingUMesh::findCellsToRenumber: Some cells not hit - Internal error should not happen");
252 + DAInt nonHitCells = hitCellsLarge->findIdsEqual(0); // variable kept for debug ...
253 + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::findCellsToRenumber: Some cells not hit - Internal error should not happen");
255 cellsRet1->transformWithIndArr(cellsAroundGroupLarge->begin(),cellsAroundGroupLarge->end());
256 cellsRet2->transformWithIndArr(cellsAroundGroupLarge->begin(),cellsAroundGroupLarge->end());
258 diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py
259 index 71740199..7402c5de 100644
260 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py
261 +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py
262 @@ -1728,6 +1728,48 @@ class MEDLoaderTest3(unittest.TestCase):
263 m_desc.checkDeepEquivalOnSameNodesWith(m2_bis, 2, 9.9999)
266 + def testBuildInnerBoundary9(self):
267 + """ 3D test where the crack is performed so that two non-connex parts are found facing one single connex part on the other side
270 + m3 = MEDCouplingUMesh('box', 3)
271 + coo = DataArrayDouble([(0,4.6,0),(3,4.6,0),(5,4.6,0),(15,4.6,0),(15,0,0),(5,-1.60551e-25,0),(5,3,0),(3,0,0),(3,3.8,0),(0,0,0),(0,3.8,0),(0,4.6,10),(0,4.6,20),(3,4.6,10),(3,4.6,20),(5,4.6,10),(5,4.6,20),(15,4.6,10),(15,4.6,20),(15,0,10),(15,0,20),(5,-1.60551e-25,10),(5,-1.60551e-25,20),(5,3,10),(5,3,20),(3,0,10),(3,0,20),(3,3.8,10),(3,3.8,20),(0,0,10),(0,0,20),(0,3.8,10),(0,3.8,20),(3,3,0),(0,3,0),(3,3,10),(3,3,20),(0,3,10),(0,3,20)])
273 + c = DataArrayInt([31, 7, 33, 6, 5, -1, 25, 21, 23, 35, -1, 7, 25, 35, 33, -1, 33, 35, 23, 6, -1, 6, 23, 21, 5, -1, 5, 21, 25, 7, 31, 25, 35, 23, 21, -1, 26, 22, 24, 36, -1, 25, 26, 36, 35, -1, 35, 36, 24, 23, -1, 23, 24, 22, 21, -1, 21, 22, 26, 25, 31, 9, 34, 33, 7, -1, 29, 25, 35, 37, -1, 9, 29, 37, 34, -1, 34, 37, 35, 33, -1, 33, 35, 25, 7, -1, 7, 25, 29, 9, 31, 29, 37, 35, 25, -1, 30, 26, 36, 38, -1, 29, 30, 38, 37, -1, 37, 38, 36, 35, -1, 35, 36, 26, 25, -1, 25, 26, 30, 29, 31, 0, 1, 8, 10, -1, 11, 31, 27, 13, -1, 0, 11, 13, 1, -1, 1, 13, 27, 8, -1, 8, 27, 31, 10, -1, 10, 31, 11, 0, 31, 11, 13, 27, 31, -1, 12, 32, 28, 14, -1, 11, 12, 14, 13, -1, 13, 14, 28, 27, -1, 27, 28, 32, 31, -1, 31, 32, 12, 11, 31, 6, 8, 1, 2, -1, 23, 15, 13, 27, -1, 6, 23, 27, 8, -1, 8, 27, 13, 1, -1, 1, 13, 15, 2, -1, 2, 15, 23, 6, 31, 23, 27, 13, 15, -1, 24, 16, 14, 28, -1, 23, 24, 28, 27, -1, 27, 28, 14, 13, -1, 13, 14, 16, 15, -1, 15, 16, 24, 23, 31, 6, 2, 3, 4, 5, -1, 23, 21, 19, 17, 15, -1, 2, 6, 23, 15, -1, 3, 2, 15, 17, -1, 4, 3, 17, 19, -1, 5, 4, 19, 21, -1, 6, 5, 21, 23, 31, 23, 15, 17, 19, 21, -1, 24, 22, 20, 18, 16, -1, 15, 23, 24, 16, -1, 17, 15, 16, 18, -1, 19, 17, 18, 20, -1, 21, 19, 20, 22, -1, 23, 21, 22, 24])
274 + cI = DataArrayInt([0, 30, 60, 90, 120, 150, 180, 210, 240, 277, 314])
275 + m3.setConnectivity(c, cI)
276 + m3.checkConsistency()
277 + m2, _, _,_,_ = m3.buildDescendingConnectivity()
278 + grpIds = DataArrayInt([4,9,35,39]); grpIds.setName("group")
279 + mfu = MEDFileUMesh()
280 + mfu.setMeshAtLevel(0, m3)
281 + mfu.setMeshAtLevel(-1, m2)
282 + mfu.setGroupsAtLevel(-1, [grpIds])
283 + m2, _, _, _, _ = m3.buildDescendingConnectivity()
284 + grpIds = DataArrayInt([4,9,35,39]); grpIds.setName("group")
285 + mfu = MEDFileUMesh()
286 + mfu.setMeshAtLevel(0, m3)
287 + mfu.setMeshAtLevel(-1, m2)
288 + mfu.setGroupsAtLevel(-1, [grpIds])
289 + nNod = m3.getNumberOfNodes()
290 + nodesDup, cells1, cells2 = mfu.buildInnerBoundaryAlongM1Group("group")
291 + m3_bis = mfu.getMeshAtLevel(0)
292 + m3_bis.checkConsistency()
293 + m2_bis = mfu.getMeshAtLevel(-1)
294 + m2_bis.checkConsistency()
295 + self.assertEqual(nNod+9, mfu.getNumberOfNodes())
296 + self.assertEqual(nNod+9, m3_bis.getNumberOfNodes())
297 + self.assertEqual(nNod+9, m2_bis.getNumberOfNodes())
298 + self.assertEqual([2, 5, 6, 15, 16, 21, 22, 23, 24], nodesDup.getValues())
299 + self.assertEqual(m3_bis.getCoords()[nodesDup].getValues(), m3_bis.getCoords()[nNod:].getValues())
300 + self.assertEqual(set([0,1,6,7]), set(cells1.getValues()))
301 + self.assertEqual(set([8,9]), set(cells2.getValues()))
302 + self.assertEqual([4,9,35,39],mfu.getGroupArr(-1,"group").getValues())
303 + self.assertEqual([49, 50, 51, 52],mfu.getGroupArr(-1,"group_dup").getValues()) # here only one cell has been duplicated
304 + m_desc, _, _, _, _ = m3_bis.buildDescendingConnectivity()
305 + m_desc.checkDeepEquivalOnSameNodesWith(m2_bis, 2, 9.9999)
309 def testBasicConstructors(self):
310 GeneratePyfile18(self)