1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
28 Implementation of the coupleMap class
32 University of Massachusetts Amherst
35 \*---------------------------------------------------------------------------*/
37 #include "coupleMap.H"
39 #include "demandDrivenData.H"
44 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
46 const char* coupleMap::names[coupleMap::INVALID + 1] =
59 // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
61 const char* coupleMap::asText(const opType oType)
66 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
74 const label patchIndex,
75 const label masterIndex,
76 const label slaveIndex
83 patchIndex_(patchIndex),
84 masterIndex_(masterIndex),
85 slaveIndex_(slaveIndex),
93 (io.readOpt() == IOobject::MUST_READ)
94 || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
97 // Construct an Istream and read from disk.
98 readData(readStream(typeName));
105 coupleMap::coupleMap(const coupleMap& cm)
107 regIOobject(cm, true),
108 twoDMesh_(cm.twoDMesh_),
109 isLocal_(cm.isLocal_),
111 patchIndex_(cm.patchIndex_),
112 masterIndex_(cm.masterIndex_),
113 slaveIndex_(cm.slaveIndex_),
114 nEntities_(cm.nEntities_),
121 (cm.readOpt() == IOobject::MUST_READ)
122 || (cm.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
125 // Construct an Istream and read from disk.
126 readData(readStream(typeName));
132 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
134 coupleMap::~coupleMap()
142 // * * * * * * * * * * * * * * * Private Functions * * * * * * * * * * * * * //
144 void coupleMap::clearAddressing() const
146 deleteDemandDrivenData(edgesPtr_);
147 deleteDemandDrivenData(facesPtr_);
148 deleteDemandDrivenData(faceEdgesPtr_);
152 void coupleMap::makeEdges() const
154 // It is an error to attempt to recalculate
155 // if the pointer is already set
158 FatalErrorIn("void coupleMap::makeEdges() const")
159 << "Edges have already been calculated."
160 << abort(FatalError);
163 label nEdges = nEntities(coupleMap::EDGE);
164 const labelList& eBuffer = entityBuffer(coupleMap::EDGE);
166 edgesPtr_ = new edgeList(nEdges);
168 edgeList& edges = *edgesPtr_;
172 edges[edgeI][0] = eBuffer[(2*edgeI)+0];
173 edges[edgeI][1] = eBuffer[(2*edgeI)+1];
178 void coupleMap::makeFaces() const
180 // It is an error to attempt to recalculate
181 // if the pointer is already set
182 if (facesPtr_ || faceEdgesPtr_)
184 FatalErrorIn("void coupleMap::makeFaces() const")
185 << "Faces have already been calculated."
186 << abort(FatalError);
189 label nFaces = nEntities(coupleMap::FACE);
191 const labelList& fBuffer = entityBuffer(coupleMap::FACE);
192 const labelList& feBuffer = entityBuffer(coupleMap::FACE_EDGE);
193 const labelList& nfeBuffer = entityBuffer(coupleMap::NFE_BUFFER);
195 facesPtr_ = new faceList(nFaces);
196 faceEdgesPtr_ = new labelListList(nFaces);
198 faceList& faces = *facesPtr_;
199 labelListList& faceEdges = *faceEdgesPtr_;
205 face& f = faces[faceI];
206 labelList& fe = faceEdges[faceI];
208 // Fetch the buffer value
209 label nfe = nfeBuffer[faceI];
215 for (label p = 0; p < nfe; p++)
217 f[p] = fBuffer[sumNFE + p];
218 fe[p] = feBuffer[sumNFE + p];
224 if (sumNFE != nEntities(coupleMap::NFE_SIZE))
226 FatalErrorIn("void coupleMap::makeFaces() const")
227 << " Mismatched buffer." << nl
228 << " sumNFE: " << sumNFE << nl
229 << " NFE_SIZE: " << nEntities(coupleMap::NFE_SIZE) << nl
230 << abort(FatalError);
235 void coupleMap::makeFaceMap() const
237 // It is an error to attempt to recalculate
238 // if the map is already calculated
241 FatalErrorIn("void coupleMap::makeFaceMap() const")
242 << "faceMap has already been calculated."
243 << abort(FatalError);
246 const Map<label>& mapFaces = entityMap(coupleMap::FACE);
249 faceMap_.setSize(mapFaces.size(), -1);
252 forAllConstIter(Map<label>, mapFaces, fIter)
254 faceMap_[fIter.key()] = fIter();
259 void coupleMap::makeCellMap() const
261 // It is an error to attempt to recalculate
262 // if the map is already calculated
265 FatalErrorIn("void coupleMap::makeCellMap() const")
266 << "cellMap has already been calculated."
267 << abort(FatalError);
270 const Map<label>& mapCells = entityMap(coupleMap::CELL);
273 cellMap_.setSize(mapCells.size(), -1);
276 forAllConstIter(Map<label>, mapCells, cIter)
278 cellMap_[cIter.key()] = cIter();
283 void coupleMap::makeInternalFaceMap() const
285 // It is an error to attempt to recalculate
286 // if the map is already calculated
287 if (internalFaceMap_.size())
289 FatalErrorIn("void coupleMap::makeInternalFaceMap() const")
290 << "internal faceMap has already been calculated."
291 << abort(FatalError);
294 // Slice for internal faces
295 internalFaceMap_ = SubList<label>(faceMap(), nEntities(INTERNAL_FACE));
299 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
301 pointField& coupleMap::pointBuffer() const
307 pointField& coupleMap::oldPointBuffer() const
309 return oldPointBuffer_;
313 labelList& coupleMap::subMeshPoints() const
315 return subMeshPoints_;
319 List<labelPair>& coupleMap::globalProcPoints() const
321 return globalProcPoints_;
325 void coupleMap::allocateBuffers() const
327 forAll(nEntities_, entityI)
329 if (nEntities_[entityI] < 0)
331 FatalErrorIn("void coupleMap::allocateBuffers() const")
332 << " Entity sizes are not valid." << nl
333 << " nEntities: " << nEntities_
334 << abort(FatalError);
338 // Size up point buffers
339 pointBuffer().setSize(nEntities(POINT));
340 oldPointBuffer().setSize(nEntities(POINT));
342 // Size up connectivity buffers
343 entityBuffer(POINT).setSize
345 nEntities(GLOBAL_POINT)
346 - nEntities(SHARED_POINT)
350 entityBuffer(EDGE).setSize(2 * nEntities(EDGE));
352 // Set addressing buffers
353 entityBuffer(OWNER).setSize(nEntities(FACE));
354 entityBuffer(NEIGHBOUR).setSize(nEntities(INTERNAL_FACE));
356 // Size up boundary buffers
357 entityBuffer(FACE_STARTS).setSize(nEntities(NBDY));
358 entityBuffer(FACE_SIZES).setSize(nEntities(NBDY));
359 entityBuffer(EDGE_STARTS).setSize(nEntities(NBDY));
360 entityBuffer(EDGE_SIZES).setSize(nEntities(NBDY));
361 entityBuffer(PATCH_ID).setSize(nEntities(NBDY));
364 entityBuffer(NFE_BUFFER).setSize(nEntities(FACE));
366 // Allocate for variable size face-lists
367 entityBuffer(FACE).setSize(nEntities(NFE_SIZE));
368 entityBuffer(FACE_EDGE).setSize(nEntities(NFE_SIZE));
372 label coupleMap::findSlave
378 Map<label>::const_iterator it = entityMap_[eType].find(Index);
380 if (it == entityMap_[eType].end())
391 label coupleMap::findMaster
397 Map<label>::const_iterator it = reverseEntityMap_[eType].find(Index);
399 if (it == reverseEntityMap_[eType].end())
410 void coupleMap::removeSlave
416 Map<label>::iterator it = reverseEntityMap_[eType].find(Index);
418 if (it != reverseEntityMap_[eType].end())
420 reverseEntityMap_[eType].erase(it);
425 void coupleMap::removeMaster
431 Map<label>::iterator it = entityMap_[eType].find(Index);
433 if (it != entityMap_[eType].end())
435 entityMap_[eType].erase(it);
440 void coupleMap::mapSlave
447 entityMap_[eType].set(master, slave);
451 void coupleMap::mapMaster
458 reverseEntityMap_[eType].set(slave, master);
462 void coupleMap::pushOperation
468 entityIndices_.setSize(entityIndices_.size() + 1, index);
469 entityOperations_.setSize(entityOperations_.size() + 1, oType);
473 void coupleMap::pushOperation
480 if (oType == coupleMap::CONVERT_PHYSICAL)
482 entityIndices_.setSize(entityIndices_.size() + 1, index);
483 entityOperations_.setSize(entityOperations_.size() + 1, oType);
485 patchIndices_.setSize(patchIndices_.size() + 1, pIndex);
489 opType t = (oType < coupleMap::INVALID ? oType : coupleMap::INVALID);
491 FatalErrorIn("void coupleMap::pushOperation() const")
492 << " Expected CONVERT_PHYSICAL" << nl
493 << " Found: " << coupleMap::names[t]
494 << abort(FatalError);
499 void coupleMap::pushOperation
503 const point& newPoint,
504 const point& oldPoint
507 entityIndices_.setSize(entityIndices_.size() + 1, index);
508 entityOperations_.setSize(entityOperations_.size() + 1, oType);
512 oType == coupleMap::MOVE_POINT ||
513 oType == coupleMap::CONVERT_PATCH
516 moveNewPoints_.setSize(moveNewPoints_.size() + 1, newPoint);
517 moveOldPoints_.setSize(moveOldPoints_.size() + 1, oldPoint);
521 opType t = (oType < coupleMap::INVALID ? oType : coupleMap::INVALID);
523 FatalErrorIn("void coupleMap::pushOperation() const")
524 << " Expected either MOVE_POINT or CONVERT_PATCH" << nl
525 << " Found: " << coupleMap::names[t]
526 << abort(FatalError);
531 void coupleMap::transferMaps
534 Map<label>& newEntityMap,
535 Map<label>& newReverseEntityMap
538 entityMap_[eType].transfer(newEntityMap);
539 reverseEntityMap_[eType].transfer(newReverseEntityMap);
543 void coupleMap::clearMaps() const
547 internalFaceMap_.clear();
549 subMeshPointMap_.clear();
550 subMeshEdgeMap_.clear();
552 forAll(entityMap_, mapI)
554 entityMap_[mapI].clear();
555 reverseEntityMap_[mapI].clear();
560 void coupleMap::clearBuffers() const
562 pointBuffer_.clear();
563 oldPointBuffer_.clear();
565 subMeshPoints_.clear();
566 globalProcPoints_.clear();
568 forAll(entityBuffer_, bufferI)
570 entityBuffer_[bufferI].clear();
573 entityIndices_.clear();
574 entityOperations_.clear();
576 patchIndices_.clear();
577 moveNewPoints_.clear();
578 moveOldPoints_.clear();
582 label coupleMap::nInternalFaces() const
584 return nEntities(INTERNAL_FACE);
588 const labelList& coupleMap::owner() const
590 return entityBuffer(OWNER);
594 const labelList& coupleMap::neighbour() const
596 return entityBuffer(NEIGHBOUR);
600 const edgeList& coupleMap::edges() const
611 const faceList& coupleMap::faces() const
622 const labelListList& coupleMap::faceEdges() const
629 return *faceEdgesPtr_;
633 const labelList& coupleMap::faceMap() const
635 if (faceMap_.empty())
644 const labelList& coupleMap::cellMap() const
646 if (cellMap_.empty())
655 const labelList& coupleMap::internalFaceMap() const
657 if (internalFaceMap_.empty())
659 makeInternalFaceMap();
662 return internalFaceMap_;
666 bool coupleMap::readData(Istream& is)
668 Map<label> tmpMap(is);
670 entityMap(coupleMap::POINT).transfer(tmpMap);
672 // Prepare the reversePointMap as well.
673 const Map<label>& pMap = entityMap(coupleMap::POINT);
674 Map<label>& rpMap = reverseEntityMap(coupleMap::POINT);
676 forAllConstIter(Map<label>, pMap, pIter)
678 rpMap.set(pIter(), pIter.key());
685 bool coupleMap::writeData(Ostream& os) const
687 // Only write-out point-map information
688 // to avoid geometric checking.
689 // The rest can be constructed topologically.
690 return (os << entityMap(coupleMap::POINT)).good();;
694 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
696 void coupleMap::operator=(const coupleMap& rhs)
698 // Check for assignment to self
701 FatalErrorIn("coupleMap::operator=(const coupleMap&)")
702 << "Attempted assignment to self"
703 << abort(FatalError);
708 } // End namespace Foam
710 // ************************************************************************* //