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