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