/*---------------------------------------------------------------------------*\ ========= | \\ / 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 "SphericalTensor.H" #include "SymmTensor.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template inline Foam::DiagTensor::DiagTensor() {} template inline Foam::DiagTensor::DiagTensor(const Foam::zero) : VectorSpace, Cmpt, 3>(Zero) {} template template inline Foam::DiagTensor::DiagTensor ( const VectorSpace, Cmpt2, 3>& vs ) : VectorSpace, Cmpt, 3>(vs) {} template inline Foam::DiagTensor::DiagTensor ( const Cmpt& vxx, const Cmpt& vyy, const Cmpt& vzz ) { this->v_[XX] = vxx; this->v_[YY] = vyy; this->v_[ZZ] = vzz; } template inline Foam::DiagTensor::DiagTensor(const Vector& v) : VectorSpace, Cmpt, 3>(v) {} template inline Foam::DiagTensor::DiagTensor(Istream& is) : VectorSpace, Cmpt, 3>(is) {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template inline const Cmpt& Foam::DiagTensor::xx() const { return this->v_[XX]; } template inline const Cmpt& Foam::DiagTensor::yy() const { return this->v_[YY]; } template inline const Cmpt& Foam::DiagTensor::zz() const { return this->v_[ZZ]; } template inline Cmpt& Foam::DiagTensor::xx() { return this->v_[XX]; } template inline Cmpt& Foam::DiagTensor::yy() { return this->v_[YY]; } template inline Cmpt& Foam::DiagTensor::zz() { return this->v_[ZZ]; } template inline Foam::DiagTensor::operator Foam::Vector() const { return Vector(xx(), yy(), zz()); } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // template inline Tensor operator+(const DiagTensor& dt1, const Tensor& t2) { return Tensor ( dt1.xx() + t2.xx(), t2.xy(), t2.xz(), t2.yx(), dt1.yy() + t2.yy(), t2.yz(), t2.zx(), t2.zy(), dt1.zz() + t2.zz() ); } template inline Tensor operator+(const Tensor& t1, const DiagTensor& dt2) { return Tensor ( t1.xx() + dt2.xx(), t1.xy(), t1.xz(), t1.yx(), t1.yy() + dt2.yy(), t1.yz(), t1.zx(), t1.zy(), t1.zz() + dt2.zz() ); } template inline Tensor operator-(const DiagTensor& dt1, const Tensor& t2) { return Tensor ( dt1.xx() - t2.xx(), -t2.xy(), -t2.xz(), -t2.yx(), dt1.yy() - t2.yy(), -t2.yz(), -t2.zx(), -t2.zy(), dt1.zz() - t2.zz() ); } template inline Tensor operator-(const Tensor& t1, const DiagTensor& dt2) { return Tensor ( t1.xx() - dt2.xx(), t1.xy(), t1.xz(), t1.yx(), t1.yy() - dt2.yy(), t1.yz(), t1.zx(), t1.zy(), t1.zz() - dt2.zz() ); } template inline SymmTensor operator+(const DiagTensor& dt1, const SymmTensor& t2) { return SymmTensor ( dt1.xx() + t2.xx(), t2.xy(), t2.xz(), dt1.yy() + t2.yy(), t2.yz(), dt1.zz() + t2.zz() ); } template inline SymmTensor operator+(const SymmTensor& t1, const DiagTensor& dt2) { return SymmTensor ( t1.xx() + dt2.xx(), t1.xy(), t1.xz(), t1.yy() + dt2.yy(), t1.yz(), t1.zz() + dt2.zz() ); } template inline SymmTensor operator-(const DiagTensor& dt1, const SymmTensor& t2) { return SymmTensor ( dt1.xx() - t2.xx(), -t2.xy(), -t2.xz(), dt1.yy() - t2.yy(), -t2.yz(), dt1.zz() - t2.zz() ); } template inline SymmTensor operator-(const SymmTensor& t1, const DiagTensor& dt2) { return SymmTensor ( t1.xx() - dt2.xx(), t1.xy(), t1.xz(), t1.yy() - dt2.yy(), t1.yz(), t1.zz() - dt2.zz() ); } //- Inner-product between two diagonal tensors template inline DiagTensor operator&(const DiagTensor& dt1, const DiagTensor& dt2) { return DiagTensor ( dt1.xx()*dt2.xx(), dt1.yy()*dt2.yy(), dt1.zz()*dt2.zz() ); } //- Inner-product between a diagonal tensor and a tensor template inline Tensor operator&(const DiagTensor& dt1, const Tensor& t2) { return Tensor ( 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() ); } //- Inner-product between a tensor and a diagonal tensor template inline Tensor operator&(const Tensor& t1, const DiagTensor& dt2) { return Tensor ( 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() ); } //- Inner-product between a diagonal tensor and a vector template inline Vector operator&(const DiagTensor& dt, const Vector& v) { return Vector ( dt.xx()*v.x(), dt.yy()*v.y(), dt.zz()*v.z() ); } //- Inner-product between a vector and a diagonal tensor template inline Vector operator&(const Vector& v, const DiagTensor& dt) { return Vector ( v.x()*dt.xx(), v.y()*dt.yy(), v.z()*dt.zz() ); } //- Division of a scalar by a diagonalTensor template inline DiagTensor operator/(const scalar s, const DiagTensor& dt) { return DiagTensor(s/dt.xx(), s/dt.yy(), s/dt.zz()); } //- Division of a vector by a diagonal tensor template inline Vector operator/(const Vector v, const DiagTensor& dt) { return Vector(v.x()/dt.xx(), v.y()/dt.yy(), v.z()/dt.zz()); } //- Return the transpose of a diagonal tensor template inline const DiagTensor& T(const DiagTensor& dt) { return dt; } //- Return the trace of a diagonal tensor template inline Cmpt tr(const DiagTensor& dt) { return dt.xx() + dt.yy() + dt.zz(); } //- Return the spherical part of a diagonal tensor template inline SphericalTensor sph(const DiagTensor& dt) { return 0.5*tr(dt); } //- Return the determinant of a diagonal tensor template inline Cmpt det(const DiagTensor& t) { return t.xx()*t.yy()*t.zz(); } //- Return the inverse of a diagonal tensor template inline DiagTensor inv(const DiagTensor& dt) { return DiagTensor(1.0/dt.xx(), 1.0/dt.yy(), 1.0/dt.zz()); } //- Return the diagonal of a symmetric tensor as a diagonal tensor template inline DiagTensor diag(const SymmTensor& t) { return DiagTensor(t.xx(), t.yy(), t.zz()); } //- Return the diagonal of a tensor as a diagonal tensor template inline DiagTensor diag(const Tensor& t) { return DiagTensor(t.xx(), t.yy(), t.zz()); } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam // ************************************************************************* //