mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add 2D det() / inv() methods for Tensor/SymmTensor (#2724)
- for cases where a 3D tensor is being used to represent 2D content, the determinant is zero. Can use inv2D(excludeDirection) to compensate and invert as if it were only 2D. ENH: consistent definitions for magSqr of symmTensors, diagSqr() norm COMP: return scalar not component type for magSqr - had inconsistent definitions with SymmTensor returning the component type and Tensor returning scalar. Only evident with complex.
This commit is contained in:
@ -370,7 +370,7 @@ void test_global_funcs(Type)
|
||||
Type(126)
|
||||
)
|
||||
);
|
||||
cmp(" Square of Frobenius norm = ", magSqr(sT), Type(205));
|
||||
cmp(" Square of Frobenius norm = ", magSqr(sT), scalar(205));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -325,7 +325,7 @@ void test_global_funcs(Type)
|
||||
Type(13)
|
||||
)
|
||||
);
|
||||
cmp(" Square of Frobenius norm = ", magSqr(sT), Type(17.999999999999996));
|
||||
cmp(" Square of Frobenius norm = ", magSqr(sT), scalar(17.999999999999996));
|
||||
cmp
|
||||
(
|
||||
" Outer-product of a Vector2D with itself = ",
|
||||
|
||||
@ -34,6 +34,9 @@ Description
|
||||
#include "complex.H"
|
||||
#include "complexFields.H"
|
||||
#include "scalarField.H"
|
||||
#include "diagTensor.H"
|
||||
#include "symmTensor.H"
|
||||
#include "symmTensor2D.H"
|
||||
#include "ListOps.H"
|
||||
#include "ops.H"
|
||||
|
||||
@ -164,6 +167,72 @@ int main(int argc, char *argv[])
|
||||
<< " => " << imags << nl;
|
||||
}
|
||||
|
||||
{
|
||||
SymmTensor<complex> st1(SymmTensor<complex>::uniform({3, 4}));
|
||||
|
||||
Info<< "symmTensor: " << st1 << nl
|
||||
<< " tr: " << tr(st1) << nl
|
||||
<< " diagSqr: " << st1.diagSqr() << nl
|
||||
<< " magSqr: " << magSqr(st1) << nl
|
||||
<< " mag: " << mag(st1) << nl;
|
||||
|
||||
SymmTensor<scalar> st2(SymmTensor<scalar>::uniform(5));
|
||||
|
||||
Info<< "symmTensor: " << st2 << nl
|
||||
<< " tr: " << tr(st2) << nl
|
||||
<< " diagSqr: " << st2.diagSqr() << nl
|
||||
<< " magSqr: " << magSqr(st2) << nl
|
||||
<< " mag: " << mag(st2) << nl;
|
||||
|
||||
st2 = Zero;
|
||||
|
||||
DiagTensor<complex> dt1(SphericalTensor<complex>({3, 4}));
|
||||
|
||||
Info<< "diagTensor: " << dt1 << nl
|
||||
<< " tr: " << tr(dt1) << nl
|
||||
<< " diagSqr: " << dt1.diagSqr() << nl
|
||||
<< " magSqr: " << magSqr(dt1) << nl
|
||||
<< " mag: " << mag(dt1) << nl;
|
||||
|
||||
|
||||
// A bit ugly...
|
||||
st1 = SphericalTensor<complex>({3, 4});
|
||||
|
||||
Info<< "symmTensor: " << st1 << nl
|
||||
<< " tr: " << tr(st1) << nl
|
||||
<< " diagSqr: " << st1.diagSqr() << nl
|
||||
<< " magSqr: " << magSqr(st1) << nl
|
||||
<< " mag: " << mag(st1) << nl;
|
||||
}
|
||||
|
||||
{
|
||||
SymmTensor2D<complex> st1(SymmTensor2D<complex>::uniform({3, 4}));
|
||||
|
||||
Info<< "symmTensor: " << st1 << nl
|
||||
<< " tr: " << tr(st1) << nl
|
||||
<< " diagSqr: " << st1.diagSqr() << nl
|
||||
<< " magSqr: " << magSqr(st1) << nl
|
||||
<< " mag: " << mag(st1) << nl;
|
||||
}
|
||||
|
||||
{
|
||||
Tensor<complex> st1(Tensor<complex>::uniform({3, 4}));
|
||||
|
||||
Info<< "tensor: " << st1 << nl
|
||||
<< " tr: " << tr(st1) << nl
|
||||
<< " diagSqr: " << st1.diagSqr() << nl
|
||||
<< " magSqr: " << magSqr(st1) << nl
|
||||
<< " mag: " << mag(st1) << endl;
|
||||
|
||||
Tensor<scalar> st2(Tensor<scalar>::uniform(5));
|
||||
|
||||
Info<< "Tensor: " << st2 << nl
|
||||
<< " tr: " << tr(st2) << nl
|
||||
<< " diagSqr: " << st2.diagSqr() << nl
|
||||
<< " magSqr: " << magSqr(st2) << nl
|
||||
<< " mag: " << mag(st2) << endl;
|
||||
}
|
||||
|
||||
complexField fld1(3, complex(2.0, 1.0));
|
||||
complexField fld2(fld1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user