1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "slidingInterface.H"
29 #include "mapPolyMesh.H"
30 #include "polyTopoChanger.H"
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 void Foam::slidingInterface::calcAttachedAddressing() const
38 Pout<< "void Foam::slidingInterface::calcAttachedAddressing() const "
39 << " for object " << name() << " : "
40 << "Calculating zone face-cell addressing."
46 // Clear existing addressing
47 clearAttachedAddressing();
49 const polyMesh& mesh = topoChanger().mesh();
50 const labelList& own = mesh.faceOwner();
51 const labelList& nei = mesh.faceNeighbour();
52 const faceZoneMesh& faceZones = mesh.faceZones();
56 const primitiveFacePatch& masterPatch =
57 faceZones[masterFaceZoneID_.index()]();
59 const labelList& masterPatchFaces =
60 faceZones[masterFaceZoneID_.index()];
62 const boolList& masterFlip =
63 faceZones[masterFaceZoneID_.index()].flipMap();
65 masterFaceCellsPtr_ = new labelList(masterPatchFaces.size());
66 labelList& mfc = *masterFaceCellsPtr_;
68 forAll (masterPatchFaces, faceI)
70 if (masterFlip[faceI])
72 mfc[faceI] = nei[masterPatchFaces[faceI]];
76 mfc[faceI] = own[masterPatchFaces[faceI]];
82 const primitiveFacePatch& slavePatch =
83 faceZones[slaveFaceZoneID_.index()]();
85 const labelList& slavePatchFaces =
86 faceZones[slaveFaceZoneID_.index()];
88 const boolList& slaveFlip =
89 faceZones[slaveFaceZoneID_.index()].flipMap();
91 slaveFaceCellsPtr_ = new labelList(slavePatchFaces.size());
92 labelList& sfc = *slaveFaceCellsPtr_;
94 forAll (slavePatchFaces, faceI)
98 sfc[faceI] = nei[slavePatchFaces[faceI]];
102 sfc[faceI] = own[slavePatchFaces[faceI]];
106 // Check that the addressing is valid
107 if (min(mfc) < 0 || min(sfc) < 0)
115 Pout << "No cell next to master patch face " << faceI
116 << ". Global face no: " << mfc[faceI]
117 << " own: " << own[masterPatchFaces[faceI]]
118 << " nei: " << nei[masterPatchFaces[faceI]]
119 << " flip: " << masterFlip[faceI] << endl;
127 Pout << "No cell next to slave patch face " << faceI
128 << ". Global face no: " << sfc[faceI]
129 << " own: " << own[slavePatchFaces[faceI]]
130 << " nei: " << nei[slavePatchFaces[faceI]]
131 << " flip: " << slaveFlip[faceI] << endl;
138 "void slidingInterface::calcAttachedAddressing()"
140 ) << "Error is zone face-cell addressing. Probable error in "
141 << "decoupled mesh or sliding interface definition."
142 << abort(FatalError);
145 // Calculate stick-out faces
146 const labelListList& pointFaces = mesh.pointFaces();
149 labelHashSet masterStickOutFaceMap
151 primitiveMesh::facesPerCell_*(masterPatch.size())
154 const labelList& masterMeshPoints = masterPatch.meshPoints();
156 forAll (masterMeshPoints, pointI)
158 const labelList& curFaces = pointFaces[masterMeshPoints[pointI]];
160 forAll (curFaces, faceI)
162 // Check if the face belongs to the master face zone;
166 faceZones.whichZone(curFaces[faceI])
167 != masterFaceZoneID_.index()
170 masterStickOutFaceMap.insert(curFaces[faceI]);
175 masterStickOutFacesPtr_ = new labelList(masterStickOutFaceMap.toc());
178 labelHashSet slaveStickOutFaceMap
180 primitiveMesh::facesPerCell_*(slavePatch.size())
183 const labelList& slaveMeshPoints = slavePatch.meshPoints();
185 forAll (slaveMeshPoints, pointI)
187 const labelList& curFaces = pointFaces[slaveMeshPoints[pointI]];
189 forAll (curFaces, faceI)
191 // Check if the face belongs to the slave face zone;
195 faceZones.whichZone(curFaces[faceI])
196 != slaveFaceZoneID_.index()
199 slaveStickOutFaceMap.insert(curFaces[faceI]);
204 slaveStickOutFacesPtr_ = new labelList(slaveStickOutFaceMap.toc());
207 // Retired point addressing does not exist at this stage.
208 // It will be filled when the interface is coupled.
209 retiredPointMapPtr_ =
212 2*faceZones[slaveFaceZoneID_.index()]().nPoints()
215 // Ditto for cut point edge map. This is a rough guess of its size
217 cutPointEdgePairMapPtr_ =
220 faceZones[slaveFaceZoneID_.index()]().nEdges()
227 "void slidingInterface::calcAttachedAddressing() const"
228 ) << "The interface is attached. The zone face-cell addressing "
229 << "cannot be assembled for object " << name()
230 << abort(FatalError);
235 Pout<< "void Foam::slidingInterface::calcAttachedAddressing() const "
236 << " for object " << name() << " : "
237 << "Finished calculating zone face-cell addressing."
243 void Foam::slidingInterface::clearAttachedAddressing() const
245 deleteDemandDrivenData(masterFaceCellsPtr_);
246 deleteDemandDrivenData(slaveFaceCellsPtr_);
248 deleteDemandDrivenData(masterStickOutFacesPtr_);
249 deleteDemandDrivenData(slaveStickOutFacesPtr_);
251 deleteDemandDrivenData(retiredPointMapPtr_);
252 deleteDemandDrivenData(cutPointEdgePairMapPtr_);
256 void Foam::slidingInterface::renumberAttachedAddressing
261 // Get reference to reverse cell renumbering
262 // The renumbering map is needed the other way around, i.e. giving
263 // the new cell number for every old cell next to the interface.
264 const labelList& reverseCellMap = m.reverseCellMap();
266 const labelList& mfc = masterFaceCells();
267 const labelList& sfc = slaveFaceCells();
270 labelList* newMfcPtr = new labelList(mfc.size(), -1);
271 labelList& newMfc = *newMfcPtr;
273 const labelList& mfzRenumber =
274 m.faceZoneFaceMap()[masterFaceZoneID_.index()];
278 label newCellI = reverseCellMap[mfc[mfzRenumber[faceI]]];
282 newMfc[faceI] = newCellI;
287 labelList* newSfcPtr = new labelList(sfc.size(), -1);
288 labelList& newSfc = *newSfcPtr;
290 const labelList& sfzRenumber =
291 m.faceZoneFaceMap()[slaveFaceZoneID_.index()];
295 label newCellI = reverseCellMap[sfc[sfzRenumber[faceI]]];
299 newSfc[faceI] = newCellI;
305 // Check if all the mapped cells are live
306 if (min(newMfc) < 0 || min(newSfc) < 0)
310 "void slidingInterface::renumberAttachedAddressing("
311 "const mapPolyMesh& m) const"
312 ) << "Error in cell renumbering for object " << name()
313 << ". Some of master cells next "
314 << "to the interface have been removed."
315 << abort(FatalError);
319 // Renumber stick-out faces
321 const labelList& reverseFaceMap = m.reverseFaceMap();
324 const labelList& msof = masterStickOutFaces();
326 labelList* newMsofPtr = new labelList(msof.size(), -1);
327 labelList& newMsof = *newMsofPtr;
331 label newFaceI = reverseFaceMap[msof[faceI]];
335 newMsof[faceI] = newFaceI;
338 // Pout << "newMsof: " << newMsof << endl;
340 const labelList& ssof = slaveStickOutFaces();
342 labelList* newSsofPtr = new labelList(ssof.size(), -1);
343 labelList& newSsof = *newSsofPtr;
347 label newFaceI = reverseFaceMap[ssof[faceI]];
351 newSsof[faceI] = newFaceI;
354 // Pout << "newSsof: " << newSsof << endl;
357 // Check if all the mapped cells are live
358 if (min(newMsof) < 0 || min(newSsof) < 0)
362 "void slidingInterface::renumberAttachedAddressing("
363 "const mapPolyMesh& m) const"
364 ) << "Error in face renumbering for object " << name()
365 << ". Some of stick-out next "
366 << "to the interface have been removed."
367 << abort(FatalError);
371 // Renumber the retired point map. Need to take a copy!
372 const Map<label> rpm = retiredPointMap();
374 Map<label>* newRpmPtr = new Map<label>(rpm.size());
375 Map<label>& newRpm = *newRpmPtr;
377 const labelList rpmToc = rpm.toc();
379 // Get reference to point renumbering
380 const labelList& reversePointMap = m.reversePointMap();
384 forAll (rpmToc, rpmTocI)
386 key = reversePointMap[rpmToc[rpmTocI]];
388 value = reversePointMap[rpm.find(rpmToc[rpmTocI])()];
392 // Check if all the mapped cells are live
393 if (key < 0 || value < 0)
397 "void slidingInterface::renumberAttachedAddressing("
398 "const mapPolyMesh& m) const"
399 ) << "Error in retired point numbering for object "
400 << name() << ". Some of master "
401 << "points have been removed."
402 << abort(FatalError);
406 newRpm.insert(key, value);
409 // Renumber the cut point edge pair map. Need to take a copy!
410 const Map<Pair<edge> > cpepm = cutPointEdgePairMap();
412 Map<Pair<edge> >* newCpepmPtr = new Map<Pair<edge> >(cpepm.size());
413 Map<Pair<edge> >& newCpepm = *newCpepmPtr;
415 const labelList cpepmToc = cpepm.toc();
417 forAll (cpepmToc, cpepmTocI)
419 key = reversePointMap[cpepmToc[cpepmTocI]];
421 const Pair<edge>& oldPe = cpepm.find(cpepmToc[cpepmTocI])();
423 // Re-do the edges in global addressing
424 const label ms = reversePointMap[oldPe.first().start()];
425 const label me = reversePointMap[oldPe.first().end()];
427 const label ss = reversePointMap[oldPe.second().start()];
428 const label se = reversePointMap[oldPe.second().end()];
432 // Check if all the mapped cells are live
433 if (key < 0 || ms < 0 || me < 0 || ss < 0 || se < 0)
437 "void slidingInterface::renumberAttachedAddressing("
438 "const mapPolyMesh& m) const"
439 ) << "Error in cut point edge pair map numbering for object "
440 << name() << ". Some of master points have been removed."
441 << abort(FatalError);
445 newCpepm.insert(key, Pair<edge>(edge(ms, me), edge(ss, se)));
448 if (!projectedSlavePointsPtr_)
452 "void slidingInterface::renumberAttachedAddressing("
453 "const mapPolyMesh& m) const"
454 ) << "Error in projected point numbering for object " << name()
455 << abort(FatalError);
458 // Renumber the projected slave zone points
459 const pointField& projectedSlavePoints = *projectedSlavePointsPtr_;
461 pointField* newProjectedSlavePointsPtr
463 new pointField(projectedSlavePoints.size())
465 pointField& newProjectedSlavePoints = *newProjectedSlavePointsPtr;
467 const labelList& sfzPointRenumber =
468 m.faceZonePointMap()[slaveFaceZoneID_.index()];
470 forAll (newProjectedSlavePoints, pointI)
472 if (sfzPointRenumber[pointI] > -1)
474 newProjectedSlavePoints[pointI] =
475 projectedSlavePoints[sfzPointRenumber[pointI]];
480 clearAttachedAddressing();
482 deleteDemandDrivenData(projectedSlavePointsPtr_);
484 masterFaceCellsPtr_ = newMfcPtr;
485 slaveFaceCellsPtr_ = newSfcPtr;
487 masterStickOutFacesPtr_ = newMsofPtr;
488 slaveStickOutFacesPtr_ = newSsofPtr;
490 retiredPointMapPtr_ = newRpmPtr;
491 cutPointEdgePairMapPtr_ = newCpepmPtr;
492 projectedSlavePointsPtr_ = newProjectedSlavePointsPtr;
496 const Foam::labelList& Foam::slidingInterface::masterFaceCells() const
498 if (!masterFaceCellsPtr_)
502 "const labelList& slidingInterface::masterFaceCells() const"
503 ) << "Master zone face-cell addressing not available for object "
505 << abort(FatalError);
508 return *masterFaceCellsPtr_;
512 const Foam::labelList& Foam::slidingInterface::slaveFaceCells() const
514 if (!slaveFaceCellsPtr_)
518 "const labelList& slidingInterface::slaveFaceCells() const"
519 ) << "Slave zone face-cell addressing not available for object "
521 << abort(FatalError);
524 return *slaveFaceCellsPtr_;
528 const Foam::labelList& Foam::slidingInterface::masterStickOutFaces() const
530 if (!masterStickOutFacesPtr_)
534 "const labelList& slidingInterface::masterStickOutFaces() const"
535 ) << "Master zone stick-out face addressing not available for object "
537 << abort(FatalError);
540 return *masterStickOutFacesPtr_;
544 const Foam::labelList& Foam::slidingInterface::slaveStickOutFaces() const
546 if (!slaveStickOutFacesPtr_)
550 "const labelList& slidingInterface::slaveStickOutFaces() const"
551 ) << "Slave zone stick-out face addressing not available for object "
553 << abort(FatalError);
556 return *slaveStickOutFacesPtr_;
560 const Foam::Map<Foam::label>& Foam::slidingInterface::retiredPointMap() const
562 if (!retiredPointMapPtr_)
566 "const Map<label>& slidingInterface::retiredPointMap() const"
567 ) << "Retired point map not available for object " << name()
568 << abort(FatalError);
571 return *retiredPointMapPtr_;
575 const Foam::Map<Foam::Pair<Foam::edge> >&
576 Foam::slidingInterface::cutPointEdgePairMap() const
578 if (!cutPointEdgePairMapPtr_)
582 "const Map<Pair<edge> >& slidingInterface::"
583 "cutPointEdgePairMap() const"
584 ) << "Retired point map not available for object " << name()
585 << abort(FatalError);
588 return *cutPointEdgePairMapPtr_;
592 // ************************************************************************* //