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

transform.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 InNamespace
00025     Foam
00026 
00027 Description
00028     3D tensor transformation operations.
00029 
00030 \*---------------------------------------------------------------------------*/
00031 
00032 #ifndef transform_H
00033 #define transform_H
00034 
00035 #include <OpenFOAM/tensor.H>
00036 #include <OpenFOAM/mathematicalConstants.H>
00037 
00038 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00039 
00040 namespace Foam
00041 {
00042 
00043 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00044 
00045 inline tensor rotationTensor
00046 (
00047     const vector& n1,
00048     const vector& n2
00049 )
00050 {
00051     return
00052         (n1 & n2)*I
00053       + (1 - (n1 & n2))*sqr(n1 ^ n2)/(magSqr(n1 ^ n2) + VSMALL)
00054       + (n2*n1 - n1*n2);
00055 }
00056 
00057 
00058 inline label transform(const tensor&, const label i)
00059 {
00060     return i;
00061 }
00062 
00063 
00064 inline scalar transform(const tensor&, const scalar s)
00065 {
00066     return s;
00067 }
00068 
00069 
00070 template<class Cmpt>
00071 inline Vector<Cmpt> transform(const tensor& tt, const Vector<Cmpt>& v)
00072 {
00073     return tt & v;
00074 }
00075 
00076 
00077 template<class Cmpt>
00078 inline Tensor<Cmpt> transform(const tensor& tt, const Tensor<Cmpt>& t)
00079 {
00080     //return tt & t & tt.T();
00081     return Tensor<Cmpt>
00082     (
00083         (tt.xx()*t.xx() + tt.xy()*t.yx() + tt.xz()*t.zx())*tt.xx()
00084       + (tt.xx()*t.xy() + tt.xy()*t.yy() + tt.xz()*t.zy())*tt.xy()
00085       + (tt.xx()*t.xz() + tt.xy()*t.yz() + tt.xz()*t.zz())*tt.xz(),
00086 
00087         (tt.xx()*t.xx() + tt.xy()*t.yx() + tt.xz()*t.zx())*tt.yx()
00088       + (tt.xx()*t.xy() + tt.xy()*t.yy() + tt.xz()*t.zy())*tt.yy()
00089       + (tt.xx()*t.xz() + tt.xy()*t.yz() + tt.xz()*t.zz())*tt.yz(),
00090 
00091         (tt.xx()*t.xx() + tt.xy()*t.yx() + tt.xz()*t.zx())*tt.zx()
00092       + (tt.xx()*t.xy() + tt.xy()*t.yy() + tt.xz()*t.zy())*tt.zy()
00093       + (tt.xx()*t.xz() + tt.xy()*t.yz() + tt.xz()*t.zz())*tt.zz(),
00094 
00095         (tt.yx()*t.xx() + tt.yy()*t.yx() + tt.yz()*t.zx())*tt.xx()
00096       + (tt.yx()*t.xy() + tt.yy()*t.yy() + tt.yz()*t.zy())*tt.xy()
00097       + (tt.yx()*t.xz() + tt.yy()*t.yz() + tt.yz()*t.zz())*tt.xz(),
00098 
00099         (tt.yx()*t.xx() + tt.yy()*t.yx() + tt.yz()*t.zx())*tt.yx()
00100       + (tt.yx()*t.xy() + tt.yy()*t.yy() + tt.yz()*t.zy())*tt.yy()
00101       + (tt.yx()*t.xz() + tt.yy()*t.yz() + tt.yz()*t.zz())*tt.yz(),
00102 
00103         (tt.yx()*t.xx() + tt.yy()*t.yx() + tt.yz()*t.zx())*tt.zx()
00104       + (tt.yx()*t.xy() + tt.yy()*t.yy() + tt.yz()*t.zy())*tt.zy()
00105       + (tt.yx()*t.xz() + tt.yy()*t.yz() + tt.yz()*t.zz())*tt.zz(),
00106         
00107         (tt.zx()*t.xx() + tt.zy()*t.yx() + tt.zz()*t.zx())*tt.xx()
00108       + (tt.zx()*t.xy() + tt.zy()*t.yy() + tt.zz()*t.zy())*tt.xy()
00109       + (tt.zx()*t.xz() + tt.zy()*t.yz() + tt.zz()*t.zz())*tt.xz(),
00110 
00111         (tt.zx()*t.xx() + tt.zy()*t.yx() + tt.zz()*t.zx())*tt.yx()
00112       + (tt.zx()*t.xy() + tt.zy()*t.yy() + tt.zz()*t.zy())*tt.yy()
00113       + (tt.zx()*t.xz() + tt.zy()*t.yz() + tt.zz()*t.zz())*tt.yz(),
00114 
00115         (tt.zx()*t.xx() + tt.zy()*t.yx() + tt.zz()*t.zx())*tt.zx()
00116       + (tt.zx()*t.xy() + tt.zy()*t.yy() + tt.zz()*t.zy())*tt.zy()
00117       + (tt.zx()*t.xz() + tt.zy()*t.yz() + tt.zz()*t.zz())*tt.zz()
00118     );
00119 }
00120 
00121 
00122 template<class Cmpt>
00123 inline SphericalTensor<Cmpt> transform
00124 (
00125     const tensor& tt,
00126     const SphericalTensor<Cmpt>& st
00127 )
00128 {
00129     return st;
00130 }
00131 
00132 
00133 template<class Cmpt>
00134 inline SymmTensor<Cmpt> transform(const tensor& tt, const SymmTensor<Cmpt>& st)
00135 {
00136     return SymmTensor<Cmpt>
00137     (
00138         (tt.xx()*st.xx() + tt.xy()*st.xy() + tt.xz()*st.xz())*tt.xx()
00139       + (tt.xx()*st.xy() + tt.xy()*st.yy() + tt.xz()*st.yz())*tt.xy()
00140       + (tt.xx()*st.xz() + tt.xy()*st.yz() + tt.xz()*st.zz())*tt.xz(),
00141 
00142         (tt.xx()*st.xx() + tt.xy()*st.xy() + tt.xz()*st.xz())*tt.yx()
00143       + (tt.xx()*st.xy() + tt.xy()*st.yy() + tt.xz()*st.yz())*tt.yy()
00144       + (tt.xx()*st.xz() + tt.xy()*st.yz() + tt.xz()*st.zz())*tt.yz(),
00145 
00146         (tt.xx()*st.xx() + tt.xy()*st.xy() + tt.xz()*st.xz())*tt.zx()
00147       + (tt.xx()*st.xy() + tt.xy()*st.yy() + tt.xz()*st.yz())*tt.zy()
00148       + (tt.xx()*st.xz() + tt.xy()*st.yz() + tt.xz()*st.zz())*tt.zz(),
00149 
00150         (tt.yx()*st.xx() + tt.yy()*st.xy() + tt.yz()*st.xz())*tt.yx()
00151       + (tt.yx()*st.xy() + tt.yy()*st.yy() + tt.yz()*st.yz())*tt.yy()
00152       + (tt.yx()*st.xz() + tt.yy()*st.yz() + tt.yz()*st.zz())*tt.yz(),
00153 
00154         (tt.yx()*st.xx() + tt.yy()*st.xy() + tt.yz()*st.xz())*tt.zx()
00155       + (tt.yx()*st.xy() + tt.yy()*st.yy() + tt.yz()*st.yz())*tt.zy()
00156       + (tt.yx()*st.xz() + tt.yy()*st.yz() + tt.yz()*st.zz())*tt.zz(),
00157         
00158         (tt.zx()*st.xx() + tt.zy()*st.xy() + tt.zz()*st.xz())*tt.zx()
00159       + (tt.zx()*st.xy() + tt.zy()*st.yy() + tt.zz()*st.yz())*tt.zy()
00160       + (tt.zx()*st.xz() + tt.zy()*st.yz() + tt.zz()*st.zz())*tt.zz()
00161     );
00162 }
00163 
00164 
00165 template<class Type1, class Type2>
00166 inline Type1 transformMask(const Type2& t)
00167 {
00168     return t;
00169 }
00170 
00171 
00172 template<>
00173 inline sphericalTensor transformMask<sphericalTensor>(const tensor& t)
00174 {
00175     return sph(t);
00176 }
00177 
00178 
00179 template<>
00180 inline symmTensor transformMask<symmTensor>(const tensor& t)
00181 {
00182     return symm(t);
00183 }
00184 
00185 //- Estimate angle of vec in coordinate system (e0, e1, e0^e1).
00186 //  Is guaranteed to return increasing number but is not correct
00187 //  angle. Used for sorting angles.  All input vectors need to be normalized.
00188 //
00189 // Calculates scalar which increases with angle going from e0 to vec in
00190 // the coordinate system e0, e1, e0^e1
00191 //
00192 // Jumps from 2PI -> 0 at -SMALL so parallel vectors with small rounding errors
00193 // should hopefully still get the same quadrant.
00194 //
00195 inline scalar pseudoAngle
00196 (
00197     const vector& e0,
00198     const vector& e1,
00199     const vector& vec
00200 )
00201 {
00202     scalar cos = vec & e0;
00203     scalar sin = vec & e1;
00204 
00205     if (sin < -SMALL)
00206     {
00207         return (3.0 + cos)*mathematicalConstant::piByTwo;
00208     }
00209     else
00210     {
00211         return (1.0 - cos)*mathematicalConstant::piByTwo;
00212     }
00213 }
00214 
00215 
00216 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00217 
00218 } // End namespace Foam
00219 
00220 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00221 
00222 #endif
00223 
00224 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines