File: starMesh.C

package info (click to toggle)
openfoam 4.1%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 163,028 kB
  • ctags: 58,990
  • sloc: cpp: 830,760; sh: 10,227; ansic: 8,215; xml: 745; lex: 437; awk: 194; sed: 91; makefile: 77; python: 18
file content (295 lines) | stat: -rw-r--r-- 10,266 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | Copyright (C) 2011-2015 OpenFOAM Foundation
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

\*---------------------------------------------------------------------------*/

#include "starMesh.H"
#include "emptyPolyPatch.H"
#include "demandDrivenData.H"
#include "cellModeller.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

// Merge tolerances
const Foam::scalar Foam::starMesh::smallMergeTol_ = 1e-3;
const Foam::scalar Foam::starMesh::cpMergePointTol_ = 1e-4;

// Cell shape models
const Foam::cellModel* Foam::starMesh::unknownPtr_ =
    Foam::cellModeller::lookup("unknown");
const Foam::cellModel* Foam::starMesh::tetPtr_ =
    Foam::cellModeller::lookup("tet");
const Foam::cellModel* Foam::starMesh::pyrPtr_ =
    Foam::cellModeller::lookup("pyr");
const Foam::cellModel* Foam::starMesh::tetWedgePtr_ =
    Foam::cellModeller::lookup("tetWedge");
const Foam::cellModel* Foam::starMesh::prismPtr_ =
    Foam::cellModeller::lookup("prism");
const Foam::cellModel* Foam::starMesh::wedgePtr_ =
    Foam::cellModeller::lookup("wedge");
const Foam::cellModel* Foam::starMesh::hexPtr_ =
    Foam::cellModeller::lookup("hex");

const Foam::cellModel* Foam::starMesh::sammTrim1Ptr_ =
    Foam::cellModeller::lookup("sammTrim1");
const Foam::cellModel* Foam::starMesh::sammTrim2Ptr_ =
    Foam::cellModeller::lookup("sammTrim2");
const Foam::cellModel* Foam::starMesh::sammTrim3Ptr_ =
    Foam::cellModeller::lookup("sammTrim3");
const Foam::cellModel* Foam::starMesh::sammTrim4Ptr_ =
    Foam::cellModeller::lookup("sammTrim4");
const Foam::cellModel* Foam::starMesh::sammTrim5Ptr_ =
    Foam::cellModeller::lookup("sammTrim5");
const Foam::cellModel* Foam::starMesh::sammTrim8Ptr_ =
    Foam::cellModeller::lookup("hexagonalPrism");

// Regular cell point addressing
// SAMM point addressing
const Foam::label Foam::starMesh::regularAddressingTable[6][8] =
{
    { 0,  1,  2,  4, -1, -1, -1, -1},    // tet
    { 0,  1,  2,  3,  4, -1, -1, -1},    // pyramid
    { 0,  1,  2,  4,  6, -1, -1, -1},    // tet wedge
    { 0,  1,  2,  4,  5,  6, -1, -1},    // prism
    { 7,  6,  5,  3,  2,  1,  0, -1},    // wedge
    { 0,  1,  2,  3,  4,  5,  6,  7}     // hex
};


// SAMM point addressing
const Foam::label Foam::starMesh::sammAddressingTable[9][12] =
{
    {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},    // samm0 - empty
    { 3,  2,  6,  7, 11,  9,  1,  5,  4, 12, -1, -1},    // samm1+
    {13,  5,  6,  2, 10, 12,  4,  7,  3, 11, -1, -1},    // samm2+
    { 2,  3,  0,  1, 10, 11, 12,  4,  8,  9, -1, -1},    // samm3+
    { 0,  1,  3,  4, 13,  8,  9, 10, 11, 12, -1, -1},    // samm4+
    {12,  7,  6,  5,  8, 11, 10,  9, -1, -1, -1, -1},    // samm5+
    {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},    // samm6 - empty
    {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},    // samm7 - empty
    {11,  3, 15, 12,  4,  8, 10,  2, 14, 13,  5,  9}     // samm8+
};


