1 /*---------------------------------------------------------------------------*\
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 -------------------------------------------------------------------------------
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/>.
25 Create intermediate mesh from SAMM files
27 \*---------------------------------------------------------------------------*/
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 void sammMesh::addRegularCell
36 const labelList& labels,
37 const label nCreatedCells
41 static labelList labelsHex(8);
42 static labelList labelsWedge(7);
43 static labelList labelsPrism(6);
44 static labelList labelsPyramid(5);
45 static labelList labelsTet(4);
46 static labelList labelsTetWedge(5);
50 labels[2] == labels[3]
51 && labels[4] == labels[5]
52 && labels[5] == labels[6]
53 && labels[6] == labels[7]
56 labelsTet[0] = labels[0];
57 labelsTet[1] = labels[1];
58 labelsTet[2] = labels[2];
59 labelsTet[3] = labels[4];
60 cellShapes_[nCreatedCells] = cellShape(*tetPtr_, labelsTet);
63 else if // Square-based pyramid
65 labels[4] == labels[5]
66 && labels[5] == labels[6]
67 && labels[6] == labels[7]
70 labelsPyramid[0] = labels[0];
71 labelsPyramid[1] = labels[1];
72 labelsPyramid[2] = labels[2];
73 labelsPyramid[3] = labels[3];
74 labelsPyramid[4] = labels[4];
75 cellShapes_[nCreatedCells] = cellShape(*pyrPtr_, labelsPyramid);
80 labels[2] == labels[3]
81 && labels[4] == labels[5]
82 && labels[6] == labels[7]
85 labelsTetWedge[0] = labels[0];
86 labelsTetWedge[1] = labels[1];
87 labelsTetWedge[2] = labels[2];
88 labelsTetWedge[3] = labels[4];
89 labelsTetWedge[4] = labels[6];
90 cellShapes_[nCreatedCells] = cellShape(*tetWedgePtr_, labelsTetWedge);
93 else if // Triangular prism
95 labels[2] == labels[3]
96 && labels[6] == labels[7]
99 labelsPrism[0] = labels[0];
100 labelsPrism[1] = labels[1];
101 labelsPrism[2] = labels[2];
102 labelsPrism[3] = labels[4];
103 labelsPrism[4] = labels[5];
104 labelsPrism[5] = labels[6];
105 cellShapes_[nCreatedCells] = cellShape(*prismPtr_, labelsPrism);
110 labels[4] == labels[7]
113 labelsWedge[0] = labels[7];
114 labelsWedge[1] = labels[6];
115 labelsWedge[2] = labels[5];
116 labelsWedge[3] = labels[3];
117 labelsWedge[4] = labels[2];
118 labelsWedge[5] = labels[1];
119 labelsWedge[6] = labels[0];
120 cellShapes_[nCreatedCells] = cellShape(*wedgePtr_, labelsWedge);
125 labelsHex[0] = labels[0];
126 labelsHex[1] = labels[1];
127 labelsHex[2] = labels[2];
128 labelsHex[3] = labels[3];
129 labelsHex[4] = labels[4];
130 labelsHex[5] = labels[5];
131 labelsHex[6] = labels[6];
132 labelsHex[7] = labels[7];
133 cellShapes_[nCreatedCells] = cellShape(*hexPtr_, labelsHex);
138 void sammMesh::addSAMMcell
140 const label typeFlag,
141 const labelList& globalLabels,
142 const label nCreatedCells
146 // grab the shape from the table
147 if (!sammShapeLookup[typeFlag] || !sammAddressingTable[typeFlag])
151 "sammMesh::addRegularCell(const labelList& labels, "
152 "const label nCreatedCells)"
153 ) << "SAMM type " << typeFlag << " has no registered label. BUG!"
154 << abort(FatalError);
157 const cellModel& curModel = *(sammShapeLookup[typeFlag]);
159 // get reference to the addressing list
160 const label* addressing = sammAddressingTable[typeFlag];
162 // make a list of labels
163 labelList sammCellLabels(curModel.nPoints(), -1);
165 forAll (sammCellLabels, labelI)
167 sammCellLabels[labelI] = globalLabels[addressing[labelI]];
170 cellShapes_[nCreatedCells] = cellShape(curModel, sammCellLabels);
174 void sammMesh::readCells()
179 fileName cellsFileName(casePrefix_ + ".cel");
182 IFstream cellsFile(cellsFileName);
184 if (cellsFile.good())
186 label lineLabel, cellLabel = -1, pointLabel, regionLabel, typeFlag;
189 while (!(cellsFile >> lineLabel).eof())
191 maxLabel = max(maxLabel, lineLabel);
192 for (int i=0; i<8; i++)
194 cellsFile >> pointLabel;
197 cellsFile >> regionLabel;
198 cellsFile >> typeFlag;
200 if (lineLabel != cellLabel)
202 cellLabel = lineLabel;
209 FatalErrorIn("sammMesh::readCells()")
210 << "Cannot read file "
212 << abort(FatalError);
216 Info<< "Number of cells = " << nCells << endl << endl;
218 cellShapes_.setSize(nCells);
220 starCellLabelLookup_.setSize(maxLabel+1);
222 // reset point labels to invalid value
223 forAll (starCellLabelLookup_, i)
225 starCellLabelLookup_[i] = -1;
231 IFstream cellsFile(cellsFileName);
233 labelList labels(24, -1);
234 label lineLabel, sammLabel, regionLabel, typeFlag;
236 for (label cellI = 0; cellI < nCells; cellI++)
240 bool addOnToCell = false;
246 FatalErrorIn("sammMesh::readCells()")
247 << "Unknown SAMM cell. "
248 << "More than 24 vertices"
249 << abort(FatalError);
252 if ((cellsFile >> lineLabel).eof())
254 FatalErrorIn("sammMesh::readCells()")
255 << "Reached end of cells file before "
256 << "all cells are read in."
257 << abort(FatalError);
260 // prepare for possible continuation
263 for (int i=nLabels-8; i<nLabels; i++)
265 cellsFile >> sammLabel;
269 // Convert Samm vertex number to point label
270 labels[i] = starPointLabelLookup_[sammLabel];
274 Info<< "Cell file not consistent with vertex file. "
275 << "Samm vertex number " << sammLabel
276 << " does not exist\n";
285 cellsFile >> regionLabel;
286 cellsFile >> typeFlag;
288 // check for continuation line
289 if (!addOnToCell && typeFlag == 255)
298 } while (typeFlag == -1 || addOnToCell);
300 starCellLabelLookup_[lineLabel] = cellI;
304 addRegularCell(labels, cellI);
308 addSAMMcell(typeFlag, labels, cellI);
314 FatalErrorIn("sammMesh::readCells()")
315 << "No cells in file "
317 << abort(FatalError);
322 // ************************************************************************* //