1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 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 "referredCell.H"
28 #include "moleculeCloud.H"
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
35 void referredCell::setConstructionData
38 const label sourceCell
41 // * * * * * * * * * * * Points * * * * * * * * * * *
43 const labelList& points = mesh.cellPoints()[sourceCell];
45 vectorList sourceCellVertices(points.size());
47 forAll(sourceCellVertices, sCV)
49 sourceCellVertices[sCV] = mesh.points()[points[sCV]];
52 vertexPositions_ = referPositions(sourceCellVertices);
54 // * * * * * * * * * * * Edges * * * * * * * * * * *
56 const labelList& edges = mesh.cellEdges()[sourceCell];
58 edgeList sourceCellEdges(edges.size());
60 forAll(sourceCellEdges, sCE)
62 sourceCellEdges[sCE] = mesh.edges()[edges[sCE]];
65 locallyMapEdgeList(points, sourceCellEdges);
67 // * * * * * * * * * * * Faces * * * * * * * * * * *
69 labelList faces(mesh.cells()[sourceCell]);
71 vectorList sourceCellFaceCentres(faces.size());
73 vectorList sourceCellFaceAreas(faces.size());
75 labelListList sourceCellFaces(faces.size());
79 sourceCellFaces[f] = mesh.faces()[faces[f]];
81 sourceCellFaceCentres[f] = mesh.faceCentres()[faces[f]];
83 sourceCellFaceAreas[f] = mesh.faceAreas()[faces[f]];
86 locallyMapFaceList(points, sourceCellFaces);
88 faceCentres_ = referPositions(sourceCellFaceCentres);
90 faceAreas_ = rotateVectors(sourceCellFaceAreas);
94 void referredCell::locallyMapEdgeList
96 const labelList& points,
97 const edgeList& sourceCellEdges
100 edges_.setSize(sourceCellEdges.size());
102 forAll(sourceCellEdges, sCE)
104 const edge& e(sourceCellEdges[sCE]);
106 edges_[sCE].start() = findIndex(points, e.start());
108 edges_[sCE].end() = findIndex(points, e.end());
112 edges_[sCE].start() == -1
113 || edges_[sCE].end() == -1
116 FatalErrorIn("Foam::referredCell::locallyMapEdgeList")
117 << "edgeList and points labelList for "
118 << "referred cell do not match: "
119 << nl << "points: " << points
120 << nl << "egdes: " << sourceCellEdges
121 << abort(FatalError);
127 void referredCell::locallyMapFaceList
129 const labelList& points,
130 const labelListList& sourceCellFaces
133 faces_.setSize(sourceCellFaces.size());
135 forAll(sourceCellFaces, sCF)
137 const labelList& sourceCellFace(sourceCellFaces[sCF]);
139 labelList& localFace(faces_[sCF]);
141 localFace.setSize(sourceCellFace.size());
143 forAll(sourceCellFace, p)
145 localFace[p] = findIndex(points, sourceCellFace[p]);
147 if (localFace[p] == -1)
149 FatalErrorIn("Foam::referredCell::locallyMapEdgeList")
150 << "edgeList and points labelList for "
151 << "referred cell do not match: "
152 << nl << "points: " << points
153 << nl << "faces: " << sourceCellFaces
154 << abort(FatalError);
161 vector referredCell::referPosition(const vector& positionToRefer)
163 return offset_ + (rotation_ & positionToRefer);
167 vectorList referredCell::referPositions(const vectorList& positionsToRefer)
169 return offset_ + (rotation_ & positionsToRefer);
173 vector referredCell::rotateVector(const vector& vectorToRotate)
175 return rotation_ & vectorToRotate;
179 vectorList referredCell::rotateVectors(const vectorList& vectorsToRotate)
181 return rotation_ & vectorsToRotate;
185 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
187 referredCell::referredCell()
189 DynamicList<referredMolecule>(),
193 offset_(vector::zero),
198 referredCell::referredCell
200 const polyMesh& mesh,
201 const label sourceProc,
202 const label sourceCell,
203 const vector& offset,
204 const tensor& rotation
207 DynamicList<referredMolecule>(),
208 sourceProc_(sourceProc),
209 sourceCell_(sourceCell),
213 setConstructionData(mesh, sourceCell);
217 referredCell::referredCell
219 const label sourceProc,
220 const label sourceCell,
221 const vectorList& vertexPositions,
222 const edgeList& localEdges,
223 const labelListList& localFaces,
224 const vectorList& faceCentres,
225 const vectorList& faceAreas,
226 const vector& offset,
227 const tensor& rotation
230 DynamicList<referredMolecule>(),
231 sourceProc_(sourceProc),
232 sourceCell_(sourceCell),
238 // Supplied vertexPositions, faceCentres and faceAreas are of the
239 // "original" cell, and need to be transformed to the referred
240 // locations on construction
242 vertexPositions_ = referPositions(vertexPositions);
244 faceCentres_ = referPositions(faceCentres);
246 faceAreas_ = rotateVectors(faceAreas);
250 referredCell::referredCell
252 const polyMesh& mesh,
253 const label sourceProc,
254 const label sourceCell,
261 DynamicList<referredMolecule>(),
262 sourceProc_(sourceProc),
263 sourceCell_(sourceCell)
265 // It is assumed that the vectors originating from the faces being referred
266 // here are correct periodic faces - i.e. they have the same area etc.
268 vector nA = -nS/mag(nS);
269 vector nB = nD/mag(nD);
271 rotation_ = rotationTensor(nA, nB);
273 offset_ = cD - (rotation_ & cS);
275 // Allow sourceCell = -1 to create a dummy referredCell
276 // to obtain the transformation
280 setConstructionData(mesh, sourceCell);
285 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
287 referredCell::~referredCell()
291 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
293 referredCell referredCell::reRefer
301 vector nA = -nS/mag(nS);
302 vector nB = nD/mag(nD);
304 tensor newRotation = rotationTensor(nA, nB);
306 vector newOffset = cD - (newRotation & cS);
308 tensor reReferredRotation = newRotation & rotation_;
310 vector reReferredOffset = newOffset + (newRotation & offset_);
316 rotation_.T() & (vertexPositions_ - offset_),
319 rotation_.T() & (faceCentres_ - offset_),
320 rotation_.T() & (faceAreas_),
327 vector referredCell::referPosition(const vector& positionToRefer) const
329 return offset_ + (rotation_ & positionToRefer);
333 vectorList referredCell::referPositions
335 const vectorList& positionsToRefer
338 return offset_ + (rotation_ & positionsToRefer);
342 vector referredCell::rotateVector(const vector& vectorToRotate) const
344 return rotation_ & vectorToRotate;
348 vectorList referredCell::rotateVectors(const vectorList& vectorsToRotate) const
350 return rotation_ & vectorsToRotate;
354 void referredCell::referInMols(const List<referredMolecule>& incomingMols)
358 forAll(incomingMols, iM)
364 incomingMols[iM].id(),
367 incomingMols[iM].position()
375 bool referredCell::duplicate(const referredCell& refCellDupl) const
379 sourceProc_ == refCellDupl.sourceProc()
380 && sourceCell_ == refCellDupl.sourceCell()
381 && mag(offset_ - refCellDupl.offset()) < moleculeCloud::transTol
386 bool referredCell::duplicate(const label procNo,const label nCells) const
390 sourceProc_ == procNo
391 && sourceCell_ < nCells
392 && mag(offset_) < moleculeCloud::transTol
397 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
399 Istream& operator>>(Istream& is, referredCell& rC)
404 >> rC.vertexPositions_
412 is.check("Istream& operator<<(Istream& f, const referredCell& rC");
418 Ostream& operator<<(Ostream& os, const referredCell& rC)
421 os << rC.sourceProc()
422 << token::SPACE << rC.sourceCell()
423 << token::SPACE << rC.vertexPositions()
424 << token::SPACE << rC.edges()
425 << token::SPACE << rC.faces()
426 << token::SPACE << rC.faceCentres()
427 << token::SPACE << rC.faceAreas()
428 << token::SPACE << rC.offset()
429 << token::SPACE << rC.rotation();
431 os.check("Ostream& operator<<(Ostream& f, const referredCell& rC");
437 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
439 } // End namespace Foam
441 // ************************************************************************* //