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

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