Commit b465592e authored by Mark Olesen's avatar Mark Olesen Committed by Andrew Heather
Browse files

ENH: added access to get/set a Tensor diagonal

parent 7b42931a
......@@ -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<Cmpt> diag() const;
//- Set values of the diagonal
inline void diag(const Vector<Cmpt>& v);
// Tensor Operations
//- Transpose
inline const SymmTensor<Cmpt>& T() const;
......
......@@ -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<Cmpt>::zz()
}
template<class Cmpt>
inline Foam::Vector<Cmpt> Foam::SymmTensor<Cmpt>::diag() const
{
return Vector<Cmpt>(this->v_[XX], this->v_[YY], this->v_[ZZ]);
}
template<class Cmpt>
inline void Foam::SymmTensor<Cmpt>::diag(const Vector<Cmpt>& v)
{
this->v_[XX] = v.x(); this->v_[YY] = v.y(); this->v_[ZZ] = v.z();
}
template<class Cmpt>
inline const Foam::SymmTensor<Cmpt>& Foam::SymmTensor<Cmpt>::T() const
{
......
......@@ -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<Cmpt> diag() const;
//- Set values of the diagonal
inline void diag(const Vector2D<Cmpt>& v);
//- Transpose
inline const SymmTensor2D<Cmpt>& T() const;
......
......@@ -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<Cmpt>::yy()
}
template<class Cmpt>
inline Foam::Vector2D<Cmpt> Foam::SymmTensor2D<Cmpt>::diag() const
{
return Vector2D<Cmpt>(this->v_[XX], this->v_[YY]);
}
template<class Cmpt>
inline void Foam::SymmTensor2D<Cmpt>::diag(const Vector2D<Cmpt>& v)
{
this->v_[XX] = v.x(); this->v_[YY] = v.y();
}
template<class Cmpt>
inline const Foam::SymmTensor2D<Cmpt>& Foam::SymmTensor2D<Cmpt>::T() const
{
......
......@@ -229,9 +229,14 @@ public:
// Runtime check of row index.
inline void row(const direction r, const Vector<Cmpt>& v);
//- Return vector for given row (0,1,2)
// Runtime check of row index.
inline Vector<Cmpt> vectorComponent(const direction cmpt) const;
// Diagonal access.
//- Extract the diagonal as a vector
inline Vector<Cmpt> diag() const;
//- Set values of the diagonal
inline void diag(const Vector<Cmpt>& v);
// Tensor Operations
......@@ -269,6 +274,16 @@ public:
//- Assign to a triad of row vectors
inline void operator=(const Vector<Vector<Cmpt>>&);
// Housekeeping
//- Deprecated(2018-12) Return vector for given row (0,1)
// \deprecated(2018-12) use row() method
Vector<Cmpt> vectorComponent(const direction cmpt) const
{
return row(cmpt);
}
};
......
......@@ -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<Cmpt>::row(const direction r, const Vector<Cmpt>& v)
template<class Cmpt>
inline Foam::Vector<Cmpt> Foam::Tensor<Cmpt>::vectorComponent
(
const direction cmpt
) const
inline Foam::Vector<Cmpt> Foam::Tensor<Cmpt>::diag() const
{
return Vector<Cmpt>(this->v_[XX], this->v_[YY], this->v_[ZZ]);
}
template<class Cmpt>
inline void Foam::Tensor<Cmpt>::diag(const Vector<Cmpt>& v)
{
return row(cmpt);
this->v_[XX] = v.x(); this->v_[YY] = v.y(); this->v_[ZZ] = v.z();
}
......
......@@ -185,9 +185,14 @@ public:
// Runtime check of row index.
inline void row(const direction r, const Vector2D<Cmpt>& v);
//- Return vector for given row (0,1)
// Runtime check of row index.
inline Vector2D<Cmpt> vectorComponent(const direction cmpt) const;
// Diagonal access.
//- Extract the diagonal as a vector
inline Vector2D<Cmpt> diag() const;
//- Set values of the diagonal
inline void diag(const Vector2D<Cmpt>& v);
// Tensor Operations
......@@ -209,6 +214,16 @@ public:
//- Copy assign from SphericalTensor2D
inline void operator=(const SphericalTensor2D<Cmpt>&);
// Housekeeping
//- Deprecated(2018-12) Return vector for given row (0,1)
// \deprecated(2018-12) use row() method
Vector2D<Cmpt> vectorComponent(const direction cmpt) const
{
return row(cmpt);
}
};
......
......@@ -305,12 +305,16 @@ inline void Foam::Tensor2D<Cmpt>::row
template<class Cmpt>
inline Foam::Vector2D<Cmpt> Foam::Tensor2D<Cmpt>::vectorComponent
(
const direction cmpt
) const
inline Foam::Vector2D<Cmpt> Foam::Tensor2D<Cmpt>::diag() const
{
return Vector2D<Cmpt>(this->v_[XX], this->v_[YY]);
}
template<class Cmpt>
inline void Foam::Tensor2D<Cmpt>::diag(const Vector2D<Cmpt>& v)
{
return row(cmpt);
this->v_[XX] = v.x(); this->v_[YY] = v.y();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment