diff --git a/src/OpenFOAM/primitives/DiagTensor/DiagTensorI.H b/src/OpenFOAM/primitives/DiagTensor/DiagTensorI.H index f34e7e3e4f..7674e74cae 100644 --- a/src/OpenFOAM/primitives/DiagTensor/DiagTensorI.H +++ b/src/OpenFOAM/primitives/DiagTensor/DiagTensorI.H @@ -115,6 +115,69 @@ inline Cmpt& Foam::DiagTensor::zz() namespace Foam { +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // + +//- Return the trace of a DiagTensor +template +inline Cmpt tr(const DiagTensor& dt) +{ + return dt.xx() + dt.yy() + dt.zz(); +} + + +//- Return the spherical part of a DiagTensor as a SphericalTensor +template +inline SphericalTensor sph(const DiagTensor& dt) +{ + return SphericalTensor + ( + (1.0/3.0)*tr(dt) + ); +} + + +//- Return the determinant of a DiagTensor +template +inline Cmpt det(const DiagTensor& dt) +{ + return dt.xx()*dt.yy()*dt.zz(); +} + + +//- Return the inverse of a DiagTensor as a DiagTensor +template +inline DiagTensor inv(const DiagTensor& dt) +{ + #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(1/dt.xx(), 1/dt.yy(), 1/dt.zz()); +} + + +//- Return the diagonal of a Tensor as a DiagTensor +template +inline DiagTensor diag(const Tensor& t) +{ + return DiagTensor(t.xx(), t.yy(), t.zz()); +} + + +//- Return the diagonal of a SymmTensor as a DiagTensor +template +inline DiagTensor diag(const SymmTensor& st) +{ + return DiagTensor(st.xx(), st.yy(), st.zz()); +} + + // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // //- Sum of a DiagTensor and a Tensor @@ -173,6 +236,66 @@ operator-(const Tensor& t1, const DiagTensor& dt2) } +//- Division of a Cmpt by a DiagTensor +template +inline DiagTensor +operator/(const Cmpt s, const DiagTensor& dt) +{ + #ifdef FULLDEBUG + if (mag(det(dt)) < VSMALL) + { + FatalErrorInFunction + << "Cmpt = " << s + << " is not divisible by the DiagTensor due to a zero element:" + << "DiagTensor = " << dt + << abort(FatalError); + } + #endif + + return DiagTensor(s/dt.xx(), s/dt.yy(), s/dt.zz()); +} + + +//- Division of a DiagTensor by a Cmpt +template +inline DiagTensor +operator/(const DiagTensor& dt, const Cmpt s) +{ + #ifdef FULLDEBUG + if (mag(s) < VSMALL) + { + FatalErrorInFunction + << "DiagTensor = " << dt + << " is not divisible due to a zero value in Cmpt:" + << "Cmpt = " << s + << abort(FatalError); + } + #endif + + return DiagTensor(dt.xx()/s, dt.yy()/s, dt.zz()/s); +} + + +//- Division of a Vector by a DiagTensor +template +inline Vector +operator/(const Vector v, const DiagTensor& dt) +{ + #ifdef FULLDEBUG + if (mag(det(dt)) < VSMALL) + { + FatalErrorInFunction + << "Vector = " << v + << " is not divisible by the DiagTensor due to a zero element:" + << "DiagTensor = " << dt + << abort(FatalError); + } + #endif + + return Vector(v.x()/dt.xx(), v.y()/dt.yy(), v.z()/dt.zz()); +} + + //- Inner-product of a DiagTensor and a DiagTensor template inline DiagTensor @@ -259,127 +382,6 @@ operator&(const Vector& v, const DiagTensor& dt) } -//- Division of a Cmpt by a DiagTensor -template -inline DiagTensor -operator/(const Cmpt s, const DiagTensor& dt) -{ - #ifdef FULLDEBUG - if (mag(det(dt)) < VSMALL) - { - FatalErrorInFunction - << "Cmpt = " << s - << " is not divisible by the DiagTensor due to a zero element:" - << "DiagTensor = " << dt - << abort(FatalError); - } - #endif - - return DiagTensor(s/dt.xx(), s/dt.yy(), s/dt.zz()); -} - - -//- Division of a DiagTensor by a Cmpt -template -inline DiagTensor -operator/(const DiagTensor& dt, const Cmpt s) -{ - #ifdef FULLDEBUG - if (mag(s) < VSMALL) - { - FatalErrorInFunction - << "DiagTensor = " << dt - << " is not divisible due to a zero value in Cmpt:" - << "Cmpt = " << s - << abort(FatalError); - } - #endif - - return DiagTensor(dt.xx()/s, dt.yy()/s, dt.zz()/s); -} - - -//- Division of a Vector by a DiagTensor -template -inline Vector -operator/(const Vector v, const DiagTensor& dt) -{ - #ifdef FULLDEBUG - if (mag(det(dt)) < VSMALL) - { - FatalErrorInFunction - << "Vector = " << v - << " is not divisible by the DiagTensor due to a zero element:" - << "DiagTensor = " << dt - << abort(FatalError); - } - #endif - - return Vector(v.x()/dt.xx(), v.y()/dt.yy(), v.z()/dt.zz()); -} - - -//- Return the trace of a DiagTensor -template -inline Cmpt tr(const DiagTensor& dt) -{ - return dt.xx() + dt.yy() + dt.zz(); -} - - -//- Return the spherical part of a DiagTensor as a SphericalTensor -template -inline SphericalTensor sph(const DiagTensor& dt) -{ - return SphericalTensor - ( - (1.0/3.0)*tr(dt) - ); -} - - -//- Return the determinant of a DiagTensor -template -inline Cmpt det(const DiagTensor& dt) -{ - return dt.xx()*dt.yy()*dt.zz(); -} - - -//- Return the inverse of a DiagTensor as a DiagTensor -template -inline DiagTensor inv(const DiagTensor& dt) -{ - #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(1/dt.xx(), 1/dt.yy(), 1/dt.zz()); -} - - -//- Return the diagonal of a Tensor as a DiagTensor -template -inline DiagTensor diag(const Tensor& t) -{ - return DiagTensor(t.xx(), t.yy(), t.zz()); -} - - -//- Return the diagonal of a SymmTensor as a DiagTensor -template -inline DiagTensor diag(const SymmTensor& st) -{ - return DiagTensor(st.xx(), st.yy(), st.zz()); -} - - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/primitives/SphericalTensor/SphericalTensorI.H b/src/OpenFOAM/primitives/SphericalTensor/SphericalTensorI.H index ff577ee653..43f8ee9ea7 100644 --- a/src/OpenFOAM/primitives/SphericalTensor/SphericalTensorI.H +++ b/src/OpenFOAM/primitives/SphericalTensor/SphericalTensorI.H @@ -91,8 +91,132 @@ Foam::SphericalTensor::T() const namespace Foam { +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // + +//- Return the trace of a SphericalTensor +template +inline Cmpt tr(const SphericalTensor& st) +{ + return 3*st.ii(); +} + + +//- Return the spherical part of a SphericalTensor, i.e. itself +template +inline SphericalTensor sph(const SphericalTensor& st) +{ + return st; +} + + +//- Return the determinant of a SphericalTensor +template +inline Cmpt det(const SphericalTensor& st) +{ + return st.ii()*st.ii()*st.ii(); +} + + +//- Return the inverse of a SphericalTensor +template +inline SphericalTensor inv(const SphericalTensor& st) +{ + #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 SphericalTensor(1/st.ii()); +} + + +//- Return the square of Frobenius norm of a SphericalTensor as a Cmpt +template +inline Cmpt magSqr(const SphericalTensor& st) +{ + return Cmpt(3*mag(st.ii()*st.ii())); +} + + +//- Return the max component of a SphericalTensor +template +inline Cmpt cmptMax(const SphericalTensor& st) +{ + return st.ii(); +} + + +//- Return the min component of a SphericalTensor +template +inline Cmpt cmptMin(const SphericalTensor& st) +{ + return st.ii(); +} + + +//- Return the sum of components of a SphericalTensor +template +inline Cmpt cmptSum(const SphericalTensor& st) +{ + return 3*st.ii(); +} + + +//- Return the arithmetic average of components of a SphericalTensor +template +inline Cmpt cmptAv(const SphericalTensor& st) +{ + return st.ii(); +} + + // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // +//- Division of a Cmpt by a SphericalTensor +template +inline SphericalTensor +operator/(const Cmpt s, const SphericalTensor& 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(s/st.ii()); +} + + +//- Division of a SphericalTensor by a Cmpt +template +inline SphericalTensor +operator/(const SphericalTensor& 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 + << abort(FatalError); + } + #endif + + return SphericalTensor(st.ii()/s); +} + + //- Inner-product of a SphericalTensor and a SphericalTensor template inline SphericalTensor @@ -139,128 +263,6 @@ operator&&(const SphericalTensor& st1, const SphericalTensor& st2) } -//- Division of a Cmpt by a SphericalTensor -template -inline SphericalTensor -operator/(const Cmpt s, const SphericalTensor& 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(s/st.ii()); -} - - -//- Division of a SphericalTensor by a Cmpt -template -inline SphericalTensor -operator/(const SphericalTensor& 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 - << abort(FatalError); - } - #endif - - return SphericalTensor(st.ii()/s); -} - - -//- Return the square of Frobenius norm of a SphericalTensor as a Cmpt -template -inline Cmpt magSqr(const SphericalTensor& st) -{ - return Cmpt(3*mag(st.ii()*st.ii())); -} - - -//- Return the max component of a SphericalTensor -template -inline Cmpt cmptMax(const SphericalTensor& st) -{ - return st.ii(); -} - - -//- Return the min component of a SphericalTensor -template -inline Cmpt cmptMin(const SphericalTensor& st) -{ - return st.ii(); -} - - -//- Return the sum of components of a SphericalTensor -template -inline Cmpt cmptSum(const SphericalTensor& st) -{ - return 3*st.ii(); -} - - -//- Return the arithmetic average of components of a SphericalTensor -template -inline Cmpt cmptAv(const SphericalTensor& st) -{ - return st.ii(); -} - - -//- Return the trace of a SphericalTensor -template -inline Cmpt tr(const SphericalTensor& st) -{ - return 3*st.ii(); -} - - -//- Return the spherical part of a SphericalTensor, i.e. itself -template -inline SphericalTensor sph(const SphericalTensor& st) -{ - return st; -} - - -//- Return the determinant of a SphericalTensor -template -inline Cmpt det(const SphericalTensor& st) -{ - return st.ii()*st.ii()*st.ii(); -} - - -//- Return the inverse of a SphericalTensor -template -inline SphericalTensor inv(const SphericalTensor& st) -{ - #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 SphericalTensor(1/st.ii()); -} - - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // template diff --git a/src/OpenFOAM/primitives/SphericalTensor2D/SphericalTensor2DI.H b/src/OpenFOAM/primitives/SphericalTensor2D/SphericalTensor2DI.H index 0555864aa0..6a4516e33c 100644 --- a/src/OpenFOAM/primitives/SphericalTensor2D/SphericalTensor2DI.H +++ b/src/OpenFOAM/primitives/SphericalTensor2D/SphericalTensor2DI.H @@ -82,47 +82,52 @@ inline Cmpt& Foam::SphericalTensor2D::ii() namespace Foam { +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // + +//- Return the trace of a SphericalTensor2D +template +inline Cmpt tr(const SphericalTensor2D& st) +{ + return 2*st.ii(); +} + + +//- Return the spherical part of a SphericalTensor2D, i.e. itself +template +inline SphericalTensor2D sph(const SphericalTensor2D& st) +{ + return st; +} + + +//- Return the determinant of a SphericalTensor2D +template +inline Cmpt det(const SphericalTensor2D& st) +{ + return st.ii()*st.ii(); +} + + +//- Return the inverse of a SphericalTensor2D +template +inline SphericalTensor2D inv(const SphericalTensor2D& st) +{ + #ifdef FULLDEBUG + if (mag(st.ii()) < VSMALL) + { + FatalErrorInFunction + << "SphericalTensor2D is not invertible due to zero determinant:" + << "det(SphericalTensor2D) = " << det(st) + << abort(FatalError); + } + #endif + + return SphericalTensor2D(1/st.ii()); +} + + // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // -//- Inner-product of a SphericalTensor2D and a SphericalTensor2D -template -inline SphericalTensor2D -operator& -( - const SphericalTensor2D& st1, - const SphericalTensor2D& st2 -) -{ - return SphericalTensor2D(st1.ii()*st2.ii()); -} - - -//- Inner-product of a SphericalTensor2D and a Vector2D -template -inline Vector2D -operator&(const SphericalTensor2D& st, const Vector2D& v) -{ - return Vector2D - ( - st.ii()*v.x(), - st.ii()*v.y() - ); -} - - -//- Inner-product of a Vector2D and a SphericalTensor2D -template -inline Vector2D -operator&(const Vector2D& v, const SphericalTensor2D& st) -{ - return Vector2D - ( - v.x()*st.ii(), - v.y()*st.ii() - ); -} - - //- Division of a Cmpt by a SphericalTensor2D template inline SphericalTensor2D @@ -163,45 +168,42 @@ operator/(const SphericalTensor2D& st, const Cmpt s) } -//- Return the trace of a SphericalTensor2D +//- Inner-product of a SphericalTensor2D and a SphericalTensor2D template -inline Cmpt tr(const SphericalTensor2D& st) +inline SphericalTensor2D +operator& +( + const SphericalTensor2D& st1, + const SphericalTensor2D& st2 +) { - return 2*st.ii(); + return SphericalTensor2D(st1.ii()*st2.ii()); } -//- Return the spherical part of a SphericalTensor2D, i.e. itself +//- Inner-product of a SphericalTensor2D and a Vector2D template -inline SphericalTensor2D sph(const SphericalTensor2D& st) +inline Vector2D +operator&(const SphericalTensor2D& st, const Vector2D& v) { - return st; + return Vector2D + ( + st.ii()*v.x(), + st.ii()*v.y() + ); } -//- Return the determinant of a SphericalTensor2D +//- Inner-product of a Vector2D and a SphericalTensor2D template -inline Cmpt det(const SphericalTensor2D& st) +inline Vector2D +operator&(const Vector2D& v, const SphericalTensor2D& st) { - return st.ii()*st.ii(); -} - - -//- Return the inverse of a SphericalTensor2D -template -inline SphericalTensor2D inv(const SphericalTensor2D& st) -{ - #ifdef FULLDEBUG - if (mag(st.ii()) < VSMALL) - { - FatalErrorInFunction - << "SphericalTensor2D is not invertible due to zero determinant:" - << "det(SphericalTensor2D) = " << det(st) - << abort(FatalError); - } - #endif - - return SphericalTensor2D(1/st.ii()); + return Vector2D + ( + v.x()*st.ii(), + v.y()*st.ii() + ); } diff --git a/src/OpenFOAM/primitives/SymmTensor/SymmTensorI.H b/src/OpenFOAM/primitives/SymmTensor/SymmTensorI.H index 0ed2d49e35..2170ea5961 100644 --- a/src/OpenFOAM/primitives/SymmTensor/SymmTensorI.H +++ b/src/OpenFOAM/primitives/SymmTensor/SymmTensorI.H @@ -227,111 +227,7 @@ inline void Foam::SymmTensor::operator=(const SphericalTensor& st) namespace Foam { -// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // - -//- Return the Hodge dual of a SymmTensor as a Vector -template -inline Vector operator*(const SymmTensor& st) -{ - return Vector(st.yz(), -st.xz(), st.xy()); -} - - -//- Inner-product of a SymmTensor and a SymmTensor -template -inline Tensor -operator&(const SymmTensor& st1, const SymmTensor& st2) -{ - return Tensor - ( - st1.xx()*st2.xx() + st1.xy()*st2.xy() + st1.xz()*st2.xz(), - st1.xx()*st2.xy() + st1.xy()*st2.yy() + st1.xz()*st2.yz(), - st1.xx()*st2.xz() + st1.xy()*st2.yz() + st1.xz()*st2.zz(), - - st1.xy()*st2.xx() + st1.yy()*st2.xy() + st1.yz()*st2.xz(), - st1.xy()*st2.xy() + st1.yy()*st2.yy() + st1.yz()*st2.yz(), - st1.xy()*st2.xz() + st1.yy()*st2.yz() + st1.yz()*st2.zz(), - - st1.xz()*st2.xx() + st1.yz()*st2.xy() + st1.zz()*st2.xz(), - st1.xz()*st2.xy() + st1.yz()*st2.yy() + st1.zz()*st2.yz(), - st1.xz()*st2.xz() + st1.yz()*st2.yz() + st1.zz()*st2.zz() - ); -} - - -//- Double-inner-product of a SymmTensor and a SymmTensor -template -inline Cmpt -operator&&(const SymmTensor& st1, const SymmTensor& st2) -{ - return - ( - st1.xx()*st2.xx() + 2*st1.xy()*st2.xy() + 2*st1.xz()*st2.xz() - + st1.yy()*st2.yy() + 2*st1.yz()*st2.yz() - + st1.zz()*st2.zz() - ); -} - - -//- Inner-product of a SymmTensor and a Vector -template -inline Vector -operator&(const SymmTensor& st, const Vector& v) -{ - return Vector - ( - st.xx()*v.x() + st.xy()*v.y() + st.xz()*v.z(), - st.xy()*v.x() + st.yy()*v.y() + st.yz()*v.z(), - st.xz()*v.x() + st.yz()*v.y() + st.zz()*v.z() - ); -} - - -//- Inner-product of a Vector and a SymmTensor -template -inline Vector -operator&(const Vector& v, const SymmTensor& st) -{ - return Vector - ( - v.x()*st.xx() + v.y()*st.xy() + v.z()*st.xz(), - v.x()*st.xy() + v.y()*st.yy() + v.z()*st.yz(), - v.x()*st.xz() + v.y()*st.yz() + v.z()*st.zz() - ); -} - - -//- Return the inner-product of a SymmTensor with itself -template -inline SymmTensor -innerSqr(const SymmTensor& st) -{ - return SymmTensor - ( - st.xx()*st.xx() + st.xy()*st.xy() + st.xz()*st.xz(), - st.xx()*st.xy() + st.xy()*st.yy() + st.xz()*st.yz(), - st.xx()*st.xz() + st.xy()*st.yz() + st.xz()*st.zz(), - - st.xy()*st.xy() + st.yy()*st.yy() + st.yz()*st.yz(), - st.xy()*st.xz() + st.yy()*st.yz() + st.yz()*st.zz(), - - st.xz()*st.xz() + st.yz()*st.yz() + st.zz()*st.zz() - ); -} - - -//- Return the square of Frobenius norm of a SymmTensor as a Cmpt -template -inline Cmpt magSqr(const SymmTensor& st) -{ - return Cmpt - ( - mag(st.xx()*st.xx()) + 2*mag(st.xy()*st.xy()) + 2*mag(st.xz()*st.xz()) - + mag(st.yy()*st.yy()) + 2*mag(st.yz()*st.yz()) - + mag(st.zz()*st.zz()) - ); -} - +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // //- Return the trace of a SymmTensor template @@ -469,6 +365,53 @@ inline Cmpt invariantIII(const SymmTensor& st) } +//- Return the inner-product of a SymmTensor with itself +template +inline SymmTensor +innerSqr(const SymmTensor& st) +{ + return SymmTensor + ( + st.xx()*st.xx() + st.xy()*st.xy() + st.xz()*st.xz(), + st.xx()*st.xy() + st.xy()*st.yy() + st.xz()*st.yz(), + st.xx()*st.xz() + st.xy()*st.yz() + st.xz()*st.zz(), + + st.xy()*st.xy() + st.yy()*st.yy() + st.yz()*st.yz(), + st.xy()*st.xz() + st.yy()*st.yz() + st.yz()*st.zz(), + + st.xz()*st.xz() + st.yz()*st.yz() + st.zz()*st.zz() + ); +} + + +//- Return the square of Frobenius norm of a SymmTensor as a Cmpt +template +inline Cmpt magSqr(const SymmTensor& st) +{ + return Cmpt + ( + mag(st.xx()*st.xx()) + 2*mag(st.xy()*st.xy()) + 2*mag(st.xz()*st.xz()) + + mag(st.yy()*st.yy()) + 2*mag(st.yz()*st.yz()) + + mag(st.zz()*st.zz()) + ); +} + + +//- Return the square of a Vector as a SymmTensor +template +inline SymmTensor sqr(const Vector& v) +{ + return SymmTensor + ( + v.x()*v.x(), v.x()*v.y(), v.x()*v.z(), + v.y()*v.y(), v.y()*v.z(), + v.z()*v.z() + ); +} + + +// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // + //- Sum of a SphericalTensor and a SymmTensor template inline SymmTensor @@ -525,6 +468,50 @@ operator-(const SymmTensor& st1, const SphericalTensor& spt2) } +//- Return the Hodge dual of a SymmTensor as a Vector +template +inline Vector operator*(const SymmTensor& st) +{ + return Vector(st.yz(), -st.xz(), st.xy()); +} + + +//- Division of a SymmTensor by a Cmpt +template +inline SymmTensor +operator/(const SymmTensor& st, const Cmpt s) +{ + return SymmTensor + ( + st.xx()/s, st.xy()/s, st.xz()/s, + st.yy()/s, st.yz()/s, + st.zz()/s + ); +} + + +//- Inner-product of a SymmTensor and a SymmTensor +template +inline Tensor +operator&(const SymmTensor& st1, const SymmTensor& st2) +{ + return Tensor + ( + st1.xx()*st2.xx() + st1.xy()*st2.xy() + st1.xz()*st2.xz(), + st1.xx()*st2.xy() + st1.xy()*st2.yy() + st1.xz()*st2.yz(), + st1.xx()*st2.xz() + st1.xy()*st2.yz() + st1.xz()*st2.zz(), + + st1.xy()*st2.xx() + st1.yy()*st2.xy() + st1.yz()*st2.xz(), + st1.xy()*st2.xy() + st1.yy()*st2.yy() + st1.yz()*st2.yz(), + st1.xy()*st2.xz() + st1.yy()*st2.yz() + st1.yz()*st2.zz(), + + st1.xz()*st2.xx() + st1.yz()*st2.xy() + st1.zz()*st2.xz(), + st1.xz()*st2.xy() + st1.yz()*st2.yy() + st1.zz()*st2.yz(), + st1.xz()*st2.xz() + st1.yz()*st2.yz() + st1.zz()*st2.zz() + ); +} + + //- Inner-product of a SphericalTensor and a SymmTensor template inline SymmTensor @@ -553,6 +540,48 @@ operator&(const SymmTensor& st1, const SphericalTensor& spt2) } +//- Inner-product of a SymmTensor and a Vector +template +inline Vector +operator&(const SymmTensor& st, const Vector& v) +{ + return Vector + ( + st.xx()*v.x() + st.xy()*v.y() + st.xz()*v.z(), + st.xy()*v.x() + st.yy()*v.y() + st.yz()*v.z(), + st.xz()*v.x() + st.yz()*v.y() + st.zz()*v.z() + ); +} + + +//- Inner-product of a Vector and a SymmTensor +template +inline Vector +operator&(const Vector& v, const SymmTensor& st) +{ + return Vector + ( + v.x()*st.xx() + v.y()*st.xy() + v.z()*st.xz(), + v.x()*st.xy() + v.y()*st.yy() + v.z()*st.yz(), + v.x()*st.xz() + v.y()*st.yz() + v.z()*st.zz() + ); +} + + +//- Double-inner-product of a SymmTensor and a SymmTensor +template +inline Cmpt +operator&&(const SymmTensor& st1, const SymmTensor& st2) +{ + return + ( + st1.xx()*st2.xx() + 2*st1.xy()*st2.xy() + 2*st1.xz()*st2.xz() + + st1.yy()*st2.yy() + 2*st1.yz()*st2.yz() + + st1.zz()*st2.zz() + ); +} + + //- Double-inner-product of a SphericalTensor and a SymmTensor template inline Cmpt @@ -571,33 +600,6 @@ operator&&(const SymmTensor& st1, const SphericalTensor& spt2) } -//- Return the square of a Vector as a SymmTensor -template -inline SymmTensor sqr(const Vector& v) -{ - return SymmTensor - ( - v.x()*v.x(), v.x()*v.y(), v.x()*v.z(), - v.y()*v.y(), v.y()*v.z(), - v.z()*v.z() - ); -} - - -//- Division of a SymmTensor by a Cmpt -template -inline SymmTensor -operator/(const SymmTensor& st, const Cmpt s) -{ - return SymmTensor - ( - st.xx()/s, st.xy()/s, st.xz()/s, - st.yy()/s, st.yz()/s, - st.zz()/s - ); -} - - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // template diff --git a/src/OpenFOAM/primitives/SymmTensor2D/SymmTensor2DI.H b/src/OpenFOAM/primitives/SymmTensor2D/SymmTensor2DI.H index edf4e7ab06..c28644c943 100644 --- a/src/OpenFOAM/primitives/SymmTensor2D/SymmTensor2DI.H +++ b/src/OpenFOAM/primitives/SymmTensor2D/SymmTensor2DI.H @@ -165,88 +165,7 @@ inline void Foam::SymmTensor2D::operator= namespace Foam { -// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // - -//- Inner-product of a SymmTensor2D and a SymmTensor2D -template -inline Tensor2D -operator&(const SymmTensor2D& st1, const SymmTensor2D& st2) -{ - return Tensor2D - ( - st1.xx()*st2.xx() + st1.xy()*st2.xy(), - st1.xx()*st2.xy() + st1.xy()*st2.yy(), - - st1.xy()*st2.xx() + st1.yy()*st2.xy(), - st1.xy()*st2.xy() + st1.yy()*st2.yy() - ); -} - - -//- Double-inner-product of a SymmTensor2D and a SymmTensor2D -template -inline Cmpt -operator&&(const SymmTensor2D& st1, const SymmTensor2D& st2) -{ - return - ( - st1.xx()*st2.xx() + 2*st1.xy()*st2.xy() - + st1.yy()*st2.yy() - ); -} - - -//- Inner-product of a SymmTensor2D and a Vector2D -template -inline Vector2D -operator&(const SymmTensor2D& st, const Vector2D& v) -{ - return Vector2D - ( - st.xx()*v.x() + st.xy()*v.y(), - st.xy()*v.x() + st.yy()*v.y() - ); -} - - -//- Inner-product of a Vector2D and a SymmTensor2D -template -inline Vector2D -operator&(const Vector2D& v, const SymmTensor2D& st) -{ - return Vector2D - ( - v.x()*st.xx() + v.y()*st.xy(), - v.x()*st.xy() + v.y()*st.yy() - ); -} - - -//- Return the inner-product of a SymmTensor2D with itself -template -inline SymmTensor2D -innerSqr(const SymmTensor2D& st) -{ - return SymmTensor2D - ( - st.xx()*st.xx() + st.xy()*st.xy(), - st.xx()*st.xy() + st.xy()*st.yy(), - st.xy()*st.xy() + st.yy()*st.yy() - ); -} - - -//- Return the square of Frobenius norm of a SymmTensor2D as a Cmpt -template -inline Cmpt magSqr(const SymmTensor2D& st) -{ - return Cmpt - ( - mag(st.xx()*st.xx()) + 2*mag(st.xy()*st.xy()) - + mag(st.yy()*st.yy()) - ); -} - +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // //- Return the trace of a SymmTensor2D template @@ -361,6 +280,46 @@ inline Cmpt invariantII(const SymmTensor2D& st) } +//- Return the inner-product of a SymmTensor2D with itself +template +inline SymmTensor2D +innerSqr(const SymmTensor2D& st) +{ + return SymmTensor2D + ( + st.xx()*st.xx() + st.xy()*st.xy(), + st.xx()*st.xy() + st.xy()*st.yy(), + st.xy()*st.xy() + st.yy()*st.yy() + ); +} + + +//- Return the square of Frobenius norm of a SymmTensor2D as a Cmpt +template +inline Cmpt magSqr(const SymmTensor2D& st) +{ + return Cmpt + ( + mag(st.xx()*st.xx()) + 2*mag(st.xy()*st.xy()) + + mag(st.yy()*st.yy()) + ); +} + + +//- Outer-product of a Vector2D with itself +template +inline SymmTensor2D sqr(const Vector2D& v) +{ + return SymmTensor2D + ( + v.x()*v.x(), v.x()*v.y(), + v.y()*v.y() + ); +} + + +// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // + //- Sum of a SphericalTensor2D and a SymmTensor2D template inline SymmTensor2D @@ -413,6 +372,35 @@ operator-(const SymmTensor2D& st1, const SphericalTensor2D& spt2) } +//- Division of a SymmTensor2D by a Cmpt +template +inline SymmTensor2D +operator/(const SymmTensor2D& st, const Cmpt s) +{ + return SymmTensor2D + ( + st.xx()/s, st.xy()/s, + st.yy()/s + ); +} + + +//- Inner-product of a SymmTensor2D and a SymmTensor2D +template +inline Tensor2D +operator&(const SymmTensor2D& st1, const SymmTensor2D& st2) +{ + return Tensor2D + ( + st1.xx()*st2.xx() + st1.xy()*st2.xy(), + st1.xx()*st2.xy() + st1.xy()*st2.yy(), + + st1.xy()*st2.xx() + st1.yy()*st2.xy(), + st1.xy()*st2.xy() + st1.yy()*st2.yy() + ); +} + + //- Inner-product of a SphericalTensor2D and a SymmTensor2D template inline SymmTensor2D @@ -439,6 +427,45 @@ operator&(const SymmTensor2D& st1, const SphericalTensor2D& spt2) } +//- Inner-product of a SymmTensor2D and a Vector2D +template +inline Vector2D +operator&(const SymmTensor2D& st, const Vector2D& v) +{ + return Vector2D + ( + st.xx()*v.x() + st.xy()*v.y(), + st.xy()*v.x() + st.yy()*v.y() + ); +} + + +//- Inner-product of a Vector2D and a SymmTensor2D +template +inline Vector2D +operator&(const Vector2D& v, const SymmTensor2D& st) +{ + return Vector2D + ( + v.x()*st.xx() + v.y()*st.xy(), + v.x()*st.xy() + v.y()*st.yy() + ); +} + + +//- Double-inner-product of a SymmTensor2D and a SymmTensor2D +template +inline Cmpt +operator&&(const SymmTensor2D& st1, const SymmTensor2D& st2) +{ + return + ( + st1.xx()*st2.xx() + 2*st1.xy()*st2.xy() + + st1.yy()*st2.yy() + ); +} + + //- Double-inner-product of a SphericalTensor2D and a SymmTensor2D template inline Cmpt @@ -457,31 +484,6 @@ operator&&(const SymmTensor2D& st1, const SphericalTensor2D& spt2) } -//- Outer-product of a Vector2D with itself -template -inline SymmTensor2D sqr(const Vector2D& v) -{ - return SymmTensor2D - ( - v.x()*v.x(), v.x()*v.y(), - v.y()*v.y() - ); -} - - -//- Division of a SymmTensor2D by a Cmpt -template -inline SymmTensor2D -operator/(const SymmTensor2D& st, const Cmpt s) -{ - return SymmTensor2D - ( - st.xx()/s, st.xy()/s, - st.yy()/s - ); -} - - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // template diff --git a/src/OpenFOAM/primitives/Tensor/TensorI.H b/src/OpenFOAM/primitives/Tensor/TensorI.H index d14549e9b2..c73d558c5f 100644 --- a/src/OpenFOAM/primitives/Tensor/TensorI.H +++ b/src/OpenFOAM/primitives/Tensor/TensorI.H @@ -610,114 +610,6 @@ inline void Foam::Tensor::operator=(const Vector>& tr) namespace Foam { -// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // - -//- Return the Hodge dual of a Tensor as a Vector -template -inline Vector operator*(const Tensor& t) -{ - return Vector(t.yz(), -t.xz(), t.xy()); -} - - -//- Return the Hodge dual of a Vector as a Tensor -template -inline Tensor operator*(const Vector& v) -{ - return Tensor - ( - Zero, -v.z(), v.y(), - v.z(), Zero, -v.x(), - -v.y(), v.x(), Zero - ); -} - - -//- Inner-product of a Tensor and a Tensor -template -inline typename innerProduct, Tensor>::type -operator&(const Tensor& t1, const Tensor& t2) -{ - return t1.inner(t2); -} - - -//- Inner-product of a Tensor and a Vector -template -inline typename innerProduct, Vector>::type -operator&(const Tensor& t, const Vector& v) -{ - return Vector - ( - t.xx()*v.x() + t.xy()*v.y() + t.xz()*v.z(), - t.yx()*v.x() + t.yy()*v.y() + t.yz()*v.z(), - t.zx()*v.x() + t.zy()*v.y() + t.zz()*v.z() - ); -} - - -//- Inner-product of a Vector and a Tensor -template -inline typename innerProduct, Tensor>::type -operator&(const Vector& v, const Tensor& t) -{ - return Vector - ( - v.x()*t.xx() + v.y()*t.yx() + v.z()*t.zx(), - v.x()*t.xy() + v.y()*t.yy() + v.z()*t.zy(), - v.x()*t.xz() + v.y()*t.yz() + v.z()*t.zz() - ); -} - - -//- Outer-product of a Vector and a Vector -template -inline typename outerProduct, Vector>::type -operator*(const Vector& v1, const Vector& v2) -{ - return Tensor - ( - v1.x()*v2.x(), v1.x()*v2.y(), v1.x()*v2.z(), - v1.y()*v2.x(), v1.y()*v2.y(), v1.y()*v2.z(), - v1.z()*v2.x(), v1.z()*v2.y(), v1.z()*v2.z() - ); -} - - -//- Division of a Vector by a Tensor -template -inline typename innerProduct, Tensor>::type -operator/(const Vector& v, const Tensor& t) -{ - return inv(t) & v; -} - - -//- Division of a Tensor by a Cmpt -template -inline Tensor -operator/(const Tensor& t, const Cmpt s) -{ - #ifdef FULLDEBUG - if (mag(s) < VSMALL) - { - FatalErrorInFunction - << "Tensor = " << t - << " is not divisible due to a zero value in Cmpt:" - << "Cmpt = " << s - << abort(FatalError); - } - #endif - - return Tensor - ( - t.xx()/s, t.xy()/s, t.xz()/s, - t.yx()/s, t.yy()/s, t.yz()/s, - t.zx()/s, t.zy()/s, t.zz()/s - ); -} - - // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // //- Return the trace of a Tensor @@ -898,7 +790,7 @@ inline Cmpt invariantIII(const Tensor& t) } -// * * * * * * * * * Mixed Tensor SphericalTensor Operators * * * * * * * * // +// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // //- Sum of a SphericalTensor and a Tensor template @@ -928,6 +820,34 @@ operator+(const Tensor& t1, const SphericalTensor& st2) } +//- Sum of a SymmTensor and a Tensor +template +inline Tensor +operator+(const SymmTensor& st1, const Tensor& t2) +{ + return Tensor + ( + st1.xx() + t2.xx(), st1.xy() + t2.xy(), st1.xz() + t2.xz(), + st1.xy() + t2.yx(), st1.yy() + t2.yy(), st1.yz() + t2.yz(), + st1.xz() + t2.zx(), st1.yz() + t2.zy(), st1.zz() + t2.zz() + ); +} + + +//- Sum of a Tensor and a SymmTensor +template +inline Tensor +operator+(const Tensor& t1, const SymmTensor& st2) +{ + return Tensor + ( + t1.xx() + st2.xx(), t1.xy() + st2.xy(), t1.xz() + st2.xz(), + t1.yx() + st2.xy(), t1.yy() + st2.yy(), t1.yz() + st2.yz(), + t1.zx() + st2.xz(), t1.zy() + st2.yz(), t1.zz() + st2.zz() + ); +} + + //- Subtract a Tensor from a SphericalTensor template inline Tensor @@ -956,118 +876,6 @@ operator-(const Tensor& t1, const SphericalTensor& st2) } -//- Inner-product of a SphericalTensor and a Tensor -template -inline Tensor -operator&(const SphericalTensor& st1, const Tensor& t2) -{ - return Tensor - ( - st1.ii()*t2.xx(), st1.ii()*t2.xy(), st1.ii()*t2.xz(), - st1.ii()*t2.yx(), st1.ii()*t2.yy(), st1.ii()*t2.yz(), - st1.ii()*t2.zx(), st1.ii()*t2.zy(), st1.ii()*t2.zz() - ); -} - - -//- Inner-product of a Tensor and a SphericalTensor -template -inline Tensor -operator&(const Tensor& t1, const SphericalTensor& st2) -{ - return Tensor - ( - t1.xx()*st2.ii(), t1.xy()*st2.ii(), t1.xz()*st2.ii(), - t1.yx()*st2.ii(), t1.yy()*st2.ii(), t1.yz()*st2.ii(), - t1.zx()*st2.ii(), t1.zy()*st2.ii(), t1.zz()*st2.ii() - ); -} - - -//- Inner-product of a SphericalTensor and a Tensor -template -inline Cmpt -operator&&(const SphericalTensor& st1, const Tensor& t2) -{ - return (st1.ii()*t2.xx() + st1.ii()*t2.yy() + st1.ii()*t2.zz()); -} - - -//- Double-inner-product of a Tensor and a SphericalTensor -template -inline Cmpt -operator&&(const Tensor& t1, const SphericalTensor& st2) -{ - return (t1.xx()*st2.ii() + t1.yy()*st2.ii() + t1.zz()*st2.ii()); -} - - -template -class typeOfSum, Tensor> -{ -public: - - typedef Tensor type; -}; - - -template -class typeOfSum, SphericalTensor> -{ -public: - - typedef Tensor type; -}; - - -template -class innerProduct, Tensor> -{ -public: - - typedef Tensor type; -}; - - -template -class innerProduct, SphericalTensor> -{ -public: - - typedef Tensor type; -}; - - -// * * * * * * * * * * Mixed Tensor SymmTensor Operators * * * * * * * * * * // - -//- Sum of a SymmTensor and a Tensor -template -inline Tensor -operator+(const SymmTensor& st1, const Tensor& t2) -{ - return Tensor - ( - st1.xx() + t2.xx(), st1.xy() + t2.xy(), st1.xz() + t2.xz(), - st1.xy() + t2.yx(), st1.yy() + t2.yy(), st1.yz() + t2.yz(), - st1.xz() + t2.zx(), st1.yz() + t2.zy(), st1.zz() + t2.zz() - ); -} - - -//- Sum of a Tensor and a SymmTensor -template -inline Tensor -operator+(const Tensor& t1, const SymmTensor& st2) -{ - return Tensor - ( - t1.xx() + st2.xx(), t1.xy() + st2.xy(), t1.xz() + st2.xz(), - t1.yx() + st2.xy(), t1.yy() + st2.yy(), t1.yz() + st2.yz(), - t1.zx() + st2.xz(), t1.zy() + st2.yz(), t1.zz() + st2.zz() - ); -} - - //- Subtract a Tensor from a SymmTensor template inline Tensor @@ -1096,6 +904,98 @@ operator-(const Tensor& t1, const SymmTensor& st2) } +//- Return the Hodge dual of a Tensor as a Vector +template +inline Vector operator*(const Tensor& t) +{ + return Vector(t.yz(), -t.xz(), t.xy()); +} + + +//- Return the Hodge dual of a Vector as a Tensor +template +inline Tensor operator*(const Vector& v) +{ + return Tensor + ( + Zero, -v.z(), v.y(), + v.z(), Zero, -v.x(), + -v.y(), v.x(), Zero + ); +} + + +//- Division of a Vector by a Tensor +template +inline typename innerProduct, Tensor>::type +operator/(const Vector& v, const Tensor& t) +{ + return inv(t) & v; +} + + +//- Division of a Tensor by a Cmpt +template +inline Tensor +operator/(const Tensor& t, const Cmpt s) +{ + #ifdef FULLDEBUG + if (mag(s) < VSMALL) + { + FatalErrorInFunction + << "Tensor = " << t + << " is not divisible due to a zero value in Cmpt:" + << "Cmpt = " << s + << abort(FatalError); + } + #endif + + return Tensor + ( + t.xx()/s, t.xy()/s, t.xz()/s, + t.yx()/s, t.yy()/s, t.yz()/s, + t.zx()/s, t.zy()/s, t.zz()/s + ); +} + + +//- Inner-product of a Tensor and a Tensor +template +inline typename innerProduct, Tensor>::type +operator&(const Tensor& t1, const Tensor& t2) +{ + return t1.inner(t2); +} + + +//- Inner-product of a SphericalTensor and a Tensor +template +inline Tensor +operator&(const SphericalTensor& st1, const Tensor& t2) +{ + return Tensor + ( + st1.ii()*t2.xx(), st1.ii()*t2.xy(), st1.ii()*t2.xz(), + st1.ii()*t2.yx(), st1.ii()*t2.yy(), st1.ii()*t2.yz(), + st1.ii()*t2.zx(), st1.ii()*t2.zy(), st1.ii()*t2.zz() + ); +} + + +//- Inner-product of a Tensor and a SphericalTensor +template +inline Tensor +operator&(const Tensor& t1, const SphericalTensor& st2) +{ + return Tensor + ( + t1.xx()*st2.ii(), t1.xy()*st2.ii(), t1.xz()*st2.ii(), + t1.yx()*st2.ii(), t1.yy()*st2.ii(), t1.yz()*st2.ii(), + t1.zx()*st2.ii(), t1.zy()*st2.ii(), t1.zz()*st2.ii() + ); +} + + //- Inner-product of a SymmTensor and a Tensor template inline Tensor @@ -1140,6 +1040,52 @@ operator&(const Tensor& t1, const SymmTensor& st2) } +//- Inner-product of a Tensor and a Vector +template +inline typename innerProduct, Vector>::type +operator&(const Tensor& t, const Vector& v) +{ + return Vector + ( + t.xx()*v.x() + t.xy()*v.y() + t.xz()*v.z(), + t.yx()*v.x() + t.yy()*v.y() + t.yz()*v.z(), + t.zx()*v.x() + t.zy()*v.y() + t.zz()*v.z() + ); +} + + +//- Inner-product of a Vector and a Tensor +template +inline typename innerProduct, Tensor>::type +operator&(const Vector& v, const Tensor& t) +{ + return Vector + ( + v.x()*t.xx() + v.y()*t.yx() + v.z()*t.zx(), + v.x()*t.xy() + v.y()*t.yy() + v.z()*t.zy(), + v.x()*t.xz() + v.y()*t.yz() + v.z()*t.zz() + ); +} + + +//- Double-inner-product of a SphericalTensor and a Tensor +template +inline Cmpt +operator&&(const SphericalTensor& st1, const Tensor& t2) +{ + return (st1.ii()*t2.xx() + st1.ii()*t2.yy() + st1.ii()*t2.zz()); +} + + +//- Double-inner-product of a Tensor and a SphericalTensor +template +inline Cmpt +operator&&(const Tensor& t1, const SphericalTensor& st2) +{ + return (t1.xx()*st2.ii() + t1.yy()*st2.ii() + t1.zz()*st2.ii()); +} + + //- Double-inner-product of a SymmTensor and a Tensor template inline Cmpt @@ -1168,6 +1114,58 @@ operator&&(const Tensor& t1, const SymmTensor& st2) } +//- Outer-product of a Vector and a Vector +template +inline typename outerProduct, Vector>::type +operator*(const Vector& v1, const Vector& v2) +{ + return Tensor + ( + v1.x()*v2.x(), v1.x()*v2.y(), v1.x()*v2.z(), + v1.y()*v2.x(), v1.y()*v2.y(), v1.y()*v2.z(), + v1.z()*v2.x(), v1.z()*v2.y(), v1.z()*v2.z() + ); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +class typeOfSum, Tensor> +{ +public: + + typedef Tensor type; +}; + + +template +class typeOfSum, SphericalTensor> +{ +public: + + typedef Tensor type; +}; + + +template +class innerProduct, Tensor> +{ +public: + + typedef Tensor type; +}; + + +template +class innerProduct, SphericalTensor> +{ +public: + + typedef Tensor type; +}; + + template class typeOfSum, Tensor> { diff --git a/src/OpenFOAM/primitives/Tensor2D/Tensor2DI.H b/src/OpenFOAM/primitives/Tensor2D/Tensor2DI.H index 3f618dbbf6..1d4523def9 100644 --- a/src/OpenFOAM/primitives/Tensor2D/Tensor2DI.H +++ b/src/OpenFOAM/primitives/Tensor2D/Tensor2DI.H @@ -405,53 +405,7 @@ inline void Foam::Tensor2D::operator=(const SphericalTensor2D& st) namespace Foam { -// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // - -//- Inner-product of a Tensor2D and a Tensor2D -template -inline typename innerProduct, Tensor2D>::type -operator&(const Tensor2D& t1, const Tensor2D& t2) -{ - return t1.inner(t2); -} - - -//- Inner-product of a Tensor2D and a Vector2D -template -inline typename innerProduct, Vector2D>::type -operator&(const Tensor2D& t, const Vector2D& v) -{ - return Vector2D - ( - t.xx()*v.x() + t.xy()*v.y(), - t.yx()*v.x() + t.yy()*v.y() - ); -} - -//- Inner-product of a Vector2D and a Tensor2D -template -inline typename innerProduct, Tensor2D>::type -operator&(const Vector2D& v, const Tensor2D& t) -{ - return Vector2D - ( - v.x()*t.xx() + v.y()*t.yx(), - v.x()*t.xy() + v.y()*t.yy() - ); -} - -//- Outer-product of a Vector2D and a Vector2D -template -inline typename outerProduct, Vector2D>::type -operator*(const Vector2D& v1, const Vector2D& v2) -{ - return Tensor2D - ( - v1.x()*v2.x(), v1.x()*v2.y(), - v1.y()*v2.x(), v1.y()*v2.y() - ); -} - +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // //- Return the trace of a Tensor2D template @@ -586,7 +540,7 @@ inline Cmpt invariantII(const Tensor2D& t) } -// * * * * * * * * * Mixed Tensor SphericalTensor Operators * * * * * * * * // +// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // //- Sum of a SphericalTensor2D and a Tensor2D template @@ -614,6 +568,32 @@ operator+(const Tensor2D& t1, const SphericalTensor2D& st2) } +//- Sum of a SymmTensor2D and a Tensor2D +template +inline Tensor2D +operator+(const SymmTensor2D& st1, const Tensor2D& t2) +{ + return Tensor2D + ( + st1.xx() + t2.xx(), st1.xy() + t2.xy(), + st1.xy() + t2.yx(), st1.yy() + t2.yy() + ); +} + + +//- Sum of a Tensor2D and a SymmTensor2D +template +inline Tensor2D +operator+(const Tensor2D& t1, const SymmTensor2D& st2) +{ + return Tensor2D + ( + t1.xx() + st2.xx(), t1.xy() + st2.xy(), + t1.yx() + st2.xy(), t1.yy() + st2.yy() + ); +} + + //- Subtract a Tensor2D from a SphericalTensor2D template inline Tensor2D @@ -640,6 +620,65 @@ operator-(const Tensor2D& t1, const SphericalTensor2D& st2) } +//- Subtract a Tensor2D from a SymmTensor2D +template +inline Tensor2D +operator-(const SymmTensor2D& st1, const Tensor2D& t2) +{ + return Tensor2D + ( + st1.xx() - t2.xx(), st1.xy() - t2.xy(), + st1.xy() - t2.yx(), st1.yy() - t2.yy() + ); +} + + +//- Subtract a SymmTensor2D from a Tensor2D +template +inline Tensor2D +operator-(const Tensor2D& t1, const SymmTensor2D& st2) +{ + return Tensor2D + ( + t1.xx() - st2.xx(), t1.xy() - st2.xy(), + t1.yx() - st2.xy(), t1.yy() - st2.yy() + ); +} + + +//- Division of a Tensor2D by a Cmpt +template +inline Tensor2D +operator/(const Tensor2D& t, const Cmpt s) +{ + #ifdef FULLDEBUG + if (mag(s) < VSMALL) + { + FatalErrorInFunction + << "Tensor2D = " << t + << " is not divisible due to a zero value in Cmpt:" + << "Cmpt = " << s + << abort(FatalError); + } + #endif + + return Tensor2D + ( + t.xx()/s, t.xy()/s, + t.yx()/s, t.yy()/s + ); +} + + +//- Inner-product of a Tensor2D and a Tensor2D +template +inline typename innerProduct, Tensor2D>::type +operator&(const Tensor2D& t1, const Tensor2D& t2) +{ + return t1.inner(t2); +} + + //- Inner-product of a SphericalTensor2D and Tensor2D template inline Tensor2D @@ -671,78 +710,6 @@ operator&(const Tensor2D& t1, const SphericalTensor2D& st2) } -//- Double-inner-product of a SphericalTensor2D and a Tensor2D -template -inline Cmpt -operator&&(const SphericalTensor2D& st1, const Tensor2D& t2) -{ - return (st1.ii()*t2.xx() + st1.ii()*t2.yy()); -} - - -//- Double-inner-product of a Tensor2D and a SphericalTensor2D -template -inline Cmpt -operator&&(const Tensor2D& t1, const SphericalTensor2D& st2) -{ - return (t1.xx()*st2.ii() + t1.yy()*st2.ii()); -} - - -// * * * * * * * * * * Mixed Tensor SymmTensor Operators * * * * * * * * * * // - -//- Sum of a SymmTensor2D and a Tensor2D -template -inline Tensor2D -operator+(const SymmTensor2D& st1, const Tensor2D& t2) -{ - return Tensor2D - ( - st1.xx() + t2.xx(), st1.xy() + t2.xy(), - st1.xy() + t2.yx(), st1.yy() + t2.yy() - ); -} - - -//- Sum of a Tensor2D and a SymmTensor2D -template -inline Tensor2D -operator+(const Tensor2D& t1, const SymmTensor2D& st2) -{ - return Tensor2D - ( - t1.xx() + st2.xx(), t1.xy() + st2.xy(), - t1.yx() + st2.xy(), t1.yy() + st2.yy() - ); -} - - -//- Subtract a Tensor2D from a SymmTensor2D -template -inline Tensor2D -operator-(const SymmTensor2D& st1, const Tensor2D& t2) -{ - return Tensor2D - ( - st1.xx() - t2.xx(), st1.xy() - t2.xy(), - st1.xy() - t2.yx(), st1.yy() - t2.yy() - ); -} - - -//- Subtract a SymmTensor2D from a Tensor2D -template -inline Tensor2D -operator-(const Tensor2D& t1, const SymmTensor2D& st2) -{ - return Tensor2D - ( - t1.xx() - st2.xx(), t1.xy() - st2.xy(), - t1.yx() - st2.xy(), t1.yy() - st2.yy() - ); -} - - //- Inner-product of a SymmTensor2D and Tensor2D template inline Tensor2D @@ -775,6 +742,51 @@ operator&(const Tensor2D& t1, const SymmTensor2D& st2) } + +//- Inner-product of a Tensor2D and a Vector2D +template +inline typename innerProduct, Vector2D>::type +operator&(const Tensor2D& t, const Vector2D& v) +{ + return Vector2D + ( + t.xx()*v.x() + t.xy()*v.y(), + t.yx()*v.x() + t.yy()*v.y() + ); +} + + +//- Inner-product of a Vector2D and a Tensor2D +template +inline typename innerProduct, Tensor2D>::type +operator&(const Vector2D& v, const Tensor2D& t) +{ + return Vector2D + ( + v.x()*t.xx() + v.y()*t.yx(), + v.x()*t.xy() + v.y()*t.yy() + ); +} + + +//- Double-inner-product of a SphericalTensor2D and a Tensor2D +template +inline Cmpt +operator&&(const SphericalTensor2D& st1, const Tensor2D& t2) +{ + return (st1.ii()*t2.xx() + st1.ii()*t2.yy()); +} + + +//- Double-inner-product of a Tensor2D and a SphericalTensor2D +template +inline Cmpt +operator&&(const Tensor2D& t1, const SphericalTensor2D& st2) +{ + return (t1.xx()*st2.ii() + t1.yy()*st2.ii()); +} + + //- Double-inner-product of a SymmTensor2D and a Tensor2D template inline Cmpt @@ -801,26 +813,15 @@ operator&&(const Tensor2D& t1, const SymmTensor2D& st2) } -//- Division of a Tensor2D by a Cmpt +//- Outer-product of a Vector2D and a Vector2D template -inline Tensor2D -operator/(const Tensor2D& t, const Cmpt s) +inline typename outerProduct, Vector2D>::type +operator*(const Vector2D& v1, const Vector2D& v2) { - #ifdef FULLDEBUG - if (mag(s) < VSMALL) - { - FatalErrorInFunction - << "Tensor2D = " << t - << " is not divisible due to a zero value in Cmpt:" - << "Cmpt = " << s - << abort(FatalError); - } - #endif - return Tensor2D ( - t.xx()/s, t.xy()/s, - t.yx()/s, t.yy()/s + v1.x()*v2.x(), v1.x()*v2.y(), + v1.y()*v2.x(), v1.y()*v2.y() ); }