Skip to content

Commit

Permalink
primitiveShapes: Generalised tetrahedron and triangle cutting. Cuts are
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Will Bainbridge committed May 22, 2017
1 parent ac6f881 commit df1f4be
Show file tree
Hide file tree
Showing 22 changed files with 1,475 additions and 889 deletions.
4 changes: 2 additions & 2 deletions applications/test/momentOfInertia/Test-momentOfInertia.C
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
126 changes: 74 additions & 52 deletions applications/test/tetTetOverlap/Test-tetTetOverlap.C
Expand Up @@ -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
Expand All @@ -29,9 +29,10 @@ Description
\*---------------------------------------------------------------------------*/

#include "tetrahedron.H"
#include "tetPointRef.H"
#include "OFstream.H"
#include "meshTools.H"
#include "cut.H"

using namespace Foam;

Expand All @@ -41,7 +42,7 @@ void writeOBJ
(
Ostream& os,
label& vertI,
const tetPoints& tet
const FixedList<point, 4>& tet
)
{
forAll(tet, fp)
Expand All @@ -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;
}

Expand Down
Expand Up @@ -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
Expand All @@ -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"
Expand Down
Expand Up @@ -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
Expand All @@ -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"
Expand Down
Expand Up @@ -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
Expand All @@ -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"

Expand Down
Expand Up @@ -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
Expand All @@ -24,7 +24,7 @@ License
\*---------------------------------------------------------------------------*/

#include "plane.H"
#include "tetrahedron.H"
#include "tetPointRef.H"
#include "pointConversion.H"
#include "CGALTriangulation3DKernel.H"

Expand Down
4 changes: 2 additions & 2 deletions src/OpenFOAM/meshes/meshShapes/tetCell/tetCell.H
Expand Up @@ -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
Expand Down Expand Up @@ -43,7 +43,7 @@ SourceFiles
#include "triFace.H"
#include "edge.H"
#include "pointField.H"
#include "tetrahedron.H"
#include "tetPointRef.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -42,7 +42,7 @@ SourceFiles
#include "polyMesh.H"
#include "coupledPolyPatch.H"
#include "syncTools.H"
#include "tetrahedron.H"
#include "tetPointRef.H"
#include "tetIndices.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit df1f4be

Please sign in to comment.