sammMesh.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 "sammMesh.H"
27 #include "emptyPolyPatch.H"
28 #include "demandDrivenData.H"
29 #include "cellModeller.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 // Cell shape models
34 const Foam::cellModel* Foam::sammMesh::unknownPtr_ =
35  Foam::cellModeller::lookup("unknown");
36 const Foam::cellModel* Foam::sammMesh::hexPtr_ =
38 const Foam::cellModel* Foam::sammMesh::wedgePtr_ =
40 const Foam::cellModel* Foam::sammMesh::prismPtr_ =
42 const Foam::cellModel* Foam::sammMesh::pyrPtr_ =
44 const Foam::cellModel* Foam::sammMesh::tetPtr_ =
46 const Foam::cellModel* Foam::sammMesh::tetWedgePtr_ =
47  Foam::cellModeller::lookup("tetWedge");
48 
49 const Foam::cellModel* Foam::sammMesh::sammTrim1Ptr_ =
50  Foam::cellModeller::lookup("sammTrim1");
51 const Foam::cellModel* Foam::sammMesh::sammTrim2Ptr_ =
52  Foam::cellModeller::lookup("sammTrim2");
53 const Foam::cellModel* Foam::sammMesh::sammTrim3Ptr_ =
54  Foam::cellModeller::lookup("sammTrim3");
55 const Foam::cellModel* Foam::sammMesh::sammTrim4Ptr_ =
56  Foam::cellModeller::lookup("sammTrim4");
57 const Foam::cellModel* Foam::sammMesh::sammTrim5Ptr_ =
58  Foam::cellModeller::lookup("sammTrim5");
59 const Foam::cellModel* Foam::sammMesh::sammTrim8Ptr_ =
60  Foam::cellModeller::lookup("hexagonalPrism");
61 
62 // lookup table giving OpenFOAM face number when looked up with shape index
63 // (first index) and STAR face number
64 // - first column is always -1
65 // - last column is -1 for all but hexagonal prism
66 // WARNING: Possible bug for sammTrim2
67 // There is a possibility that the lookup table for SAMM shapes is based on
68 // the rotation of the shape. This would imply that the table below would need
69 // to be split between the regular shapes (3-9), which are OK, and the SAMM
70 // shapes, for which the face lookup needs to be done based on the rotation.
71 // However, at the moment I haven't got enough info to complete the toble and
72 // there are no cases that break it. Please reconsider in the light of mode
73 // information.
74 const Foam::label Foam::sammMesh::shapeFaceLookup[19][9] =
75 {
76  {-1, -1, -1, -1, -1, -1, -1, -1, -1}, // shape 0 - empty+
77  {-1, -1, -1, -1, -1, -1, -1, -1, -1}, // shape 1 - empty+
78  {-1, -1, -1, -1, -1, -1, -1, -1, -1}, // shape 2 - empty+
79  {-1, 4, 5, 2, 3, 0, 1, -1, -1}, // shape 3 - hex+
80  {-1, 4, 5, 2, 3, 0, 1, -1, -1}, // shape 4 - wedge+
81  {-1, 0, 1, 4, -1, 2, 3, -1, -1}, // shape 5 - prism+
82  {-1, 0, -1, 4, 2, 1, 3, -1, -1}, // shape 6 - pyr+
83  {-1, 3, -1, 2, -1, 1, 0, -1, -1}, // shape 7 - tet+
84  {-1, -1, -1, -1, -1, -1, -1, -1, -1}, // shape 8 - splitHex (empty)
85  {-1, 0, -1, 1, -1, 2, 3, -1, -1}, // shape 9 - tetWedge+
86  {-1, -1, -1, -1, -1, -1, -1, -1, -1}, // shape 10 - empty+
87  {-1, 5, 4, 0, 1, 2, 3, 6, -1}, // shape 11 - sammTrim1+
88 // {-1, 1, 0, 2, 3, 4, 5, 6, -1}, // shape 12 - sammTrim2 ?
89  {-1, 1, 0, 2, 4, 3, 5, 6, -1}, // shape 12 - sammTrim2 f(4)=4
90  {-1, 5, 4, 0, 1, 2, 3, 6, -1}, // shape 13 - sammTrim3+
91  {-1, 5, 4, 1, 0, 3, 2, 6, -1}, // shape 14 - sammTrim4
92  {-1, 4, 3, 2, 5, 1, 0, -1, -1}, // shape 15 - sammTrim5
93  {-1, -1, -1, -1, -1, -1, -1, -1, -1}, // shape 16 - empty
94  {-1, -1, -1, -1, -1, -1, -1, -1, -1}, // shape 17 - empty
95  {-1, 0, 1, 2, 5, 3, 6, 4, 7} // shape 18 - sammTrim8
96 };
97 
98 // SAMM cell lookup data
99 
100 // List of pointers used instead of pointer list o avoid
101 // de-allocation problems
102 Foam::List<const Foam::cellModel*> Foam::sammMesh::sammShapeLookup
103 (
104  256,
105  reinterpret_cast<cellModel*>(0)
106 );
107 
108 Foam::List<const Foam::label*> Foam::sammMesh::sammAddressingTable
109 (
110  256,
111  reinterpret_cast<label*>(0)
112 );
113 
114 
115 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
116 
117 void Foam::sammMesh::createPolyMeshData()
118 {
119  Info<< "Creating a polyMesh" << endl;
120 
121  createPolyCells();
122 
123  Info<< "\nNumber of internal faces: "
124  << nInternalFaces_ << endl;
125 
126  createPolyBoundary();
127 
128  label nProblemCells = 0;
129 
130  // check that there is no zeros in the cellPolys_
131  forAll(cellPolys_, celli)
132  {
133  const labelList& curFaceLabels = cellPolys_[celli];
134 
135  forAll(curFaceLabels, facei)
136  {
137  if (curFaceLabels[facei] == -1)
138  {
139  Info<< "cell " << celli
140  << " has got an unmatched face. "
141  << "Index: " << cellShapes_[celli].model().index() << endl
142 // << "cell shape: " << cellShapes_[celli] << endl
143 // << "shape faces: " << cellShapes_[celli].faces() << endl
144  << "cellPolys: " << cellPolys_[celli] << endl
145 // << "cell faces: " << cellFaces_[celli]
146  << endl;
147 
148  nProblemCells++;
149 
150  break;
151  }
152  }
153  }
154 
155  if (nProblemCells > 0)
156  {
157  Info<< "Number of problem cells: " << nProblemCells << endl;
158  }
159 }
160 
161 
162 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
163 
164 Foam::sammMesh::sammMesh
165 (
166  const fileName& prefix,
167  const Time& rt,
168  const scalar scaleFactor
169 )
170 :
171  casePrefix_(prefix),
172  runTime_(rt),
173  points_(0),
174  cellShapes_(0),
175  boundary_(0),
176  patchTypes_(0),
177  defaultFacesName_("defaultFaces"),
178  defaultFacesType_(emptyPolyPatch::typeName),
179  patchNames_(0),
180  patchPhysicalTypes_(0),
181  starPointLabelLookup_(0),
182  starCellLabelLookup_(0),
183  cellFaces_(0),
184  meshFaces_(0),
185  cellPolys_(0),
186  nInternalFaces_(0),
187  polyBoundaryPatchStartIndices_(0),
188  pointCellsPtr_(nullptr),
189  isShapeMesh_(true)
190 {
191  // Fill in the lookup tables
192  fillSammCellShapeTable();
193  fillSammAddressingTable();
194 
195  readPoints(scaleFactor);
196 
197  readCells();
198 
199  readBoundary();
200 
201  fixCollapsedEdges();
202 
203  readCouples();
204 
205  // create boundary faces
206  createBoundaryFaces();
207 
208  // after all this is done do couples
209 }
210 
211 
212 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
213 
215 {
216  deleteDemandDrivenData(pointCellsPtr_);
217 }
218 
219 
220 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
static const cellModel * lookup(const word &)
Look up a model by name and return a pointer to the model or nullptr.
Definition: cellModeller.C:88
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:60
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
List< label > labelList
A List of labels.
Definition: labelList.H:56
~sammMesh()
Destructor.
Template functions to aid in the implementation of demand driven data.
Maps a geometry to a set of cell primitives, which enables geometric cell data to be calculated witho...
Definition: cellModel.H:64
messageStream Info
void deleteDemandDrivenData(DataPtr &dataPtr)