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/>.
24 \*---------------------------------------------------------------------------*/
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
35 label hexBlock::vtxLabel(label a, label b, label c) const
37 return (a + b*(xDim_ + 1) + c*(xDim_ + 1)*(yDim_ + 1));
41 // Calculate the handedness of the block by looking at the orientation
42 // of the spanning edges of a hex. Loops until valid cell found (since might
44 void hexBlock::setHandedness()
46 const pointField& p = points_;
48 for (label k = 0; k <= zDim_ - 1; k++)
50 for (label j = 0; j <= yDim_ - 1; j++)
52 for (label i = 0; i <= xDim_ - 1; i++)
54 vector x = p[vtxLabel(i+1, j, k)] - p[vtxLabel(i, j, k)];
55 vector y = p[vtxLabel(i, j+1, k)] - p[vtxLabel(i, j, k)];
56 vector z = p[vtxLabel(i, j, k+1)] - p[vtxLabel(i, j, k)];
58 if (mag(x) > SMALL && mag(y) > SMALL && mag(z) > SMALL)
60 Info<< "Looking at cell "
61 << i << ' ' << j << ' ' << k
62 << " to determine orientation."
65 if (((x ^ y) & z) > 0)
67 Info<< "Right-handed block." << endl;
68 blockHandedness_ = right;
72 Info << "Left-handed block." << endl;
73 blockHandedness_ = left;
79 Info<< "Cannot determine orientation of cell "
80 << i << ' ' << j << ' ' << k
81 << " since has base vectors " << x << y << z << endl;
87 if (blockHandedness_ == noPoints)
89 WarningIn("hexBlock::hexBlock::setHandedness()")
90 << "Cannot determine orientation of block."
91 << " Continuing as if right handed." << endl;
92 blockHandedness_ = right;
97 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
99 // Construct from components
100 hexBlock::hexBlock(const label nx, const label ny, const label nz)
105 blockHandedness_(noPoints),
106 points_((xDim_ + 1)*(yDim_ + 1)*(zDim_ + 1))
110 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
112 void hexBlock::readPoints
114 const bool readBlank,
115 const scalar twoDThicknes,
121 label nPoints = points_.size();
123 if (twoDThicknes > 0)
128 Info<< "Reading " << nPoints << " x coordinates..." << endl;
129 for (label i=0; i < nPoints; i++)
131 is >> points_[i].x();
134 Info<< "Reading " << nPoints << " y coordinates..." << endl;
135 for (label i=0; i < nPoints; i++)
137 is >> points_[i].y();
140 if (twoDThicknes > 0)
142 Info<< "Extruding " << nPoints << " points in z direction..." << endl;
144 for (label i=0; i < nPoints; i++)
146 points_[i+nPoints] = points_[i];
148 for (label i=0; i < nPoints; i++)
151 points_[i+nPoints].z() = twoDThicknes;
156 Info<< "Reading " << nPoints << " z coordinates..." << endl;
157 for (label i=0; i < nPoints; i++)
159 is >> points_[i].z();
166 Info<< "Reading " << nPoints << " blanks..." << endl;
167 for (label i=0; i < nPoints; i++)
173 // Set left- or righthandedness of block by looking at a cell.
178 labelListList hexBlock::blockCells() const
180 labelListList result(xDim_*yDim_*zDim_);
184 if (blockHandedness_ == right)
186 for (label k = 0; k <= zDim_ - 1; k++)
188 for (label j = 0; j <= yDim_ - 1; j++)
190 for (label i = 0; i <= xDim_ - 1; i++)
192 labelList& hexLabels = result[cellNo];
193 hexLabels.setSize(8);
195 hexLabels[0] = vtxLabel(i, j, k);
196 hexLabels[1] = vtxLabel(i+1, j, k);
197 hexLabels[2] = vtxLabel(i+1, j+1, k);
198 hexLabels[3] = vtxLabel(i, j+1, k);
199 hexLabels[4] = vtxLabel(i, j, k+1);
200 hexLabels[5] = vtxLabel(i+1, j, k+1);
201 hexLabels[6] = vtxLabel(i+1, j+1, k+1);
202 hexLabels[7] = vtxLabel(i, j+1, k+1);
209 else if (blockHandedness_ == left)
211 for (label k = 0; k <= zDim_ - 1; k++)
213 for (label j = 0; j <= yDim_ - 1; j++)
215 for (label i = 0; i <= xDim_ - 1; i++)
217 labelList& hexLabels = result[cellNo];
218 hexLabels.setSize(8);
220 hexLabels[0] = vtxLabel(i, j, k+1);
221 hexLabels[1] = vtxLabel(i+1, j, k+1);
222 hexLabels[2] = vtxLabel(i+1, j+1, k+1);
223 hexLabels[3] = vtxLabel(i, j+1, k+1);
224 hexLabels[4] = vtxLabel(i, j, k);
225 hexLabels[5] = vtxLabel(i+1, j, k);
226 hexLabels[6] = vtxLabel(i+1, j+1, k);
227 hexLabels[7] = vtxLabel(i, j+1, k);
236 FatalErrorIn("hexBlock::cellShapes()")
237 << "Unable to determine block handedness as points "
238 << "have not been read in yet"
239 << abort(FatalError);
246 // Return block patch faces given direction and range limits
247 // From the cfx manual: direction
248 // 0 = solid (3-D patch),
249 // 1 = high i, 2 = high j, 3 = high k
250 // 4 = low i, 5 = low j, 6 = low k
251 faceList hexBlock::patchFaces(const label direc, const labelList& range) const
253 if (range.size() != 6)
257 "patchFaces(const label direc, const labelList& range) const"
258 ) << "Invalid size of the range array: " << range.size()
259 << ". Should be 6 (xMin, xMax, yMin, yMax, zMin, zMax"
260 << abort(FatalError);
263 label xMinRange = range[0];
264 label xMaxRange = range[1];
265 label yMinRange = range[2];
266 label yMaxRange = range[3];
267 label zMinRange = range[4];
268 label zMaxRange = range[5];
280 (yMaxRange - yMinRange + 1)*(zMaxRange - zMinRange + 1)
284 for (label k = zMinRange - 1; k <= zMaxRange - 1; k++)
286 for (label j = yMinRange - 1; j <= yMaxRange - 1; j++)
288 result[p].setSize(4);
291 result[p][0] = vtxLabel(xDim_, j, k);
292 result[p][1] = vtxLabel(xDim_, j+1, k);
293 result[p][2] = vtxLabel(xDim_, j+1, k+1);
294 result[p][3] = vtxLabel(xDim_, j, k+1);
309 (xMaxRange - xMinRange + 1)*(zMaxRange - zMinRange + 1)
313 for (label i = xMinRange - 1; i <= xMaxRange - 1; i++)
315 for (label k = zMinRange - 1; k <= zMaxRange - 1; k++)
317 result[p].setSize(4);
320 result[p][0] = vtxLabel(i, yDim_, k);
321 result[p][1] = vtxLabel(i, yDim_, k + 1);
322 result[p][2] = vtxLabel(i + 1, yDim_, k + 1);
323 result[p][3] = vtxLabel(i + 1, yDim_, k);
338 (xMaxRange - xMinRange + 1)*(yMaxRange - yMinRange + 1)
342 for (label i = xMinRange - 1; i <= xMaxRange - 1; i++)
344 for (label j = yMinRange - 1; j <= yMaxRange - 1; j++)
346 result[p].setSize(4);
349 result[p][0] = vtxLabel(i, j, zDim_);
350 result[p][1] = vtxLabel(i + 1, j, zDim_);
351 result[p][2] = vtxLabel(i + 1, j + 1, zDim_);
352 result[p][3] = vtxLabel(i, j + 1, zDim_);
367 (yMaxRange - yMinRange + 1)*(zMaxRange - zMinRange + 1)
371 for (label k = zMinRange - 1; k <= zMaxRange - 1; k++)
373 for (label j = yMinRange - 1; j <= yMaxRange - 1; j++)
375 result[p].setSize(4);
378 result[p][0] = vtxLabel(0, j, k);
379 result[p][1] = vtxLabel(0, j, k + 1);
380 result[p][2] = vtxLabel(0, j + 1, k + 1);
381 result[p][3] = vtxLabel(0, j + 1, k);
396 (xMaxRange - xMinRange + 1)*(zMaxRange - zMinRange + 1)
400 for (label i = xMinRange - 1; i <= xMaxRange - 1; i++)
402 for (label k = zMinRange - 1; k <= zMaxRange - 1; k++)
404 result[p].setSize(4);
407 result[p][0] = vtxLabel(i, 0, k);
408 result[p][1] = vtxLabel(i + 1, 0, k);
409 result[p][2] = vtxLabel(i + 1, 0, k + 1);
410 result[p][3] = vtxLabel(i, 0, k + 1);
425 (xMaxRange - xMinRange + 1)*(yMaxRange - yMinRange + 1)
429 for (label i = xMinRange - 1; i <= xMaxRange - 1; i++)
431 for (label j = yMinRange - 1; j <= yMaxRange - 1; j++)
433 result[p].setSize(4);
436 result[p][0] = vtxLabel(i, j, 0);
437 result[p][1] = vtxLabel(i, j + 1, 0);
438 result[p][2] = vtxLabel(i + 1, j + 1, 0);
439 result[p][3] = vtxLabel(i + 1, j, 0);
453 "patchFaces(const label direc, const labelList& range) const"
454 ) << "direction out of range (1 to 6): " << direc
455 << abort(FatalError);
459 // Correct the face orientation based on the handedness of the block.
460 // Do nothing for the right-handed block
461 if (blockHandedness_ == noPoints)
465 "patchFaces(const label direc, const labelList& range) const"
466 ) << "Unable to determine block handedness as points "
467 << "have not been read in yet"
468 << abort(FatalError);
470 else if (blockHandedness_ == left)
472 // turn all faces inside out
473 forAll (result, faceI)
475 result[faceI] = result[faceI].reverseFace();
483 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
485 } // End namespace Foam
487 // ************************************************************************* //