tetOverlapVolumeTemplates.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) 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 "tetOverlapVolume.H"
27 #include "primitiveMesh.H"
28 
29 // * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * * //
30 
31 template<class tetPointsOp>
33 (
34  const tetPoints& tetA,
35  const tetPoints& tetB,
36  tetPointsOp& insideOp
37 )
38 {
39  static tetPointRef::tetIntersectionList insideTets;
40  label nInside = 0;
41  static tetPointRef::tetIntersectionList cutInsideTets;
42  label nCutInside = 0;
43 
44  tetPointRef::storeOp inside(insideTets, nInside);
45  tetPointRef::storeOp cutInside(cutInsideTets, nCutInside);
46  tetPointRef::dummyOp outside;
47 
48  if (tetA.tet().mag() < minTetVolume_ || tetB.tet().mag() < minTetVolume_)
49  {
50  return;
51  }
52 
53  // face0
54  plane pl0(tetB[1], tetB[3], tetB[2]);
55  tetA.tet().sliceWithPlane(pl0, cutInside, outside);
56  if (nCutInside == 0)
57  {
58  return;
59  }
60 
61  // face1
62  plane pl1(tetB[0], tetB[2], tetB[3]);
63  nInside = 0;
64  for (label i = 0; i < nCutInside; i++)
65  {
66  const tetPointRef t = cutInsideTets[i].tet();
67  t.sliceWithPlane(pl1, inside, outside);
68  }
69  if (nInside == 0)
70  {
71  return;
72  }
73 
74  // face2
75  plane pl2(tetB[0], tetB[3], tetB[1]);
76  nCutInside = 0;
77  for (label i = 0; i < nInside; i++)
78  {
79  const tetPointRef t = insideTets[i].tet();
80  t.sliceWithPlane(pl2, cutInside, outside);
81  }
82  if (nCutInside == 0)
83  {
84  return;
85  }
86 
87  // face3
88  plane pl3(tetB[0], tetB[1], tetB[2]);
89  for (label i = 0; i < nCutInside; i++)
90  {
91  const tetPointRef t = cutInsideTets[i].tet();
92  t.sliceWithPlane(pl3, insideOp, outside);
93  }
94 }
95 
96 
97 template<class tetsOp>
99 (
100  const primitiveMesh& meshA,
101  const label cellAI,
102 
103  const primitiveMesh& meshB,
104  const label cellBI,
105  const treeBoundBox& cellBbB,
106  tetsOp& combineTetsOp
107 )
108 {
109  const cell& cFacesA = meshA.cells()[cellAI];
110  const point& ccA = meshA.cellCentres()[cellAI];
111 
112  const cell& cFacesB = meshB.cells()[cellBI];
113  const point& ccB = meshB.cellCentres()[cellBI];
114 
115  forAll(cFacesA, cFA)
116  {
117  label faceAI = cFacesA[cFA];
118 
119  const face& fA = meshA.faces()[faceAI];
120  const treeBoundBox pyrA = pyrBb(meshA.points(), fA, ccA);
121  if (!pyrA.overlaps(cellBbB))
122  {
123  continue;
124  }
125 
126  bool ownA = (meshA.faceOwner()[faceAI] == cellAI);
127 
128  label tetBasePtAI = 0;
129 
130  const point& tetBasePtA = meshA.points()[fA[tetBasePtAI]];
131 
132  for (label tetPtI = 1; tetPtI < fA.size() - 1; tetPtI++)
133  {
134  label facePtAI = (tetPtI + tetBasePtAI) % fA.size();
135  label otherFacePtAI = fA.fcIndex(facePtAI);
136 
137  label pt0I = -1;
138  label pt1I = -1;
139 
140  if (ownA)
141  {
142  pt0I = fA[facePtAI];
143  pt1I = fA[otherFacePtAI];
144  }
145  else
146  {
147  pt0I = fA[otherFacePtAI];
148  pt1I = fA[facePtAI];
149  }
150 
151  const tetPoints tetA
152  (
153  ccA,
154  tetBasePtA,
155  meshA.points()[pt0I],
156  meshA.points()[pt1I]
157  );
158  const treeBoundBox tetABb(tetA.bounds());
159 
160  // Loop over tets of cellB
161  forAll(cFacesB, cFB)
162  {
163  label faceBI = cFacesB[cFB];
164 
165  const face& fB = meshB.faces()[faceBI];
166  const treeBoundBox pyrB = pyrBb(meshB.points(), fB, ccB);
167  if (!pyrB.overlaps(pyrA))
168  {
169  continue;
170  }
171 
172  bool ownB = (meshB.faceOwner()[faceBI] == cellBI);
173 
174  label tetBasePtBI = 0;
175 
176  const point& tetBasePtB = meshB.points()[fB[tetBasePtBI]];
177 
178  for (label tetPtI = 1; tetPtI < fB.size() - 1; tetPtI++)
179  {
180  label facePtBI = (tetPtI + tetBasePtBI) % fB.size();
181  label otherFacePtBI = fB.fcIndex(facePtBI);
182 
183  label pt0I = -1;
184  label pt1I = -1;
185 
186  if (ownB)
187  {
188  pt0I = fB[facePtBI];
189  pt1I = fB[otherFacePtBI];
190  }
191  else
192  {
193  pt0I = fB[otherFacePtBI];
194  pt1I = fB[facePtBI];
195  }
196 
197  const tetPoints tetB
198  (
199  ccB,
200  tetBasePtB,
201  meshB.points()[pt0I],
202  meshB.points()[pt1I]
203  );
204  if (!tetB.bounds().overlaps(tetABb))
205  {
206  continue;
207  }
208 
209  if (combineTetsOp(tetA, tetB))
210  {
211  return;
212  }
213  }
214  }
215  }
216  }
217 }
218 
219 
220 // ************************************************************************* //
Foam::primitiveMesh::points
virtual const pointField & points() const =0
Return mesh points.
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::primitiveMesh::faces
virtual const faceList & faces() const =0
Return faces.
Foam::tetrahedron::dummyOp
Dummy.
Definition: tetrahedron.H:100
Foam::treeBoundBox
Standard boundBox + extra functionality for use in octree.
Definition: treeBoundBox.H:75
Foam::tetOverlapVolume::tetTetOverlap
static void tetTetOverlap(const tetPoints &tetA, const tetPoints &tetB, tetPointsOp &insideOp)
Tet overlap calculation.
Definition: tetOverlapVolumeTemplates.C:33
Foam::primitiveMesh::faceOwner
virtual const labelList & faceOwner() const =0
Face face-owner addresing.
Foam::primitiveMesh::cells
const cellList & cells() const
Definition: primitiveMeshCells.C:136
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::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::tetOverlapVolume::cellCellOverlapMinDecomp
static void cellCellOverlapMinDecomp(const primitiveMesh &meshA, const label cellAI, const primitiveMesh &meshB, const label cellBI, const treeBoundBox &cellBbB, tetsOp &combineTetsOp)
Cell overlap calculation.
Definition: tetOverlapVolumeTemplates.C:99
Foam::tetPoints::tet
tetPointRef tet() const
Return the tetrahedron.
Definition: tetPoints.H:80
Foam::tetrahedron::storeOp
Store resulting tets.
Definition: tetrahedron.H:118
tetOverlapVolume.H
Foam::tetPoints
Tet storage. Null constructable (unfortunately tetrahedron<point, point> is not)
Definition: tetPoints.H:50
Foam::primitiveMesh::cellCentres
const vectorField & cellCentres() const
Definition: primitiveMeshCellCentresAndVols.C:211
Foam::Vector< scalar >
Foam::FixedList
A 1D vector of objects of type <T> with a fixed size <Size>.
Definition: FixedList.H:53
Foam::tetPoints::bounds
treeBoundBox bounds() const
Calculate the bounding box.
Definition: tetPoints.H:92
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
Foam::treeBoundBox::overlaps
bool overlaps(const boundBox &) const
Overlaps other bounding box?
Definition: boundBoxI.H:120
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::tetrahedron::mag
scalar mag() const
Return volume.
Definition: tetrahedronI.H:171
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:56
Foam::tetrahedron::sliceWithPlane
void sliceWithPlane(const plane &pl, AboveTetOp &aboveOp, BelowTetOp &belowOp) const
Decompose tet into tets above and below plane.
Definition: tetrahedronI.H:985
Foam::tetrahedron
A tetrahedron primitive.
Definition: tetrahedron.H:62
Foam::primitiveMesh
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:79