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) 2011-2016 OpenFOAM Foundation
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 "polyMesh.H"
28 #include "ListOps.H"
29 #include "meshTools.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(cellLooper, 0);
36  defineRunTimeSelectionTable(cellLooper, word);
37 }
38 
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
43 (
44  const word& type,
45  const polyMesh& mesh
46 )
47 {
48  wordConstructorTable::iterator cstrIter =
49  wordConstructorTablePtr_->find(type);
50 
51  if (cstrIter == wordConstructorTablePtr_->end())
52  {
54  << "Unknown set type "
55  << type << nl << nl
56  << "Valid cellLooper types : " << endl
57  << wordConstructorTablePtr_->sortedToc()
58  << exit(FatalError);
59  }
60 
61  return autoPtr<cellLooper>(cstrIter()(mesh));
62 }
63 
64 
65 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
66 
67 // Get faces (on cell) connected to vertI which are not using edgeI
69 (
70  const label celli,
71  const label edgeI,
72  const label vertI
73 ) const
74 {
75  // Get faces connected to startEdge
76  label face0, face1;
77  meshTools::getEdgeFaces(mesh(), celli, edgeI, face0, face1);
78 
79  const labelList& pFaces = mesh().pointFaces()[vertI];
80 
81  labelList vertFaces(pFaces.size());
82  label vertFacei = 0;
83 
84  forAll(pFaces, pFacei)
85  {
86  label facei = pFaces[pFacei];
87 
88  if
89  (
90  (facei != face0)
91  && (facei != face1)
92  && (meshTools::faceOnCell(mesh(), celli, facei))
93  )
94  {
95  vertFaces[vertFacei++] = facei;
96  }
97  }
98  vertFaces.setSize(vertFacei);
99 
100  return vertFaces;
101 }
102 
103 
104 // Get first edge connected to vertI and on facei
106 (
107  const label facei,
108  const label vertI
109 ) const
110 {
111  const labelList& fEdges = mesh().faceEdges()[facei];
112 
113  forAll(fEdges, fEdgeI)
114  {
115  label edgeI = fEdges[fEdgeI];
116 
117  const edge& e = mesh().edges()[edgeI];
118 
119  if ((e.start() == vertI) || (e.end() == vertI))
120  {
121  return edgeI;
122  }
123  }
124 
126  << "Can not find edge on face " << facei
127  << " using vertex " << vertI
128  << abort(FatalError);
129 
130  return -1;
131 }
132 
133 
134 // Get edges (on cell) connected to vertI which are not on facei
136 (
137  const label celli,
138  const label facei,
139  const label vertI
140 ) const
141 {
142  const labelList& exclEdges = mesh().faceEdges()[facei];
143 
144  const labelList& pEdges = mesh().pointEdges()[vertI];
145 
146  labelList vertEdges(pEdges.size());
147  label vertEdgeI = 0;
148 
149  forAll(pEdges, pEdgeI)
150  {
151  label edgeI = pEdges[pEdgeI];
152 
153  if
154  (
155  (findIndex(exclEdges, edgeI) == -1)
156  && meshTools::edgeOnCell(mesh(), celli, edgeI)
157  )
158  {
159  vertEdges[vertEdgeI++] = edgeI;
160  }
161  }
162 
163  vertEdges.setSize(vertEdgeI);
164 
165  return vertEdges;
166 }
167 
168 
169 // Return edge from cellEdges that is most perpendicular
170 // to refinement direction.
172 (
173  const vector& refDir,
174  const label celli
175 ) const
176 {
177  const labelList& cEdges = mesh().cellEdges()[celli];
178 
179  label cutEdgeI = -1;
180  scalar maxCos = -GREAT;
181 
182  forAll(cEdges, cEdgeI)
183  {
184  label edgeI = cEdges[cEdgeI];
185 
186  scalar cosAngle = mag(refDir & meshTools::normEdgeVec(mesh(), edgeI));
187 
188  if (cosAngle > maxCos)
189  {
190  maxCos = cosAngle;
191 
192  cutEdgeI = edgeI;
193  }
194  }
195 
196  return cutEdgeI;
197 }
198 
199 
200 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
201 
202 Foam::cellLooper::cellLooper(const polyMesh& mesh)
203 :
204  edgeVertex(mesh)
205 {}
206 
207 
208 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
209 
211 {}
212 
213 
214 // ************************************************************************* //
const labelListList & pointFaces() const
label end() const
Return end vertex label.
Definition: edgeI.H:92
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
labelList getVertFacesNonEdge(const label celli, const label edgeI, const label vertI) const
Get faces (on cell) connected to vertI which are not using edgeI.
Definition: cellLooper.C:69
vector normEdgeVec(const primitiveMesh &, const label edgeI)
Normalized edge vector.
Definition: meshTools.C:189
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
const double e
Elementary charge.
Definition: doubleFloat.H:78
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
bool edgeOnCell(const primitiveMesh &, const label celli, const label edgeI)
Is edge used by cell.
Definition: meshTools.C:285
const edgeList & edges() const
Return mesh edges. Uses calcEdges.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
labelList getVertEdgesNonFace(const label celli, const label facei, const label vertI) const
Get edges (on cell) connected to vertI which are not on facei.
Definition: cellLooper.C:136
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
bool faceOnCell(const primitiveMesh &, const label celli, const label facei)
Is face used by cell.
Definition: meshTools.C:308
label getMisAlignedEdge(const vector &refDir, const label celli) const
Return edge from cellEdges that is most perpendicular.
Definition: cellLooper.C:172
Various functions to operate on Lists.
label getFirstVertEdge(const label facei, const label vertI) const
Get first edge connected to vertI and on facei.
Definition: cellLooper.C:106
dynamicFvMesh & mesh
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:58
A class for handling words, derived from string.
Definition: word.H:59
Info<< "Finished reading KIVA file"<< endl;cellShapeList cellShapes(nPoints);labelList cellZoning(nPoints,-1);const cellModel &hex=*(cellModeller::lookup("hex"));labelList hexLabels(8);label activeCells=0;labelList pointMap(nPoints);forAll(pointMap, i){pointMap[i]=i;}for(label i=0;i< nPoints;i++){if(f[i] > 0.0){hexLabels[0]=i;hexLabels[1]=i1tab[i];hexLabels[2]=i3tab[i1tab[i]];hexLabels[3]=i3tab[i];hexLabels[4]=i8tab[i];hexLabels[5]=i1tab[i8tab[i]];hexLabels[6]=i3tab[i1tab[i8tab[i]]];hexLabels[7]=i3tab[i8tab[i]];cellShapes[activeCells]=cellShape(hex, hexLabels);edgeList edges=cellShapes[activeCells].edges();forAll(edges, ei){if(edges[ei].mag(points)< SMALL){label start=pointMap[edges[ei].start()];while(start!=pointMap[start]){start=pointMap[start];}label end=pointMap[edges[ei].end()];while(end!=pointMap[end]){end=pointMap[end];}label minLabel=min(start, end);pointMap[start]=pointMap[end]=minLabel;}}cellZoning[activeCells]=idreg[i];activeCells++;}}cellShapes.setSize(activeCells);cellZoning.setSize(activeCells);forAll(cellShapes, celli){cellShape &cs=cellShapes[celli];forAll(cs, i){cs[i]=pointMap[cs[i]];}cs.collapse();}label bcIDs[11]={-1, 0, 2, 4,-1, 5,-1, 6, 7, 8, 9};const label nBCs=12;const word *kivaPatchTypes[nBCs]={&wallPolyPatch::typeName,&wallPolyPatch::typeName,&wallPolyPatch::typeName,&wallPolyPatch::typeName,&symmetryPolyPatch::typeName,&wedgePolyPatch::typeName,&polyPatch::typeName,&polyPatch::typeName,&polyPatch::typeName,&polyPatch::typeName,&symmetryPolyPatch::typeName,&oldCyclicPolyPatch::typeName};enum patchTypeNames{PISTON, VALVE, LINER, CYLINDERHEAD, AXIS, WEDGE, INFLOW, OUTFLOW, PRESIN, PRESOUT, SYMMETRYPLANE, CYCLIC};const char *kivaPatchNames[nBCs]={"piston","valve","liner","cylinderHead","axis","wedge","inflow","outflow","presin","presout","symmetryPlane","cyclic"};List< SLList< face > > pFaces[nBCs]
Definition: readKivaGrid.H:235
Combines edge or vertex in single label. Used to specify cuts across cell circumference.
Definition: edgeVertex.H:52
const labelListList & pointEdges() const
errorManip< error > abort(error &err)
Definition: errorManip.H:131
label start() const
Return start vertex label.
Definition: edgeI.H:81
static const char nl
Definition: Ostream.H:262
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
const labelListList & cellEdges() const
defineTypeNameAndDebug(combustionModel, 0)
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurence of given element and return index,.
void setSize(const label)
Reset size of List.
Definition: List.C:295
virtual ~cellLooper()
Destructor.
Definition: cellLooper.C:210
dimensioned< scalar > mag(const dimensioned< Type > &)
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:53
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
static autoPtr< cellLooper > New(const word &type, const polyMesh &mesh)
Return a reference to the selected cellLooper.
Definition: cellLooper.C:43
const labelListList & faceEdges() const
void getEdgeFaces(const primitiveMesh &, const label celli, const label edgeI, label &face0, label &face1)
Get faces on cell using edgeI. Throws error if no two found.
Definition: meshTools.C:458
Namespace for OpenFOAM.