00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
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
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 }
00164
00165
00166
00167 #include <OpenFOAM/undefFieldFunctionsM.H>
00168
00169