/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2018 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 "error.H" #include "products.H" #include "VectorSpaceOps.H" #include "ops.H" #include // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template inline VectorSpace::VectorSpace() {} template inline VectorSpace::VectorSpace(const Foam::zero) { VectorSpaceOps::eqOpS(*this, Zero, eqOp()); } template inline VectorSpace::VectorSpace ( const VectorSpace& vs ) { VectorSpaceOps::eqOp(*this, vs, eqOp()); } template template inline VectorSpace::VectorSpace ( const VectorSpace& vs ) { VectorSpaceOps::eqOp(*this, vs, eqOp()); } template template inline VectorSpace::ConstBlock::ConstBlock ( const vsType& vs ) : vs_(vs) { static_assert ( vsType::nComponents >= BStart + nComponents, "Requested block size > VectorSpace size" ); } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template inline direction VectorSpace::size() { return Ncmpts; } template inline const Cmpt& VectorSpace::component ( const direction d ) const { #ifdef FULLDEBUG if (d >= Ncmpts) { FatalErrorInFunction << "index out of range" << abort(FatalError); } #endif return v_[d]; } template inline Cmpt& VectorSpace::component ( const direction d ) { #ifdef FULLDEBUG if (d >= Ncmpts) { FatalErrorInFunction << "index out of range" << abort(FatalError); } #endif return v_[d]; } template inline void VectorSpace::component ( Cmpt& c, const direction d ) const { #ifdef FULLDEBUG if (d >= Ncmpts) { FatalErrorInFunction << "index out of range" << abort(FatalError); } #endif c = v_[d]; } template inline void VectorSpace::replace ( const direction d, const Cmpt& c ) { #ifdef FULLDEBUG if (d >= Ncmpts) { FatalErrorInFunction << "index out of range" << abort(FatalError); } #endif v_[d] = c; } template inline Form VectorSpace::uniform(const Cmpt& s) { Form v; VectorSpaceOps::eqOpS(v, s, eqOp()); return v; } template template inline const typename VectorSpace::template ConstBlock VectorSpace::block() const { return *this; } // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template inline const Cmpt& VectorSpace::operator[] ( const direction d ) const { #ifdef FULLDEBUG if (d >= Ncmpts) { FatalErrorInFunction << "index out of range" << abort(FatalError); } #endif return v_[d]; } template inline Cmpt& VectorSpace::operator[] ( const direction d ) { #ifdef FULLDEBUG if (d >= Ncmpts) { FatalErrorInFunction << "index out of range" << abort(FatalError); } #endif return v_[d]; } template template inline const Cmpt& VectorSpace:: ConstBlock::operator[] ( const direction i ) const { #ifdef FULLDEBUG if (i >= Ncmpts) { FatalErrorInFunction << "index out of range" << abort(FatalError); } #endif return vs_[BStart + i]; } template template inline const Cmpt& VectorSpace:: ConstBlock::operator() ( const direction i, const direction j ) const { #ifdef FULLDEBUG if (i >= Ncmpts) { FatalErrorInFunction << "index out of range" << abort(FatalError); } if (j != 0) { FatalErrorInFunction << "j != 0" << abort(FatalError); } #endif return vs_[BStart + i]; } template inline void VectorSpace::operator= ( const VectorSpace& vs ) { VectorSpaceOps::eqOp(*this, vs, eqOp()); } template inline void VectorSpace::operator+= ( const VectorSpace& vs ) { VectorSpaceOps::eqOp(*this, vs, plusEqOp()); } template inline void VectorSpace::operator-= ( const VectorSpace& vs ) { VectorSpaceOps::eqOp(*this, vs, minusEqOp()); } template inline void VectorSpace::operator=(const Foam::zero) { VectorSpaceOps::eqOpS(*this, 0, eqOp()); } template inline void VectorSpace::operator*= ( const scalar s ) { VectorSpaceOps::eqOpS(*this, s, multiplyEqOp2()); } template inline void VectorSpace::operator/= ( const scalar s ) { VectorSpaceOps::eqOpS(*this, s, divideEqOp2()); } // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // template inline Cmpt& setComponent ( VectorSpace& vs, const direction d ) { return vs.component(d); } template inline const Cmpt& component ( const VectorSpace& vs, const direction d ) { return vs.component(d); } // Powers of a Form // Equivalent to outer-products between the Form and itself // Form^0 = 1.0 template inline typename powProduct::type pow ( const VectorSpace&, typename powProduct::type = pTraits::type>::zero ) { return 1.0; } // Form^1 = Form template inline typename powProduct::type pow ( const VectorSpace& v, typename powProduct::type = pTraits::type>::zero ) { return static_cast(v); } // Form^2 = sqr(Form) template inline typename powProduct::type pow ( const VectorSpace& v, typename powProduct::type = pTraits::type>::zero ) { return sqr(static_cast(v)); } template inline scalar magSqr ( const VectorSpace& vs ) { scalar ms = magSqr(vs.v_[0]); VectorSpaceOps::SeqOp(ms, vs, plusEqMagSqrOp2()); return ms; } template inline scalar mag ( const VectorSpace& vs ) { return ::sqrt(magSqr(static_cast(vs))); } template inline VectorSpace normalised ( const VectorSpace& vs ) { const scalar magVs = mag(vs); return magVs > 0 ? vs/magVs : Zero; } template inline VectorSpace cmptMultiply ( const VectorSpace& vs1, const VectorSpace& vs2 ) { Form v; VectorSpaceOps::op(v, vs1, vs2, cmptMultiplyOp()); return v; } template inline VectorSpace cmptPow ( const VectorSpace& vs1, const VectorSpace& vs2 ) { Form v; VectorSpaceOps::op(v, vs1, vs2, cmptPowOp()); return v; } template inline VectorSpace cmptDivide ( const VectorSpace& vs1, const VectorSpace& vs2 ) { Form v; VectorSpaceOps::op(v, vs1, vs2, cmptDivideOp()); return v; } template inline VectorSpace stabilise ( const VectorSpace& vs, const Cmpt& small ) { Form v; VectorSpaceOps::opVS(v, vs, small, stabiliseOp()); return v; } template inline Cmpt cmptMax ( const VectorSpace& vs ) { Cmpt cMax = vs.v_[0]; VectorSpaceOps::SeqOp(cMax, vs, maxEqOp()); return cMax; } template inline Cmpt cmptMin ( const VectorSpace& vs ) { Cmpt cMin = vs.v_[0]; VectorSpaceOps::SeqOp(cMin, vs, minEqOp()); return cMin; } template inline Cmpt cmptSum ( const VectorSpace& vs ) { Cmpt sum = vs.v_[0]; VectorSpaceOps::SeqOp(sum, vs, plusEqOp()); return sum; } template inline Cmpt cmptAv ( const VectorSpace& vs ) { return cmptSum(vs)/Ncmpts; } template inline Cmpt cmptProduct ( const VectorSpace& vs ) { Cmpt product = vs.v_[0]; VectorSpaceOps::SeqOp(product, vs, multiplyEqOp()); return product; } template inline Form cmptSqr ( const VectorSpace& vs ) { Form v; VectorSpaceOps::eqOp(v, vs, eqSqrOp()); return v; } template inline Form cmptMag ( const VectorSpace& vs ) { Form v; VectorSpaceOps::eqOp(v, vs, eqMagOp()); return v; } template inline Form max ( const VectorSpace& vs1, const VectorSpace& vs2 ) { Form v; VectorSpaceOps::op(v, vs1, vs2, maxOp()); return v; } template inline Form min ( const VectorSpace& vs1, const VectorSpace& vs2 ) { Form v; VectorSpaceOps::op(v, vs1, vs2, minOp()); return v; } template inline Form minMod ( const VectorSpace& vs1, const VectorSpace& vs2 ) { Form v; VectorSpaceOps::op(v, vs1, vs2, minModOp()); return v; } template inline Type dot(const scalar s, const Type& t) { return s * t; } template inline Type dot(const Type& t, const scalar s) { return t * s; } template < class Form1, class Cmpt1, direction Ncmpts1, class Form2, class Cmpt2, direction Ncmpts2 > inline typename innerProduct::type dot ( const VectorSpace& t1, const VectorSpace& t2 ) { return static_cast(t1) & static_cast(t2); } // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // template inline Form operator- ( const VectorSpace& vs ) { Form v; VectorSpaceOps::eqOp(v, vs, eqMinusOp()); return v; } template inline Form operator+ ( const VectorSpace& vs1, const VectorSpace& vs2 ) { Form v; VectorSpaceOps::op(v, vs1, vs2, plusOp()); return v; } template inline Form operator- ( const VectorSpace& vs1, const VectorSpace& vs2 ) { Form v; VectorSpaceOps::op(v, vs1, vs2, minusOp()); return v; } template inline Form operator* ( scalar s, const VectorSpace& vs ) { Form v; VectorSpaceOps::opSV(v, s, vs, multiplyOp3()); return v; } template inline Form operator* ( const VectorSpace& vs, scalar s ) { Form v; VectorSpaceOps::opVS(v, vs, s, multiplyOp3()); return v; } template inline Form operator/ ( const VectorSpace& vs, scalar s ) { Form v; VectorSpaceOps::opVS(v, vs, s, divideOp3()); return v; } /* template inline Form operator/ ( const VectorSpace& vs1, const VectorSpace& vs2 ) { Form v; VectorSpaceOps::op(v, vs1, vs2, divideOp()); return v; } template inline Form operator/ ( scalar s, const VectorSpace& vs ) { Form v; VectorSpaceOps::opSV(v, s, vs, divideOp2()); return v; } */ template inline Cmpt operator&& ( const VectorSpace& vs1, const VectorSpace& vs2 ) { Cmpt ddProd = vs1.v_[0]*vs2.v_[0]; for (direction i=1; i inline bool operator== ( const VectorSpace& vs1, const VectorSpace& vs2 ) { bool eq = true; for (direction i=0; i inline bool operator!= ( const VectorSpace& vs1, const VectorSpace& vs2 ) { return !(vs1 == vs2); } template inline bool operator> ( const VectorSpace& vs1, const VectorSpace& vs2 ) { bool gt = true; for (direction i=0; i vs2.v_[i])) break; } return gt; } template inline bool operator< ( const VectorSpace& vs1, const VectorSpace& vs2 ) { bool lt = true; for (direction i=0; i inline bool operator>= ( const VectorSpace& vs1, const VectorSpace& vs2 ) { return !(vs1 < vs2); } template inline bool operator<= ( const VectorSpace& vs1, const VectorSpace& vs2 ) { return !(vs1 > vs2); } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam // ************************************************************************* //