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

ENH: add rows/cols setters to Tensor, Tensor2D

- also support transposed construction when given a set of vectors
parent 0d71607b
......@@ -111,15 +111,22 @@ public:
//- Construct given SymmTensor
inline Tensor(const SymmTensor<Cmpt>& st);
//- Construct given triad of row vectors
inline Tensor(const Vector<Vector<Cmpt>>& tr);
//- Construct given triad of row vectors,
//- optionally treated as transposed (ie, column vectors)
inline Tensor
(
const Vector<Vector<Cmpt>>& vecs,
const bool transposed = false
);
//- Construct given the three row vectors
//- Construct given the three row vectors,
//- optionally treated as transposed (ie, column vectors)
inline Tensor
(
const Vector<Cmpt>& x,
const Vector<Cmpt>& y,
const Vector<Cmpt>& z
const Vector<Cmpt>& z,
const bool transposed = false
);
//- Construct given the nine components
......@@ -200,6 +207,14 @@ public:
// Runtime check of column index.
inline void col(const direction c, const Vector<Cmpt>& v);
//- Set column values
inline void cols
(
const Vector<Cmpt>& x,
const Vector<Cmpt>& y,
const Vector<Cmpt>& z
);
// Row-vector access.
......@@ -230,6 +245,14 @@ public:
// Runtime check of row index.
inline void row(const direction r, const Vector<Cmpt>& v);
//- Set row values
inline void rows
(
const Vector<Cmpt>& x,
const Vector<Cmpt>& y,
const Vector<Cmpt>& z
);
// Diagonal access.
......
......@@ -66,10 +66,12 @@ inline Foam::Tensor<Cmpt>::Tensor
template<class Cmpt>
inline Foam::Tensor<Cmpt>::Tensor(const SphericalTensor<Cmpt>& st)
:
Tensor::msType(Zero)
{
this->v_[XX] = st.ii(); this->v_[XY] = 0; this->v_[XZ] = 0;
this->v_[YX] = 0; this->v_[YY] = st.ii(); this->v_[YZ] = 0;
this->v_[ZX] = 0; this->v_[ZY] = 0; this->v_[ZZ] = st.ii();
this->v_[XX] = st.ii();
this->v_[YY] = st.ii();
this->v_[ZZ] = st.ii();
}
......@@ -83,20 +85,14 @@ inline Foam::Tensor<Cmpt>::Tensor(const SymmTensor<Cmpt>& st)
template<class Cmpt>
inline Foam::Tensor<Cmpt>::Tensor(const Vector<Vector<Cmpt>>& tr)
{
this->v_[XX] = tr.x().x();
this->v_[XY] = tr.x().y();
this->v_[XZ] = tr.x().z();
this->v_[YX] = tr.y().x();
this->v_[YY] = tr.y().y();
this->v_[YZ] = tr.y().z();
this->v_[ZX] = tr.z().x();
this->v_[ZY] = tr.z().y();
this->v_[ZZ] = tr.z().z();
}
inline Foam::Tensor<Cmpt>::Tensor
(
const Vector<Vector<Cmpt>>& vecs,
const bool transposed
)
:
Tensor<Cmpt>(vecs.x(), vecs.y(), vecs.z(), transposed)
{}
template<class Cmpt>
......@@ -104,12 +100,18 @@ inline Foam::Tensor<Cmpt>::Tensor
(
const Vector<Cmpt>& x,
const Vector<Cmpt>& y,
const Vector<Cmpt>& z
const Vector<Cmpt>& z,
const bool transposed
)
{
this->v_[XX] = x.x(); this->v_[XY] = x.y(); this->v_[XZ] = x.z();
this->v_[YX] = y.x(); this->v_[YY] = y.y(); this->v_[YZ] = y.z();
this->v_[ZX] = z.x(); this->v_[ZY] = z.y(); this->v_[ZZ] = z.z();
if (transposed)
{
this->cols(x, y, z);
}
else
{
this->rows(x, y, z);
}
}
......@@ -428,6 +430,34 @@ inline void Foam::Tensor<Cmpt>::row(const Vector<Cmpt>& v)
}
template<class Cmpt>
inline void Foam::Tensor<Cmpt>::cols
(
const Vector<Cmpt>& x,
const Vector<Cmpt>& y,
const Vector<Cmpt>& z
)
{
this->v_[XX] = x.x(); this->v_[XY] = y.x(); this->v_[XZ] = z.x();
this->v_[YX] = x.y(); this->v_[YY] = y.y(); this->v_[YZ] = z.y();
this->v_[ZX] = x.z(); this->v_[ZY] = y.z(); this->v_[ZZ] = z.z();
}
template<class Cmpt>
inline void Foam::Tensor<Cmpt>::rows
(
const Vector<Cmpt>& x,
const Vector<Cmpt>& y,
const Vector<Cmpt>& z
)
{
this->v_[XX] = x.x(); this->v_[XY] = x.y(); this->v_[XZ] = x.z();
this->v_[YX] = y.x(); this->v_[YY] = y.y(); this->v_[YZ] = y.z();
this->v_[ZX] = z.x(); this->v_[ZY] = z.y(); this->v_[ZZ] = z.z();
}
template<class Cmpt>
inline void Foam::Tensor<Cmpt>::col(const direction c, const Vector<Cmpt>& v)
{
......
......@@ -159,6 +159,9 @@ public:
// Runtime check of column index.
inline void col(const direction c, const Vector2D<Cmpt>& v);
//- Set column values
inline void cols(const Vector2D<Cmpt>& x, const Vector2D<Cmpt>& y);
// Row-vector access.
......@@ -186,6 +189,9 @@ public:
// Runtime check of row index.
inline void row(const direction r, const Vector2D<Cmpt>& v);
//- Set row values
inline void rows(const Vector2D<Cmpt>& x, const Vector2D<Cmpt>& y);
// Diagonal access.
......
......@@ -60,9 +60,11 @@ inline Foam::Tensor2D<Cmpt>::Tensor2D(const SymmTensor2D<Cmpt>& st)
template<class Cmpt>
inline Foam::Tensor2D<Cmpt>::Tensor2D(const SphericalTensor2D<Cmpt>& st)
:
Tensor2D::msType(Zero)
{
this->v_[XX] = st.ii(); this->v_[XY] = 0;
this->v_[YX] = 0; this->v_[YY] = st.ii();
this->v_[XX] = st.ii();
this->v_[YY] = st.ii();
}
......@@ -267,6 +269,30 @@ inline void Foam::Tensor2D<Cmpt>::row(const Vector2D<Cmpt>& v)
}
template<class Cmpt>
inline void Foam::Tensor2D<Cmpt>::cols
(
const Vector2D<Cmpt>& x,
const Vector2D<Cmpt>& y
)
{
this->v_[XX] = x.x(); this->v_[XY] = y.x();
this->v_[YX] = x.y(); this->v_[YY] = y.y();
}
template<class Cmpt>
inline void Foam::Tensor2D<Cmpt>::rows
(
const Vector2D<Cmpt>& x,
const Vector2D<Cmpt>& y
)
{
this->v_[XX] = x.x(); this->v_[XY] = x.y();
this->v_[YX] = y.x(); this->v_[YY] = y.y();
}
template<class Cmpt>
inline void Foam::Tensor2D<Cmpt>::col
(
......
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