ENH: add FixedList templated get<unsigned>() methods

- provides fast compile-time indexing for FixedList
  (invalid indices trigger a compiler error).

  This enables noexcept access, which can propagate into various
  other uses (eg, triFace, triPoints, ...)

ENH: add triangle edge vectors
This commit is contained in:
Mark Olesen
2022-11-01 13:57:10 +01:00
committed by Andrew Heather
parent c7e6ae30bf
commit d3e285b48b
22 changed files with 318 additions and 262 deletions

View File

@ -189,6 +189,12 @@ int main(int argc, char *argv[])
<< " hash:" << FixedList<label, 4>::hasher()(list1) << nl
<< " hash:" << Hash<FixedList<label, 4>>()(list1) << nl;
Info<< "get<0>: " << list1.get<0>() << nl;
Info<< "get<1>: " << list1.get<1>() << nl;
Info<< "get<2>: " << list1.get<2>() << nl;
Info<< "get<3>: " << list1.get<3>() << nl;
// Will not compile: Info<< "get<4>: " << list1.get<4>() << nl;
label a[4] = {0, 1, 2, 3};
FixedList<label, 4> list2(a);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -43,7 +43,7 @@ void print(const boolVector& v)
<< " any:" << Switch::name(v.any())
<< " all:" << Switch::name(v.all())
<< " none:" << Switch::name(v.none())
<< " count:" << v.count() << nl;
<< " on:" << v.count() << " off:" << v.count(false) << nl;
}
@ -68,7 +68,7 @@ int main(int argc, char *argv[])
Info<< nl;
{
boolVector vec{1, 0, 1};
boolVector vec(1, 0, 1);
print(vec);
vec.flip();

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2021 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -33,6 +33,7 @@ Description
#include "argList.H"
#include "labelledTri.H"
#include "edge.H"
#include "faceList.H"
#include "triFaceList.H"
#include "pointList.H"
@ -131,10 +132,25 @@ int main(int argc, char *argv[])
testSign(f1, points2, testPoints);
Info<< nl;
triFace t1({1, 2, 3});
// Initializer list
// triFace t1({1, 2, 3});
// Component-wise
{
edge e1(3, 2, 1); // Inadvertent sort!!!
Info<< "edge:" << e1 << nl;
}
// Component-wise
triFace t1(1, 2, 3);
Info<< "triFace:"; faceInfo(t1, points1); Info << nl;
testSign(t1, points1, testPoints);
{
scalarField fld({0, 20, 20, 30});
Info<< "avg:" << t1.average(pointField::null(), fld) << nl;
}
Info<< "triFace:"; faceInfo(t1, points2); Info << nl;
testSign(t1, points2, testPoints);
Info<< nl;

View File

@ -1,3 +1,4 @@
#include "argList.H"
#include "point.H"
#include "triangle.H"
#include "tetrahedron.H"
@ -5,7 +6,7 @@
using namespace Foam;
int main()
int main(int argc, char *argv[])
{
triangle<point, point> tri
(
@ -14,6 +15,12 @@ int main()
vector(1, 1, 0)
);
Info<< "triangle: " << tri << nl
<< " vecA: " << tri.vecA() << nl
<< " vecB: " << tri.vecB() << nl
<< " vecC: " << tri.vecC() << nl
<< endl;
Info<< "tri circumCentre = " << tri.circumCentre() << endl;
Info<< "tri circumRadius = " << tri.circumRadius() << endl;
@ -28,6 +35,8 @@ int main()
Info<< "tet circumCentre = " << tet.circumCentre() << endl;
Info<< "tet circumRadius = " << tet.circumRadius() << endl;
InfoErr<< "Enter four points: " << endl;
vector a(Sin);
vector b(Sin);
vector c(Sin);
@ -36,5 +45,6 @@ int main()
Info<< "tet circumRadius = "
<< tetrahedron<point, point>(a, b, c, d).circumRadius() << endl;
Info<< "\nEnd\n";
return 0;
}