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

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