hexCellLooper.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "hexCellLooper.H"
27 #include "cellFeatures.H"
28 #include "polyMesh.H"
29 #include "cellModeller.H"
30 #include "plane.H"
31 #include "ListOps.H"
32 #include "meshTools.H"
33 #include "OFstream.H"
34 
36 
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41 defineTypeNameAndDebug(hexCellLooper, 0);
42 addToRunTimeSelectionTable(cellLooper, hexCellLooper, word);
43 }
44 
45 
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47 
48 // Starting from cut edge start walking.
50 (
51  const label cellI,
52  const label startFaceI,
53  const label startEdgeI,
54 
55  labelList& loop,
56  scalarField& loopWeights
57 ) const
58 {
59  label faceI = startFaceI;
60 
61  label edgeI = startEdgeI;
62 
63  label cutI = 0;
64 
65  do
66  {
67  if (debug & 2)
68  {
69  Pout<< " walkHex : inserting cut onto edge:" << edgeI
70  << " vertices:" << mesh().edges()[edgeI] << endl;
71  }
72 
73  // Store cut through edge. For now cut edges halfway.
74  loop[cutI] = edgeToEVert(edgeI);
75  loopWeights[cutI] = 0.5;
76  cutI++;
77 
78  faceI = meshTools::otherFace(mesh(), cellI, faceI, edgeI);
79 
80  const edge& e = mesh().edges()[edgeI];
81 
82  // Walk two edges further
83  edgeI = meshTools::walkFace(mesh(), faceI, edgeI, e.end(), 2);
84 
85  if (edgeI == startEdgeI)
86  {
87  break;
88  }
89  }
90  while (true);
91 
92  // Checks.
93  if (cutI > 4)
94  {
95  Pout<< "hexCellLooper::walkHex" << "Problem : cell:" << cellI
96  << " collected loop:";
97  writeCuts(Pout, loop, loopWeights);
98  Pout<< "loopWeights:" << loopWeights << endl;
99 
100  return false;
101  }
102  else
103  {
104  return true;
105  }
106 }
107 
108 
109 
111 (
112  const labelList& loop,
113  const scalarField& loopWeights,
114 
115  labelList& faceVerts,
116  pointField& facePoints
117 ) const
118 {
119  facePoints.setSize(loop.size());
120  faceVerts.setSize(loop.size());
121 
122  forAll(loop, cutI)
123  {
124  label cut = loop[cutI];
125 
126  if (isEdge(cut))
127  {
128  label edgeI = getEdge(cut);
129 
130  const edge& e = mesh().edges()[edgeI];
131 
132  const point& v0 = mesh().points()[e.start()];
133  const point& v1 = mesh().points()[e.end()];
134 
135  facePoints[cutI] =
136  loopWeights[cutI]*v1 + (1.0-loopWeights[cutI])*v0;
137  }
138  else
139  {
140  label vertI = getVertex(cut);
141 
142  facePoints[cutI] = mesh().points()[vertI];
143  }
144 
145  faceVerts[cutI] = cutI;
146  }
147 }
148 
149 
150 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
151 
152 // Construct from components
154 :
156  hex_(*(cellModeller::lookup("hex")))
157 {}
158 
159 
160 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
161 
163 {}
164 
165 
166 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
167 
169 (
170  const vector& refDir,
171  const label cellI,
172  const boolList& vertIsCut,
173  const boolList& edgeIsCut,
174  const scalarField& edgeWeight,
175 
176  labelList& loop,
177  scalarField& loopWeights
178 ) const
179 {
180  bool success = false;
181 
182  if (mesh().cellShapes()[cellI].model() == hex_)
183  {
184  // Get starting edge. Note: should be compatible with way refDir is
185  // determined.
186  label edgeI = meshTools::cutDirToEdge(mesh(), cellI, refDir);
187 
188  // Get any face using edge
189  label face0;
190  label face1;
191  meshTools::getEdgeFaces(mesh(), cellI, edgeI, face0, face1);
192 
193  // Walk circumference of hex, cutting edges only
194  loop.setSize(4);
195  loopWeights.setSize(4);
196 
197  success = walkHex(cellI, face0, edgeI, loop, loopWeights);
198  }
199  else
200  {
202  (
203  refDir,
204  cellI,
205  vertIsCut,
206  edgeIsCut,
207  edgeWeight,
208 
209  loop,
210  loopWeights
211  );
212  }
213 
214  if (debug)
215  {
216  if (loop.empty())
217  {
219  << "could not cut cell " << cellI << endl;
220 
221  fileName cutsFile("hexCellLooper_" + name(cellI) + ".obj");
222 
223  Pout<< "hexCellLooper : writing cell to " << cutsFile << endl;
224 
225  OFstream cutsStream(cutsFile);
226 
228  (
229  cutsStream,
230  mesh().cells(),
231  mesh().faces(),
232  mesh().points(),
233  labelList(1, cellI)
234  );
235 
236  return false;
237  }
238 
239  // Check for duplicate cuts.
240  labelHashSet loopSet(loop.size());
241 
242  forAll(loop, elemI)
243  {
244  label elem = loop[elemI];
245 
246  if (loopSet.found(elem))
247  {
249  << abort(FatalError);
250  }
251  loopSet.insert(elem);
252  }
253 
254 
255  face faceVerts(loop.size());
256  pointField facePoints(loop.size());
257 
258  makeFace(loop, loopWeights, faceVerts, facePoints);
259 
260  if ((faceVerts.mag(facePoints) < SMALL) || (loop.size() < 3))
261  {
263  << " on points:" << facePoints << endl
264  << UIndirectList<point>(facePoints, faceVerts)()
265  << abort(FatalError);
266  }
267  }
268  return success;
269 }
270 
271 
272 // No shortcuts for cutting with arbitrary plane.
274 (
275  const plane& cutPlane,
276  const label cellI,
277  const boolList& vertIsCut,
278  const boolList& edgeIsCut,
279  const scalarField& edgeWeight,
280 
281  labelList& loop,
282  scalarField& loopWeights
283 ) const
284 {
285  return
287  (
288  cutPlane,
289  cellI,
290  vertIsCut,
291  edgeIsCut,
292  edgeWeight,
293 
294  loop,
295  loopWeights
296  );
297 }
298 
299 
300 // ************************************************************************* //
cellShapes
const cellShapeList & cellShapes
Definition: getFieldScalar.H:35
Foam::hexCellLooper::cut
virtual bool cut(const vector &refDir, const label cellI, const boolList &vertIsCut, const boolList &edgeIsCut, const scalarField &edgeWeight, labelList &loop, scalarField &loopWeights) const
Create cut along circumference of cellI. Gets current mesh cuts.
Definition: hexCellLooper.C:169
meshTools.H
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::labelList
List< label > labelList
A List of labels.
Definition: labelList.H:56
Foam::face::mag
scalar mag(const pointField &) const
Magnitude of face area.
Definition: faceI.H:97
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
success
bool success
Definition: LISASMDCalcMethod1.H:16
Foam::meshTools::writeOBJ
void writeOBJ(Ostream &os, const point &pt)
Write obj representation of point.
Definition: meshTools.C:203
Foam::hexCellLooper::walkHex
bool walkHex(const label cellI, const label startFaceI, const label startEdgeI, labelList &loop, scalarField &loopWeights) const
Walk across faces of hex. Update loop/loopWeights with edges cut.
Definition: hexCellLooper.C:50
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::edge
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:58
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
polyMesh.H
Foam::HashSet< label, Hash< label > >
Foam::hexCellLooper::~hexCellLooper
virtual ~hexCellLooper()
Destructor.
Definition: hexCellLooper.C:162
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::hexCellLooper::makeFace
void makeFace(const labelList &loop, const scalarField &loopWeights, labelList &faceVerts, pointField &facePoints) const
Convert loop into face and points.
Definition: hexCellLooper.C:111
OFstream.H
Foam::plane
Geometric class that creates a 2D plane and can return the intersection point between a line and the ...
Definition: plane.H:60
Foam::cellModeller
A static collection of cell models, and a means of looking them up.
Definition: cellModeller.H:52
cellModeller.H
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
plane.H
Foam::geomCellLooper
Implementation of cellLooper. Does pure geometric cut through cell.
Definition: geomCellLooper.H:63
Foam::meshTools::walkFace
label walkFace(const primitiveMesh &, const label faceI, const label startEdgeI, const label startVertI, const label nEdges)
Returns label of edge nEdges away from startEdge (in the direction.
Definition: meshTools.C:580
cut
Patchify triangles based on orientation w.r.t other (triangulated or triangulatable) surfaces.
Foam::FatalError
error FatalError
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::HashTable::found
bool found(const Key &) const
Return true if hashedEntry is found in table.
Definition: HashTable.C:109
cellFeatures.H
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::hexCellLooper::hexCellLooper
hexCellLooper(const hexCellLooper &)
Disallow default bitwise copy construct.
Foam::OFstream
Output to file stream.
Definition: OFstream.H:81
Foam::meshTools::getEdgeFaces
void getEdgeFaces(const primitiveMesh &, const label cellI, const label edgeI, label &face0, label &face1)
Get faces on cell using edgeI. Throws error if no two found.
Definition: meshTools.C:456
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::meshTools::cutDirToEdge
label cutDirToEdge(const primitiveMesh &, const label cellI, const vector &cutDir)
Reverse of edgeToCutDir: given direction find edge bundle and.
Definition: meshTools.C:787
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::Pout
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
Foam::meshTools::otherFace
label otherFace(const primitiveMesh &, const label cellI, const label faceI, const label edgeI)
Return face on cell using edgeI but not faceI. Throws error.
Definition: meshTools.C:532
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: doubleFloat.H:94
Foam::HashSet::insert
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:116
Foam::UIndirectList
A List with indirect addressing.
Definition: fvMatrix.H:106
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
cells
const cellShapeList & cells
Definition: gmvOutputHeader.H:3
ListOps.H
Various functions to operate on Lists.
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259
hexCellLooper.H
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
lookup
stressControl lookup("compactNormalStress") >> compactNormalStress
Foam::geomCellLooper::cut
virtual bool cut(const vector &refDir, const label cellI, const boolList &vertIsCut, const boolList &edgeIsCut, const scalarField &edgeWeight, labelList &loop, scalarField &loopWeights) const
Create cut along circumference of cellI. Gets current mesh cuts.
Definition: geomCellLooper.C:229