FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

referredCell.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 2008-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*----------------------------------------------------------------------------*/
00025 
00026 #include "referredCell.H"
00027 #include <molecule/interactionLists.H>
00028 
00029 namespace Foam
00030 {
00031 
00032 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00033 
00034 void referredCell::setConstructionData
00035 (
00036     const polyMesh& mesh,
00037     const label sourceCell
00038 )
00039 {
00040     // Points
00041 
00042     const labelList& points = mesh.cellPoints()[sourceCell];
00043 
00044     vectorList sourceCellVertices(points.size());
00045 
00046     forAll(sourceCellVertices, sCV)
00047     {
00048         sourceCellVertices[sCV] = mesh.points()[points[sCV]];
00049     }
00050 
00051     vertexPositions_ = referPositions(sourceCellVertices);
00052 
00053 
00054     // Edges
00055 
00056     const labelList& edges = mesh.cellEdges()[sourceCell];
00057 
00058     edgeList sourceCellEdges(edges.size());
00059 
00060     forAll(sourceCellEdges, sCE)
00061     {
00062         sourceCellEdges[sCE] = mesh.edges()[edges[sCE]];
00063     }
00064 
00065     locallyMapEdgeList(points, sourceCellEdges);
00066 
00067 
00068     // Faces
00069 
00070     labelList faces(mesh.cells()[sourceCell]);
00071 
00072     vectorList sourceCellFaceCentres(faces.size());
00073 
00074     vectorList sourceCellFaceAreas(faces.size());
00075 
00076     labelListList sourceCellFaces(faces.size());
00077 
00078     forAll(faces, f)
00079     {
00080         sourceCellFaces[f] = mesh.faces()[faces[f]];
00081 
00082         sourceCellFaceCentres[f] = mesh.faceCentres()[faces[f]];
00083 
00084         sourceCellFaceAreas[f] = mesh.faceAreas()[faces[f]];
00085     }
00086 
00087     locallyMapFaceList(points, sourceCellFaces);
00088 
00089     faceCentres_ = referPositions(sourceCellFaceCentres);
00090 
00091     faceAreas_ = rotateVectors(sourceCellFaceAreas);
00092 }
00093 
00094 
00095 void referredCell::locallyMapEdgeList
00096 (
00097     const labelList& points,
00098     const edgeList& sourceCellEdges
00099 )
00100 {
00101     edges_.setSize(sourceCellEdges.size());
00102 
00103     forAll(sourceCellEdges, sCE)
00104     {
00105         const edge& e(sourceCellEdges[sCE]);
00106 
00107         edges_[sCE].start() = findIndex(points, e.start());
00108 
00109         edges_[sCE].end() = findIndex(points, e.end());
00110 
00111         if
00112         (
00113             edges_[sCE].start() == -1
00114          || edges_[sCE].end() == -1
00115         )
00116         {
00117             FatalErrorIn("Foam::referredCell::locallyMapEdgeList")
00118                 << "edgeList and points labelList for "
00119                 << "referred cell do not match: "
00120                 << nl << "points: " << points
00121                 << nl << "egdes: " << sourceCellEdges
00122                 << abort(FatalError);
00123         }
00124     }
00125 }
00126 
00127 
00128 void referredCell::locallyMapFaceList
00129 (
00130     const labelList& points,
00131     const labelListList& sourceCellFaces
00132 )
00133 {
00134     faces_.setSize(sourceCellFaces.size());
00135 
00136     forAll(sourceCellFaces, sCF)
00137     {
00138         const labelList& sourceCellFace(sourceCellFaces[sCF]);
00139 
00140         labelList& localFace(faces_[sCF]);
00141 
00142         localFace.setSize(sourceCellFace.size());
00143 
00144         forAll(sourceCellFace, p)
00145         {
00146             localFace[p] = findIndex(points, sourceCellFace[p]);
00147 
00148             if (localFace[p] == -1)
00149             {
00150                 FatalErrorIn("Foam::referredCell::locallyMapEdgeList")
00151                     << "edgeList and points labelList for "
00152                     << "referred cell do not match: "
00153                     << nl << "points: " << points
00154                     << nl << "faces: " << sourceCellFaces
00155                     << abort(FatalError);
00156             }
00157         }
00158     }
00159 }
00160 
00161 
00162 vector referredCell::referPosition(const vector& positionToRefer)
00163 {
00164     return offset_ + (rotation_ & positionToRefer);
00165 }
00166 
00167 
00168 vectorList referredCell::referPositions(const vectorList& positionsToRefer)
00169 {
00170     return offset_ + (rotation_ & positionsToRefer);
00171 }
00172 
00173 
00174 vector referredCell::rotateVector(const vector& vectorToRotate)
00175 {
00176     return rotation_ & vectorToRotate;
00177 }
00178 
00179 
00180 vectorList referredCell::rotateVectors(const vectorList& vectorsToRotate)
00181 {
00182     return rotation_ & vectorsToRotate;
00183 }
00184 
00185 
00186 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00187 
00188 referredCell::referredCell()
00189 :
00190     DynamicList<referredMolecule>(),
00191     sourceProc_(-1),
00192     sourceCell_(-1),
00193     vertexPositions_(),
00194     offset_(vector::zero),
00195     rotation_(I)
00196 {}
00197 
00198 
00199 referredCell::referredCell
00200 (
00201     const polyMesh& mesh,
00202     const label sourceProc,
00203     const label sourceCell,
00204     const vector& offset,
00205     const tensor& rotation
00206 )
00207 :
00208     DynamicList<referredMolecule>(),
00209     sourceProc_(sourceProc),
00210     sourceCell_(sourceCell),
00211     offset_(offset),
00212     rotation_(rotation)
00213 {
00214     setConstructionData(mesh, sourceCell);
00215 }
00216 
00217 
00218 referredCell::referredCell
00219 (
00220     const label sourceProc,
00221     const label sourceCell,
00222     const vectorList& vertexPositions,
00223     const edgeList& localEdges,
00224     const labelListList& localFaces,
00225     const vectorList& faceCentres,
00226     const vectorList& faceAreas,
00227     const vector& offset,
00228     const tensor& rotation
00229 )
00230 :
00231     DynamicList<referredMolecule>(),
00232     sourceProc_(sourceProc),
00233     sourceCell_(sourceCell),
00234     edges_(localEdges),
00235     faces_(localFaces),
00236     offset_(offset),
00237     rotation_(rotation)
00238 {
00239     // Supplied vertexPositions, faceCentres and faceAreas are of the
00240     // "original" cell, and need to be transformed to the referred
00241     // locations on construction
00242 
00243     vertexPositions_ = referPositions(vertexPositions);
00244 
00245     faceCentres_ = referPositions(faceCentres);
00246 
00247     faceAreas_ = rotateVectors(faceAreas);
00248 }
00249 
00250 
00251 referredCell::referredCell
00252 (
00253     const polyMesh& mesh,
00254     const label sourceProc,
00255     const label sourceCell,
00256     const vector& cS,
00257     const vector& cD,
00258     const vector& nS,
00259     const vector& nD
00260 )
00261 :
00262     DynamicList<referredMolecule>(),
00263     sourceProc_(sourceProc),
00264     sourceCell_(sourceCell)
00265 {
00266     // It is assumed that the vectors originating from the faces being referred
00267     // here are correct periodic faces - i.e. they have the same area etc.
00268 
00269     vector nA = -nS/mag(nS);
00270     vector nB = nD/mag(nD);
00271 
00272     rotation_ = rotationTensor(nA, nB);
00273 
00274     offset_ = cD - (rotation_ & cS);
00275 
00276     // Allow sourceCell = -1 to create a dummy referredCell
00277     // to obtain the transformation
00278 
00279     if(sourceCell >= 0)
00280     {
00281         setConstructionData(mesh, sourceCell);
00282     }
00283 }
00284 
00285 
00286 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00287 
00288 referredCell::~referredCell()
00289 {}
00290 
00291 
00292 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00293 
00294 referredCell referredCell::reRefer
00295 (
00296     const vector& cS,
00297     const vector& cD,
00298     const vector& nS,
00299     const vector& nD
00300 )
00301 {
00302     vector nA = -nS/mag(nS);
00303     vector nB = nD/mag(nD);
00304 
00305     tensor newRotation = rotationTensor(nA, nB);
00306 
00307     vector newOffset = cD - (newRotation & cS);
00308 
00309     tensor reReferredRotation = newRotation & rotation_;
00310 
00311     vector reReferredOffset = newOffset + (newRotation & offset_);
00312 
00313     return referredCell
00314     (
00315         sourceProc_,
00316         sourceCell_,
00317         rotation_.T() & (vertexPositions_ - offset_),
00318         edges_,
00319         faces_,
00320         rotation_.T() & (faceCentres_ - offset_),
00321         rotation_.T() & (faceAreas_),
00322         reReferredOffset,
00323         reReferredRotation
00324     );
00325 }
00326 
00327 
00328 vector referredCell::referPosition(const vector& positionToRefer) const
00329 {
00330     return offset_ + (rotation_ & positionToRefer);
00331 }
00332 
00333 
00334 vectorList referredCell::referPosition
00335 (
00336     const vectorList& positionsToRefer
00337 ) const
00338 {
00339     return offset_ + (rotation_ & positionsToRefer);
00340 }
00341 
00342 
00343 vector referredCell::rotateVector(const vector& vectorToRotate) const
00344 {
00345     return rotation_ & vectorToRotate;
00346 }
00347 
00348 
00349 vectorList referredCell::rotateVectors(const vectorList& vectorsToRotate) const
00350 {
00351     return rotation_ & vectorsToRotate;
00352 }
00353 
00354 
00355 void referredCell::referInMols(const List<referredMolecule>& incomingMols)
00356 {
00357     clear();
00358 
00359     forAll(incomingMols, iM)
00360     {
00361         append
00362         (
00363             referredMolecule
00364             (
00365                 incomingMols[iM].id(),
00366                 referPosition
00367                 (
00368                     incomingMols[iM].position()
00369                 ),
00370                 referPosition
00371                 (
00372                     incomingMols[iM].sitePositions()
00373                 )
00374             )
00375         );
00376     }
00377 
00378     shrink();
00379 }
00380 
00381 
00382 bool referredCell::duplicate(const referredCell& refCellDupl) const
00383 {
00384     return
00385     (
00386         sourceProc_ == refCellDupl.sourceProc()
00387      && sourceCell_ == refCellDupl.sourceCell()
00388      && mag(offset_ - refCellDupl.offset()) < interactionLists::transTol
00389     );
00390 }
00391 
00392 
00393 bool referredCell::duplicate(const label procNo,const label nCells) const
00394 {
00395     return
00396     (
00397         sourceProc_ == procNo
00398      && sourceCell_ < nCells
00399      && mag(offset_) < interactionLists::transTol
00400     );
00401 }
00402 
00403 
00404 // * * * * * * * * * * * * * * * Friend Functions  * * * * * * * * * * * * * //
00405 
00406 Istream& operator>>(Istream& is, referredCell& rC)
00407 {
00408 
00409     is  >> rC.sourceProc_
00410         >> rC.sourceCell_
00411         >> rC.vertexPositions_
00412         >> rC.edges_
00413         >> rC.faces_
00414         >> rC.faceCentres_
00415         >> rC.faceAreas_
00416         >> rC.offset_
00417         >> rC.rotation_;
00418 
00419     is.check("Istream& operator<<(Istream& f, const referredCell& rC");
00420 
00421     return is;
00422 }
00423 
00424 
00425 Ostream& operator<<(Ostream& os, const referredCell& rC)
00426 {
00427 
00428     os  << rC.sourceProc()
00429         << token::SPACE << rC.sourceCell()
00430         << token::SPACE << rC.vertexPositions()
00431         << token::SPACE << rC.edges()
00432         << token::SPACE << rC.faces()
00433         << token::SPACE << rC.faceCentres()
00434         << token::SPACE << rC.faceAreas()
00435         << token::SPACE << rC.offset()
00436         << token::SPACE << rC.rotation();
00437 
00438     os.check("Ostream& operator<<(Ostream& f, const referredCell& rC");
00439 
00440     return os;
00441 }
00442 
00443 
00444 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00445 
00446 }  // End namespace Foam
00447 
00448 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines