STYLE: retrieve tensor diagonal directly instead of via diagTensor

This commit is contained in:
Mark Olesen
2025-03-11 10:00:23 +01:00
parent 6ca0c59519
commit f7c8bfdce0
8 changed files with 52 additions and 27 deletions

View File

@ -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<class Cmpt2>
@ -123,6 +123,9 @@ public:
// Diagonal access and manipulation
//- Extract the diagonal as a vector
inline Vector<Cmpt> diag() const;
//- The L2-norm squared of the diagonal
inline scalar diagSqr() const;
};

View File

@ -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<class Cmpt>
inline Foam::DiagTensor<Cmpt>::DiagTensor(const Foam::zero)
inline Foam::DiagTensor<Cmpt>::DiagTensor(Foam::zero)
:
VectorSpace<DiagTensor<Cmpt>, Cmpt, 3>(Zero)
VectorSpace<DiagTensor<Cmpt>, Cmpt, 3>(Foam::zero{})
{}
@ -81,6 +81,13 @@ inline Foam::DiagTensor<Cmpt>::DiagTensor(Istream& is)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Cmpt>
inline Foam::Vector<Cmpt> Foam::DiagTensor<Cmpt>::diag() const
{
return Vector<Cmpt>(this->xx(), this->yy(), this->zz());
}
template<class Cmpt>
inline Foam::scalar Foam::DiagTensor<Cmpt>::diagSqr() const
{

View File

@ -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<class Cmpt2>
@ -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

View File

@ -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<class Cmpt>
inline Foam::SymmTensor<Cmpt>::SymmTensor(const Foam::zero)
inline Foam::SymmTensor<Cmpt>::SymmTensor(Foam::zero)
:
SymmTensor::vsType(Zero)
SymmTensor::vsType(Foam::zero{})
{}
@ -238,6 +238,21 @@ inline Foam::scalar Foam::SymmTensor<Cmpt>::diagSqr() const
}
template<class Cmpt>
inline bool Foam::SymmTensor<Cmpt>::is_identity(const scalar tol) const
{
return
(
Foam::mag(xx() - pTraits<Cmpt>::one) < tol
&& Foam::mag(yy() - pTraits<Cmpt>::one) < tol
&& Foam::mag(zz() - pTraits<Cmpt>::one) < tol
&& Foam::mag(xy()) < tol
&& Foam::mag(xz()) < tol
&& Foam::mag(yz()) < tol
);
}
template<class Cmpt>
inline Cmpt Foam::SymmTensor<Cmpt>::det() const
{

View File

@ -410,12 +410,12 @@ inline bool Foam::Tensor<Cmpt>::is_identity(const scalar tol) const
{
return
(
mag(xx() - pTraits<Cmpt>::one) < tol
&& mag(yy() - pTraits<Cmpt>::one) < tol
&& mag(zz() - pTraits<Cmpt>::one) < tol
&& mag(xy()) < tol && mag(xz()) < tol
&& mag(yx()) < tol && mag(yz()) < tol
&& mag(zx()) < tol && mag(zy()) < tol
Foam::mag(xx() - pTraits<Cmpt>::one) < tol
&& Foam::mag(yy() - pTraits<Cmpt>::one) < tol
&& Foam::mag(zz() - pTraits<Cmpt>::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
);
}

View File

@ -29,7 +29,6 @@ License
#include "wedgeFaPatchField.H"
#include "transformField.H"
#include "symmTransform.H"
#include "diagTensor.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -138,10 +137,9 @@ template<class Type>
Foam::tmp<Foam::Field<Type>>
Foam::wedgeFaPatchField<Type>::snGradTransformDiag() const
{
const diagTensor diagT =
0.5*diag(I - refCast<const wedgeFaPatch>(this->patch()).faceT());
const auto& rot = refCast<const wedgeFaPatch>(this->patch()).faceT();
const vector diagV(diagT.xx(), diagT.yy(), diagT.zz());
const vector diagV = 0.5*(I - rot).diag();
return tmp<Field<Type>>::New
(

View File

@ -155,9 +155,7 @@ template<class Type>
Foam::tmp<Foam::Field<Type>>
Foam::symmetryPlaneFvPatchField<Type>::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<Field<Type>>::New
(

View File

@ -30,7 +30,6 @@ License
#include "wedgeFvPatchField.H"
#include "transformField.H"
#include "symmTransform.H"
#include "diagTensor.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -152,10 +151,9 @@ template<class Type>
Foam::tmp<Foam::Field<Type>>
Foam::wedgeFvPatchField<Type>::snGradTransformDiag() const
{
const diagTensor diagT =
0.5*diag(I - refCast<const wedgeFvPatch>(this->patch()).cellT());
const auto& rot = refCast<const wedgeFvPatch>(this->patch()).cellT();
const vector diagV(diagT.xx(), diagT.yy(), diagT.zz());
const vector diagV = 0.5*(I - rot).diag();
return tmp<Field<Type>>::New
(