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

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