src/OpenFOAM/primitives: Moved the standard static data members for vector and tensor types into VectorSpace

This simplifies the code easing maintenance and the addition of other
VectorSpace types.
This commit is contained in:
Henry Weller
2016-03-08 10:57:41 +00:00
parent 8a93701ef2
commit 93285d5fe1
49 changed files with 771 additions and 649 deletions

View File

@ -75,13 +75,6 @@ public:
// Static data members
static const char* const typeName;
static const char* componentNames[];
static const Tensor zero;
static const Tensor one;
static const Tensor max;
static const Tensor min;
static const Tensor I;

View File

@ -25,28 +25,26 @@ License
#include "SymmTensor.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Cmpt>
inline Tensor<Cmpt>::Tensor()
inline Foam::Tensor<Cmpt>::Tensor()
{}
template<class Cmpt>
template<class Cmpt2>
inline Tensor<Cmpt>::Tensor(const VectorSpace<Tensor<Cmpt2>, Cmpt2, 9>& vs)
inline Foam::Tensor<Cmpt>::Tensor
(
const VectorSpace<Tensor<Cmpt2>, Cmpt2, 9>& vs
)
:
VectorSpace<Tensor<Cmpt>, Cmpt, 9>(vs)
{}
template<class Cmpt>
inline Tensor<Cmpt>::Tensor(const SphericalTensor<Cmpt>& st)
inline Foam::Tensor<Cmpt>::Tensor(const SphericalTensor<Cmpt>& st)
{
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;
@ -55,7 +53,7 @@ inline Tensor<Cmpt>::Tensor(const SphericalTensor<Cmpt>& st)
template<class Cmpt>
inline Tensor<Cmpt>::Tensor(const SymmTensor<Cmpt>& st)
inline Foam::Tensor<Cmpt>::Tensor(const SymmTensor<Cmpt>& st)
{
this->v_[XX] = st.xx(); this->v_[XY] = st.xy(); this->v_[XZ] = st.xz();
this->v_[YX] = st.xy(); this->v_[YY] = st.yy(); this->v_[YZ] = st.yz();
@ -64,7 +62,7 @@ inline Tensor<Cmpt>::Tensor(const SymmTensor<Cmpt>& st)
template<class Cmpt>
inline Tensor<Cmpt>::Tensor(const Vector<Vector<Cmpt>>& tr)
inline Foam::Tensor<Cmpt>::Tensor(const Vector<Vector<Cmpt>>& tr)
{
this->v_[XX] = tr.x().x();
this->v_[XY] = tr.x().y();
@ -81,7 +79,7 @@ inline Tensor<Cmpt>::Tensor(const Vector<Vector<Cmpt>>& tr)
template<class Cmpt>
inline Tensor<Cmpt>::Tensor
inline Foam::Tensor<Cmpt>::Tensor
(
const Vector<Cmpt>& x,
const Vector<Cmpt>& y,
@ -95,7 +93,7 @@ inline Tensor<Cmpt>::Tensor
template<class Cmpt>
inline Tensor<Cmpt>::Tensor
inline Foam::Tensor<Cmpt>::Tensor
(
const Cmpt txx, const Cmpt txy, const Cmpt txz,
const Cmpt tyx, const Cmpt tyy, const Cmpt tyz,
@ -109,7 +107,7 @@ inline Tensor<Cmpt>::Tensor
template<class Cmpt>
inline Tensor<Cmpt>::Tensor(Istream& is)
inline Foam::Tensor<Cmpt>::Tensor(Istream& is)
:
VectorSpace<Tensor<Cmpt>, Cmpt, 9>(is)
{}
@ -118,28 +116,31 @@ inline Tensor<Cmpt>::Tensor(Istream& is)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Cmpt>
inline Vector<Cmpt> Tensor<Cmpt>::x() const
inline Foam::Vector<Cmpt> Foam::Tensor<Cmpt>::x() const
{
return Vector<Cmpt>(this->v_[XX], this->v_[XY], this->v_[XZ]);
}
template<class Cmpt>
inline Vector<Cmpt> Tensor<Cmpt>::y() const
inline Foam::Vector<Cmpt> Foam::Tensor<Cmpt>::y() const
{
return Vector<Cmpt>(this->v_[YX], this->v_[YY], this->v_[YZ]);
}
template<class Cmpt>
inline Vector<Cmpt> Tensor<Cmpt>::z() const
inline Foam::Vector<Cmpt> Foam::Tensor<Cmpt>::z() const
{
return Vector<Cmpt>(this->v_[ZX], this->v_[ZY], this->v_[ZZ]);
}
template<class Cmpt>
inline Vector<Cmpt> Tensor<Cmpt>::vectorComponent(const direction cmpt) const
inline Foam::Vector<Cmpt> Foam::Tensor<Cmpt>::vectorComponent
(
const direction cmpt
) const
{
switch (cmpt)
{
@ -157,133 +158,133 @@ inline Vector<Cmpt> Tensor<Cmpt>::vectorComponent(const direction cmpt) const
template<class Cmpt>
inline const Cmpt& Tensor<Cmpt>::xx() const
inline const Cmpt& Foam::Tensor<Cmpt>::xx() const
{
return this->v_[XX];
}
template<class Cmpt>
inline const Cmpt& Tensor<Cmpt>::xy() const
inline const Cmpt& Foam::Tensor<Cmpt>::xy() const
{
return this->v_[XY];
}
template<class Cmpt>
inline const Cmpt& Tensor<Cmpt>::xz() const
inline const Cmpt& Foam::Tensor<Cmpt>::xz() const
{
return this->v_[XZ];
}
template<class Cmpt>
inline const Cmpt& Tensor<Cmpt>::yx() const
inline const Cmpt& Foam::Tensor<Cmpt>::yx() const
{
return this->v_[YX];
}
template<class Cmpt>
inline const Cmpt& Tensor<Cmpt>::yy() const
inline const Cmpt& Foam::Tensor<Cmpt>::yy() const
{
return this->v_[YY];
}
template<class Cmpt>
inline const Cmpt& Tensor<Cmpt>::yz() const
inline const Cmpt& Foam::Tensor<Cmpt>::yz() const
{
return this->v_[YZ];
}
template<class Cmpt>
inline const Cmpt& Tensor<Cmpt>::zx() const
inline const Cmpt& Foam::Tensor<Cmpt>::zx() const
{
return this->v_[ZX];
}
template<class Cmpt>
inline const Cmpt& Tensor<Cmpt>::zy() const
inline const Cmpt& Foam::Tensor<Cmpt>::zy() const
{
return this->v_[ZY];
}
template<class Cmpt>
inline const Cmpt& Tensor<Cmpt>::zz() const
inline const Cmpt& Foam::Tensor<Cmpt>::zz() const
{
return this->v_[ZZ];
}
template<class Cmpt>
inline Cmpt& Tensor<Cmpt>::xx()
inline Cmpt& Foam::Tensor<Cmpt>::xx()
{
return this->v_[XX];
}
template<class Cmpt>
inline Cmpt& Tensor<Cmpt>::xy()
inline Cmpt& Foam::Tensor<Cmpt>::xy()
{
return this->v_[XY];
}
template<class Cmpt>
inline Cmpt& Tensor<Cmpt>::xz()
inline Cmpt& Foam::Tensor<Cmpt>::xz()
{
return this->v_[XZ];
}
template<class Cmpt>
inline Cmpt& Tensor<Cmpt>::yx()
inline Cmpt& Foam::Tensor<Cmpt>::yx()
{
return this->v_[YX];
}
template<class Cmpt>
inline Cmpt& Tensor<Cmpt>::yy()
inline Cmpt& Foam::Tensor<Cmpt>::yy()
{
return this->v_[YY];
}
template<class Cmpt>
inline Cmpt& Tensor<Cmpt>::yz()
inline Cmpt& Foam::Tensor<Cmpt>::yz()
{
return this->v_[YZ];
}
template<class Cmpt>
inline Cmpt& Tensor<Cmpt>::zx()
inline Cmpt& Foam::Tensor<Cmpt>::zx()
{
return this->v_[ZX];
}
template<class Cmpt>
inline Cmpt& Tensor<Cmpt>::zy()
inline Cmpt& Foam::Tensor<Cmpt>::zy()
{
return this->v_[ZY];
}
template<class Cmpt>
inline Cmpt& Tensor<Cmpt>::zz()
inline Cmpt& Foam::Tensor<Cmpt>::zz()
{
return this->v_[ZZ];
}
template<class Cmpt>
inline Tensor<Cmpt> Tensor<Cmpt>::T() const
inline Foam::Tensor<Cmpt> Foam::Tensor<Cmpt>::T() const
{
return Tensor<Cmpt>
(
@ -297,7 +298,7 @@ inline Tensor<Cmpt> Tensor<Cmpt>::T() const
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Cmpt>
inline void Tensor<Cmpt>::operator&=(const Tensor<Cmpt>& t)
inline void Foam::Tensor<Cmpt>::operator&=(const Tensor<Cmpt>& t)
{
*this =
(
@ -320,7 +321,7 @@ inline void Tensor<Cmpt>::operator&=(const Tensor<Cmpt>& t)
template<class Cmpt>
inline void Tensor<Cmpt>::operator=(const SphericalTensor<Cmpt>& st)
inline void Foam::Tensor<Cmpt>::operator=(const SphericalTensor<Cmpt>& st)
{
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;
@ -329,7 +330,7 @@ inline void Tensor<Cmpt>::operator=(const SphericalTensor<Cmpt>& st)
template<class Cmpt>
inline void Tensor<Cmpt>::operator=(const SymmTensor<Cmpt>& st)
inline void Foam::Tensor<Cmpt>::operator=(const SymmTensor<Cmpt>& st)
{
this->v_[XX] = st.xx(); this->v_[XY] = st.xy(); this->v_[XZ] = st.xz();
this->v_[YX] = st.xy(); this->v_[YY] = st.yy(); this->v_[YZ] = st.yz();
@ -338,7 +339,7 @@ inline void Tensor<Cmpt>::operator=(const SymmTensor<Cmpt>& st)
template<class Cmpt>
inline void Tensor<Cmpt>::operator=(const Vector<Vector<Cmpt>>& tr)
inline void Foam::Tensor<Cmpt>::operator=(const Vector<Vector<Cmpt>>& tr)
{
this->v_[XX] = tr.x().x();
this->v_[XY] = tr.x().y();
@ -354,6 +355,11 @@ inline void Tensor<Cmpt>::operator=(const Vector<Vector<Cmpt>>& tr)
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
template<class Cmpt>

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -28,35 +28,52 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
template<>
const char* const Foam::labelTensor::vsType::typeName = "labelTensor";
template<>
const char* const Foam::labelTensor::vsType::componentNames[] =
{
template<>
const char* const Foam::labelTensor::typeName = "labelTensor";
"xx", "xy", "xz",
"yx", "yy", "yz",
"zx", "zy", "zz"
};
template<>
const char* Foam::labelTensor::componentNames[] =
{
"xx", "xy", "xz",
"yx", "yy", "yz",
"zx", "zy", "zz"
};
template<>
const Foam::labelTensor Foam::labelTensor::vsType::zero
(
labelTensor::uniform(0)
);
template<>
const Foam::labelTensor Foam::labelTensor::zero
(
0, 0, 0,
0, 0, 0,
0, 0, 0
);
template<>
const Foam::labelTensor Foam::labelTensor::vsType::one
(
labelTensor::uniform(1)
);
template<>
const Foam::labelTensor Foam::labelTensor::one
(
1, 1, 1,
1, 1, 1,
1, 1, 1
);
}
template<>
const Foam::labelTensor Foam::labelTensor::vsType::max
(
labelTensor::uniform(labelMax)
);
template<>
const Foam::labelTensor Foam::labelTensor::vsType::min
(
labelTensor::uniform(-labelMax)
);
template<>
const Foam::labelTensor Foam::labelTensor::vsType::rootMax
(
labelTensor::uniform(sqrt(scalar(labelMax)))
);
template<>
const Foam::labelTensor Foam::labelTensor::vsType::rootMin
(
labelTensor::uniform(-sqrt(scalar(labelMax)))
);
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -30,59 +30,42 @@ using namespace Foam::constant::mathematical;
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
template<>
const char* const Foam::tensor::vsType::typeName = "tensor";
template<>
const char* const Foam::tensor::vsType::componentNames[] =
{
template<>
const char* const tensor::typeName = "tensor";
"xx", "xy", "xz",
"yx", "yy", "yz",
"zx", "zy", "zz"
};
template<>
const char* tensor::componentNames[] =
{
"xx", "xy", "xz",
"yx", "yy", "yz",
"zx", "zy", "zz"
};
template<>
const Foam::tensor Foam::tensor::vsType::zero(tensor::uniform(0));
template<>
const tensor tensor::zero
(
0, 0, 0,
0, 0, 0,
0, 0, 0
);
template<>
const Foam::tensor Foam::tensor::vsType::one(tensor::uniform(1));
template<>
const tensor tensor::one
(
1, 1, 1,
1, 1, 1,
1, 1, 1
);
template<>
const Foam::tensor Foam::tensor::vsType::max(tensor::uniform(VGREAT));
template<>
const tensor tensor::max
(
VGREAT, VGREAT, VGREAT,
VGREAT, VGREAT, VGREAT,
VGREAT, VGREAT, VGREAT
);
template<>
const Foam::tensor Foam::tensor::vsType::min(tensor::uniform(-VGREAT));
template<>
const tensor tensor::min
(
-VGREAT, -VGREAT, -VGREAT,
-VGREAT, -VGREAT, -VGREAT,
-VGREAT, -VGREAT, -VGREAT
);
template<>
const Foam::tensor Foam::tensor::vsType::rootMax(tensor::uniform(ROOTVGREAT));
template<>
const tensor tensor::I
(
1, 0, 0,
0, 1, 0,
0, 0, 1
);
}
template<>
const Foam::tensor Foam::tensor::vsType::rootMin(tensor::uniform(-ROOTVGREAT));
template<>
const Foam::tensor Foam::tensor::I
(
1, 0, 0,
0, 1, 0,
0, 0, 1
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //