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

symmTensorField.C

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 "symmTensorField.H"
00028 #include "transformField.H"
00029 
00030 #define TEMPLATE
00031 #include "FieldFunctionsM.C"
00032 
00033 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00034 
00035 namespace Foam
00036 {
00037 
00038 // * * * * * * * * * * * * * * * global functions  * * * * * * * * * * * * * //
00039 
00040 UNARY_FUNCTION(symmTensor, vector, sqr)
00041 
00042 UNARY_FUNCTION(scalar, symmTensor, tr)
00043 UNARY_FUNCTION(sphericalTensor, symmTensor, sph)
00044 UNARY_FUNCTION(symmTensor, symmTensor, symm)
00045 UNARY_FUNCTION(symmTensor, symmTensor, twoSymm)
00046 UNARY_FUNCTION(symmTensor, symmTensor, dev)
00047 UNARY_FUNCTION(symmTensor, symmTensor, dev2)
00048 UNARY_FUNCTION(scalar, symmTensor, det)
00049 UNARY_FUNCTION(symmTensor, symmTensor, cof)
00050 
00051 void inv(Field<symmTensor>& tf, const UList<symmTensor>& tf1)
00052 {
00053     if (tf.empty())
00054     {
00055         return;
00056     }
00057 
00058     scalar scale = magSqr(tf1[0]);
00059     Vector<bool> removeCmpts
00060     (
00061         magSqr(tf1[0].xx())/scale < SMALL,
00062         magSqr(tf1[0].yy())/scale < SMALL,
00063         magSqr(tf1[0].zz())/scale < SMALL
00064     );
00065 
00066     if (removeCmpts.x() || removeCmpts.y() || removeCmpts.z())
00067     {
00068         symmTensorField tf1Plus(tf1);
00069 
00070         if (removeCmpts.x())
00071         {
00072             tf1Plus += symmTensor(1,0,0,0,0,0);
00073         }
00074 
00075         if (removeCmpts.y())
00076         {
00077             tf1Plus += symmTensor(0,0,0,1,0,0);
00078         }
00079 
00080         if (removeCmpts.z())
00081         {
00082             tf1Plus += symmTensor(0,0,0,0,0,1);
00083         }
00084 
00085         TFOR_ALL_F_OP_FUNC_F(symmTensor, tf, =, inv, symmTensor, tf1Plus)
00086 
00087         if (removeCmpts.x())
00088         {
00089             tf -= symmTensor(1,0,0,0,0,0);
00090         }
00091 
00092         if (removeCmpts.y())
00093         {
00094             tf -= symmTensor(0,0,0,1,0,0);
00095         }
00096 
00097         if (removeCmpts.z())
00098         {
00099             tf -= symmTensor(0,0,0,0,0,1);
00100         }
00101     }
00102     else
00103     {
00104         TFOR_ALL_F_OP_FUNC_F(symmTensor, tf, =, inv, symmTensor, tf1)
00105     }
00106 }
00107 
00108 tmp<symmTensorField> inv(const UList<symmTensor>& tf)
00109 {
00110     tmp<symmTensorField> result(new symmTensorField(tf.size()));
00111     inv(result(), tf);
00112     return result;
00113 }
00114 
00115 tmp<symmTensorField> inv(const tmp<symmTensorField>& tf)
00116 {
00117     tmp<symmTensorField> tRes = reuseTmp<symmTensor, symmTensor>::New(tf);
00118     inv(tRes(), tf());
00119     reuseTmp<symmTensor, symmTensor>::clear(tf);
00120     return tRes;
00121 }
00122 
00123 
00124 template<>
00125 tmp<Field<symmTensor> > transformFieldMask<symmTensor>
00126 (
00127     const tensorField& tf
00128 )
00129 {
00130     return symm(tf);
00131 }
00132 
00133 template<>
00134 tmp<Field<symmTensor> > transformFieldMask<symmTensor>
00135 (
00136     const tmp<tensorField>& ttf
00137 )
00138 {
00139     tmp<Field<symmTensor> > ret = transformFieldMask<symmTensor>(ttf());
00140     ttf.clear();
00141     return ret;
00142 }
00143 
00144 
00145 template<>
00146 tmp<Field<symmTensor> > transformFieldMask<symmTensor>
00147 (
00148     const symmTensorField& stf
00149 )
00150 {
00151     return stf;
00152 }
00153 
00154 template<>
00155 tmp<Field<symmTensor> > transformFieldMask<symmTensor>
00156 (
00157     const tmp<symmTensorField>& tstf
00158 )
00159 {
00160     return tstf;
00161 }
00162 
00163 
00164 // * * * * * * * * * * * * * * * global operators  * * * * * * * * * * * * * //
00165 
00166 UNARY_OPERATOR(vector, symmTensor, *, hdual)
00167 
00168 
00169 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00170 
00171 } // End namespace Foam
00172 
00173 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00174 
00175 #include "undefFieldFunctionsM.H"
00176 
00177 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd