1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "slidingInterface.H"
28 #include "mapPolyMesh.H"
29 #include "polyTopoChanger.H"
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 void Foam::slidingInterface::calcAttachedAddressing() const
37 Pout<< "void Foam::slidingInterface::calcAttachedAddressing() const "
38 << " for object " << name() << " : "
39 << "Calculating zone face-cell addressing."
45 // Clear existing addressing
46 clearAttachedAddressing();
48 const polyMesh& mesh = topoChanger().mesh();
49 const labelList& own = mesh.faceOwner();
50 const labelList& nei = mesh.faceNeighbour();
51 const faceZoneMesh& faceZones = mesh.faceZones();
55 const primitiveFacePatch& masterPatch =
56 faceZones[masterFaceZoneID_.index()]();
58 const labelList& masterPatchFaces =
59 faceZones[masterFaceZoneID_.index()];
61 const boolList& masterFlip =
62 faceZones[masterFaceZoneID_.index()].flipMap();
64 masterFaceCellsPtr_ = new labelList(masterPatchFaces.size());
65 labelList& mfc = *masterFaceCellsPtr_;
67 forAll(masterPatchFaces, faceI)
69 if (masterFlip[faceI])
71 mfc[faceI] = nei[masterPatchFaces[faceI]];
75 mfc[faceI] = own[masterPatchFaces[faceI]];
81 const primitiveFacePatch& slavePatch =
82 faceZones[slaveFaceZoneID_.index()]();
84 const labelList& slavePatchFaces =
85 faceZones[slaveFaceZoneID_.index()];
87 const boolList& slaveFlip =
88 faceZones[slaveFaceZoneID_.index()].flipMap();
90 slaveFaceCellsPtr_ = new labelList(slavePatchFaces.size());
91 labelList& sfc = *slaveFaceCellsPtr_;
93 forAll(slavePatchFaces, faceI)
97 sfc[faceI] = nei[slavePatchFaces[faceI]];
101 sfc[faceI] = own[slavePatchFaces[faceI]];
105 // Check that the addressing is valid
106 if (min(mfc) < 0 || min(sfc) < 0)
114 Pout<< "No cell next to master patch face " << faceI
115 << ". Global face no: " << mfc[faceI]
116 << " own: " << own[masterPatchFaces[faceI]]
117 << " nei: " << nei[masterPatchFaces[faceI]]
118 << " flip: " << masterFlip[faceI] << endl;
126 Pout<< "No cell next to slave patch face " << faceI
127 << ". Global face no: " << sfc[faceI]
128 << " own: " << own[slavePatchFaces[faceI]]
129 << " nei: " << nei[slavePatchFaces[faceI]]
130 << " flip: " << slaveFlip[faceI] << endl;
137 "void slidingInterface::calcAttachedAddressing()"
139 ) << "Error is zone face-cell addressing. Probable error in "
140 << "decoupled mesh or sliding interface definition."
141 << abort(FatalError);
144 // Calculate stick-out faces
145 const labelListList& pointFaces = mesh.pointFaces();
148 labelHashSet masterStickOutFaceMap
150 primitiveMesh::facesPerCell_*(masterPatch.size())
153 const labelList& masterMeshPoints = masterPatch.meshPoints();
155 forAll(masterMeshPoints, pointI)
157 const labelList& curFaces = pointFaces[masterMeshPoints[pointI]];
159 forAll(curFaces, faceI)
161 // Check if the face belongs to the master face zone;
165 faceZones.whichZone(curFaces[faceI])
166 != masterFaceZoneID_.index()
169 masterStickOutFaceMap.insert(curFaces[faceI]);
174 masterStickOutFacesPtr_ = new labelList(masterStickOutFaceMap.toc());
177 labelHashSet slaveStickOutFaceMap
179 primitiveMesh::facesPerCell_*(slavePatch.size())
182 const labelList& slaveMeshPoints = slavePatch.meshPoints();
184 forAll(slaveMeshPoints, pointI)
186 const labelList& curFaces = pointFaces[slaveMeshPoints[pointI]];
188 forAll(curFaces, faceI)
190 // Check if the face belongs to the slave face zone;
194 faceZones.whichZone(curFaces[faceI])
195 != slaveFaceZoneID_.index()
198 slaveStickOutFaceMap.insert(curFaces[faceI]);
203 slaveStickOutFacesPtr_ = new labelList(slaveStickOutFaceMap.toc());
206 // Retired point addressing does not exist at this stage.
207 // It will be filled when the interface is coupled.
208 retiredPointMapPtr_ =
211 2*faceZones[slaveFaceZoneID_.index()]().nPoints()
214 // Ditto for cut point edge map. This is a rough guess of its size
216 cutPointEdgePairMapPtr_ =
219 faceZones[slaveFaceZoneID_.index()]().nEdges()
226 "void slidingInterface::calcAttachedAddressing() const"
227 ) << "The interface is attached. The zone face-cell addressing "
228 << "cannot be assembled for object " << name()
229 << abort(FatalError);
234 Pout<< "void Foam::slidingInterface::calcAttachedAddressing() const "
235 << " for object " << name() << " : "
236 << "Finished calculating zone face-cell addressing."
242 void Foam::slidingInterface::clearAttachedAddressing() const
244 deleteDemandDrivenData(masterFaceCellsPtr_);
245 deleteDemandDrivenData(slaveFaceCellsPtr_);
247 deleteDemandDrivenData(masterStickOutFacesPtr_);
248 deleteDemandDrivenData(slaveStickOutFacesPtr_);
250 deleteDemandDrivenData(retiredPointMapPtr_);
251 deleteDemandDrivenData(cutPointEdgePairMapPtr_);
255 void Foam::slidingInterface::renumberAttachedAddressing
260 // Get reference to reverse cell renumbering
261 // The renumbering map is needed the other way around, i.e. giving
262 // the new cell number for every old cell next to the interface.
263 const labelList& reverseCellMap = m.reverseCellMap();
265 const labelList& mfc = masterFaceCells();
266 const labelList& sfc = slaveFaceCells();
269 labelList* newMfcPtr = new labelList(mfc.size(), -1);
270 labelList& newMfc = *newMfcPtr;
272 const labelList& mfzRenumber =
273 m.faceZoneFaceMap()[masterFaceZoneID_.index()];
277 label newCellI = reverseCellMap[mfc[mfzRenumber[faceI]]];
281 newMfc[faceI] = newCellI;
286 labelList* newSfcPtr = new labelList(sfc.size(), -1);
287 labelList& newSfc = *newSfcPtr;
289 const labelList& sfzRenumber =
290 m.faceZoneFaceMap()[slaveFaceZoneID_.index()];
294 label newCellI = reverseCellMap[sfc[sfzRenumber[faceI]]];
298 newSfc[faceI] = newCellI;
304 // Check if all the mapped cells are live
305 if (min(newMfc) < 0 || min(newSfc) < 0)
309 "void slidingInterface::renumberAttachedAddressing("
310 "const mapPolyMesh& m) const"
311 ) << "Error in cell renumbering for object " << name()
312 << ". Some of master cells next "
313 << "to the interface have been removed."
314 << abort(FatalError);
318 // Renumber stick-out faces
320 const labelList& reverseFaceMap = m.reverseFaceMap();
323 const labelList& msof = masterStickOutFaces();
325 labelList* newMsofPtr = new labelList(msof.size(), -1);
326 labelList& newMsof = *newMsofPtr;
330 label newFaceI = reverseFaceMap[msof[faceI]];
334 newMsof[faceI] = newFaceI;
337 // Pout<< "newMsof: " << newMsof << endl;
339 const labelList& ssof = slaveStickOutFaces();
341 labelList* newSsofPtr = new labelList(ssof.size(), -1);
342 labelList& newSsof = *newSsofPtr;
346 label newFaceI = reverseFaceMap[ssof[faceI]];
350 newSsof[faceI] = newFaceI;
353 // Pout<< "newSsof: " << newSsof << endl;
356 // Check if all the mapped cells are live
357 if (min(newMsof) < 0 || min(newSsof) < 0)
361 "void slidingInterface::renumberAttachedAddressing("
362 "const mapPolyMesh& m) const"
363 ) << "Error in face renumbering for object " << name()
364 << ". Some of stick-out next "
365 << "to the interface have been removed."
366 << abort(FatalError);
370 // Renumber the retired point map. Need to take a copy!
371 const Map<label> rpm = retiredPointMap();
373 Map<label>* newRpmPtr = new Map<label>(rpm.size());
374 Map<label>& newRpm = *newRpmPtr;
376 const labelList rpmToc = rpm.toc();
378 // Get reference to point renumbering
379 const labelList& reversePointMap = m.reversePointMap();
383 forAll(rpmToc, rpmTocI)
385 key = reversePointMap[rpmToc[rpmTocI]];
387 value = reversePointMap[rpm.find(rpmToc[rpmTocI])()];
391 // Check if all the mapped cells are live
392 if (key < 0 || value < 0)
396 "void slidingInterface::renumberAttachedAddressing("
397 "const mapPolyMesh& m) const"
398 ) << "Error in retired point numbering for object "
399 << name() << ". Some of master "
400 << "points have been removed."
401 << abort(FatalError);
405 newRpm.insert(key, value);
408 // Renumber the cut point edge pair map. Need to take a copy!
409 const Map<Pair<edge> > cpepm = cutPointEdgePairMap();
411 Map<Pair<edge> >* newCpepmPtr = new Map<Pair<edge> >(cpepm.size());
412 Map<Pair<edge> >& newCpepm = *newCpepmPtr;
414 const labelList cpepmToc = cpepm.toc();
416 forAll(cpepmToc, cpepmTocI)
418 key = reversePointMap[cpepmToc[cpepmTocI]];
420 const Pair<edge>& oldPe = cpepm.find(cpepmToc[cpepmTocI])();
422 // Re-do the edges in global addressing
423 const label ms = reversePointMap[oldPe.first().start()];
424 const label me = reversePointMap[oldPe.first().end()];
426 const label ss = reversePointMap[oldPe.second().start()];
427 const label se = reversePointMap[oldPe.second().end()];
431 // Check if all the mapped cells are live
432 if (key < 0 || ms < 0 || me < 0 || ss < 0 || se < 0)
436 "void slidingInterface::renumberAttachedAddressing("
437 "const mapPolyMesh& m) const"
438 ) << "Error in cut point edge pair map numbering for object "
439 << name() << ". Some of master points have been removed."
440 << abort(FatalError);
444 newCpepm.insert(key, Pair<edge>(edge(ms, me), edge(ss, se)));
447 if (!projectedSlavePointsPtr_)
451 "void slidingInterface::renumberAttachedAddressing("
452 "const mapPolyMesh& m) const"
453 ) << "Error in projected point numbering for object " << name()
454 << abort(FatalError);
457 // Renumber the projected slave zone points
458 const pointField& projectedSlavePoints = *projectedSlavePointsPtr_;
460 pointField* newProjectedSlavePointsPtr
462 new pointField(projectedSlavePoints.size())
464 pointField& newProjectedSlavePoints = *newProjectedSlavePointsPtr;
466 const labelList& sfzPointRenumber =
467 m.faceZonePointMap()[slaveFaceZoneID_.index()];
469 forAll(newProjectedSlavePoints, pointI)
471 if (sfzPointRenumber[pointI] > -1)
473 newProjectedSlavePoints[pointI] =
474 projectedSlavePoints[sfzPointRenumber[pointI]];
479 clearAttachedAddressing();
481 deleteDemandDrivenData(projectedSlavePointsPtr_);
483 masterFaceCellsPtr_ = newMfcPtr;
484 slaveFaceCellsPtr_ = newSfcPtr;
486 masterStickOutFacesPtr_ = newMsofPtr;
487 slaveStickOutFacesPtr_ = newSsofPtr;
489 retiredPointMapPtr_ = newRpmPtr;
490 cutPointEdgePairMapPtr_ = newCpepmPtr;
491 projectedSlavePointsPtr_ = newProjectedSlavePointsPtr;
495 const Foam::labelList& Foam::slidingInterface::masterFaceCells() const
497 if (!masterFaceCellsPtr_)
501 "const labelList& slidingInterface::masterFaceCells() const"
502 ) << "Master zone face-cell addressing not available for object "
504 << abort(FatalError);
507 return *masterFaceCellsPtr_;
511 const Foam::labelList& Foam::slidingInterface::slaveFaceCells() const
513 if (!slaveFaceCellsPtr_)
517 "const labelList& slidingInterface::slaveFaceCells() const"
518 ) << "Slave zone face-cell addressing not available for object "
520 << abort(FatalError);
523 return *slaveFaceCellsPtr_;
527 const Foam::labelList& Foam::slidingInterface::masterStickOutFaces() const
529 if (!masterStickOutFacesPtr_)
533 "const labelList& slidingInterface::masterStickOutFaces() const"
534 ) << "Master zone stick-out face addressing not available for object "
536 << abort(FatalError);
539 return *masterStickOutFacesPtr_;
543 const Foam::labelList& Foam::slidingInterface::slaveStickOutFaces() const
545 if (!slaveStickOutFacesPtr_)
549 "const labelList& slidingInterface::slaveStickOutFaces() const"
550 ) << "Slave zone stick-out face addressing not available for object "
552 << abort(FatalError);
555 return *slaveStickOutFacesPtr_;
559 const Foam::Map<Foam::label>& Foam::slidingInterface::retiredPointMap() const
561 if (!retiredPointMapPtr_)
565 "const Map<label>& slidingInterface::retiredPointMap() const"
566 ) << "Retired point map not available for object " << name()
567 << abort(FatalError);
570 return *retiredPointMapPtr_;
574 const Foam::Map<Foam::Pair<Foam::edge> >&
575 Foam::slidingInterface::cutPointEdgePairMap() const
577 if (!cutPointEdgePairMapPtr_)
581 "const Map<Pair<edge> >& slidingInterface::"
582 "cutPointEdgePairMap() const"
583 ) << "Retired point map not available for object " << name()
584 << abort(FatalError);
587 return *cutPointEdgePairMapPtr_;
591 // ************************************************************************* //