Forward compatibility: flex
[foam-extend-3.2.git] / applications / utilities / mesh / conversion / sammToFoam / sammMesh.C
blobd526e9f166093464f2b894fd27323b580261a570
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "sammMesh.H"
27 #include "emptyPolyPatch.H"
28 #include "demandDrivenData.H"
29 #include "cellModeller.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
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");
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");
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] =
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
85 // SAMM cell lookup data
87 // List of pointers used instead of pointer list o avoid
88 // de-allocation problems
89 List<const cellModel*> sammMesh::sammShapeLookup
91     256,
92     reinterpret_cast<cellModel*>(0)
95 List<const label*> sammMesh::sammAddressingTable
97     256,
98     reinterpret_cast<label*>(0)
101 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
103 // Make polyhedral mesh data (packing)
104 void sammMesh::createPolyMeshData()
106     Info << "Creating a polyMesh" << endl;
108     createPolyCells();
110     Info<< "\nNumber of internal faces: "
111         << nInternalFaces_ << endl;
113     createPolyBoundary();
115     label nProblemCells = 0;
117     // check that there is no zeros in the cellPolys_
118     forAll (cellPolys_, cellI)
119     {
120         const labelList& curFaceLabels = cellPolys_[cellI];
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;
135                 nProblemCells++;
137                 break;
138             }
139         }
140     }
142     if (nProblemCells > 0)
143     {
144         Info << "Number of problem cells: " << nProblemCells << endl;
145     }
148 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
150 // Construct from components
151 sammMesh::sammMesh
153     const fileName& prefix,
154     const Time& rt,
155     const scalar scaleFactor
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)
178     // Fill in the lookup tables
179     fillSammCellShapeTable();
180     fillSammAddressingTable();
182     readPoints(scaleFactor);
184     readCells();
186     readBoundary();
188     fixCollapsedEdges();
190     readCouples();
192     // create boundary faces
193     createBoundaryFaces();
195     // after all this is done do couples
199 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
201 sammMesh::~sammMesh()
203     deleteDemandDrivenData(pointCellsPtr_);
207 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
210 // ************************************************************************* //