OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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