1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "coordinateRotation.H"
28 #include "dictionary.H"
29 #include "addToRunTimeSelectionTable.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 defineTypeNameAndDebug(coordinateRotation, 0);
36 defineRunTimeSelectionTable(coordinateRotation, dictionary);
39 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
41 void Foam::coordinateRotation::calcTransform
45 const axisOrder& order
48 vector a = axis1 / mag(axis1);
51 // Absorb minor non-orthogonality into axis2
56 FatalErrorIn("coordinateRotation::calcTransform()")
57 << "axis1, axis2 appear co-linear: "
58 << axis1 << ", " << axis2 << endl
65 // the global -> local transformation
70 Rtr = tensor(a, b, c);
74 Rtr = tensor(c, a, b);
78 Rtr = tensor(b, c, a);
82 FatalErrorIn("coordinateRotation::calcTransform()")
83 << "programmer error" << endl
85 // To satisfy compiler warnings
90 // the local -> global transformation
91 tensor::operator=( Rtr.T() );
95 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
97 Foam::coordinateRotation::coordinateRotation()
99 tensor(sphericalTensor::I)
103 Foam::coordinateRotation::coordinateRotation
109 tensor(sphericalTensor::I)
111 calcTransform(axis, dir, e3e1);
115 Foam::coordinateRotation::coordinateRotation
117 const dictionary& dict
120 tensor(sphericalTensor::I)
126 Foam::coordinateRotation::coordinateRotation
132 tensor(sphericalTensor::I)
134 scalar c = cos(angle);
136 scalar sm = sin(angle)/m;
142 c, -v.z()*sm, v.y()*sm,
143 v.z()*sm, c, -v.x()*sm,
144 -v.y()*sm, v.x()*sm, c
147 // the local -> global transformation
148 tensor::operator=(Rtr.T());
152 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
154 Foam::autoPtr<Foam::coordinateRotation> Foam::coordinateRotation::New
156 const dictionary& dict
161 Pout<< "coordinateRotation::New(const dictionary&) : "
162 << "constructing coordinateRotation"
166 // default type is self (alias: "axes")
167 word rotType(typeName_());
168 dict.readIfPresent("type", rotType);
170 // can (must) construct base class directly
171 if (rotType == typeName_() || rotType == "axes")
173 return autoPtr<coordinateRotation>(new coordinateRotation(dict));
177 dictionaryConstructorTable::iterator cstrIter =
178 dictionaryConstructorTablePtr_->find(rotType);
180 if (cstrIter == dictionaryConstructorTablePtr_->end())
184 "coordinateRotation::New(const dictionary&)",
186 ) << "Unknown coordinateRotation type "
187 << rotType << nl << nl
188 << "Valid coordinateRotation types are :" << nl
189 << "[default: axes " << typeName_() << "]"
190 << dictionaryConstructorTablePtr_->toc()
191 << exit(FatalIOError);
194 return autoPtr<coordinateRotation>(cstrIter()(dict));
198 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
200 void Foam::coordinateRotation::operator=(const dictionary& rhs)
204 Pout<< "coordinateRotation::operator=(const dictionary&) : "
205 << "assign from " << rhs << endl;
208 // allow as embedded sub-dictionary "coordinateRotation"
209 const dictionary& dict =
211 rhs.found(typeName_())
212 ? rhs.subDict(typeName_())
217 axisOrder order = e3e1;
219 if (dict.readIfPresent("e1", axis1) && dict.readIfPresent("e2", axis2))
225 dict.readIfPresent("e2", axis1)
226 && dict.readIfPresent("e3", axis2)
233 dict.readIfPresent("e3", axis1)
234 && dict.readIfPresent("e1", axis2)
239 else if (dict.found("axis") || dict.found("direction"))
241 // let it bomb if only one of axis/direction is defined
243 axis1 = vector(dict.lookup("axis"));
244 axis2 = vector(dict.lookup("direction"));
248 // unspecified axes revert to the global system
249 tensor::operator=(sphericalTensor::I);
253 calcTransform(axis1, axis2, order);
257 // ************************************************************************* //