ENH: simplify tetrahedron and triangle handling

- combine header definitions, more pass-through methods

- face/triFace: support += operator (vertex offset)
This commit is contained in:
Mark Olesen
2022-07-04 12:19:25 +02:00
parent a27c8560a8
commit b4a482751b
95 changed files with 1204 additions and 1131 deletions

View File

@ -0,0 +1,3 @@
Test-barycentric.C
EXE = $(FOAM_USER_APPBIN)/Test-barycentric

View File

@ -0,0 +1,2 @@
/* EXE_INC = */
/* EXE_LIBS = */

View File

@ -0,0 +1,93 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
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/>.
Application
Test-barycentric
Description
Some simple tests for barycentric coordinates and transforms
\*---------------------------------------------------------------------------*/
#include "barycentricTensor.H"
#include "tetrahedron.H"
#include "vectorField.H"
#include "IOstreams.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
// Tets to test
tetPoints tetA
(
point(0, 0, 0),
point(1, 0, 0),
point(1, 1, 0),
point(1, 1, 1)
);
const barycentricTensor baryT(tetA[0], tetA[1], tetA[2], tetA[3]);
Info<< nl << "Tet: " << tetA << nl;
Info<< "tens:" << baryT << nl;
for
(
const barycentric& bary :
List<barycentric>
({
{0.25, 0.25, 0.25, 0.25},
{1, 0, 0, 0},
{0, 1, 0, 0},
{0, 0, 1, 0},
{0, 0, 0, 1},
{0, 0, 0, 0} // Not really valid
})
)
{
vector v(tetA.tet().barycentricToPoint(bary));
barycentric b(tetA.tet().pointToBarycentric(v));
Info<< nl
<< "bary: " << bary << nl
<< "vec: " << v << nl
// << "Vec: " << baryT.inner(bary) << nl
<< "Vec: " << (baryT & bary) << nl
<< "bary: " << b << nl
// This won't work (needs a differently defined tensor)
// << "Bary: " << (v & baryT) << nl
;
}
Info<< "\nEnd\n" << nl;
return 0;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -38,7 +38,7 @@ Description
#include "polyMesh.H"
#include "ListOps.H"
#include "face.H"
#include "tetPointRef.H"
#include "tetrahedron.H"
#include "triFaceList.H"
#include "OFstream.H"
#include "meshTools.H"

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2017 OpenFOAM Foundation
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -31,7 +32,7 @@ Description
\*---------------------------------------------------------------------------*/
#include "tetPointRef.H"
#include "tetrahedron.H"
#include "OFstream.H"
#include "meshTools.H"
#include "cut.H"
@ -44,12 +45,12 @@ void writeOBJ
(
Ostream& os,
label& vertI,
const FixedList<point, 4>& tet
const tetPoints& tet
)
{
forAll(tet, fp)
for (const point& p : tet)
{
meshTools::writeOBJ(os, tet[fp]);
meshTools::writeOBJ(os, p);
}
os << "l " << vertI+1 << ' ' << vertI+2 << nl
<< "l " << vertI+1 << ' ' << vertI+3 << nl
@ -61,33 +62,27 @@ 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[])
{
// Tets to test
FixedList<point, 4> tetA
({
tetPoints tetA
(
point(0, 0, 0),
point(1, 0, 0),
point(1, 1, 0),
point(1, 1, 1)
});
FixedList<point, 4> tetB
({
);
tetPoints 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)
});
);
// Do intersection
typedef DynamicList<FixedList<point, 4>> tetList;
typedef DynamicList<tetPoints> tetList;
tetList tetsIn1, tetsIn2, tetsOut;
cut::appendOp<tetList> tetOpIn1(tetsIn1);
cut::appendOp<tetList> tetOpIn2(tetsIn2);
@ -155,25 +150,25 @@ int main(int argc, char *argv[])
// Check the volumes
Info<< "Vol A: " << makeTetPointRef(tetA).mag() << endl;
Info<< "Vol A: " << tetA.tet().mag() << endl;
scalar volIn = 0;
forAll(tetsIn, i)
for (const auto& t : tetsIn)
{
volIn += makeTetPointRef(tetsIn[i]).mag();
volIn += t.tet().mag();
}
Info<< "Vol A inside B: " << volIn << endl;
scalar volOut = 0;
forAll(tetsOut, i)
for (const auto& t : tetsOut)
{
volOut += makeTetPointRef(tetsOut[i]).mag();
volOut += t.tet().mag();
}
Info<< "Vol A outside B: " << volOut << endl;
Info<< "Sum inside and outside: " << volIn + volOut << endl;
if (mag(volIn + volOut - makeTetPointRef(tetA).mag()) > SMALL)
if (mag(volIn + volOut - tetA.tet().mag()) > SMALL)
{
FatalErrorInFunction
<< "Tet volumes do not sum up to input tet."

View File

@ -31,7 +31,7 @@ License
#include "pointIOField.H"
#include "scalarIOField.H"
#include "triadIOField.H"
#include "tetPointRef.H"
#include "tetrahedron.H"
#include "plane.H"
#include "transform.H"
#include "meshTools.H"

View File

@ -27,7 +27,6 @@ License
#include "fileControl.H"
#include "addToRunTimeSelectionTable.H"
#include "tetPointRef.H"
#include "scalarList.H"
#include "vectorTools.H"
#include "pointIOField.H"
@ -50,9 +49,6 @@ addToRunTimeSelectionTable
}
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileControl::fileControl

View File

@ -31,7 +31,6 @@ License
#include "cellSizeFunction.H"
#include "triSurfaceMesh.H"
#include "searchableBox.H"
#include "tetPointRef.H"
#include "vectorTools.H"
#include "quaternion.H"

View File

@ -26,7 +26,7 @@ License
\*---------------------------------------------------------------------------*/
#include "plane.H"
#include "tetPointRef.H"
#include "tetrahedron.H"
#include "pointConversion.H"
#include "CGALTriangulation3DKernel.H"

View File

@ -4,7 +4,7 @@
#include "polyMeshTools.H"
#include "zeroGradientFvPatchFields.H"
#include "syncTools.H"
#include "tetPointRef.H"
#include "tetrahedron.H"
#include "regionSplit.H"
#include "wallDist.H"
#include "cellAspectRatio.H"