Commit 62e3d373 authored by Will Bainbridge's avatar Will Bainbridge Committed by Andrew Heather
Browse files

primitiveShapes: Generalised tetrahedron and triangle cutting. Cuts are

now possible with level-sets as well as planes. Removed tetPoints class
as this wasn't really used anywhere except for the old tet-cutting
routines. Restored tetPointRef.H to be consistent with other primitive
shapes. Re-wrote tet-overlap mapping in terms of the new cutting.
parent 04c11064
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -35,7 +35,7 @@ Description
#include "polyMesh.H"
#include "ListOps.H"
#include "face.H"
#include "tetrahedron.H"
#include "tetPointRef.H"
#include "triFaceList.H"
#include "OFstream.H"
#include "meshTools.H"
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -29,9 +29,10 @@ Description
\*---------------------------------------------------------------------------*/
#include "tetrahedron.H"
#include "tetPointRef.H"
#include "OFstream.H"
#include "meshTools.H"
#include "cut.H"
using namespace Foam;
......@@ -41,7 +42,7 @@ void writeOBJ
(
Ostream& os,
label& vertI,
const tetPoints& tet
const FixedList<point, 4>& tet
)
{
forAll(tet, fp)
......@@ -58,105 +59,126 @@ void writeOBJ
}
tetPointRef makeTetPointRef(const FixedList<point, 4>& p)
{
return tetPointRef(p[0], p[1], p[2], p[3]);
}
int main(int argc, char *argv[])
{
tetPoints A
(
// Tets to test
FixedList<point, 4> tetA
({
point(0, 0, 0),
point(1, 0, 0),
point(1, 1, 0),
point(1, 1, 1)
);
const tetPointRef tetA = A.tet();
tetPoints B
(
});
FixedList<point, 4> tetB
({
point(0.1, 0.1, 0.1),
point(1.1, 0.1, 0.1),
point(1.1, 1.1, 0.1),
point(1.1, 1.1, 1.1)
);
const tetPointRef tetB = B.tet();
});
tetPointRef::tetIntersectionList insideTets;
label nInside = 0;
tetPointRef::tetIntersectionList outsideTets;
label nOutside = 0;
// Do intersection
typedef DynamicList<FixedList<point, 4>> tetList;
tetList tetsIn1, tetsIn2, tetsOut;
cut::appendOp<tetList> tetOpIn1(tetsIn1);
cut::appendOp<tetList> tetOpIn2(tetsIn2);
cut::appendOp<tetList> tetOpOut(tetsOut);
tetA.tetOverlap
(
tetB,
insideTets,
nInside,
outsideTets,
nOutside
);
const plane p0(tetB[1], tetB[3], tetB[2]);
tetsIn1.clear();
tetCut(tetA, p0, tetOpIn1, tetOpOut);
const plane p1(tetB[0], tetB[2], tetB[3]);
tetsIn2.clear();
forAll(tetsIn1, i)
{
tetCut(tetsIn1[i], p1, tetOpIn2, tetOpOut);
}
// Dump to file
// ~~~~~~~~~~~~
const plane p2(tetB[0], tetB[3], tetB[1]);
tetsIn1.clear();
forAll(tetsIn2, i)
{
tetCut(tetsIn2[i], p2, tetOpIn1, tetOpOut);
}
const plane p3(tetB[0], tetB[1], tetB[2]);
tetsIn2.clear();
forAll(tetsIn1, i)
{
OFstream str("tetA.obj");
tetCut(tetsIn1[i], p3, tetOpIn2, tetOpOut);
}
const tetList& tetsIn = tetsIn2;
// Dump to file
{
OFstream str("A.obj");
Info<< "Writing A to " << str.name() << endl;
label vertI = 0;
writeOBJ(str, vertI, A);
writeOBJ(str, vertI, tetA);
}
{
OFstream str("tetB.obj");
OFstream str("B.obj");
Info<< "Writing B to " << str.name() << endl;
label vertI = 0;
writeOBJ(str, vertI, B);
writeOBJ(str, vertI, tetB);
}
{
OFstream str("inside.obj");
Info<< "Writing parts of A inside B to " << str.name() << endl;
OFstream str("AInB.obj");
Info<< "Writing parts of B inside A to " << str.name() << endl;
label vertI = 0;
for (label i = 0; i < nInside; ++i)
forAll(tetsIn, i)
{
writeOBJ(str, vertI, insideTets[i]);
writeOBJ(str, vertI, tetsIn[i]);
}
}
{
OFstream str("outside.obj");
Info<< "Writing parts of A outside B to " << str.name() << endl;
OFstream str("AOutB.obj");
Info<< "Writing parts of B inside A to " << str.name() << endl;
label vertI = 0;
for (label i = 0; i < nOutside; ++i)
forAll(tetsOut, i)
{
writeOBJ(str, vertI, outsideTets[i]);
writeOBJ(str, vertI, tetsOut[i]);
}
}
// Check
// ~~~~~
// Check the volumes
Info<< "Vol A: " << makeTetPointRef(tetA).mag() << endl;
Info<< "Vol A:" << tetA.mag() << endl;
scalar volInside = 0;
for (label i = 0; i < nInside; ++i)
scalar volIn = 0;
forAll(tetsIn, i)
{
volInside += insideTets[i].tet().mag();
volIn += makeTetPointRef(tetsIn[i]).mag();
}
Info<< "Vol A inside B:" << volInside << endl;
Info<< "Vol A inside B: " << volIn << endl;
scalar volOutside = 0;
for (label i = 0; i < nOutside; ++i)
scalar volOut = 0;
forAll(tetsOut, i)
{
volOutside += outsideTets[i].tet().mag();
volOut += makeTetPointRef(tetsOut[i]).mag();
}
Info<< "Vol A outside B:" << volOutside << endl;
Info<< "Vol A outside B: " << volOut << endl;
Info<< "Sum inside and outside:" << volInside+volOutside << endl;
Info<< "Sum inside and outside: " << volIn + volOut << endl;
if (mag(volInside+volOutside-tetA.mag()) > SMALL)
if (mag(volIn + volOut - makeTetPointRef(tetA).mag()) > SMALL)
{
FatalErrorInFunction
<< "Tet volumes do not sum up to input tet."
<< exit(FatalError);
}
return 0;
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
......@@ -28,7 +28,7 @@ License
#include "pointIOField.H"
#include "scalarIOField.H"
#include "triadIOField.H"
#include "tetrahedron.H"
#include "tetPointRef.H"
#include "plane.H"
#include "transform.H"
#include "meshTools.H"
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -25,7 +25,7 @@ License
#include "fileControl.H"
#include "addToRunTimeSelectionTable.H"
#include "tetrahedron.H"
#include "tetPointRef.H"
#include "scalarList.H"
#include "vectorTools.H"
#include "pointIOField.H"
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -28,7 +28,7 @@ License
#include "cellSizeFunction.H"
#include "triSurfaceMesh.H"
#include "searchableBox.H"
#include "tetrahedron.H"
#include "tetPointRef.H"
#include "vectorTools.H"
#include "quaternion.H"
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -24,7 +24,7 @@ License
\*---------------------------------------------------------------------------*/
#include "plane.H"
#include "tetrahedron.H"
#include "tetPointRef.H"
#include "pointConversion.H"
#include "CGALTriangulation3DKernel.H"
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -43,7 +43,7 @@ SourceFiles
#include "triFace.H"
#include "edge.H"
#include "pointField.H"
#include "tetrahedron.H"
#include "tetPointRef.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -42,7 +42,7 @@ SourceFiles
#include "polyMesh.H"
#include "coupledPolyPatch.H"
#include "syncTools.H"
#include "tetrahedron.H"
#include "tetPointRef.H"
#include "tetIndices.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -56,7 +56,7 @@ SourceFiles
#define tetIndices_H
#include "label.H"
#include "tetrahedron.H"
#include "tetPointRef.H"
#include "triPointRef.H"
#include "polyMesh.H"
#include "triFace.H"
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description:
Functions which cut triangles and tetrahedra. Generic operations are
applied to each half of a cut.
SourceFiles:
cutI.H
cutTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef cut_H
#define cut_H
#include "FixedList.H"
#include "nil.H"
#include "plane.H"
#include "tetPointRef.H"
#include "triPointRef.H"
#include "zero.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace cut
{
/*---------------------------------------------------------------------------*\
Class uniformOp Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class uniformOp
{
private:
//- Data
Type data_;
public:
// Constructors
//- Construct null
uniformOp()
{}
//- Construct from data
uniformOp(Type data)
:
data_(data)
{}
// Member functions
//- Access the data
Type data() const
{
return data_;
}
};
/*---------------------------------------------------------------------------*\
Class noOp Declaration
\*---------------------------------------------------------------------------*/
class noOp
:
public uniformOp<nil>
{
public:
// Typedefs
//- Result type
typedef zero result;
// Constructors
//- Construct null
noOp()
{}
//- Construct from base
noOp(const uniformOp<nil>& op)
:
uniformOp<nil>(op)
{}
// Member operators
//- Operate on nothing
result operator()() const
{
return result();
}
//- Operate on a triangle or tetrahedron
template<unsigned Size>
result operator()(const FixedList<point, Size>& p) const
{
return result();
}
};
/*---------------------------------------------------------------------------*\
Class areaOp Declaration
\*---------------------------------------------------------------------------*/
class areaOp
:
public uniformOp<nil>
{
public:
// Typedefs
//- Result type
typedef vector result;
// Constructors
//- Construct null
areaOp()
{}
//- Construct from base
areaOp(const uniformOp<nil>& op)
:
uniformOp<nil>(op)
{}
// Member operators
//- Operate on nothing
result operator()() const
{
return vector::zero;
}
//- Operate on a triangle
result operator()(const FixedList<point, 3>& p) const
{
return result(triPointRef(p[0], p[1], p[2]).normal());
}
};
/*---------------------------------------------------------------------------*\
Class volumeOp Declaration
\*---------------------------------------------------------------------------*/
class volumeOp
:
public uniformOp<nil>
{
public:
// Typedefs
//- Result type
typedef scalar result;
// Constructors
//- Construct null
volumeOp()
{}
//- Construct from base
volumeOp(const uniformOp<nil>& op)
:
uniformOp<nil>(op)
{}
// Member operators
//- Operate on nothing
result operator()() const
{
return 0;
}
//- Operate on a tetrahedron
result operator()(const FixedList<point, 4>& p) const
{
return result(tetPointRef(p[0], p[1], p[2], p[3]).mag());
}
};
/*---------------------------------------------------------------------------*\
Class areaIntegrateOp Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class areaIntegrateOp
:
public FixedList<Type, 3>
{
public:
// Typedefs
//- Result type
typedef typename outerProduct<Type, vector>::type result;
// Constructors
//- Construct from base
areaIntegrateOp(const FixedList<Type, 3>& x)
:
FixedList<Type, 3>(x)
{}