OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

SphericalTensorI.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "Vector.H"
00028 
00029 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033 
00034 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00035 
00036 // Construct null
00037 template <class Cmpt>
00038 inline SphericalTensor<Cmpt>::SphericalTensor()
00039 {}
00040 
00041 
00042 // Construct given VectorSpace
00043 template <class Cmpt>
00044 inline SphericalTensor<Cmpt>::SphericalTensor
00045 (
00046     const VectorSpace<SphericalTensor<Cmpt>, Cmpt, 1>& vs
00047 )
00048 :
00049     VectorSpace<SphericalTensor<Cmpt>, Cmpt, 1>(vs)
00050 {}
00051 
00052 
00053 // Construct given three Cmpts
00054 template <class Cmpt>
00055 inline SphericalTensor<Cmpt>::SphericalTensor(const Cmpt& stii)
00056 {
00057     this->v_[II] = stii;
00058 }
00059 
00060 
00061 // Construct from Istream
00062 template <class Cmpt>
00063 inline SphericalTensor<Cmpt>::SphericalTensor(Istream& is)
00064 :
00065     VectorSpace<SphericalTensor<Cmpt>, Cmpt, 1>(is)
00066 {}
00067 
00068 
00069 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00070 
00071 template <class Cmpt>
00072 inline const Cmpt&  SphericalTensor<Cmpt>::ii() const
00073 {
00074     return this->v_[II];
00075 }
00076 
00077 
00078 template <class Cmpt>
00079 inline Cmpt& SphericalTensor<Cmpt>::ii()
00080 {
00081     return this->v_[II];
00082 }
00083 
00084 
00085 template <class Cmpt>
00086 inline const SphericalTensor<Cmpt>& SphericalTensor<Cmpt>::T() const
00087 {
00088     return *this;
00089 }
00090 
00091 
00092 // * * * * * * * * * * * * * * * Global Operators  * * * * * * * * * * * * * //
00093 
00094 //- Inner-product between two spherical tensors
00095 template <class Cmpt>
00096 inline SphericalTensor<Cmpt>
00097 operator&(const SphericalTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& st2)
00098 {
00099     return SphericalTensor<Cmpt>(st1.ii()*st2.ii());
00100 }
00101 
00102 
00103 //- Inner-product between a spherical tensor and a vector
00104 template <class Cmpt>
00105 inline Vector<Cmpt>
00106 operator&(const SphericalTensor<Cmpt>& st, const Vector<Cmpt>& v)
00107 {
00108     return Vector<Cmpt>
00109     (
00110         st.ii()*v.x(),
00111                        st.ii()*v.y(),
00112                                       st.ii()*v.z()
00113     );
00114 }
00115 
00116 
00117 //- Inner-product between a vector and a spherical tensor
00118 template <class Cmpt>
00119 inline Vector<Cmpt>
00120 operator&(const Vector<Cmpt>& v, const SphericalTensor<Cmpt>& st)
00121 {
00122     return Vector<Cmpt>
00123     (
00124         v.x()*st.ii(),
00125                        v.y()*st.ii(),
00126                                       v.z()*st.ii()
00127     );
00128 }
00129 
00130 
00131 //- Double-dot-product between a spherical tensor and a spherical tensor
00132 template <class Cmpt>
00133 inline Cmpt
00134 operator&&(const SphericalTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& st2)
00135 {
00136     return 3*st1.ii()*st2.ii();
00137 }
00138 
00139 
00140 //- Division of a scalar by a sphericalTensor
00141 template <class Cmpt>
00142 inline SphericalTensor<Cmpt>
00143 operator/(const scalar s, const SphericalTensor<Cmpt>& st)
00144 {
00145     return SphericalTensor<Cmpt>(s/st.ii());
00146 }
00147 
00148 
00149 template <class Cmpt>
00150 inline Cmpt magSqr(const SphericalTensor<Cmpt>& st)
00151 {
00152     return 3*magSqr(st.ii());
00153 }
00154 
00155 
00156 //- Return the trace of a spherical tensor
00157 template <class Cmpt>
00158 inline Cmpt tr(const SphericalTensor<Cmpt>& st)
00159 {
00160     return 3*st.ii();
00161 }
00162 
00163 
00164 //- Return the spherical part of a spherical tensor, i.e. itself
00165 template <class Cmpt>
00166 inline SphericalTensor<Cmpt> sph(const SphericalTensor<Cmpt>& st)
00167 {
00168     return st;
00169 }
00170 
00171 
00172 //- Return the determinant of a spherical tensor
00173 template <class Cmpt>
00174 inline Cmpt det(const SphericalTensor<Cmpt>& st)
00175 {
00176     return st.ii()*st.ii()*st.ii();
00177 }
00178 
00179 
00180 //- Return the inverse of a spherical tensor
00181 template <class Cmpt>
00182 inline SphericalTensor<Cmpt> inv(const SphericalTensor<Cmpt>& st)
00183 {
00184     return SphericalTensor<Cmpt>(1.0/st.ii());
00185 }
00186 
00187 
00188 template<class Cmpt>
00189 class outerProduct<SphericalTensor<Cmpt>, Cmpt>
00190 {
00191 public:
00192 
00193     typedef SphericalTensor<Cmpt> type;
00194 };
00195 
00196 template<class Cmpt>
00197 class outerProduct<Cmpt, SphericalTensor<Cmpt> >
00198 {
00199 public:
00200 
00201     typedef SphericalTensor<Cmpt> type;
00202 };
00203 
00204 
00205 template<class Cmpt>
00206 class innerProduct<SphericalTensor<Cmpt>, SphericalTensor<Cmpt> >
00207 {
00208 public:
00209 
00210     typedef SphericalTensor<Cmpt> type;
00211 };
00212 
00213 
00214 template<class Cmpt>
00215 class innerProduct<SphericalTensor<Cmpt>, Vector<Cmpt> >
00216 {
00217 public:
00218 
00219     typedef Vector<Cmpt> type;
00220 };
00221 
00222 template<class Cmpt>
00223 class innerProduct<Vector<Cmpt>, SphericalTensor<Cmpt> >
00224 {
00225 public:
00226 
00227     typedef Vector<Cmpt> type;
00228 };
00229 
00230 
00231 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00232 
00233 } // End namespace Foam
00234 
00235 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd