1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "hexCellLooper.H"
27 #include "cellFeatures.H"
29 #include "cellModeller.H"
32 #include "meshTools.H"
35 #include "addToRunTimeSelectionTable.H"
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
41 defineTypeNameAndDebug(hexCellLooper, 0);
42 addToRunTimeSelectionTable(cellLooper, hexCellLooper, word);
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
48 // Starting from cut edge start walking.
49 bool Foam::hexCellLooper::walkHex
52 const label startFaceI,
53 const label startEdgeI,
56 scalarField& loopWeights
59 label faceI = startFaceI;
61 label edgeI = startEdgeI;
69 Pout<< " walkHex : inserting cut onto edge:" << edgeI
70 << " vertices:" << mesh().edges()[edgeI] << endl;
73 // Store cut through edge. For now cut edges halfway.
74 loop[cutI] = edgeToEVert(edgeI);
75 loopWeights[cutI] = 0.5;
78 faceI = meshTools::otherFace(mesh(), cellI, faceI, edgeI);
80 const edge& e = mesh().edges()[edgeI];
82 // Walk two edges further
83 edgeI = meshTools::walkFace(mesh(), faceI, edgeI, e.end(), 2);
85 if (edgeI == startEdgeI)
95 Pout<< "hexCellLooper::walkHex" << "Problem : cell:" << cellI
96 << " collected loop:";
97 writeCuts(Pout, loop, loopWeights);
98 Pout<< "loopWeights:" << loopWeights << endl;
110 void Foam::hexCellLooper::makeFace
112 const labelList& loop,
113 const scalarField& loopWeights,
115 labelList& faceVerts,
116 pointField& facePoints
119 facePoints.setSize(loop.size());
120 faceVerts.setSize(loop.size());
124 label cut = loop[cutI];
128 label edgeI = getEdge(cut);
130 const edge& e = mesh().edges()[edgeI];
132 const point& v0 = mesh().points()[e.start()];
133 const point& v1 = mesh().points()[e.end()];
136 loopWeights[cutI]*v1 + (1.0-loopWeights[cutI])*v0;
140 label vertI = getVertex(cut);
142 facePoints[cutI] = mesh().points()[vertI];
145 faceVerts[cutI] = cutI;
150 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
152 // Construct from components
153 Foam::hexCellLooper::hexCellLooper(const polyMesh& mesh)
155 geomCellLooper(mesh),
156 hex_(*(cellModeller::lookup("hex")))
160 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
162 Foam::hexCellLooper::~hexCellLooper()
166 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
168 bool Foam::hexCellLooper::cut
170 const vector& refDir,
172 const boolList& vertIsCut,
173 const boolList& edgeIsCut,
174 const scalarField& edgeWeight,
177 scalarField& loopWeights
180 bool success = false;
182 if (mesh().cellShapes()[cellI].model() == hex_)
184 // Get starting edge. Note: should be compatible with way refDir is
186 label edgeI = meshTools::cutDirToEdge(mesh(), cellI, refDir);
188 // Get any face using edge
191 meshTools::getEdgeFaces(mesh(), cellI, edgeI, face0, face1);
193 // Walk circumference of hex, cutting edges only
195 loopWeights.setSize(4);
197 success = walkHex(cellI, face0, edgeI, loop, loopWeights);
201 success = geomCellLooper::cut
218 WarningIn("hexCellLooper")
219 << "could not cut cell " << cellI << endl;
221 fileName cutsFile("hexCellLooper_" + name(cellI) + ".obj");
223 Pout<< "hexCellLooper : writing cell to " << cutsFile << endl;
225 OFstream cutsStream(cutsFile);
239 // Check for duplicate cuts.
240 labelHashSet loopSet(loop.size());
244 label elem = loop[elemI];
246 if (loopSet.found(elem))
248 FatalErrorIn("hexCellLooper::walkHex") << " duplicate cut"
249 << abort(FatalError);
251 loopSet.insert(elem);
255 face faceVerts(loop.size());
256 pointField facePoints(loop.size());
258 makeFace(loop, loopWeights, faceVerts, facePoints);
260 if ((faceVerts.mag(facePoints) < SMALL) || (loop.size() < 3))
262 FatalErrorIn("hexCellLooper::walkHex") << "Face:" << faceVerts
263 << " on points:" << facePoints << endl
264 << UIndirectList<point>(facePoints, faceVerts)()
265 << abort(FatalError);
272 // No shortcuts for cutting with arbitrary plane.
273 bool Foam::hexCellLooper::cut
275 const plane& cutPlane,
277 const boolList& vertIsCut,
278 const boolList& edgeIsCut,
279 const scalarField& edgeWeight,
282 scalarField& loopWeights
300 // ************************************************************************* //