mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: expand VectorSpaceOps to include copy_n/fill_n methods
- similar to what std::copy_n and std::fill_n would do, except with
templated loops. This allows compile-time transcribing with loop
unrolling. For example,
vector vec1 = ..., vec2 = ...;
FixedList<scalar, 6> values;
VectorSpaceOps<3>::copy_n(vec1.begin(), values.begin());
VectorSpaceOps<3>::copy_n(vec2.begin(), values.begin(3))
// do something with all of these values
STYLE: make start index of VectorSpaceOps optional
ENH: add clamped begin(int) versions to FixedList as per UList
This commit is contained in:
76
applications/test/vectorTools/Test-vectorTools.cxx
Normal file
76
applications/test/vectorTools/Test-vectorTools.cxx
Normal file
@ -0,0 +1,76 @@
|
||||
#include "vector.H"
|
||||
#include "IOstreams.H"
|
||||
#include "vectorTools.H"
|
||||
#include "unitConversion.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
|
||||
void test(const vector& a, const vector& b, const scalar tolerance)
|
||||
{
|
||||
Info<< "Vectors " << a << " and " << b
|
||||
<< " are (to tolerance of " << tolerance << "): ";
|
||||
|
||||
if (vectorTools::areParallel(a, b, tolerance))
|
||||
Info<< " parallel ";
|
||||
|
||||
if (vectorTools::areOrthogonal(a, b, tolerance))
|
||||
Info<< " orthogonal ";
|
||||
|
||||
if (vectorTools::areAcute(a, b))
|
||||
Info<< " acute ";
|
||||
|
||||
if (vectorTools::areObtuse(a, b))
|
||||
Info<< " obtuse ";
|
||||
|
||||
Info<< ", angle = " << vectorTools::degAngleBetween(a, b);
|
||||
|
||||
Info<< endl;
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
vector a(vector::uniform(1));
|
||||
vector b;
|
||||
b.fill(2);
|
||||
|
||||
test(a, b, 0.0);
|
||||
test(a, b, VSMALL);
|
||||
test(a, b, SMALL);
|
||||
test(a, b, 1e-3);
|
||||
test(a, b, 1e-1);
|
||||
|
||||
a = vector(1,0,0);
|
||||
b = vector(0,2,0);
|
||||
|
||||
test(a, b, 0.0);
|
||||
test(a, b, VSMALL);
|
||||
test(a, b, SMALL);
|
||||
test(a, b, 1e-3);
|
||||
test(a, b, 1e-1);
|
||||
|
||||
a = vector(1,0,0);
|
||||
b = vector(-1,0,0);
|
||||
|
||||
test(a, b, 0.0);
|
||||
test(a, b, VSMALL);
|
||||
test(a, b, SMALL);
|
||||
test(a, b, 1e-3);
|
||||
test(a, b, 1e-1);
|
||||
|
||||
a = vector(1,0,0);
|
||||
b = vector(-1,2,0);
|
||||
|
||||
test(a, b, 0.0);
|
||||
test(a, b, VSMALL);
|
||||
test(a, b, SMALL);
|
||||
test(a, b, 1e-3);
|
||||
test(a, b, 1e-1);
|
||||
|
||||
Info<< "\nEnd\n" << nl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
Reference in New Issue
Block a user