Commit 6a53794e authored by Kutalmis Bercin's avatar Kutalmis Bercin Committed by Andrew Heather
Browse files

STYLE: reorder global funcs and opers in Tensor types

  - In the course of time, global funcs/opers of Tensor types expanded
    leaving funcs/opers unordered.

  - Therefore, by following the order designated in Matrix class, the order
    of global funcs and global opers are reordered:
    - oper+ oper- oper* oper/ inner-product double-inner-product outer-product
parent 66b02ca5
......@@ -115,146 +115,123 @@ inline Cmpt& Foam::DiagTensor<Cmpt>::zz()
namespace Foam
{
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
//- Sum of a DiagTensor and a Tensor
//- Return the trace of a DiagTensor
template<class Cmpt>
inline Tensor<Cmpt>
operator+(const DiagTensor<Cmpt>& dt1, const Tensor<Cmpt>& t2)
inline Cmpt tr(const DiagTensor<Cmpt>& dt)
{
return Tensor<Cmpt>
(
dt1.xx() + t2.xx(), t2.xy(), t2.xz(),
t2.yx(), dt1.yy() + t2.yy(), t2.yz(),
t2.zx(), t2.zy(), dt1.zz() + t2.zz()
);
return dt.xx() + dt.yy() + dt.zz();
}
//- Sum of a Tensor and a DiagTensor
//- Return the spherical part of a DiagTensor as a SphericalTensor
template<class Cmpt>
inline Tensor<Cmpt>
operator+(const Tensor<Cmpt>& t1, const DiagTensor<Cmpt>& dt2)
inline SphericalTensor<Cmpt> sph(const DiagTensor<Cmpt>& dt)
{
return Tensor<Cmpt>
return SphericalTensor<Cmpt>
(
t1.xx() + dt2.xx(), t1.xy(), t1.xz(),
t1.yx(), t1.yy() + dt2.yy(), t1.yz(),
t1.zx(), t1.zy(), t1.zz() + dt2.zz()
(1.0/3.0)*tr(dt)
);
}
//- Subtract a Tensor from a DiagTensor
//- Return the determinant of a DiagTensor
template<class Cmpt>
inline Tensor<Cmpt>
operator-(const DiagTensor<Cmpt>& dt1, const Tensor<Cmpt>& t2)
inline Cmpt det(const DiagTensor<Cmpt>& dt)
{
return Tensor<Cmpt>
(
dt1.xx() - t2.xx(), -t2.xy(), -t2.xz(),
-t2.yx(), dt1.yy() - t2.yy(), -t2.yz(),
-t2.zx(), -t2.zy(), dt1.zz() - t2.zz()
);
return dt.xx()*dt.yy()*dt.zz();
}
//- Subtract a DiagTensor from a Tensor
//- Return the inverse of a DiagTensor as a DiagTensor
template<class Cmpt>
inline Tensor<Cmpt>
operator-(const Tensor<Cmpt>& t1, const DiagTensor<Cmpt>& dt2)
inline DiagTensor<Cmpt> inv(const DiagTensor<Cmpt>& dt)
{
return Tensor<Cmpt>
(
t1.xx() - dt2.xx(), t1.xy(), t1.xz(),
t1.yx(), t1.yy() - dt2.yy(), t1.yz(),
t1.zx(), t1.zy(), t1.zz() - dt2.zz()
);
#ifdef FULLDEBUG
if (mag(det(dt)) < VSMALL)
{
FatalErrorInFunction
<< "DiagTensor is not invertible due to the zero determinant:"
<< "det(DiagTensor) = " << det(dt)
<< abort(FatalError);
}
#endif
return DiagTensor<Cmpt>(1/dt.xx(), 1/dt.yy(), 1/dt.zz());
}
//- Inner-product of a DiagTensor and a DiagTensor
//- Return the diagonal of a Tensor as a DiagTensor
template<class Cmpt>
inline DiagTensor<Cmpt>
operator&(const DiagTensor<Cmpt>& dt1, const DiagTensor<Cmpt>& dt2)
inline DiagTensor<Cmpt> diag(const Tensor<Cmpt>& t)
{
return DiagTensor<Cmpt>
(
dt1.xx()*dt2.xx(),
dt1.yy()*dt2.yy(),
dt1.zz()*dt2.zz()
);
return DiagTensor<Cmpt>(t.xx(), t.yy(), t.zz());
}
//- Inner-product of a DiagTensor and a Tensor
//- Return the diagonal of a SymmTensor as a DiagTensor
template<class Cmpt>
inline DiagTensor<Cmpt> diag(const SymmTensor<Cmpt>& st)
{
return DiagTensor<Cmpt>(st.xx(), st.yy(), st.zz());
}
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
//- Sum of a DiagTensor and a Tensor
template<class Cmpt>
inline Tensor<Cmpt>
operator&(const DiagTensor<Cmpt>& dt1, const Tensor<Cmpt>& t2)
operator+(const DiagTensor<Cmpt>& dt1, const Tensor<Cmpt>& t2)
{
return Tensor<Cmpt>
(
dt1.xx()*t2.xx(),
dt1.xx()*t2.xy(),
dt1.xx()*t2.xz(),
dt1.yy()*t2.yx(),
dt1.yy()*t2.yy(),
dt1.yy()*t2.yz(),
dt1.zz()*t2.zx(),
dt1.zz()*t2.zy(),
dt1.zz()*t2.zz()
dt1.xx() + t2.xx(), t2.xy(), t2.xz(),
t2.yx(), dt1.yy() + t2.yy(), t2.yz(),
t2.zx(), t2.zy(), dt1.zz() + t2.zz()
);
}
//- Inner-product of a Tensor and a DiagTensor
//- Sum of a Tensor and a DiagTensor
template<class Cmpt>
inline Tensor<Cmpt>
operator&(const Tensor<Cmpt>& t1, const DiagTensor<Cmpt>& dt2)
operator+(const Tensor<Cmpt>& t1, const DiagTensor<Cmpt>& dt2)
{
return Tensor<Cmpt>
(
t1.xx()*dt2.xx(),
t1.xy()*dt2.yy(),
t1.xz()*dt2.zz(),
t1.yx()*dt2.xx(),
t1.yy()*dt2.yy(),
t1.yz()*dt2.zz(),
t1.zx()*dt2.xx(),
t1.zy()*dt2.yy(),
t1.zz()*dt2.zz()
t1.xx() + dt2.xx(), t1.xy(), t1.xz(),
t1.yx(), t1.yy() + dt2.yy(), t1.yz(),
t1.zx(), t1.zy(), t1.zz() + dt2.zz()
);
}
//- Inner-product of a DiagTensor and a Vector
//- Subtract a Tensor from a DiagTensor
template<class Cmpt>
inline Vector<Cmpt>
operator&(const DiagTensor<Cmpt>& dt, const Vector<Cmpt>& v)
inline Tensor<Cmpt>
operator-(const DiagTensor<Cmpt>& dt1, const Tensor<Cmpt>& t2)
{
return Vector<Cmpt>
return Tensor<Cmpt>
(
dt.xx()*v.x(),
dt.yy()*v.y(),
dt.zz()*v.z()
dt1.xx() - t2.xx(), -t2.xy(), -t2.xz(),
-t2.yx(), dt1.yy() - t2.yy(), -t2.yz(),
-t2.zx(), -t2.zy(), dt1.zz() - t2.zz()
);
}
//- Inner-product of a Vector and a DiagTensor
//- Subtract a DiagTensor from a Tensor
template<class Cmpt>
inline Vector<Cmpt>
operator&(const Vector<Cmpt>& v, const DiagTensor<Cmpt>& dt)
inline Tensor<Cmpt>
operator-(const Tensor<Cmpt>& t1, const DiagTensor<Cmpt>& dt2)
{
return Vector<Cmpt>
return Tensor<Cmpt>
(
v.x()*dt.xx(),
v.y()*dt.yy(),
v.z()*dt.zz()
t1.xx() - dt2.xx(), t1.xy(), t1.xz(),
t1.yx(), t1.yy() - dt2.yy(), t1.yz(),
t1.zx(), t1.zy(), t1.zz() - dt2.zz()
);
}
......@@ -319,64 +296,89 @@ operator/(const Vector<Cmpt> v, const DiagTensor<Cmpt>& dt)
}
//- Return the trace of a DiagTensor
//- Inner-product of a DiagTensor and a DiagTensor
template<class Cmpt>
inline Cmpt tr(const DiagTensor<Cmpt>& dt)
inline DiagTensor<Cmpt>
operator&(const DiagTensor<Cmpt>& dt1, const DiagTensor<Cmpt>& dt2)
{
return dt.xx() + dt.yy() + dt.zz();
return DiagTensor<Cmpt>
(
dt1.xx()*dt2.xx(),
dt1.yy()*dt2.yy(),
dt1.zz()*dt2.zz()
);
}
//- Return the spherical part of a DiagTensor as a SphericalTensor
//- Inner-product of a DiagTensor and a Tensor
template<class Cmpt>
inline SphericalTensor<Cmpt> sph(const DiagTensor<Cmpt>& dt)
inline Tensor<Cmpt>
operator&(const DiagTensor<Cmpt>& dt1, const Tensor<Cmpt>& t2)
{
return SphericalTensor<Cmpt>
return Tensor<Cmpt>
(
(1.0/3.0)*tr(dt)
);
}
dt1.xx()*t2.xx(),
dt1.xx()*t2.xy(),
dt1.xx()*t2.xz(),
dt1.yy()*t2.yx(),
dt1.yy()*t2.yy(),
dt1.yy()*t2.yz(),
//- Return the determinant of a DiagTensor
template<class Cmpt>
inline Cmpt det(const DiagTensor<Cmpt>& dt)
{
return dt.xx()*dt.yy()*dt.zz();
dt1.zz()*t2.zx(),
dt1.zz()*t2.zy(),
dt1.zz()*t2.zz()
);
}
//- Return the inverse of a DiagTensor as a DiagTensor
//- Inner-product of a Tensor and a DiagTensor
template<class Cmpt>
inline DiagTensor<Cmpt> inv(const DiagTensor<Cmpt>& dt)
inline Tensor<Cmpt>
operator&(const Tensor<Cmpt>& t1, const DiagTensor<Cmpt>& dt2)
{
#ifdef FULLDEBUG
if (mag(det(dt)) < VSMALL)
{
FatalErrorInFunction
<< "DiagTensor is not invertible due to the zero determinant:"
<< "det(DiagTensor) = " << det(dt)
<< abort(FatalError);
}
#endif
return Tensor<Cmpt>
(
t1.xx()*dt2.xx(),
t1.xy()*dt2.yy(),
t1.xz()*dt2.zz(),
return DiagTensor<Cmpt>(1/dt.xx(), 1/dt.yy(), 1/dt.zz());
t1.yx()*dt2.xx(),
t1.yy()*dt2.yy(),
t1.yz()*dt2.zz(),
t1.zx()*dt2.xx(),
t1.zy()*dt2.yy(),
t1.zz()*dt2.zz()
);
}
//- Return the diagonal of a Tensor as a DiagTensor
//- Inner-product of a DiagTensor and a Vector
template<class Cmpt>
inline DiagTensor<Cmpt> diag(const Tensor<Cmpt>& t)
inline Vector<Cmpt>
operator&(const DiagTensor<Cmpt>& dt, const Vector<Cmpt>& v)
{
return DiagTensor<Cmpt>(t.xx(), t.yy(), t.zz());
return Vector<Cmpt>
(
dt.xx()*v.x(),
dt.yy()*v.y(),
dt.zz()*v.z()
);
}
//- Return the diagonal of a SymmTensor as a DiagTensor
//- Inner-product of a Vector and a DiagTensor
template<class Cmpt>
inline DiagTensor<Cmpt> diag(const SymmTensor<Cmpt>& st)
inline Vector<Cmpt>
operator&(const Vector<Cmpt>& v, const DiagTensor<Cmpt>& dt)
{
return DiagTensor<Cmpt>(st.xx(), st.yy(), st.zz());
return Vector<Cmpt>
(
v.x()*dt.xx(),
v.y()*dt.yy(),
v.z()*dt.zz()
);
}
......
......@@ -91,91 +91,47 @@ Foam::SphericalTensor<Cmpt>::T() const
namespace Foam
{
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
//- Inner-product of a SphericalTensor and a SphericalTensor
template<class Cmpt>
inline SphericalTensor<Cmpt>
operator&(const SphericalTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& st2)
{
return SphericalTensor<Cmpt>(st1.ii()*st2.ii());
}
//- Inner-product of a SphericalTensor and a Vector
//- Return the trace of a SphericalTensor
template<class Cmpt>
inline Vector<Cmpt>
operator&(const SphericalTensor<Cmpt>& st, const Vector<Cmpt>& v)
inline Cmpt tr(const SphericalTensor<Cmpt>& st)
{
return Vector<Cmpt>
(
st.ii()*v.x(),
st.ii()*v.y(),
st.ii()*v.z()
);
return 3*st.ii();
}
//- Inner-product of a Vector and a SphericalTensor
//- Return the spherical part of a SphericalTensor, i.e. itself
template<class Cmpt>
inline Vector<Cmpt>
operator&(const Vector<Cmpt>& v, const SphericalTensor<Cmpt>& st)
inline SphericalTensor<Cmpt> sph(const SphericalTensor<Cmpt>& st)
{
return Vector<Cmpt>
(
v.x()*st.ii(),
v.y()*st.ii(),
v.z()*st.ii()
);
return st;
}
//- Double-inner-product of a SphericalTensor and a SphericalTensor
//- Return the determinant of a SphericalTensor
template<class Cmpt>
inline Cmpt
operator&&(const SphericalTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& st2)
inline Cmpt det(const SphericalTensor<Cmpt>& st)
{
return 3*st1.ii()*st2.ii();
return st.ii()*st.ii()*st.ii();
}
//- Division of a Cmpt by a SphericalTensor
//- Return the inverse of a SphericalTensor
template<class Cmpt>
inline SphericalTensor<Cmpt>
operator/(const Cmpt s, const SphericalTensor<Cmpt>& st)
inline SphericalTensor<Cmpt> inv(const SphericalTensor<Cmpt>& st)
{
#ifdef FULLDEBUG
if (mag(st.ii()) < VSMALL)
{
FatalErrorInFunction
<< "Cmpt = " << s
<< " is not divisible due to a zero element in SphericalTensor:"
<< "SphericalTensor = " << st
<< abort(FatalError);
}
#endif
return SphericalTensor<Cmpt>(s/st.ii());
}
//- Division of a SphericalTensor by a Cmpt
template<class Cmpt>
inline SphericalTensor<Cmpt>
operator/(const SphericalTensor<Cmpt>& st, const Cmpt s)
{
#ifdef FULLDEBUG
if (mag(s) < VSMALL)
{
FatalErrorInFunction
<< "SphericalTensor = " << st
<< " is not divisible due to a zero value in Cmpt:"
<< "Cmpt = " << s
<< "SphericalTensor is not invertible due to the zero determinant:"
<< "det(SphericalTensor) = " << det(st)
<< abort(FatalError);
}
#endif
return SphericalTensor<Cmpt>(st.ii()/s);
return SphericalTensor<Cmpt>(1/st.ii());
}
......@@ -219,45 +175,91 @@ inline Cmpt cmptAv(const SphericalTensor<Cmpt>& st)
}
//- Return the trace of a SphericalTensor
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
//- Division of a Cmpt by a SphericalTensor
template<class Cmpt>
inline Cmpt tr(const SphericalTensor<Cmpt>& st)
inline SphericalTensor<Cmpt>
operator/(const Cmpt s, const SphericalTensor<Cmpt>& st)
{
return 3*st.ii();
#ifdef FULLDEBUG
if (mag(st.ii()) < VSMALL)
{
FatalErrorInFunction
<< "Cmpt = " << s
<< " is not divisible due to a zero element in SphericalTensor:"
<< "SphericalTensor = " << st
<< abort(FatalError);
}
#endif
return SphericalTensor<Cmpt>(s/st.ii());
}
//- Return the spherical part of a SphericalTensor, i.e. itself
//- Division of a SphericalTensor by a Cmpt
template<class Cmpt>
inline SphericalTensor<Cmpt> sph(const SphericalTensor<Cmpt>& st)
inline SphericalTensor<Cmpt>
operator/(const SphericalTensor<Cmpt>& st, const Cmpt s)
{
return st;
#ifdef FULLDEBUG
if (mag(s) < VSMALL)
{
FatalErrorInFunction
<< "SphericalTensor = " << st
<< " is not divisible due to a zero value in Cmpt:"
<< "Cmpt = " << s
<< abort(FatalError);
}
#endif
return SphericalTensor<Cmpt>(st.ii()/s);
}
//- Return the determinant of a SphericalTensor
//- Inner-product of a SphericalTensor and a SphericalTensor
template<class Cmpt>
inline Cmpt det(const SphericalTensor<Cmpt>& st)
inline SphericalTensor<Cmpt>
operator&(const SphericalTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& st2)
{
return st.ii()*st.ii()*st.ii();
return SphericalTensor<Cmpt>(st1.ii()*st2.ii());
}
//- Return the inverse of a SphericalTensor
//- Inner-product of a SphericalTensor and a Vector
template<class Cmpt>
inline SphericalTensor<Cmpt> inv(const SphericalTensor<Cmpt>& st)
inline Vector<Cmpt>
operator&(const SphericalTensor<Cmpt>& st, const Vector<Cmpt>& v)
{
#ifdef FULLDEBUG
if (mag(st.ii()) < VSMALL)
{
FatalErrorInFunction
<< "SphericalTensor is not invertible due to the zero determinant:"
<< "det(SphericalTensor) = " << det(st)
<< abort(FatalError);
}
#endif
return Vector<Cmpt>
(
st.ii()*v.x(),
st.ii()*v.y(),
st.ii()*v.z()
);
}
return SphericalTensor<Cmpt>(1/st.ii());
//- Inner-product of a Vector and a SphericalTensor
template<class Cmpt>
inline Vector<Cmpt>
operator&(const Vector<Cmpt>& v, const SphericalTensor<Cmpt>& st)
{
return Vector<Cmpt>
(
v.x()*st.ii(),
v.y()*st.ii(),
v.z()*st.ii()
);
}
//- Double-inner-product of a SphericalTensor and a SphericalTensor
template<class Cmpt>
inline Cmpt
operator&&(const SphericalTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& st2)
{
return 3*st1.ii()*st2.ii();
}
......
......@@ -82,47 +82,52 @@ inline Cmpt& Foam::SphericalTensor2D<Cmpt>::ii()
namespace Foam
{
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
//- Inner-product of a SphericalTensor2D and a SphericalTensor2D
//- Return the trace of a SphericalTensor2D
template<class Cmpt>
inline SphericalTensor2D<Cmpt>
operator&
(
const SphericalTensor2D<Cmpt>& st1,
const SphericalTensor2D<Cmpt>& st2
)
inline Cmpt tr(const SphericalTensor2D<Cmpt>& st)
{
return SphericalTensor2D<Cmpt>(st1.ii()*st2.ii());
return 2*st.ii();
}
//- Inner-product of a SphericalTensor2D and a Vector2D
//- Return the spherical part of a SphericalTensor2D, i.e. itself
template<class Cmpt>
inline Vector2D<Cmpt>
operator&(const SphericalTensor2D<Cmpt>& st, const Vector2D<Cmpt>& v)
inline SphericalTensor2D<Cmpt> sph(const SphericalTensor2D<Cmpt>& st)
{
return Vector2D<Cmpt>
(
st.ii()*v.x(),
st.ii()*v.y()