diff --git a/src/OpenFOAM/primitives/DiagTensor/DiagTensor.H b/src/OpenFOAM/primitives/DiagTensor/DiagTensor.H index c4d141d667..efd21592fb 100644 --- a/src/OpenFOAM/primitives/DiagTensor/DiagTensor.H +++ b/src/OpenFOAM/primitives/DiagTensor/DiagTensor.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019-2023 OpenCFD Ltd. + Copyright (C) 2019-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -92,7 +92,7 @@ public: // Constructors //- Construct initialized to zero - inline DiagTensor(const Foam::zero); + inline DiagTensor(Foam::zero); //- Construct given VectorSpace template @@ -123,6 +123,9 @@ public: // Diagonal access and manipulation + //- Extract the diagonal as a vector + inline Vector diag() const; + //- The L2-norm squared of the diagonal inline scalar diagSqr() const; }; diff --git a/src/OpenFOAM/primitives/DiagTensor/DiagTensorI.H b/src/OpenFOAM/primitives/DiagTensor/DiagTensorI.H index e898e8181d..0590463031 100644 --- a/src/OpenFOAM/primitives/DiagTensor/DiagTensorI.H +++ b/src/OpenFOAM/primitives/DiagTensor/DiagTensorI.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2020-2023 OpenCFD Ltd. + Copyright (C) 2020-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -32,9 +32,9 @@ License // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template -inline Foam::DiagTensor::DiagTensor(const Foam::zero) +inline Foam::DiagTensor::DiagTensor(Foam::zero) : - VectorSpace, Cmpt, 3>(Zero) + VectorSpace, Cmpt, 3>(Foam::zero{}) {} @@ -81,6 +81,13 @@ inline Foam::DiagTensor::DiagTensor(Istream& is) // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +template +inline Foam::Vector Foam::DiagTensor::diag() const +{ + return Vector(this->xx(), this->yy(), this->zz()); +} + + template inline Foam::scalar Foam::DiagTensor::diagSqr() const { diff --git a/src/OpenFOAM/primitives/SymmTensor/SymmTensor.H b/src/OpenFOAM/primitives/SymmTensor/SymmTensor.H index 2f38d3e481..acc667eb43 100644 --- a/src/OpenFOAM/primitives/SymmTensor/SymmTensor.H +++ b/src/OpenFOAM/primitives/SymmTensor/SymmTensor.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019-2023 OpenCFD Ltd. + Copyright (C) 2019-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -94,7 +94,7 @@ public: // Constructors //- Construct initialized to zero - inline SymmTensor(const Foam::zero); + inline SymmTensor(Foam::zero); //- Construct given VectorSpace of the same rank template @@ -234,6 +234,12 @@ public: inline scalar diagSqr() const; + // Characteristics + + //- Is identity tensor? + inline bool is_identity(const scalar tol = ROOTVSMALL) const; + + // Tensor Operations //- Return non-Hermitian transpose diff --git a/src/OpenFOAM/primitives/SymmTensor/SymmTensorI.H b/src/OpenFOAM/primitives/SymmTensor/SymmTensorI.H index 3b654f175f..53ed33fdb1 100644 --- a/src/OpenFOAM/primitives/SymmTensor/SymmTensorI.H +++ b/src/OpenFOAM/primitives/SymmTensor/SymmTensorI.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019-2023 OpenCFD Ltd. + Copyright (C) 2019-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -31,9 +31,9 @@ License // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template -inline Foam::SymmTensor::SymmTensor(const Foam::zero) +inline Foam::SymmTensor::SymmTensor(Foam::zero) : - SymmTensor::vsType(Zero) + SymmTensor::vsType(Foam::zero{}) {} @@ -238,6 +238,21 @@ inline Foam::scalar Foam::SymmTensor::diagSqr() const } +template +inline bool Foam::SymmTensor::is_identity(const scalar tol) const +{ + return + ( + Foam::mag(xx() - pTraits::one) < tol + && Foam::mag(yy() - pTraits::one) < tol + && Foam::mag(zz() - pTraits::one) < tol + && Foam::mag(xy()) < tol + && Foam::mag(xz()) < tol + && Foam::mag(yz()) < tol + ); +} + + template inline Cmpt Foam::SymmTensor::det() const { diff --git a/src/OpenFOAM/primitives/Tensor/TensorI.H b/src/OpenFOAM/primitives/Tensor/TensorI.H index 89352d73b2..7c46f93639 100644 --- a/src/OpenFOAM/primitives/Tensor/TensorI.H +++ b/src/OpenFOAM/primitives/Tensor/TensorI.H @@ -410,12 +410,12 @@ inline bool Foam::Tensor::is_identity(const scalar tol) const { return ( - mag(xx() - pTraits::one) < tol - && mag(yy() - pTraits::one) < tol - && mag(zz() - pTraits::one) < tol - && mag(xy()) < tol && mag(xz()) < tol - && mag(yx()) < tol && mag(yz()) < tol - && mag(zx()) < tol && mag(zy()) < tol + Foam::mag(xx() - pTraits::one) < tol + && Foam::mag(yy() - pTraits::one) < tol + && Foam::mag(zz() - pTraits::one) < tol + && Foam::mag(xy()) < tol && Foam::mag(xz()) < tol + && Foam::mag(yx()) < tol && Foam::mag(yz()) < tol + && Foam::mag(zx()) < tol && Foam::mag(zy()) < tol ); } diff --git a/src/finiteArea/fields/faPatchFields/constraint/wedge/wedgeFaPatchField.C b/src/finiteArea/fields/faPatchFields/constraint/wedge/wedgeFaPatchField.C index d3e5c31d78..deded81e75 100644 --- a/src/finiteArea/fields/faPatchFields/constraint/wedge/wedgeFaPatchField.C +++ b/src/finiteArea/fields/faPatchFields/constraint/wedge/wedgeFaPatchField.C @@ -29,7 +29,6 @@ License #include "wedgeFaPatchField.H" #include "transformField.H" #include "symmTransform.H" -#include "diagTensor.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -138,10 +137,9 @@ template Foam::tmp> Foam::wedgeFaPatchField::snGradTransformDiag() const { - const diagTensor diagT = - 0.5*diag(I - refCast(this->patch()).faceT()); + const auto& rot = refCast(this->patch()).faceT(); - const vector diagV(diagT.xx(), diagT.yy(), diagT.zz()); + const vector diagV = 0.5*(I - rot).diag(); return tmp>::New ( diff --git a/src/finiteVolume/fields/fvPatchFields/constraint/symmetryPlane/symmetryPlaneFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/constraint/symmetryPlane/symmetryPlaneFvPatchField.C index b83f6c80a9..4a9705bada 100644 --- a/src/finiteVolume/fields/fvPatchFields/constraint/symmetryPlane/symmetryPlaneFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/constraint/symmetryPlane/symmetryPlaneFvPatchField.C @@ -155,9 +155,7 @@ template Foam::tmp> Foam::symmetryPlaneFvPatchField::snGradTransformDiag() const { - vector nHat(symmetryPlanePatch_.n()); - - const vector diag(mag(nHat.x()), mag(nHat.y()), mag(nHat.z())); + const vector diag(cmptMag(symmetryPlanePatch_.n())); return tmp>::New ( diff --git a/src/finiteVolume/fields/fvPatchFields/constraint/wedge/wedgeFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/constraint/wedge/wedgeFvPatchField.C index 8c2b3eb61c..c8094daa0c 100644 --- a/src/finiteVolume/fields/fvPatchFields/constraint/wedge/wedgeFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/constraint/wedge/wedgeFvPatchField.C @@ -30,7 +30,6 @@ License #include "wedgeFvPatchField.H" #include "transformField.H" #include "symmTransform.H" -#include "diagTensor.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -152,10 +151,9 @@ template Foam::tmp> Foam::wedgeFvPatchField::snGradTransformDiag() const { - const diagTensor diagT = - 0.5*diag(I - refCast(this->patch()).cellT()); + const auto& rot = refCast(this->patch()).cellT(); - const vector diagV(diagT.xx(), diagT.yy(), diagT.zz()); + const vector diagV = 0.5*(I - rot).diag(); return tmp>::New (