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

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