1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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
29 Implementation of the coupleMap class
33 University of Massachusetts Amherst
36 \*---------------------------------------------------------------------------*/
38 #include "coupleMap.H"
40 #include "demandDrivenData.H"
45 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
47 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 for 2D meshes
209 label nfe = twoDMesh_ ? nfeBuffer[faceI] : 3;
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 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
285 pointField& coupleMap::pointBuffer() const
291 pointField& coupleMap::oldPointBuffer() const
293 return oldPointBuffer_;
297 labelList& coupleMap::subMeshPoints() const
299 return subMeshPoints_;
303 List<labelPair>& coupleMap::globalProcPoints() const
305 return globalProcPoints_;
309 void coupleMap::allocateBuffers() const
311 forAll(nEntities_, entityI)
313 if (nEntities_[entityI] < 0)
315 FatalErrorIn("void coupleMap::allocateBuffers() const")
316 << " Entity sizes are not valid." << nl
317 << " nEntities: " << nEntities_
318 << abort(FatalError);
322 // Size up point buffers
323 pointBuffer().setSize(nEntities(POINT));
324 oldPointBuffer().setSize(nEntities(POINT));
326 // Size up connectivity buffers
327 entityBuffer(POINT).setSize
329 nEntities(GLOBAL_POINT)
330 - nEntities(SHARED_POINT)
334 entityBuffer(EDGE).setSize(2 * nEntities(EDGE));
336 // Set addressing buffers
337 entityBuffer(OWNER).setSize(nEntities(FACE));
338 entityBuffer(NEIGHBOUR).setSize(nEntities(INTERNAL_FACE));
340 // Size up boundary buffers
341 entityBuffer(FACE_STARTS).setSize(nEntities(NBDY));
342 entityBuffer(FACE_SIZES).setSize(nEntities(NBDY));
343 entityBuffer(EDGE_STARTS).setSize(nEntities(NBDY));
344 entityBuffer(EDGE_SIZES).setSize(nEntities(NBDY));
345 entityBuffer(PATCH_ID).setSize(nEntities(NBDY));
347 // nFaceEdges buffer is required only for 2D,
348 // due to a mix of triangle / quad faces
351 entityBuffer(NFE_BUFFER).setSize(nEntities(FACE));
354 // Allocate for variable size face-lists
355 entityBuffer(FACE).setSize(nEntities(NFE_SIZE));
356 entityBuffer(FACE_EDGE).setSize(nEntities(NFE_SIZE));
360 label coupleMap::findSlave
366 Map<label>::const_iterator it = entityMap_[eType].find(Index);
368 if (it == entityMap_[eType].end())
379 label coupleMap::findMaster
385 Map<label>::const_iterator it = reverseEntityMap_[eType].find(Index);
387 if (it == reverseEntityMap_[eType].end())
398 void coupleMap::removeSlave
404 Map<label>::iterator it = reverseEntityMap_[eType].find(Index);
406 if (it != reverseEntityMap_[eType].end())
408 reverseEntityMap_[eType].erase(it);
413 void coupleMap::removeMaster
419 Map<label>::iterator it = entityMap_[eType].find(Index);
421 if (it != entityMap_[eType].end())
423 entityMap_[eType].erase(it);
428 void coupleMap::mapSlave
435 entityMap_[eType].set(master, slave);
439 void coupleMap::mapMaster
446 reverseEntityMap_[eType].set(slave, master);
450 void coupleMap::pushOperation
454 const point& newPoint,
455 const point& oldPoint
458 entityIndices_.setSize(entityIndices_.size() + 1, index);
459 entityOperations_.setSize(entityOperations_.size() + 1, oType);
463 oType == coupleMap::MOVE_POINT ||
464 oType == coupleMap::CONVERT_PATCH
467 moveNewPoints_.setSize(moveNewPoints_.size() + 1, newPoint);
468 moveOldPoints_.setSize(moveOldPoints_.size() + 1, oldPoint);
473 void coupleMap::transferMaps
476 Map<label>& newEntityMap,
477 Map<label>& newReverseEntityMap
480 entityMap_[eType].transfer(newEntityMap);
481 reverseEntityMap_[eType].transfer(newReverseEntityMap);
485 void coupleMap::clearMaps() const
490 forAll(entityMap_, mapI)
492 entityMap_[mapI].clear();
493 reverseEntityMap_[mapI].clear();
498 void coupleMap::clearBuffers() const
500 pointBuffer_.clear();
501 oldPointBuffer_.clear();
503 subMeshPoints_.clear();
504 globalProcPoints_.clear();
506 forAll(entityBuffer_, bufferI)
508 entityBuffer_[bufferI].clear();
511 entityIndices_.clear();
512 entityOperations_.clear();
514 moveNewPoints_.clear();
515 moveOldPoints_.clear();
519 label coupleMap::nInternalFaces() const
521 return nEntities(INTERNAL_FACE);
525 const labelList& coupleMap::owner() const
527 return entityBuffer(OWNER);
531 const labelList& coupleMap::neighbour() const
533 return entityBuffer(NEIGHBOUR);
537 const edgeList& coupleMap::edges() const
548 const faceList& coupleMap::faces() const
559 const labelListList& coupleMap::faceEdges() const
566 return *faceEdgesPtr_;
570 const labelList& coupleMap::faceMap() const
572 if (faceMap_.empty())
581 const labelList& coupleMap::cellMap() const
583 if (cellMap_.empty())
592 bool coupleMap::readData(Istream& is)
594 Map<label> tmpMap(is);
596 entityMap(coupleMap::POINT).transfer(tmpMap);
598 // Prepare the reversePointMap as well.
599 const Map<label>& pMap = entityMap(coupleMap::POINT);
600 Map<label>& rpMap = reverseEntityMap(coupleMap::POINT);
602 forAllConstIter(Map<label>, pMap, pIter)
604 rpMap.set(pIter(), pIter.key());
611 bool coupleMap::writeData(Ostream& os) const
613 // Only write-out point-map information
614 // to avoid geometric checking.
615 // The rest can be constructed topologically.
616 return (os << entityMap(coupleMap::POINT)).good();;
620 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
622 void coupleMap::operator=(const coupleMap& rhs)
624 // Check for assignment to self
627 FatalErrorIn("coupleMap::operator=(const coupleMap&)")
628 << "Attempted assignment to self"
629 << abort(FatalError);
634 } // End namespace Foam
636 // ************************************************************************* //