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
00027 #include "tensorField.H"
00028 #include "transformField.H"
00029
00030 #define TEMPLATE
00031 #include "FieldFunctionsM.C"
00032
00033
00034
00035 namespace Foam
00036 {
00037
00038
00039
00040 UNARY_FUNCTION(scalar, tensor, tr)
00041 UNARY_FUNCTION(sphericalTensor, tensor, sph)
00042 UNARY_FUNCTION(symmTensor, tensor, symm)
00043 UNARY_FUNCTION(symmTensor, tensor, twoSymm)
00044 UNARY_FUNCTION(tensor, tensor, skew)
00045 UNARY_FUNCTION(tensor, tensor, dev)
00046 UNARY_FUNCTION(tensor, tensor, dev2)
00047 UNARY_FUNCTION(scalar, tensor, det)
00048 UNARY_FUNCTION(tensor, tensor, cof)
00049
00050 void inv(Field<tensor>& tf, const UList<tensor>& 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 tensorField tf1Plus(tf1);
00068
00069 if (removeCmpts.x())
00070 {
00071 tf1Plus += tensor(1,0,0,0,0,0,0,0,0);
00072 }
00073
00074 if (removeCmpts.y())
00075 {
00076 tf1Plus += tensor(0,0,0,0,1,0,0,0,0);
00077 }
00078
00079 if (removeCmpts.z())
00080 {
00081 tf1Plus += tensor(0,0,0,0,0,0,0,0,1);
00082 }
00083
00084 TFOR_ALL_F_OP_FUNC_F(tensor, tf, =, inv, tensor, tf1Plus)
00085
00086 if (removeCmpts.x())
00087 {
00088 tf -= tensor(1,0,0,0,0,0,0,0,0);
00089 }
00090
00091 if (removeCmpts.y())
00092 {
00093 tf -= tensor(0,0,0,0,1,0,0,0,0);
00094 }
00095
00096 if (removeCmpts.z())
00097 {
00098 tf -= tensor(0,0,0,0,0,0,0,0,1);
00099 }
00100 }
00101 else
00102 {
00103 TFOR_ALL_F_OP_FUNC_F(tensor, tf, =, inv, tensor, tf1)
00104 }
00105 }
00106
00107 tmp<tensorField> inv(const UList<tensor>& tf)
00108 {
00109 tmp<tensorField> result(new tensorField(tf.size()));
00110 inv(result(), tf);
00111 return result;
00112 }
00113
00114 tmp<tensorField> inv(const tmp<tensorField>& tf)
00115 {
00116 tmp<tensorField> tRes = reuseTmp<tensor, tensor>::New(tf);
00117 inv(tRes(), tf());
00118 reuseTmp<tensor, tensor>::clear(tf);
00119 return tRes;
00120 }
00121
00122 UNARY_FUNCTION(vector, tensor, eigenValues)
00123 UNARY_FUNCTION(tensor, tensor, eigenVectors)
00124
00125 UNARY_FUNCTION(vector, symmTensor, eigenValues)
00126 UNARY_FUNCTION(tensor, symmTensor, eigenVectors)
00127
00128
00129 template<>
00130 tmp<Field<tensor> > transformFieldMask<tensor>
00131 (
00132 const symmTensorField& stf
00133 )
00134 {
00135 tmp<tensorField> tRes(new tensorField(stf.size()));
00136 tensorField& res = tRes();
00137 TFOR_ALL_F_OP_F(tensor, res, =, symmTensor, stf)
00138 return tRes;
00139 }
00140
00141 template<>
00142 tmp<Field<tensor> > transformFieldMask<tensor>
00143 (
00144 const tmp<symmTensorField>& tstf
00145 )
00146 {
00147 tmp<Field<tensor> > ret = transformFieldMask<tensor>(tstf());
00148 tstf.clear();
00149 return ret;
00150 }
00151
00152
00153
00154
00155 UNARY_OPERATOR(vector, tensor, *, hdual)
00156 UNARY_OPERATOR(tensor, vector, *, hdual)
00157
00158 BINARY_OPERATOR(vector, vector, tensor, /, divide)
00159 BINARY_TYPE_OPERATOR(vector, vector, tensor, /, divide)
00160
00161
00162
00163
00164 }
00165
00166
00167
00168 #include "undefFieldFunctionsM.H"
00169
00170