FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include <OpenFOAM/Vector_.H>
00027 
00028 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00029 
00030 namespace Foam
00031 {
00032 
00033 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00034 
00035 // Construct null
00036 template <class Cmpt>
00037 inline SphericalTensor<Cmpt>::SphericalTensor()
00038 {}
00039 
00040 
00041 // Construct given VectorSpace
00042 template <class Cmpt>
00043 inline SphericalTensor<Cmpt>::SphericalTensor
00044 (
00045     const VectorSpace<SphericalTensor<Cmpt>, Cmpt, 1>& vs
00046 )
00047 :
00048     VectorSpace<SphericalTensor<Cmpt>, Cmpt, 1>(vs)
00049 {}
00050 
00051 
00052 // Construct given three Cmpts
00053 template <class Cmpt>
00054 inline SphericalTensor<Cmpt>::SphericalTensor(const Cmpt& stii)
00055 {
00056     this->v_[II] = stii;
00057 }
00058 
00059 
00060 // Construct from Istream
00061 template <class Cmpt>
00062 inline SphericalTensor<Cmpt>::SphericalTensor(Istream& is)
00063 :
00064     VectorSpace<SphericalTensor<Cmpt>, Cmpt, 1>(is)
00065 {}
00066 
00067 
00068 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00069 
00070 template <class Cmpt>
00071 inline const Cmpt&  SphericalTensor<Cmpt>::ii() const
00072 {
00073     return this->v_[II];
00074 }
00075 
00076 
00077 template <class Cmpt>
00078 inline Cmpt& SphericalTensor<Cmpt>::ii()
00079 {
00080     return this->v_[II];
00081 }
00082 
00083 
00084 template <class Cmpt>
00085 inline const SphericalTensor<Cmpt>& SphericalTensor<Cmpt>::T() const
00086 {
00087     return *this;
00088 }
00089 
00090 
00091 // * * * * * * * * * * * * * * * Global Operators  * * * * * * * * * * * * * //
00092 
00093 //- Inner-product between two spherical tensors
00094 template <class Cmpt>
00095 inline SphericalTensor<Cmpt>
00096 operator&(const SphericalTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& st2)
00097 {
00098     return SphericalTensor<Cmpt>(st1.ii()*st2.ii());
00099 }
00100 
00101 
00102 //- Inner-product between a spherical tensor and a vector
00103 template <class Cmpt>
00104 inline Vector<Cmpt>
00105 operator&(const SphericalTensor<Cmpt>& st, const Vector<Cmpt>& v)
00106 {
00107     return Vector<Cmpt>
00108     (
00109         st.ii()*v.x(),
00110                        st.ii()*v.y(),
00111                                       st.ii()*v.z()
00112     );
00113 }
00114 
00115 
00116 //- Inner-product between a vector and a spherical tensor
00117 template <class Cmpt>
00118 inline Vector<Cmpt>
00119 operator&(const Vector<Cmpt>& v, const SphericalTensor<Cmpt>& st)
00120 {
00121     return Vector<Cmpt>
00122     (
00123         v.x()*st.ii(),
00124                        v.y()*st.ii(),
00125                                       v.z()*st.ii()
00126     );
00127 }
00128 
00129 
00130 //- Double-dot-product between a spherical tensor and a spherical tensor
00131 template <class Cmpt>
00132 inline Cmpt
00133 operator&&(const SphericalTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& st2)
00134 {
00135     return 3*st1.ii()*st2.ii();
00136 }
00137 
00138 
00139 //- Division of a scalar by a sphericalTensor
00140 template <class Cmpt>
00141 inline SphericalTensor<Cmpt>
00142 operator/(const scalar s, const SphericalTensor<Cmpt>& st)
00143 {
00144     return SphericalTensor<Cmpt>(s/st.ii());
00145 }
00146 
00147 
00148 template <class Cmpt>
00149 inline Cmpt magSqr(const SphericalTensor<Cmpt>& st)
00150 {
00151     return 3*magSqr(st.ii());
00152 }
00153 
00154 
00155 //- Return the trace of a spherical tensor
00156 template <class Cmpt>
00157 inline Cmpt tr(const SphericalTensor<Cmpt>& st)
00158 {
00159     return 3*st.ii();
00160 }
00161 
00162 
00163 //- Return the spherical part of a spherical tensor, i.e. itself
00164 template <class Cmpt>
00165 inline SphericalTensor<Cmpt> sph(const SphericalTensor<Cmpt>& st)
00166 {
00167     return st;
00168 }
00169 
00170 
00171 //- Return the determinant of a spherical tensor
00172 template <class Cmpt>
00173 inline Cmpt det(const SphericalTensor<Cmpt>& st)
00174 {
00175     return st.ii()*st.ii()*st.ii();
00176 }
00177 
00178 
00179 //- Return the inverse of a spherical tensor
00180 template <class Cmpt>
00181 inline SphericalTensor<Cmpt> inv(const SphericalTensor<Cmpt>& st)
00182 {
00183     return SphericalTensor<Cmpt>(1.0/st.ii());
00184 }
00185 
00186 
00187 template<class Cmpt>
00188 class outerProduct<SphericalTensor<Cmpt>, Cmpt>
00189 {
00190 public:
00191 
00192     typedef SphericalTensor<Cmpt> type;
00193 };
00194 
00195 template<class Cmpt>
00196 class outerProduct<Cmpt, SphericalTensor<Cmpt> >
00197 {
00198 public:
00199 
00200     typedef SphericalTensor<Cmpt> type;
00201 };
00202 
00203 
00204 template<class Cmpt>
00205 class innerProduct<SphericalTensor<Cmpt>, SphericalTensor<Cmpt> >
00206 {
00207 public:
00208 
00209     typedef SphericalTensor<Cmpt> type;
00210 };
00211 
00212 
00213 template<class Cmpt>
00214 class innerProduct<SphericalTensor<Cmpt>, Vector<Cmpt> >
00215 {
00216 public:
00217 
00218     typedef Vector<Cmpt> type;
00219 };
00220 
00221 template<class Cmpt>
00222 class innerProduct<Vector<Cmpt>, SphericalTensor<Cmpt> >
00223 {
00224 public:
00225 
00226     typedef Vector<Cmpt> type;
00227 };
00228 
00229 
00230 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00231 
00232 } // End namespace Foam
00233 
00234 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines