/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Copyright (C) 2011-2026 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . \*---------------------------------------------------------------------------*/ #include "Vector.H" #include "Tensor.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template inline Foam::SymmTensor::SymmTensor() {} template inline Foam::SymmTensor::SymmTensor(const Foam::zero) : SymmTensor::vsType(Zero) {} template template inline Foam::SymmTensor::SymmTensor ( const VectorSpace, Cmpt2, 6>& vs ) : SymmTensor::vsType(vs) {} template inline Foam::SymmTensor::SymmTensor(const SphericalTensor& st) { this->v_[XX] = st.ii(); this->v_[XY] = 0; this->v_[XZ] = 0; this->v_[YY] = st.ii(); this->v_[YZ] = 0; this->v_[ZZ] = st.ii(); } template inline Foam::SymmTensor::SymmTensor ( const Cmpt txx, const Cmpt txy, const Cmpt txz, const Cmpt tyy, const Cmpt tyz, const Cmpt tzz ) { this->v_[XX] = txx; this->v_[XY] = txy; this->v_[XZ] = txz; this->v_[YY] = tyy; this->v_[YZ] = tyz; this->v_[ZZ] = tzz; } template inline Foam::SymmTensor::SymmTensor(Istream& is) : SymmTensor::vsType(is) {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template inline const Cmpt& Foam::SymmTensor::xx() const { return this->v_[XX]; } template inline const Cmpt& Foam::SymmTensor::xy() const { return this->v_[XY]; } template inline const Cmpt& Foam::SymmTensor::xz() const { return this->v_[XZ]; } template inline const Cmpt& Foam::SymmTensor::yx() const { return this->v_[XY]; } template inline const Cmpt& Foam::SymmTensor::yy() const { return this->v_[YY]; } template inline const Cmpt& Foam::SymmTensor::yz() const { return this->v_[YZ]; } template inline const Cmpt& Foam::SymmTensor::zx() const { return this->v_[XZ]; } template inline const Cmpt& Foam::SymmTensor::zy() const { return this->v_[YZ]; } template inline const Cmpt& Foam::SymmTensor::zz() const { return this->v_[ZZ]; } template inline Cmpt& Foam::SymmTensor::xx() { return this->v_[XX]; } template inline Cmpt& Foam::SymmTensor::xy() { return this->v_[XY]; } template inline Cmpt& Foam::SymmTensor::xz() { return this->v_[XZ]; } template inline Cmpt& Foam::SymmTensor::yy() { return this->v_[YY]; } template inline Cmpt& Foam::SymmTensor::yz() { return this->v_[YZ]; } template inline Cmpt& Foam::SymmTensor::zz() { return this->v_[ZZ]; } template inline const Foam::SymmTensor& Foam::SymmTensor::T() const { return *this; } // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template inline void Foam::SymmTensor::operator=(const SphericalTensor& st) { this->v_[XX] = st.ii(); this->v_[XY] = 0; this->v_[XZ] = 0; this->v_[YY] = st.ii(); this->v_[YZ] = 0; this->v_[ZZ] = st.ii(); } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // //- Hodge Dual operator (tensor -> vector) template inline Vector operator*(const SymmTensor& st) { return Vector(st.yz(), -st.xz(), st.xy()); } //- Inner-product between two symmetric tensors 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-dot-product between a symmetric tensor and a symmetric tensor 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 between a symmetric tensor 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 between a vector and a symmetric tensor 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() ); } //- Inner-sqr of a symmetric tensor 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() ); } template inline Cmpt magSqr(const SymmTensor& st) { return ( magSqr(st.xx()) + 2*magSqr(st.xy()) + 2*magSqr(st.xz()) + magSqr(st.yy()) + 2*magSqr(st.yz()) + magSqr(st.zz()) ); } //- Return the transpose of a symmetric tensor template inline const SymmTensor& T(const SymmTensor& st) { return st; } //- Return the trace of a symmetric tensor template inline Cmpt tr(const SymmTensor& st) { return st.xx() + st.yy() + st.zz(); } //- Return the spherical part of a symmetric tensor template inline SphericalTensor sph(const SymmTensor& st) { return (1.0/3.0)*tr(st); } //- Return the symmetric part of a symmetric tensor, i.e. itself template inline const SymmTensor& symm(const SymmTensor& st) { return st; } //- Return twice the symmetric part of a symmetric tensor template inline SymmTensor twoSymm(const SymmTensor& st) { return 2*st; } //- Return the deviatoric part of a symmetric tensor template inline SymmTensor dev(const SymmTensor& st) { return st - SphericalTensor::oneThirdI*tr(st); } //- Return the deviatoric part of a symmetric tensor template inline SymmTensor dev2(const SymmTensor& st) { return st - SphericalTensor::twoThirdsI*tr(st); } //- Return the determinant of a symmetric tensor template inline Cmpt det(const SymmTensor& st) { return ( st.xx()*st.yy()*st.zz() + st.xy()*st.yz()*st.xz() + st.xz()*st.xy()*st.yz() - st.xx()*st.yz()*st.yz() - st.xy()*st.xy()*st.zz() - st.xz()*st.yy()*st.xz() ); } //- Return the cofactor symmetric tensor of a symmetric tensor template inline SymmTensor cof(const SymmTensor& st) { return SymmTensor ( st.yy()*st.zz() - st.yz()*st.yz(), st.xz()*st.yz() - st.xy()*st.zz(), st.xy()*st.yz() - st.xz()*st.yy(), st.xx()*st.zz() - st.xz()*st.xz(), st.xy()*st.xz() - st.xx()*st.yz(), st.xx()*st.yy() - st.xy()*st.xy() ); } //- Return the inverse of a symmetric tensor give the determinant template inline SymmTensor inv(const SymmTensor& st, const Cmpt detst) { return SymmTensor ( st.yy()*st.zz() - st.yz()*st.yz(), st.xz()*st.yz() - st.xy()*st.zz(), st.xy()*st.yz() - st.xz()*st.yy(), st.xx()*st.zz() - st.xz()*st.xz(), st.xy()*st.xz() - st.xx()*st.yz(), st.xx()*st.yy() - st.xy()*st.xy() )/detst; } //- Return the inverse of a symmetric tensor template inline SymmTensor inv(const SymmTensor& st) { return inv(st, det(st)); } //- Return the 1st invariant of a symmetric tensor template inline Cmpt invariantI(const SymmTensor& st) { return tr(st); } //- Return the 2nd invariant of a symmetric tensor template inline Cmpt invariantII(const SymmTensor& st) { return ( st.xx()*st.yy() + st.yy()*st.zz() + st.xx()*st.zz() - sqr(st.xy()) - sqr(st.yz()) - sqr(st.xz()) ); } //- Return the 3rd invariant of a symmetric tensor template inline Cmpt invariantIII(const SymmTensor& st) { return det(st); } template inline SymmTensor operator+(const SphericalTensor& spt1, const SymmTensor& st2) { return SymmTensor ( spt1.ii() + st2.xx(), st2.xy(), st2.xz(), spt1.ii() + st2.yy(), st2.yz(), spt1.ii() + st2.zz() ); } template inline SymmTensor operator+(const SymmTensor& st1, const SphericalTensor& spt2) { return SymmTensor ( st1.xx() + spt2.ii(), st1.xy(), st1.xz(), st1.yy() + spt2.ii(), st1.yz(), st1.zz() + spt2.ii() ); } template inline SymmTensor operator-(const SphericalTensor& spt1, const SymmTensor& st2) { return SymmTensor ( spt1.ii() - st2.xx(), -st2.xy(), -st2.xz(), spt1.ii() - st2.yy(), -st2.yz(), spt1.ii() - st2.zz() ); } template inline SymmTensor operator-(const SymmTensor& st1, const SphericalTensor& spt2) { return SymmTensor ( st1.xx() - spt2.ii(), st1.xy(), st1.xz(), st1.yy() - spt2.ii(), st1.yz(), st1.zz() - spt2.ii() ); } //- Inner-product between a spherical symmetric tensor and a symmetric tensor template inline SymmTensor operator&(const SphericalTensor& spt1, const SymmTensor& st2) { return SymmTensor ( spt1.ii()*st2.xx(), spt1.ii()*st2.xy(), spt1.ii()*st2.xz(), spt1.ii()*st2.yy(), spt1.ii()*st2.yz(), spt1.ii()*st2.zz() ); } //- Inner-product between a tensor and a spherical tensor template inline SymmTensor operator&(const SymmTensor& st1, const SphericalTensor& spt2) { return SymmTensor ( st1.xx()*spt2.ii(), st1.xy()*spt2.ii(), st1.xz()*spt2.ii(), st1.yy()*spt2.ii(), st1.yz()*spt2.ii(), st1.zz()*spt2.ii() ); } //- Double-dot-product between a spherical tensor and a symmetric tensor template inline Cmpt operator&&(const SphericalTensor& spt1, const SymmTensor& st2) { return(spt1.ii()*st2.xx() + spt1.ii()*st2.yy() + spt1.ii()*st2.zz()); } //- Double-dot-product between a tensor and a spherical tensor template inline Cmpt operator&&(const SymmTensor& st1, const SphericalTensor& spt2) { return(st1.xx()*spt2.ii() + st1.yy()*spt2.ii() + st1.zz()*spt2.ii()); } 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() ); } template class outerProduct, Cmpt> { public: typedef SymmTensor type; }; template class outerProduct> { public: typedef SymmTensor type; }; template class innerProduct, SymmTensor> { public: typedef Tensor type; }; template class innerProduct, Vector> { public: typedef Vector type; }; template class innerProduct, SymmTensor> { public: typedef Vector type; }; template class typeOfSum, SymmTensor> { public: typedef SymmTensor type; }; template class typeOfSum, SphericalTensor> { public: typedef SymmTensor type; }; template class innerProduct, SymmTensor> { public: typedef SymmTensor type; }; template class innerProduct, SphericalTensor> { public: typedef SymmTensor type; }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam // ************************************************************************* //