// lookup table giving OpenFOAM face number when looked up with shape index
// (first index) and STAR face number
// - first column is always -1
// - last column is -1 for all but hexagonal prism
// WARNING: Possible bug for sammTrim2
// The lookup table for SAMM shapes is based on the rotation of the
// shape. This would imply that the table below needs to be split between
// the regular shapes (3-9), which are OK, and the SAMM shapes, for which
// the face lookup needs to be done based on the rotation. Thus, for a samm
// cell, firts find out the face index in the normal rotation using the cell
// face permutation table and then use the index from the shape face lookup.
// Additionally, have in mind that this silliness does not allow matches
// on face 7 and 8 of the samm cell.

const Foam::label Foam::starMesh::sammFacePermutationTable[24][8] =
{
  {-1, 1, 2, 3, 4, 5, 6, 7},    // permutation   0
  {-1, 3, 4, 5, 6, 1, 2, 7},    // permutation   1
  {-1, 5, 6, 1, 2, 3, 4, 7},    // permutation   2
  {-1, 1, 2, 5, 6, 4, 3, 7},    // permutation   3
  {-1, 3, 4, 1, 2, 6, 5, 7},    // permutation   4
  {-1, 5, 6, 3, 4, 2, 1, 7},    // permutation   5
  {-1, 1, 2, 4, 3, 6, 5, 7},    // permutation   6
  {-1, 3, 4, 6, 5, 2, 1, 7},    // permutation   7
  {-1, 5, 6, 2, 1, 4, 3, 7},    // permutation   8
  {-1, 1, 2, 6, 5, 3, 4, 7},    // permutation   9
  {-1, 3, 4, 2, 1, 5, 6, 7},    // permutation  10
  {-1, 5, 6, 4, 3, 1, 2, 7},    // permutation  11
  {-1, 2, 1, 5, 6, 3, 4, 7},    // permutation  12
  {-1, 4, 3, 1, 2, 5, 6, 7},    // permutation  13
  {-1, 6, 5, 3, 4, 1, 2, 7},    // permutation  14
  {-1, 2, 1, 3, 4, 6, 5, 7},    // permutation  15
  {-1, 4, 3, 5, 6, 2, 1, 7},    // permutation  16
  {-1, 6, 5, 1, 2, 4, 3, 7},    // permutation  17
  {-1, 2, 1, 6, 5, 4, 3, 7},    // permutation  18
  {-1, 4, 3, 2, 1, 6, 5, 7},    // permutation  19
  {-1, 6, 5, 4, 3, 2, 1, 7},    // permutation  20
  {-1, 2, 1, 4, 3, 5, 6, 7},    // permutation  21
  {-1, 4, 3, 6, 5, 1, 2, 7},    // permutation  22
  {-1, 6, 5, 2, 1, 3, 4, 7}     // permutation  23
};

const Foam::label Foam::starMesh::shapeFaceLookup[19][9] =
{
    {-1, -1, -1, -1, -1, -1, -1, -1, -1},    // shape  0 - empty+
    {-1, -1, -1, -1, -1, -1, -1, -1, -1},    // shape  1 - empty+
    {-1, -1, -1, -1, -1, -1, -1, -1, -1},    // shape  2 - empty+
    {-1,  4,  5,  2,  3,  0,  1, -1, -1},    // shape  3 - hex+
    {-1,  1,  0,  5,  4,  2,  3, -1, -1},    // shape  4 - wedge+
    {-1,  0,  1,  4, -1,  2,  3, -1, -1},    // shape  5 - prism+
    {-1,  0, -1,  4,  2,  1,  3, -1, -1},    // shape  6 - pyr+
    {-1,  3, -1,  2, -1,  1,  0, -1, -1},    // shape  7 - tet+
    {-1, -1, -1, -1, -1, -1, -1, -1, -1},    // shape  8 - splitHex (empty)
    {-1,  0, -1,  1, -1,  2,  3, -1, -1},    // shape  9 - tetWedge+
    {-1, -1, -1, -1, -1, -1, -1, -1, -1},    // shape 10 - empty+
    {-1,  1,  0,  3,  2,  5,  4,  6, -1},    // shape 11 - sammTrim1
    {-1,  5,  4,  1,  0,  3,  2,  6, -1},    // shape 12 - sammTrim2
    {-1,  2,  3,  0,  1,  4,  5,  6, -1},    // shape 13 - sammTrim3
    {-1,  2,  3,  0,  1,  4,  5,  6, -1},    // shape 14 - sammTrim4
    {-1,  5,  2,  4,  3,  1,  0, -1, -1},    // shape 15 - sammTrim5
    {-1, -1, -1, -1, -1, -1, -1, -1, -1},    // shape 16 - empty
    {-1, -1, -1, -1, -1, -1, -1, -1, -1},    // shape 17 - empty
    {-1,  1,  0,  6,  7,  2,  3,  4,  5}     // shape 18 - sammTrim8
};


