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

cellLooper.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) 1991-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 "cellLooper.H"
00027 #include <OpenFOAM/polyMesh.H>
00028 #include <OpenFOAM/ListOps.H>
00029 #include <meshTools/meshTools.H>
00030 
00031 
00032 
00033 namespace Foam
00034 {
00035 
00036 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00037 
00038 defineTypeNameAndDebug(cellLooper, 0);
00039 defineRunTimeSelectionTable(cellLooper, word);
00040 
00041 
00042 
00043 // Construct named object from given arguments
00044 autoPtr<cellLooper> cellLooper::New
00045 (
00046     const word& type,
00047     const polyMesh& mesh
00048 )
00049 {
00050     wordConstructorTable::iterator cstrIter =
00051         wordConstructorTablePtr_
00052             ->find(type);
00053 
00054     if (cstrIter == wordConstructorTablePtr_->end())
00055     {
00056         FatalErrorIn
00057         (
00058             "cellLooper::New(const word&, const polyMesh&)"
00059         )   << "Unknown set type " << type
00060             << endl << endl
00061             << "Valid cellLooper types : " << endl
00062             << wordConstructorTablePtr_->sortedToc()
00063             << exit(FatalError);
00064     }
00065 
00066     return autoPtr<cellLooper>(cstrIter()(mesh));
00067 }
00068 
00069 }
00070 
00071 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00072 
00073 // Get faces (on cell) connected to vertI which are not using edgeI
00074 Foam::labelList Foam::cellLooper::getVertFacesNonEdge
00075 (
00076     const label cellI,
00077     const label edgeI,
00078     const label vertI
00079 ) const
00080 {
00081     // Get faces connected to startEdge
00082     label face0, face1;
00083     meshTools::getEdgeFaces(mesh(), cellI, edgeI, face0, face1);
00084 
00085     const labelList& pFaces = mesh().pointFaces()[vertI];
00086 
00087     labelList vertFaces(pFaces.size());
00088     label vertFaceI = 0;
00089 
00090     forAll(pFaces, pFaceI)
00091     {
00092         label faceI = pFaces[pFaceI];
00093 
00094         if
00095         (
00096             (faceI != face0)
00097          && (faceI != face1)
00098          && (meshTools::faceOnCell(mesh(), cellI, faceI))
00099         )
00100         {
00101             vertFaces[vertFaceI++] = faceI;
00102         }
00103     }
00104     vertFaces.setSize(vertFaceI);
00105 
00106     return vertFaces;
00107 }
00108 
00109 
00110 // Get first edge connected to vertI and on faceI
00111 Foam::label Foam::cellLooper::getFirstVertEdge
00112 (
00113     const label faceI,
00114     const label vertI
00115 ) const
00116 {
00117     const labelList& fEdges = mesh().faceEdges()[faceI];
00118 
00119     forAll(fEdges, fEdgeI)
00120     {
00121         label edgeI = fEdges[fEdgeI];
00122 
00123         const edge& e = mesh().edges()[edgeI];
00124 
00125         if ((e.start() == vertI) || (e.end() == vertI))
00126         {
00127             return edgeI;
00128         }
00129     }
00130 
00131     FatalErrorIn
00132     (
00133         "getFirstVertEdge(const label, const label)"
00134     )   << "Can not find edge on face " << faceI
00135         << " using vertex " << vertI
00136         << abort(FatalError);
00137 
00138     return -1;
00139 }
00140 
00141 
00142 // Get edges (on cell) connected to vertI which are not on faceI
00143 Foam::labelList Foam::cellLooper::getVertEdgesNonFace
00144 (
00145     const label cellI,
00146     const label faceI,
00147     const label vertI
00148 ) const
00149 {
00150     const labelList& exclEdges = mesh().faceEdges()[faceI];
00151 
00152     const labelList& pEdges = mesh().pointEdges()[vertI];
00153 
00154     labelList vertEdges(pEdges.size());
00155     label vertEdgeI = 0;
00156 
00157     forAll(pEdges, pEdgeI)
00158     {
00159         label edgeI = pEdges[pEdgeI];
00160 
00161         if
00162         (
00163             (findIndex(exclEdges, edgeI) == -1)
00164          && meshTools::edgeOnCell(mesh(), cellI, edgeI)
00165         )
00166         {
00167             vertEdges[vertEdgeI++] = edgeI;
00168         }
00169     }
00170 
00171     vertEdges.setSize(vertEdgeI);
00172 
00173     return vertEdges;
00174 }
00175 
00176 
00177 // Return edge from cellEdges that is most perpendicular
00178 // to refinement direction.
00179 Foam::label Foam::cellLooper::getMisAlignedEdge
00180 (
00181     const vector& refDir,
00182     const label cellI
00183 ) const
00184 {
00185     const labelList& cEdges = mesh().cellEdges()[cellI];
00186 
00187     label cutEdgeI = -1;
00188     scalar maxCos = -GREAT;
00189 
00190     forAll(cEdges, cEdgeI)
00191     {
00192         label edgeI = cEdges[cEdgeI];
00193 
00194         scalar cosAngle = mag(refDir & meshTools::normEdgeVec(mesh(), edgeI));
00195 
00196         if (cosAngle > maxCos)
00197         {
00198             maxCos = cosAngle;
00199 
00200             cutEdgeI = edgeI;
00201         }
00202     }
00203 
00204     return cutEdgeI;
00205 }
00206 
00207 
00208 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00209 
00210 // Construct from components
00211 Foam::cellLooper::cellLooper(const polyMesh& mesh)
00212 :
00213     edgeVertex(mesh)
00214 {}
00215 
00216 
00217 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00218 
00219 Foam::cellLooper::~cellLooper()
00220 {}
00221 
00222 
00223 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines