FreeFOAM The Cross-Platform CFD Toolkit
cellLooper.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "cellLooper.H"
27 #include <OpenFOAM/polyMesh.H>
28 #include <OpenFOAM/ListOps.H>
29 #include <meshTools/meshTools.H>
30 
31 
32 
33 namespace Foam
34 {
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 defineTypeNameAndDebug(cellLooper, 0);
39 defineRunTimeSelectionTable(cellLooper, word);
40 
41 
42 
43 // Construct named object from given arguments
44 autoPtr<cellLooper> cellLooper::New
45 (
46  const word& type,
47  const polyMesh& mesh
48 )
49 {
50  wordConstructorTable::iterator cstrIter =
51  wordConstructorTablePtr_
52  ->find(type);
53 
54  if (cstrIter == wordConstructorTablePtr_->end())
55  {
57  (
58  "cellLooper::New(const word&, const polyMesh&)"
59  ) << "Unknown set type " << type
60  << endl << endl
61  << "Valid cellLooper types : " << endl
62  << wordConstructorTablePtr_->sortedToc()
63  << exit(FatalError);
64  }
65 
66  return autoPtr<cellLooper>(cstrIter()(mesh));
67 }
68 
69 }
70 
71 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
72 
73 // Get faces (on cell) connected to vertI which are not using edgeI
75 (
76  const label cellI,
77  const label edgeI,
78  const label vertI
79 ) const
80 {
81  // Get faces connected to startEdge
82  label face0, face1;
83  meshTools::getEdgeFaces(mesh(), cellI, edgeI, face0, face1);
84 
85  const labelList& pFaces = mesh().pointFaces()[vertI];
86 
87  labelList vertFaces(pFaces.size());
88  label vertFaceI = 0;
89 
90  forAll(pFaces, pFaceI)
91  {
92  label faceI = pFaces[pFaceI];
93 
94  if
95  (
96  (faceI != face0)
97  && (faceI != face1)
98  && (meshTools::faceOnCell(mesh(), cellI, faceI))
99  )
100  {
101  vertFaces[vertFaceI++] = faceI;
102  }
103  }
104  vertFaces.setSize(vertFaceI);
105 
106  return vertFaces;
107 }
108 
109 
110 // Get first edge connected to vertI and on faceI
112 (
113  const label faceI,
114  const label vertI
115 ) const
116 {
117  const labelList& fEdges = mesh().faceEdges()[faceI];
118 
119  forAll(fEdges, fEdgeI)
120  {
121  label edgeI = fEdges[fEdgeI];
122 
123  const edge& e = mesh().edges()[edgeI];
124 
125  if ((e.start() == vertI) || (e.end() == vertI))
126  {
127  return edgeI;
128  }
129  }
130 
132  (
133  "getFirstVertEdge(const label, const label)"
134  ) << "Can not find edge on face " << faceI
135  << " using vertex " << vertI
136  << abort(FatalError);
137 
138  return -1;
139 }
140 
141 
142 // Get edges (on cell) connected to vertI which are not on faceI
144 (
145  const label cellI,
146  const label faceI,
147  const label vertI
148 ) const
149 {
150  const labelList& exclEdges = mesh().faceEdges()[faceI];
151 
152  const labelList& pEdges = mesh().pointEdges()[vertI];
153 
154  labelList vertEdges(pEdges.size());
155  label vertEdgeI = 0;
156 
157  forAll(pEdges, pEdgeI)
158  {
159  label edgeI = pEdges[pEdgeI];
160 
161  if
162  (
163  (findIndex(exclEdges, edgeI) == -1)
164  && meshTools::edgeOnCell(mesh(), cellI, edgeI)
165  )
166  {
167  vertEdges[vertEdgeI++] = edgeI;
168  }
169  }
170 
171  vertEdges.setSize(vertEdgeI);
172 
173  return vertEdges;
174 }
175 
176 
177 // Return edge from cellEdges that is most perpendicular
178 // to refinement direction.
180 (
181  const vector& refDir,
182  const label cellI
183 ) const
184 {
185  const labelList& cEdges = mesh().cellEdges()[cellI];
186 
187  label cutEdgeI = -1;
188  scalar maxCos = -GREAT;
189 
190  forAll(cEdges, cEdgeI)
191  {
192  label edgeI = cEdges[cEdgeI];
193 
194  scalar cosAngle = mag(refDir & meshTools::normEdgeVec(mesh(), edgeI));
195 
196  if (cosAngle > maxCos)
197  {
198  maxCos = cosAngle;
199 
200  cutEdgeI = edgeI;
201  }
202  }
203 
204  return cutEdgeI;
205 }
206 
207 
208 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
209 
210 // Construct from components
211 Foam::cellLooper::cellLooper(const polyMesh& mesh)
212 :
213  edgeVertex(mesh)
214 {}
215 
216 
217 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
218 
220 {}
221 
222 
223 // ************************ vim: set sw=4 sts=4 et: ************************ //