// The star to foam face order mapping tables are potentially incomplete
// Currently available data is listed below.
// 1) hex and degenerate hex: OK
// samm trim 1:
// star number: 1 2 3 4 5 6 7 8  In ROTATION 0
// foam number: 5 4 1 0 3 2 6
// confirmed:   1 0 3 2 5 4 6

// samm trim 2:
// star number: 1 2 3 4 5 6 7 8  In ROTATION 0
// foam number: 5 4 1 0 3 2 6
// confirmed:     4   0 3 2

// samm trim 3:
// star number: 1 2 3 4 5 6 7 8  In ROTATION 0
// foam number: 2 3 0 1 4 5 6
// confirmed:

// samm trim 4:
// star number: 1 2 3 4 5 6 7 8  In ROTATION 0
// foam number: 2 3 0 1 4 5 6
// confirmed:

// samm trim 5:
// star number: 1 2 3 4 5 6 7 8  In ROTATION 0
// foam number: 2 4 3 1 0 5
// confirmed:   5 2 4 3 1 0

// samm trim 8:
// star number: 1 2 3 4 5 6 7 8  In ROTATION 0
// foam number: 2 5 4 7 1 0 3 6
// confirmed:   1 0 6


// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //

void Foam::starMesh::createPolyMeshData()
{
    Info<< "Creating a polyMesh" << endl;

    createPolyCells();

    Info<< "\nNumber of internal faces: "
        << nInternalFaces_ << endl;

    createPolyBoundary();
}


void Foam::starMesh::clearExtraStorage()
{
    Info<< "Clearing extra storage" << endl;

    starPointLabelLookup_.setSize(0);
    starPointID_.setSize(0);
    starCellID_.setSize(0);
    starCellLabelLookup_.setSize(0);
    starCellPermutation_.setSize(0);
    cellFaces_.setSize(0);
    boundaryCellIDs_.setSize(0);
    boundaryCellFaceIDs_.setSize(0);
    couples_.clear();

    deleteDemandDrivenData(pointCellsPtr_);
}


// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

Foam::starMesh::starMesh
(
    const fileName& prefix,
    const Time& rt,
    const scalar scaleFactor
)
:
    casePrefix_(prefix),
    runTime_(rt),
    points_(0),
    cellShapes_(0),
    boundary_(0),
    patchTypes_(0),
    defaultFacesName_("defaultFaces"),
    defaultFacesType_(emptyPolyPatch::typeName),
    patchNames_(0),
    patchPhysicalTypes_(0),
    starPointLabelLookup_(0),
    starPointID_(0),
    starCellID_(0),
    starCellLabelLookup_(0),
    starCellPermutation_(0),
    cellFaces_(0),
    boundaryCellIDs_(0),
    boundaryCellFaceIDs_(0),
    meshFaces_(0),
    cellPolys_(0),
    nInternalFaces_(0),
    polyBoundaryPatchStartIndices_(0),
    pointCellsPtr_(NULL),
    couples_(0),
    isShapeMesh_(true)
{
    readPoints(scaleFactor);

    readCells();

    readBoundary();

    fixCollapsedEdges();

    readCouples();

    if (couples_.size())
    {
        createCoupleMatches();
    }

    markBoundaryFaces();

    mergeCoupleFacePoints();

    purgeCellShapes();

    collectBoundaryFaces();
}


// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //

Foam::starMesh::~starMesh()
{
    deleteDemandDrivenData(pointCellsPtr_);
}


// ************************************************************************* //