Merge branch 'upstream/OpenFOAM' into master
[freefoam.git] / src / dynamicMesh / meshCut / cellLooper / cellLooper.C
blobfaac310f6b2664210538f66856272ae1a417aa07
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 Description
27 \*---------------------------------------------------------------------------*/
29 #include "cellLooper.H"
30 #include <OpenFOAM/polyMesh.H>
31 #include <OpenFOAM/ListOps.H>
32 #include <meshTools/meshTools.H>
36 namespace Foam
39 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
41 defineTypeNameAndDebug(cellLooper, 0);
42 defineRunTimeSelectionTable(cellLooper, word);
46 // Construct named object from given arguments
47 autoPtr<cellLooper> cellLooper::New
49     const word& type,
50     const polyMesh& mesh
53     wordConstructorTable::iterator cstrIter =
54         wordConstructorTablePtr_
55             ->find(type);
57     if (cstrIter == wordConstructorTablePtr_->end())
58     {
59         FatalErrorIn
60         (
61             "cellLooper::New(const word&, const polyMesh&)"
62         )   << "Unknown set type " << type
63             << endl << endl
64             << "Valid cellLooper types : " << endl
65             << wordConstructorTablePtr_->toc()
66             << exit(FatalError);
67     }
69     return autoPtr<cellLooper>(cstrIter()(mesh));
74 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
76 // Get faces (on cell) connected to vertI which are not using edgeI
77 Foam::labelList Foam::cellLooper::getVertFacesNonEdge
79     const label cellI,
80     const label edgeI,
81     const label vertI
82 ) const
84     // Get faces connected to startEdge
85     label face0, face1;
86     meshTools::getEdgeFaces(mesh(), cellI, edgeI, face0, face1);
88     const labelList& pFaces = mesh().pointFaces()[vertI];
90     labelList vertFaces(pFaces.size());
91     label vertFaceI = 0;
93     forAll(pFaces, pFaceI)
94     {
95         label faceI = pFaces[pFaceI];
97         if
98         (
99             (faceI != face0)
100          && (faceI != face1)
101          && (meshTools::faceOnCell(mesh(), cellI, faceI))
102         )
103         {
104             vertFaces[vertFaceI++] = faceI;
105         }
106     }
107     vertFaces.setSize(vertFaceI);
109     return vertFaces;
113 // Get first edge connected to vertI and on faceI
114 Foam::label Foam::cellLooper::getFirstVertEdge
116     const label faceI,
117     const label vertI
118 ) const
120     const labelList& fEdges = mesh().faceEdges()[faceI];
122     forAll(fEdges, fEdgeI)
123     {
124         label edgeI = fEdges[fEdgeI];
126         const edge& e = mesh().edges()[edgeI];
128         if ((e.start() == vertI) || (e.end() == vertI))
129         {
130             return edgeI;
131         }
132     }
134     FatalErrorIn
135     (
136         "getFirstVertEdge(const label, const label)"
137     )   << "Can not find edge on face " << faceI
138         << " using vertex " << vertI
139         << abort(FatalError);
141     return -1;
145 // Get edges (on cell) connected to vertI which are not on faceI
146 Foam::labelList Foam::cellLooper::getVertEdgesNonFace
148     const label cellI,
149     const label faceI,
150     const label vertI
151 ) const
153     const labelList& exclEdges = mesh().faceEdges()[faceI];
155     const labelList& pEdges = mesh().pointEdges()[vertI];
157     labelList vertEdges(pEdges.size());
158     label vertEdgeI = 0;
160     forAll(pEdges, pEdgeI)
161     {
162         label edgeI = pEdges[pEdgeI];
164         if
165         (
166             (findIndex(exclEdges, edgeI) == -1)
167          && meshTools::edgeOnCell(mesh(), cellI, edgeI)
168         )
169         {
170             vertEdges[vertEdgeI++] = edgeI;
171         }
172     }
174     vertEdges.setSize(vertEdgeI);
176     return vertEdges;
180 // Return edge from cellEdges that is most perpendicular
181 // to refinement direction.
182 Foam::label Foam::cellLooper::getMisAlignedEdge
184     const vector& refDir,
185     const label cellI
186 ) const
188     const labelList& cEdges = mesh().cellEdges()[cellI];
190     label cutEdgeI = -1;
191     scalar maxCos = -GREAT;
193     forAll(cEdges, cEdgeI)
194     {
195         label edgeI = cEdges[cEdgeI];
197         scalar cosAngle = mag(refDir & meshTools::normEdgeVec(mesh(), edgeI));
199         if (cosAngle > maxCos)
200         {
201             maxCos = cosAngle;
203             cutEdgeI = edgeI;
204         }
205     }
207     return cutEdgeI;
211 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
213 // Construct from components
214 Foam::cellLooper::cellLooper(const polyMesh& mesh)
216     edgeVertex(mesh)
220 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
222 Foam::cellLooper::~cellLooper()
226 // ************************ vim: set sw=4 sts=4 et: ************************ //