meshTools.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-2013 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 "meshTools.H"
27 #include "polyMesh.H"
28 #include "hexMatcher.H"
29 
30 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
31 
32 // Check if n is in same direction as normals of all faceLabels
34 (
35  const vector& n,
36  const vectorField& faceNormals,
37  const labelList& faceLabels
38 )
39 {
40  forAll(faceLabels, i)
41  {
42  if ((faceNormals[faceLabels[i]] & n) < SMALL)
43  {
44  // Found normal in different direction from n.
45  return false;
46  }
47  }
48 
49  return true;
50 }
51 
52 
54 {
55  vectorField octantNormal(8);
56  octantNormal[mXmYmZ] = vector(-1, -1, -1);
57  octantNormal[pXmYmZ] = vector(1, -1, -1);
58  octantNormal[mXpYmZ] = vector(-1, 1, -1);
59  octantNormal[pXpYmZ] = vector(1, 1, -1);
60 
61  octantNormal[mXmYpZ] = vector(-1, -1, 1);
62  octantNormal[pXmYpZ] = vector(1, -1, 1);
63  octantNormal[mXpYpZ] = vector(-1, 1, 1);
64  octantNormal[pXpYpZ] = vector(1, 1, 1);
65 
66  octantNormal /= mag(octantNormal);
67 
68 
69  vectorField pn(pp.nPoints());
70 
71  const vectorField& faceNormals = pp.faceNormals();
72  const vectorField& pointNormals = pp.pointNormals();
73  const labelListList& pointFaces = pp.pointFaces();
74 
75  forAll(pointFaces, pointI)
76  {
77  const labelList& pFaces = pointFaces[pointI];
78 
79  if (visNormal(pointNormals[pointI], faceNormals, pFaces))
80  {
81  pn[pointI] = pointNormals[pointI];
82  }
83  else
84  {
85  WarningIn
86  (
87  "Foam::meshTools::calcBoxPointNormals(const primitivePatch& pp)"
88  ) << "Average point normal not visible for point:"
89  << pp.meshPoints()[pointI] << endl;
90 
91  label visOctant =
93  | pXmYmZMask
94  | mXpYmZMask
95  | pXpYmZMask
96  | mXmYpZMask
97  | pXmYpZMask
98  | mXpYpZMask
99  | pXpYpZMask;
100 
101  forAll(pFaces, i)
102  {
103  const vector& n = faceNormals[pFaces[i]];
104 
105  if (n.x() > SMALL)
106  {
107  // All -x octants become invisible
108  visOctant &= ~mXmYmZMask;
109  visOctant &= ~mXmYpZMask;
110  visOctant &= ~mXpYmZMask;
111  visOctant &= ~mXpYpZMask;
112  }
113  else if (n.x() < -SMALL)
114  {
115  // All +x octants become invisible
116  visOctant &= ~pXmYmZMask;
117  visOctant &= ~pXmYpZMask;
118  visOctant &= ~pXpYmZMask;
119  visOctant &= ~pXpYpZMask;
120  }
121 
122  if (n.y() > SMALL)
123  {
124  visOctant &= ~mXmYmZMask;
125  visOctant &= ~mXmYpZMask;
126  visOctant &= ~pXmYmZMask;
127  visOctant &= ~pXmYpZMask;
128  }
129  else if (n.y() < -SMALL)
130  {
131  visOctant &= ~mXpYmZMask;
132  visOctant &= ~mXpYpZMask;
133  visOctant &= ~pXpYmZMask;
134  visOctant &= ~pXpYpZMask;
135  }
136 
137  if (n.z() > SMALL)
138  {
139  visOctant &= ~mXmYmZMask;
140  visOctant &= ~mXpYmZMask;
141  visOctant &= ~pXmYmZMask;
142  visOctant &= ~pXpYmZMask;
143  }
144  else if (n.z() < -SMALL)
145  {
146  visOctant &= ~mXmYpZMask;
147  visOctant &= ~mXpYpZMask;
148  visOctant &= ~pXmYpZMask;
149  visOctant &= ~pXpYpZMask;
150  }
151  }
152 
153  label visI = -1;
154 
155  label mask = 1;
156 
157  for (label octant = 0; octant < 8; octant++)
158  {
159  if (visOctant & mask)
160  {
161  // Take first visible octant found. Note: could use
162  // combination of visible octants here.
163  visI = octant;
164 
165  break;
166  }
167  mask <<= 1;
168  }
169 
170  if (visI != -1)
171  {
172  // Take a vector in this octant.
173  pn[pointI] = octantNormal[visI];
174  }
175  else
176  {
177  pn[pointI] = vector::zero;
178 
179  WarningIn
180  (
181  "Foam::meshTools::calcBoxPointNormals"
182  "(const primitivePatch& pp)"
183  ) << "No visible octant for point:" << pp.meshPoints()[pointI]
184  << " cooord:" << pp.points()[pp.meshPoints()[pointI]] << nl
185  << "Normal set to " << pn[pointI] << endl;
186  }
187  }
188  }
189 
190  return pn;
191 }
192 
193 
195 (
196  const primitiveMesh& mesh,
197  const label edgeI
198 )
199 {
200  vector eVec = mesh.edges()[edgeI].vec(mesh.points());
201 
202  eVec /= mag(eVec);
203 
204  return eVec;
205 }
206 
207 
209 (
210  Ostream& os,
211  const point& pt
212 )
213 {
214  os << "v " << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl;
215 }
216 
217 
219 (
220  Ostream& os,
221  const triad& t,
222  const point& pt
223 )
224 {
225  forAll(t, dirI)
226  {
227  writeOBJ(os, pt, pt + t[dirI]);
228  }
229 }
230 
231 
233 (
234  Ostream& os,
235  const point& p1,
236  const point& p2,
237  label& count
238 )
239 {
240  os << "v" << ' ' << p1.x() << ' ' << p1.y() << ' ' << p1.z() << endl;
241  os << "v" << ' ' << p2.x() << ' ' << p2.y() << ' ' << p2.z() << endl;
242 
243  os << "l" << " " << (count + 1) << " " << (count + 2) << endl;
244 
245  count += 2;
246 }
247 
248 
250 (
251  Ostream& os,
252  const point& p1,
253  const point& p2
254 )
255 {
256  os << "v" << ' ' << p1.x() << ' ' << p1.y() << ' ' << p1.z() << endl;
257 
258  os << "vn"
259  << ' ' << p2.x() - p1.x()
260  << ' ' << p2.y() - p1.y()
261  << ' ' << p2.z() - p1.z() << endl;
262 }
263 
264 
266 (
267  Ostream& os,
268  const cellList& cells,
269  const faceList& faces,
270  const pointField& points,
271  const labelList& cellLabels
272 )
273 {
274  labelHashSet usedFaces(4*cellLabels.size());
275 
276  forAll(cellLabels, i)
277  {
278  const cell& cFaces = cells[cellLabels[i]];
279 
280  forAll(cFaces, j)
281  {
282  usedFaces.insert(cFaces[j]);
283  }
284  }
285 
286  writeOBJ(os, faces, points, usedFaces.toc());
287 }
288 
289 
291 (
292  const primitiveMesh& mesh,
293  const label cellI,
294  const label edgeI
295 )
296 {
297  return findIndex(mesh.edgeCells(edgeI), cellI) != -1;
298 }
299 
300 
302 (
303  const primitiveMesh& mesh,
304  const label faceI,
305  const label edgeI
306 )
307 {
308  return findIndex(mesh.faceEdges(faceI), edgeI) != -1;
309 }
310 
311 
312 // Return true if faceI part of cellI
314 (
315  const primitiveMesh& mesh,
316  const label cellI,
317  const label faceI
318 )
319 {
320  if (mesh.isInternalFace(faceI))
321  {
322  if
323  (
324  (mesh.faceOwner()[faceI] == cellI)
325  || (mesh.faceNeighbour()[faceI] == cellI)
326  )
327  {
328  return true;
329  }
330  }
331  else
332  {
333  if (mesh.faceOwner()[faceI] == cellI)
334  {
335  return true;
336  }
337  }
338  return false;
339 }
340 
341 
343 (
344  const edgeList& edges,
345  const labelList& candidates,
346  const label v0,
347  const label v1
348 )
349 {
350  forAll(candidates, i)
351  {
352  label edgeI = candidates[i];
353 
354  const edge& e = edges[edgeI];
355 
356  if ((e[0] == v0 && e[1] == v1) || (e[0] == v1 && e[1] == v0))
357  {
358  return edgeI;
359  }
360  }
361  return -1;
362 }
363 
364 
366 (
367  const primitiveMesh& mesh,
368  const label v0,
369  const label v1
370 )
371 {
372  const edgeList& edges = mesh.edges();
373 
374  const labelList& v0Edges = mesh.pointEdges()[v0];
375 
376  forAll(v0Edges, i)
377  {
378  label edgeI = v0Edges[i];
379 
380  const edge& e = edges[edgeI];
381 
382  if ((e.start() == v1) || (e.end() == v1))
383  {
384  return edgeI;
385  }
386  }
387  return -1;
388 }
389 
390 
392 (
393  const primitiveMesh& mesh,
394  const label f0,
395  const label f1
396 )
397 {
398  const labelList& f0Edges = mesh.faceEdges()[f0];
399  const labelList& f1Edges = mesh.faceEdges()[f1];
400 
401  forAll(f0Edges, f0EdgeI)
402  {
403  label edge0 = f0Edges[f0EdgeI];
404 
405  forAll(f1Edges, f1EdgeI)
406  {
407  label edge1 = f1Edges[f1EdgeI];
408 
409  if (edge0 == edge1)
410  {
411  return edge0;
412  }
413  }
414  }
416  (
417  "meshTools::getSharedEdge(const primitiveMesh&, const label"
418  ", const label)"
419  ) << "Faces " << f0 << " and " << f1 << " do not share an edge"
420  << abort(FatalError);
421 
422  return -1;
423 
424 }
425 
426 
428 (
429  const primitiveMesh& mesh,
430  const label cell0I,
431  const label cell1I
432 )
433 {
434  const cell& cFaces = mesh.cells()[cell0I];
435 
436  forAll(cFaces, cFaceI)
437  {
438  label faceI = cFaces[cFaceI];
439 
440  if
441  (
442  mesh.isInternalFace(faceI)
443  && (
444  mesh.faceOwner()[faceI] == cell1I
445  || mesh.faceNeighbour()[faceI] == cell1I
446  )
447  )
448  {
449  return faceI;
450  }
451  }
452 
453 
455  (
456  "meshTools::getSharedFace(const primitiveMesh&, const label"
457  ", const label)"
458  ) << "No common face for"
459  << " cell0I:" << cell0I << " faces:" << cFaces
460  << " cell1I:" << cell1I << " faces:"
461  << mesh.cells()[cell1I]
462  << abort(FatalError);
463 
464  return -1;
465 }
466 
467 
468 // Get the two faces on cellI using edgeI.
470 (
471  const primitiveMesh& mesh,
472  const label cellI,
473  const label edgeI,
474  label& face0,
475  label& face1
476 )
477 {
478  const labelList& eFaces = mesh.edgeFaces(edgeI);
479 
480  face0 = -1;
481  face1 = -1;
482 
483  forAll(eFaces, eFaceI)
484  {
485  label faceI = eFaces[eFaceI];
486 
487  if (faceOnCell(mesh, cellI, faceI))
488  {
489  if (face0 == -1)
490  {
491  face0 = faceI;
492  }
493  else
494  {
495  face1 = faceI;
496 
497  return;
498  }
499  }
500  }
501 
502  if ((face0 == -1) || (face1 == -1))
503  {
505  (
506  "meshTools::getEdgeFaces(const primitiveMesh&, const label"
507  ", const label, label&, label&"
508  ) << "Can not find faces using edge " << mesh.edges()[edgeI]
509  << " on cell " << cellI << abort(FatalError);
510  }
511 }
512 
513 
514 // Return label of other edge connected to vertex
516 (
517  const primitiveMesh& mesh,
518  const labelList& edgeLabels,
519  const label thisEdgeI,
520  const label thisVertI
521 )
522 {
523  forAll(edgeLabels, edgeLabelI)
524  {
525  label edgeI = edgeLabels[edgeLabelI];
526 
527  if (edgeI != thisEdgeI)
528  {
529  const edge& e = mesh.edges()[edgeI];
530 
531  if ((e.start() == thisVertI) || (e.end() == thisVertI))
532  {
533  return edgeI;
534  }
535  }
536  }
537 
539  (
540  "meshTools::otherEdge(const primitiveMesh&, const labelList&"
541  ", const label, const label)"
542  ) << "Can not find edge in "
543  << UIndirectList<edge>(mesh.edges(), edgeLabels)()
544  << " connected to edge "
545  << thisEdgeI << " with vertices " << mesh.edges()[thisEdgeI]
546  << " on side " << thisVertI << abort(FatalError);
547 
548  return -1;
549 }
550 
551 
552 // Return face on other side of edgeI
554 (
555  const primitiveMesh& mesh,
556  const label cellI,
557  const label faceI,
558  const label edgeI
559 )
560 {
561  label face0;
562  label face1;
563 
564  getEdgeFaces(mesh, cellI, edgeI, face0, face1);
565 
566  if (face0 == faceI)
567  {
568  return face1;
569  }
570  else
571  {
572  return face0;
573  }
574 }
575 
576 
577 // Return face on other side of edgeI
579 (
580  const primitiveMesh& mesh,
581  const label otherCellI,
582  const label faceI
583 )
584 {
585  if (!mesh.isInternalFace(faceI))
586  {
588  (
589  "meshTools::otherCell(const primitiveMesh&, const label"
590  ", const label)"
591  ) << "Face " << faceI << " is not internal"
592  << abort(FatalError);
593  }
594 
595  label newCellI = mesh.faceOwner()[faceI];
596 
597  if (newCellI == otherCellI)
598  {
599  newCellI = mesh.faceNeighbour()[faceI];
600  }
601  return newCellI;
602 }
603 
604 
605 // Returns label of edge nEdges away from startEdge (in the direction of
606 // startVertI)
608 (
609  const primitiveMesh& mesh,
610  const label faceI,
611  const label startEdgeI,
612  const label startVertI,
613  const label nEdges
614 )
615 {
616  const labelList& fEdges = mesh.faceEdges(faceI);
617 
618  label edgeI = startEdgeI;
619 
620  label vertI = startVertI;
621 
622  for (label iter = 0; iter < nEdges; iter++)
623  {
624  edgeI = otherEdge(mesh, fEdges, edgeI, vertI);
625 
626  vertI = mesh.edges()[edgeI].otherVertex(vertI);
627  }
628 
629  return edgeI;
630 }
631 
632 
634 (
635  const polyMesh& mesh,
636  point& pt
637 )
638 {
639  const Vector<label>& dirs = mesh.geometricD();
640 
641  const point& min = mesh.bounds().min();
642  const point& max = mesh.bounds().max();
643 
644  for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
645  {
646  if (dirs[cmpt] == -1)
647  {
648  pt[cmpt] = 0.5*(min[cmpt] + max[cmpt]);
649  }
650  }
651 }
652 
653 
655 (
656  const polyMesh& mesh,
657  pointField& pts
658 )
659 {
660  const Vector<label>& dirs = mesh.geometricD();
661 
662  const point& min = mesh.bounds().min();
663  const point& max = mesh.bounds().max();
664 
665  bool isConstrained = false;
666  for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
667  {
668  if (dirs[cmpt] == -1)
669  {
670  isConstrained = true;
671  break;
672  }
673  }
674 
675  if (isConstrained)
676  {
677  forAll(pts, i)
678  {
679  for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
680  {
681  if (dirs[cmpt] == -1)
682  {
683  pts[i][cmpt] = 0.5*(min[cmpt] + max[cmpt]);
684  }
685  }
686  }
687  }
688 }
689 
690 
691 //- Set the constrained components of directions/velocity to zero
693 (
694  const polyMesh& mesh,
695  const Vector<label>& dirs,
696  vector& d
697 )
698 {
699  for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
700  {
701  if (dirs[cmpt] == -1)
702  {
703  d[cmpt] = 0.0;
704  }
705  }
706 }
707 
708 
710 (
711  const polyMesh& mesh,
712  const Vector<label>& dirs,
713  vectorField& d
714 )
715 {
716  bool isConstrained = false;
717  for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
718  {
719  if (dirs[cmpt] == -1)
720  {
721  isConstrained = true;
722  break;
723  }
724  }
725 
726  if (isConstrained)
727  {
728  forAll(d, i)
729  {
730  for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
731  {
732  if (dirs[cmpt] == -1)
733  {
734  d[i][cmpt] = 0.0;
735  }
736  }
737  }
738  }
739 }
740 
741 
743 (
744  const primitiveMesh& mesh,
745  const label cellI,
746  const label e0,
747  label& e1,
748  label& e2,
749  label& e3
750 )
751 {
752  // Go to any face using e0
753  label faceI = meshTools::otherFace(mesh, cellI, -1, e0);
754 
755  // Opposite edge on face
756  e1 = meshTools::walkFace(mesh, faceI, e0, mesh.edges()[e0].end(), 2);
757 
758  faceI = meshTools::otherFace(mesh, cellI, faceI, e1);
759 
760  e2 = meshTools::walkFace(mesh, faceI, e1, mesh.edges()[e1].end(), 2);
761 
762  faceI = meshTools::otherFace(mesh, cellI, faceI, e2);
763 
764  e3 = meshTools::walkFace(mesh, faceI, e2, mesh.edges()[e2].end(), 2);
765 }
766 
767 
769 (
770  const primitiveMesh& mesh,
771  const label cellI,
772  const label startEdgeI
773 )
774 {
775  if (!hexMatcher().isA(mesh, cellI))
776  {
778  (
779  "Foam::meshTools::getCutDir(const label, const label)"
780  ) << "Not a hex : cell:" << cellI << abort(FatalError);
781  }
782 
783 
784  vector avgVec(normEdgeVec(mesh, startEdgeI));
785 
786  label edgeI = startEdgeI;
787 
788  label faceI = -1;
789 
790  for (label i = 0; i < 3; i++)
791  {
792  // Step to next face, next edge
793  faceI = meshTools::otherFace(mesh, cellI, faceI, edgeI);
794 
795  vector eVec(normEdgeVec(mesh, edgeI));
796 
797  if ((eVec & avgVec) > 0)
798  {
799  avgVec += eVec;
800  }
801  else
802  {
803  avgVec -= eVec;
804  }
805 
806  label vertI = mesh.edges()[edgeI].end();
807 
808  edgeI = meshTools::walkFace(mesh, faceI, edgeI, vertI, 2);
809  }
810 
811  avgVec /= mag(avgVec) + VSMALL;
812 
813  return avgVec;
814 }
815 
816 
817 // Find edges most aligned with cutDir
819 (
820  const primitiveMesh& mesh,
821  const label cellI,
822  const vector& cutDir
823 )
824 {
825  if (!hexMatcher().isA(mesh, cellI))
826  {
828  (
829  "Foam::meshTools::getCutDir(const label, const vector&)"
830  ) << "Not a hex : cell:" << cellI << abort(FatalError);
831  }
832 
833  const labelList& cEdges = mesh.cellEdges()[cellI];
834 
835  labelHashSet doneEdges(2*cEdges.size());
836 
837  scalar maxCos = -GREAT;
838  label maxEdgeI = -1;
839 
840  for (label i = 0; i < 4; i++)
841  {
842  forAll(cEdges, cEdgeI)
843  {
844  label e0 = cEdges[cEdgeI];
845 
846  if (!doneEdges.found(e0))
847  {
848  vector avgDir(edgeToCutDir(mesh, cellI, e0));
849 
850  scalar cosAngle = mag(avgDir & cutDir);
851 
852  if (cosAngle > maxCos)
853  {
854  maxCos = cosAngle;
855  maxEdgeI = e0;
856  }
857 
858  // Mark off edges in cEdges.
859  label e1, e2, e3;
860  getParallelEdges(mesh, cellI, e0, e1, e2, e3);
861 
862  doneEdges.insert(e0);
863  doneEdges.insert(e1);
864  doneEdges.insert(e2);
865  doneEdges.insert(e3);
866  }
867  }
868  }
869 
870  forAll(cEdges, cEdgeI)
871  {
872  if (!doneEdges.found(cEdges[cEdgeI]))
873  {
875  (
876  "meshTools::cutDirToEdge(const label, const vector&)"
877  ) << "Cell:" << cellI << " edges:" << cEdges << endl
878  << "Edge:" << cEdges[cEdgeI] << " not yet handled"
879  << abort(FatalError);
880  }
881  }
882 
883  if (maxEdgeI == -1)
884  {
886  (
887  "meshTools::cutDirToEdge(const label, const vector&)"
888  ) << "Problem : did not find edge aligned with " << cutDir
889  << " on cell " << cellI << abort(FatalError);
890  }
891 
892  return maxEdgeI;
893 }
894 
895 
896 // ************************************************************************* //
iterator end()
Return an iterator to end traversing the UList.
Definition: UListI.H:237
static const label mXmYmZ
Definition: meshTools.H:63
unsigned char direction
Definition: direction.H:43
const point & min() const
Minimum describing the bounding box.
Definition: boundBoxI.H:54
virtual const pointField & points() const =0
Return mesh points.
const Field< PointType > & pointNormals() const
Return point normals for patch.
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurence of given element and return index,.
label getSharedEdge(const primitiveMesh &, const label f0, const label f1)
Return edge shared by two faces. Throws error if no edge found.
Definition: meshTools.C:392
vector normEdgeVec(const primitiveMesh &, const label edgeI)
Normalized edge vector.
Definition: meshTools.C:195
dimensioned< scalar > mag(const dimensioned< Type > &)
const edgeList & edges() const
Return mesh edges. Uses calcEdges.
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:56
const labelListList & pointEdges() const
label getSharedFace(const primitiveMesh &, const label cell0, const label cell1)
Return face shared by two cells. Throws error if none found.
Definition: meshTools.C:428
static const label mXpYpZ
Definition: meshTools.H:70
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:470
const labelListList & pointFaces() const
Return point-face addressing.
scalar f1
Definition: createFields.H:28
vectorField calcBoxPointNormals(const primitivePatch &pp)
Calculate point normals on a &#39;box&#39; mesh (all edges aligned with.
Definition: meshTools.C:53
label cutDirToEdge(const primitiveMesh &, const label cellI, const vector &cutDir)
Reverse of edgeToCutDir: given direction find edge bundle and.
Definition: meshTools.C:819
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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
const cellList & cells() const
static const label mXmYpZMask
Definition: meshTools.H:78
bool faceOnCell(const primitiveMesh &, const label cellI, const label faceI)
Is face used by cell.
Definition: meshTools.C:314
static const label mXmYmZMask
Definition: meshTools.H:73
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:58
const labelListList & faceEdges() const
label nPoints() const
Return number of points supporting patch faces.
static const label pXmYpZMask
Definition: meshTools.H:79
const labelListList & cellEdges() const
vector edgeToCutDir(const primitiveMesh &, const label cellI, const label edgeI)
Given edge on hex find all &#39;parallel&#39; (i.e. non-connected)
Definition: meshTools.C:769
static const label mXmYpZ
Definition: meshTools.H:68
bool edgeOnCell(const primitiveMesh &, const label cellI, const label edgeI)
Is edge used by cell.
Definition: meshTools.C:291
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:74
static const char nl
Definition: Ostream.H:260
const Cmpt & y() const
Definition: VectorI.H:71
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
#define WarningIn(functionName)
Report a warning using Foam::Warning.
void constrainDirection(const polyMesh &mesh, const Vector< label > &dirs, vector &d)
Set the constrained components of directions/velocity to zero.
Definition: meshTools.C:693
A List with indirect addressing.
Definition: fvMatrix.H:106
const dimensionedScalar e
Elementary charge.
Definition: doubleFloat.H:78
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
const labelList & meshPoints() const
Return labelList of mesh points in patch. They are constructed.
#define forAll(list, i)
Definition: UList.H:421
void getParallelEdges(const primitiveMesh &, const label cellI, const label e0, label &, label &, label &)
Given edge on hex find other &#39;parallel&#39;, non-connected edges.
Definition: meshTools.C:743
const Cmpt & x() const
Definition: VectorI.H:65
Representation of a 3D Cartesian coordinate system as a Vector of vectors.
Definition: triad.H:65
static const label pXpYmZMask
Definition: meshTools.H:76
const point & max() const
Maximum describing the bounding box.
Definition: boundBoxI.H:60
const Cmpt & z() const
Definition: VectorI.H:77
A cellMatcher for hex cells.
Definition: hexMatcher.H:51
errorManip< error > abort(error &err)
Definition: errorManip.H:131
const Field< PointType > & faceNormals() const
Return face normals for patch.
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:554
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
static const label pXpYmZ
Definition: meshTools.H:66
A list of faces which address into the list of points.
label otherEdge(const primitiveMesh &, const labelList &edgeLabels, const label edgeI, const label vertI)
Return label of other edge (out of candidates edgeLabels)
Definition: meshTools.C:516
static const label mXpYmZ
Definition: meshTools.H:65
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
error FatalError
const Vector< label > & geometricD() const
Return the vector of geometric directions in mesh.
Definition: polyMesh.C:830
const labelListList & edgeFaces() const
const boundBox & bounds() const
Return mesh bounding box.
Definition: polyMesh.H:427
static const label pXpYpZ
Definition: meshTools.H:71
label end() const
Return end vertex label.
Definition: edgeI.H:92
static const label pXpYpZMask
Definition: meshTools.H:81
void constrainToMeshCentre(const polyMesh &mesh, point &pt)
Set the constrained components of position to mesh centre.
Definition: meshTools.C:634
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
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:608
label otherCell(const primitiveMesh &, const label cellI, const label faceI)
Return cell on other side of face. Throws error.
Definition: meshTools.C:579
label start() const
Return start vertex label.
Definition: edgeI.H:81
const labelListList & edgeCells() const
Info<< "Finished reading KIVA file"<< endl;cellShapeList cellShapes(nPoints);labelList cellZoning(nPoints,-1);const cellModel &hex=*(cellModeller::lookup("hex"));labelList hexLabels(8);label activeCells=0;labelList pointMap(nPoints);forAll(pointMap, i){pointMap[i]=i;}for(label i=0;i< nPoints;i++){if(f[i] > 0.0){hexLabels[0]=i;hexLabels[1]=i1tab[i];hexLabels[2]=i3tab[i1tab[i]];hexLabels[3]=i3tab[i];hexLabels[4]=i8tab[i];hexLabels[5]=i1tab[i8tab[i]];hexLabels[6]=i3tab[i1tab[i8tab[i]]];hexLabels[7]=i3tab[i8tab[i]];cellShapes[activeCells]=cellShape(hex, hexLabels);edgeList edges=cellShapes[activeCells].edges();forAll(edges, ei){if(edges[ei].mag(points)< SMALL){label start=pointMap[edges[ei].start()];while(start!=pointMap[start]){start=pointMap[start];}label end=pointMap[edges[ei].end()];while(end!=pointMap[end]){end=pointMap[end];}label minLabel=min(start, end);pointMap[start]=pointMap[end]=minLabel;}}cellZoning[activeCells]=idreg[i];activeCells++;}}cellShapes.setSize(activeCells);cellZoning.setSize(activeCells);forAll(cellShapes, celli){cellShape &cs=cellShapes[celli];forAll(cs, i){cs[i]=pointMap[cs[i]];}cs.collapse();}label bcIDs[11]={-1, 0, 2, 4,-1, 5,-1, 6, 7, 8, 9};const label nBCs=12;const word *kivaPatchTypes[nBCs]={&wallPolyPatch::typeName,&wallPolyPatch::typeName,&wallPolyPatch::typeName,&wallPolyPatch::typeName,&symmetryPolyPatch::typeName,&wedgePolyPatch::typeName,&polyPatch::typeName,&polyPatch::typeName,&polyPatch::typeName,&polyPatch::typeName,&symmetryPolyPatch::typeName,&oldCyclicPolyPatch::typeName};enum patchTypeNames{PISTON, VALVE, LINER, CYLINDERHEAD, AXIS, WEDGE, INFLOW, OUTFLOW, PRESIN, PRESOUT, SYMMETRYPLANE, CYCLIC};const char *kivaPatchNames[nBCs]={"piston","valve","liner","cylinderHead","axis","wedge","inflow","outflow","presin","presout","symmetryPlane","cyclic"};List< SLList< face > > pFaces[nBCs]
Definition: readKivaGrid.H:235
bool edgeOnFace(const primitiveMesh &, const label faceI, const label edgeI)
Is edge used by face.
Definition: meshTools.C:302
static const label mXpYmZMask
Definition: meshTools.H:75
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
label findEdge(const edgeList &edges, const labelList &candidates, const label v0, const label v1)
Return edge among candidates that uses the two vertices.
Definition: meshTools.C:343
void writeOBJ(Ostream &os, const point &pt)
Write obj representation of point.
Definition: meshTools.C:209
static const label pXmYmZMask
Definition: meshTools.H:74
virtual const labelList & faceOwner() const =0
Face face-owner addresing.
static const label mXpYpZMask
Definition: meshTools.H:80
bool isA(const Type &t)
Check if a dynamic_cast to typeid is possible.
Definition: typeInfo.H:134
virtual const labelList & faceNeighbour() const =0
Face face-neighbour addressing.
static const label pXmYpZ
Definition: meshTools.H:69
const Field< PointType > & points() const
Return reference to global points.
static const label pXmYmZ
Definition: meshTools.H:64
bool visNormal(const vector &n, const vectorField &faceNormals, const labelList &faceLabels)
Check if n is in same direction as normals of all faceLabels.
Definition: meshTools.C:34
bool isInternalFace(const label faceIndex) const
Return true if given face label is internal to the mesh.