tensor2D.C
Go to the documentation of this file.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 "tensor2D.H"
00028 #include "mathematicalConstants.H"
00029
00030
00031
00032 namespace Foam
00033 {
00034
00035
00036
00037 template<>
00038 const char* const tensor2D::typeName = "tensor2D";
00039
00040 template<>
00041 const char* tensor2D::componentNames[] =
00042 {
00043 "xx", "xy",
00044 "yx", "yy"
00045 };
00046
00047 template<>
00048 const tensor2D tensor2D::zero
00049 (
00050 0, 0,
00051 0, 0
00052 );
00053
00054 template<>
00055 const tensor2D tensor2D::one
00056 (
00057 1, 1,
00058 1, 1
00059 );
00060
00061 template<>
00062 const tensor2D tensor2D::max
00063 (
00064 VGREAT, VGREAT,
00065 VGREAT, VGREAT
00066 );
00067
00068 template<>
00069 const tensor2D tensor2D::min
00070 (
00071 -VGREAT, -VGREAT,
00072 -VGREAT, -VGREAT
00073 );
00074
00075
00076
00077
00078
00079 vector2D eigenValues(const tensor2D& t)
00080 {
00081 scalar i = 0;
00082 scalar ii = 0;
00083
00084 if (mag(t.xy()) < SMALL && mag(t.yx()) < SMALL)
00085 {
00086 i = t.xx();
00087 ii = t.yy();
00088 }
00089 else
00090 {
00091 scalar mb = t.xx() + t.yy();
00092 scalar c = t.xx()*t.yy() - t.xy()*t.yx();
00093
00094
00095 if (mag(c) < SMALL)
00096 {
00097 i = 0;
00098 ii = mb;
00099 }
00100 else
00101 {
00102 scalar disc = sqr(mb) - 4*c;
00103
00104 if (disc > 0)
00105 {
00106 scalar q = sqrt(disc);
00107
00108 i = 0.5*(mb - q);
00109 ii = 0.5*(mb + q);
00110 }
00111 else
00112 {
00113 FatalErrorIn("eigenValues(const tensor2D&)")
00114 << "zero and complex eigenvalues in tensor2D: " << t
00115 << abort(FatalError);
00116 }
00117 }
00118 }
00119
00120
00121 if (mag(i) > mag(ii))
00122 {
00123 Swap(i, ii);
00124 }
00125
00126 return vector2D(i, ii);
00127 }
00128
00129
00130 vector2D eigenVector(const tensor2D& t, const scalar lambda)
00131 {
00132 if (lambda < SMALL)
00133 {
00134 return vector2D::zero;
00135 }
00136
00137 if (mag(t.xy()) < SMALL && mag(t.yx()) < SMALL)
00138 {
00139 if (lambda > min(t.xx(), t.yy()))
00140 {
00141 return vector2D(1, 0);
00142 }
00143 else
00144 {
00145 return vector2D(0, 1);
00146 }
00147 }
00148 else if (mag(t.xy()) < SMALL)
00149 {
00150 return vector2D(lambda - t.yy(), t.yx());
00151 }
00152 else
00153 {
00154 return vector2D(t.xy(), lambda - t.yy());
00155 }
00156 }
00157
00158
00159 tensor2D eigenVectors(const tensor2D& t)
00160 {
00161 vector2D evals(eigenValues(t));
00162
00163 tensor2D evs;
00164 evs.x() = eigenVector(t, evals.x());
00165 evs.y() = eigenVector(t, evals.y());
00166
00167 return evs;
00168 }
00169
00170
00171
00172
00173 }
00174
00175
Copyright © 2000-2009 OpenCFD Ltd