coordinateRotation.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 "coordinateRotation.H"
00028 #include "dictionary.H"
00029 #include "addToRunTimeSelectionTable.H"
00030
00031
00032
00033 namespace Foam
00034 {
00035 defineTypeNameAndDebug(coordinateRotation, 0);
00036 defineRunTimeSelectionTable(coordinateRotation, dictionary);
00037 }
00038
00039
00040
00041 void Foam::coordinateRotation::calcTransform
00042 (
00043 const vector& axis1,
00044 const vector& axis2,
00045 const axisOrder& order
00046 )
00047 {
00048 vector a = axis1 / mag(axis1);
00049 vector b = axis2;
00050
00051
00052 b = b - (b & a)*a;
00053
00054 if (mag(b) < SMALL)
00055 {
00056 FatalErrorIn("coordinateRotation::calcTransform()")
00057 << "axis1, axis2 appear co-linear: "
00058 << axis1 << ", " << axis2 << endl
00059 << abort(FatalError);
00060 }
00061
00062 b = b / mag(b);
00063 vector c = a ^ b;
00064
00065
00066 tensor Rtr;
00067 switch (order)
00068 {
00069 case e1e2:
00070 Rtr.x() = a;
00071 Rtr.y() = b;
00072 Rtr.z() = c;
00073 break;
00074
00075 case e2e3:
00076 Rtr.x() = c;
00077 Rtr.y() = a;
00078 Rtr.z() = b;
00079 break;
00080
00081 case e3e1:
00082 Rtr.x() = b;
00083 Rtr.y() = c;
00084 Rtr.z() = a;
00085 break;
00086
00087 default:
00088 FatalErrorIn("coordinateRotation::calcTransform()")
00089 << "programmer error" << endl
00090 << abort(FatalError);
00091 break;
00092 }
00093
00094
00095 tensor::operator=( Rtr.T() );
00096 }
00097
00098
00099
00100
00101 Foam::coordinateRotation::coordinateRotation()
00102 :
00103 tensor(sphericalTensor::I)
00104 {}
00105
00106
00107 Foam::coordinateRotation::coordinateRotation
00108 (
00109 const vector& axis,
00110 const vector& dir
00111 )
00112 :
00113 tensor(sphericalTensor::I)
00114 {
00115 calcTransform(axis, dir, e3e1);
00116 }
00117
00118
00119 Foam::coordinateRotation::coordinateRotation
00120 (
00121 const dictionary& dict
00122 )
00123 :
00124 tensor(sphericalTensor::I)
00125 {
00126 operator=(dict);
00127 }
00128
00129
00130
00131 Foam::autoPtr<Foam::coordinateRotation> Foam::coordinateRotation::New
00132 (
00133 const dictionary& dict
00134 )
00135 {
00136 if (debug)
00137 {
00138 Pout<< "coordinateRotation::New(const dictionary&) : "
00139 << "constructing coordinateRotation"
00140 << endl;
00141 }
00142
00143
00144 word rotType(typeName_());
00145 dict.readIfPresent("type", rotType);
00146
00147
00148 if (rotType == typeName_() || rotType == "axes")
00149 {
00150 return autoPtr<coordinateRotation>(new coordinateRotation(dict));
00151 }
00152
00153
00154 dictionaryConstructorTable::iterator cstrIter =
00155 dictionaryConstructorTablePtr_->find(rotType);
00156
00157 if (cstrIter == dictionaryConstructorTablePtr_->end())
00158 {
00159 FatalIOErrorIn
00160 (
00161 "coordinateRotation::New(const dictionary&)",
00162 dict
00163 ) << "Unknown coordinateRotation type " << rotType << nl << nl
00164 << "Valid coordinateRotation types are :" << nl
00165 << "[default: axes " << typeName_() << "]"
00166 << dictionaryConstructorTablePtr_->toc()
00167 << exit(FatalIOError);
00168 }
00169
00170 return autoPtr<coordinateRotation>(cstrIter()(dict));
00171 }
00172
00173
00174
00175
00176 void Foam::coordinateRotation::operator=(const dictionary& rhs)
00177 {
00178 if (debug)
00179 {
00180 Pout<< "coordinateRotation::operator=(const dictionary&) : "
00181 << "assign from " << rhs << endl;
00182 }
00183
00184
00185 const dictionary& dict =
00186 (
00187 rhs.found(typeName_())
00188 ? rhs.subDict(typeName_())
00189 : rhs
00190 );
00191
00192 vector axis1, axis2;
00193 axisOrder order(e3e1);
00194
00195 if (dict.readIfPresent("e1", axis1) && dict.readIfPresent("e2", axis2))
00196 {
00197 order = e1e2;
00198 }
00199 else if (dict.readIfPresent("e2", axis1) && dict.readIfPresent("e3", axis2))
00200 {
00201 order = e2e3;
00202 }
00203 else if (dict.readIfPresent("e3", axis1) && dict.readIfPresent("e1", axis2))
00204 {
00205 order = e3e1;
00206 }
00207 else if (dict.found("axis") || dict.found("direction"))
00208 {
00209
00210 order = e3e1;
00211 dict.lookup("axis") >> axis1;
00212 dict.lookup("direction") >> axis2;
00213 }
00214 else
00215 {
00216
00217 tensor::operator=(sphericalTensor::I);
00218 return;
00219 }
00220
00221 calcTransform(axis1, axis2, order);
00222 }
00223
00224
00225
Copyright © 2000-2009 OpenCFD Ltd