Test-tetTetOverlap.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) 2012-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 Application
25  Test-tetTetOverlap
26 
27 Description
28  Overlap volume of two tets
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #include "tetrahedron.H"
33 #include "OFstream.H"
34 #include "meshTools.H"
35 
36 using namespace Foam;
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 void writeOBJ
41 (
42  Ostream& os,
43  label& vertI,
44  const tetPoints& tet
45 )
46 {
47  forAll(tet, fp)
48  {
49  meshTools::writeOBJ(os, tet[fp]);
50  }
51  os << "l " << vertI+1 << ' ' << vertI+2 << nl
52  << "l " << vertI+1 << ' ' << vertI+3 << nl
53  << "l " << vertI+1 << ' ' << vertI+4 << nl
54  << "l " << vertI+2 << ' ' << vertI+3 << nl
55  << "l " << vertI+2 << ' ' << vertI+4 << nl
56  << "l " << vertI+3 << ' ' << vertI+4 << nl;
57  vertI += 4;
58 }
59 
60 
61 int main(int argc, char *argv[])
62 {
63  tetPoints A
64  (
65  point(0, 0, 0),
66  point(1, 0, 0),
67  point(1, 1, 0),
68  point(1, 1, 1)
69  );
70  const tetPointRef tetA = A.tet();
71 
72  tetPoints B
73  (
74  point(0.1, 0.1, 0.1),
75  point(1.1, 0.1, 0.1),
76  point(1.1, 1.1, 0.1),
77  point(1.1, 1.1, 1.1)
78  );
79  const tetPointRef tetB = B.tet();
80 
81 
83  label nInside = 0;
85  label nOutside = 0;
86 
87  tetA.tetOverlap
88  (
89  tetB,
90  insideTets,
91  nInside,
92  outsideTets,
93  nOutside
94  );
95 
96 
97  // Dump to file
98  // ~~~~~~~~~~~~
99 
100  {
101  OFstream str("tetA.obj");
102  Info<< "Writing A to " << str.name() << endl;
103  label vertI = 0;
104  writeOBJ(str, vertI, A);
105  }
106  {
107  OFstream str("tetB.obj");
108  Info<< "Writing B to " << str.name() << endl;
109  label vertI = 0;
110  writeOBJ(str, vertI, B);
111  }
112  {
113  OFstream str("inside.obj");
114  Info<< "Writing parts of A inside B to " << str.name() << endl;
115  label vertI = 0;
116  for (label i = 0; i < nInside; ++i)
117  {
118  writeOBJ(str, vertI, insideTets[i]);
119  }
120  }
121  {
122  OFstream str("outside.obj");
123  Info<< "Writing parts of A outside B to " << str.name() << endl;
124  label vertI = 0;
125  for (label i = 0; i < nOutside; ++i)
126  {
127  writeOBJ(str, vertI, outsideTets[i]);
128  }
129  }
130 
131 
132  // Check
133  // ~~~~~
134 
135  Info<< "Vol A:" << tetA.mag() << endl;
136 
137  scalar volInside = 0;
138  for (label i = 0; i < nInside; ++i)
139  {
140  volInside += insideTets[i].tet().mag();
141  }
142  Info<< "Vol A inside B:" << volInside << endl;
143 
144  scalar volOutside = 0;
145  for (label i = 0; i < nOutside; ++i)
146  {
147  volOutside += outsideTets[i].tet().mag();
148  }
149  Info<< "Vol A outside B:" << volOutside << endl;
150 
151  Info<< "Sum inside and outside:" << volInside+volOutside << endl;
152 
153  if (mag(volInside+volOutside-tetA.mag()) > SMALL)
154  {
156  << "Tet volumes do not sum up to input tet."
157  << exit(FatalError);
158  }
159 
160  return 0;
161 }
162 
163 
164 // ************************************************************************* //
meshTools.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
writeOBJ
void writeOBJ(Ostream &os, label &vertI, const tetPoints &tet)
Definition: Test-tetTetOverlap.C:38
Foam::meshTools::writeOBJ
void writeOBJ(Ostream &os, const point &pt)
Write obj representation of point.
Definition: meshTools.C:203
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
A
simpleMatrix< scalar > A(Nc)
OFstream.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::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::FatalError
error FatalError
Foam::tetPoints::tet
tetPointRef tet() const
Return the tetrahedron.
Definition: tetPoints.H:80
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::OFstream
Output to file stream.
Definition: OFstream.H:81
Foam::tetPoints
Tet storage. Null constructable (unfortunately tetrahedron<point, point> is not)
Definition: tetPoints.H:50
main
int main(int argc, char *argv[])
Definition: Test-tetTetOverlap.C:58
Foam::tetrahedron::tetOverlap
void tetOverlap(const tetrahedron< Point, PointRef > &tetB, tetIntersectionList &insideTets, label &nInside, tetIntersectionList &outsideTets, label &nOutside) const
Decompose tet into tets inside and outside other tet.
Definition: tetrahedron.C:34
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::FixedList
A 1D vector of objects of type <T> with a fixed size <Size>.
Definition: FixedList.H:53
Foam::OFstream::name
const fileName & name() const
Return the name of the stream.
Definition: OFstream.H:118
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::point
vector point
Point is a vector.
Definition: point.H:41
Foam::tetrahedron::mag
scalar mag() const
Return volume.
Definition: tetrahedronI.H:171
tetrahedron.H
Foam::tetrahedron
A tetrahedron primitive.
Definition: tetrahedron.H:62