From b465592ee248f0ae1d28dd6e2c4f85b9fea24ed0 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 10 Oct 2019 10:44:29 +0200 Subject: [PATCH] ENH: added access to get/set a Tensor diagonal --- .../primitives/SymmTensor/SymmTensor.H | 18 +++++++++++++--- .../primitives/SymmTensor/SymmTensorI.H | 17 +++++++++++++-- .../primitives/SymmTensor2D/SymmTensor2D.H | 14 +++++++++++-- .../primitives/SymmTensor2D/SymmTensor2DI.H | 17 +++++++++++++-- src/OpenFOAM/primitives/Tensor/Tensor.H | 21 ++++++++++++++++--- src/OpenFOAM/primitives/Tensor/TensorI.H | 16 ++++++++------ src/OpenFOAM/primitives/Tensor2D/Tensor2D.H | 21 ++++++++++++++++--- src/OpenFOAM/primitives/Tensor2D/Tensor2DI.H | 14 ++++++++----- 8 files changed, 112 insertions(+), 26 deletions(-) diff --git a/src/OpenFOAM/primitives/SymmTensor/SymmTensor.H b/src/OpenFOAM/primitives/SymmTensor/SymmTensor.H index 8d5f5d43bf..76db32c69a 100644 --- a/src/OpenFOAM/primitives/SymmTensor/SymmTensor.H +++ b/src/OpenFOAM/primitives/SymmTensor/SymmTensor.H @@ -41,7 +41,7 @@ SourceFiles #define SymmTensor_H #include "contiguous.H" -#include "VectorSpace.H" +#include "Vector.H" #include "SphericalTensor.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -104,12 +104,12 @@ public: ); //- Construct from Istream - SymmTensor(Istream&); + inline SymmTensor(Istream&); // Member Functions - // Access + // Component access inline const Cmpt& xx() const; inline const Cmpt& xy() const; @@ -125,6 +125,18 @@ public: inline Cmpt& yz(); inline Cmpt& zz(); + + // Diagonal access. + + //- Extract the diagonal as a vector + inline Vector diag() const; + + //- Set values of the diagonal + inline void diag(const Vector& v); + + + // Tensor Operations + //- Transpose inline const SymmTensor& T() const; diff --git a/src/OpenFOAM/primitives/SymmTensor/SymmTensorI.H b/src/OpenFOAM/primitives/SymmTensor/SymmTensorI.H index 2f43ad41d3..9893b83c30 100644 --- a/src/OpenFOAM/primitives/SymmTensor/SymmTensorI.H +++ b/src/OpenFOAM/primitives/SymmTensor/SymmTensorI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | + \\ / A nd | Copyright (C) 2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -25,7 +25,6 @@ License \*---------------------------------------------------------------------------*/ -#include "Vector.H" #include "Tensor.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -159,6 +158,20 @@ inline Cmpt& Foam::SymmTensor::zz() } +template +inline Foam::Vector Foam::SymmTensor::diag() const +{ + return Vector(this->v_[XX], this->v_[YY], this->v_[ZZ]); +} + + +template +inline void Foam::SymmTensor::diag(const Vector& v) +{ + this->v_[XX] = v.x(); this->v_[YY] = v.y(); this->v_[ZZ] = v.z(); +} + + template inline const Foam::SymmTensor& Foam::SymmTensor::T() const { diff --git a/src/OpenFOAM/primitives/SymmTensor2D/SymmTensor2D.H b/src/OpenFOAM/primitives/SymmTensor2D/SymmTensor2D.H index f76790d29a..e1ec619ca9 100644 --- a/src/OpenFOAM/primitives/SymmTensor2D/SymmTensor2D.H +++ b/src/OpenFOAM/primitives/SymmTensor2D/SymmTensor2D.H @@ -41,7 +41,7 @@ SourceFiles #define SymmTensor2D_H #include "contiguous.H" -#include "VectorSpace.H" +#include "Vector2D.H" #include "SphericalTensor2D.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -102,7 +102,7 @@ public: ); //- Construct from Istream - SymmTensor2D(Istream&); + inline SymmTensor2D(Istream&); // Member Functions @@ -117,6 +117,16 @@ public: inline Cmpt& xy(); inline Cmpt& yy(); + + // Diagonal access. + + //- Extract the diagonal as a vector + inline Vector2D diag() const; + + //- Set values of the diagonal + inline void diag(const Vector2D& v); + + //- Transpose inline const SymmTensor2D& T() const; diff --git a/src/OpenFOAM/primitives/SymmTensor2D/SymmTensor2DI.H b/src/OpenFOAM/primitives/SymmTensor2D/SymmTensor2DI.H index c91a38e427..e957c88deb 100644 --- a/src/OpenFOAM/primitives/SymmTensor2D/SymmTensor2DI.H +++ b/src/OpenFOAM/primitives/SymmTensor2D/SymmTensor2DI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | + \\ / A nd | Copyright (C) 2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -25,7 +25,6 @@ License \*---------------------------------------------------------------------------*/ -#include "Vector2D.H" #include "Tensor2D.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -119,6 +118,20 @@ inline Cmpt& Foam::SymmTensor2D::yy() } +template +inline Foam::Vector2D Foam::SymmTensor2D::diag() const +{ + return Vector2D(this->v_[XX], this->v_[YY]); +} + + +template +inline void Foam::SymmTensor2D::diag(const Vector2D& v) +{ + this->v_[XX] = v.x(); this->v_[YY] = v.y(); +} + + template inline const Foam::SymmTensor2D& Foam::SymmTensor2D::T() const { diff --git a/src/OpenFOAM/primitives/Tensor/Tensor.H b/src/OpenFOAM/primitives/Tensor/Tensor.H index 322e6b31e2..94f8b388ba 100644 --- a/src/OpenFOAM/primitives/Tensor/Tensor.H +++ b/src/OpenFOAM/primitives/Tensor/Tensor.H @@ -229,9 +229,14 @@ public: // Runtime check of row index. inline void row(const direction r, const Vector& v); - //- Return vector for given row (0,1,2) - // Runtime check of row index. - inline Vector vectorComponent(const direction cmpt) const; + + // Diagonal access. + + //- Extract the diagonal as a vector + inline Vector diag() const; + + //- Set values of the diagonal + inline void diag(const Vector& v); // Tensor Operations @@ -269,6 +274,16 @@ public: //- Assign to a triad of row vectors inline void operator=(const Vector>&); + + + // Housekeeping + + //- Deprecated(2018-12) Return vector for given row (0,1) + // \deprecated(2018-12) use row() method + Vector vectorComponent(const direction cmpt) const + { + return row(cmpt); + } }; diff --git a/src/OpenFOAM/primitives/Tensor/TensorI.H b/src/OpenFOAM/primitives/Tensor/TensorI.H index b5cbada94d..afb86da786 100644 --- a/src/OpenFOAM/primitives/Tensor/TensorI.H +++ b/src/OpenFOAM/primitives/Tensor/TensorI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -460,12 +460,16 @@ inline void Foam::Tensor::row(const direction r, const Vector& v) template -inline Foam::Vector Foam::Tensor::vectorComponent -( - const direction cmpt -) const +inline Foam::Vector Foam::Tensor::diag() const { - return row(cmpt); + return Vector(this->v_[XX], this->v_[YY], this->v_[ZZ]); +} + + +template +inline void Foam::Tensor::diag(const Vector& v) +{ + this->v_[XX] = v.x(); this->v_[YY] = v.y(); this->v_[ZZ] = v.z(); } diff --git a/src/OpenFOAM/primitives/Tensor2D/Tensor2D.H b/src/OpenFOAM/primitives/Tensor2D/Tensor2D.H index f0cff04b73..e6865f6abc 100644 --- a/src/OpenFOAM/primitives/Tensor2D/Tensor2D.H +++ b/src/OpenFOAM/primitives/Tensor2D/Tensor2D.H @@ -185,9 +185,14 @@ public: // Runtime check of row index. inline void row(const direction r, const Vector2D& v); - //- Return vector for given row (0,1) - // Runtime check of row index. - inline Vector2D vectorComponent(const direction cmpt) const; + + // Diagonal access. + + //- Extract the diagonal as a vector + inline Vector2D diag() const; + + //- Set values of the diagonal + inline void diag(const Vector2D& v); // Tensor Operations @@ -209,6 +214,16 @@ public: //- Copy assign from SphericalTensor2D inline void operator=(const SphericalTensor2D&); + + + // Housekeeping + + //- Deprecated(2018-12) Return vector for given row (0,1) + // \deprecated(2018-12) use row() method + Vector2D vectorComponent(const direction cmpt) const + { + return row(cmpt); + } }; diff --git a/src/OpenFOAM/primitives/Tensor2D/Tensor2DI.H b/src/OpenFOAM/primitives/Tensor2D/Tensor2DI.H index f5a88023e8..fd8079a02e 100644 --- a/src/OpenFOAM/primitives/Tensor2D/Tensor2DI.H +++ b/src/OpenFOAM/primitives/Tensor2D/Tensor2DI.H @@ -305,12 +305,16 @@ inline void Foam::Tensor2D::row template -inline Foam::Vector2D Foam::Tensor2D::vectorComponent -( - const direction cmpt -) const +inline Foam::Vector2D Foam::Tensor2D::diag() const { - return row(cmpt); + return Vector2D(this->v_[XX], this->v_[YY]); +} + + +template +inline void Foam::Tensor2D::diag(const Vector2D& v) +{ + this->v_[XX] = v.x(); this->v_[YY] = v.y(); }