1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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 nonorthogonality into axis2
56 FatalErrorIn("coordinateRotation::calcTransform()")
57 << "axis1, axis2 appear co-linear: "
58 << axis1 << ", " << axis2 << endl
65 // the global -> local transformation
88 FatalErrorIn("coordinateRotation::calcTransform()")
89 << "programmer error" << endl
94 // the local -> global transformation
95 tensor::operator=( Rtr.T() );
99 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
101 Foam::coordinateRotation::coordinateRotation()
103 tensor(sphericalTensor::I)
107 Foam::coordinateRotation::coordinateRotation
113 tensor(sphericalTensor::I)
115 calcTransform(axis, dir, e3e1);
119 Foam::coordinateRotation::coordinateRotation
121 const dictionary& dict
124 tensor(sphericalTensor::I)
129 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
131 Foam::autoPtr<Foam::coordinateRotation> Foam::coordinateRotation::New
133 const dictionary& dict
138 Pout<< "coordinateRotation::New(const dictionary&) : "
139 << "constructing coordinateRotation"
143 // default type is self (alias: "axes")
144 word rotType(typeName_());
145 dict.readIfPresent("type", rotType);
147 // can (must) construct base class directly
148 if (rotType == typeName_() || rotType == "axes")
150 return autoPtr<coordinateRotation>(new coordinateRotation(dict));
154 dictionaryConstructorTable::iterator cstrIter =
155 dictionaryConstructorTablePtr_->find(rotType);
157 if (cstrIter == dictionaryConstructorTablePtr_->end())
161 "coordinateRotation::New(const dictionary&)",
163 ) << "Unknown coordinateRotation type " << rotType << nl << nl
164 << "Valid coordinateRotation types are :" << nl
165 << "[default: axes " << typeName_() << "]"
166 << dictionaryConstructorTablePtr_->toc()
167 << exit(FatalIOError);
170 return autoPtr<coordinateRotation>(cstrIter()(dict));
174 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
176 void Foam::coordinateRotation::operator=(const dictionary& rhs)
180 Pout<< "coordinateRotation::operator=(const dictionary&) : "
181 << "assign from " << rhs << endl;
184 // allow as embedded sub-dictionary "coordinateRotation"
185 const dictionary& dict =
187 rhs.found(typeName_())
188 ? rhs.subDict(typeName_())
193 axisOrder order(e3e1);
195 if (dict.readIfPresent("e1", axis1) && dict.readIfPresent("e2", axis2))
199 else if (dict.readIfPresent("e2", axis1) && dict.readIfPresent("e3", axis2))
203 else if (dict.readIfPresent("e3", axis1) && dict.readIfPresent("e1", axis2))
207 else if (dict.found("axis") || dict.found("direction"))
209 // let it bomb if only one of axis/direction is defined
211 dict.lookup("axis") >> axis1;
212 dict.lookup("direction") >> axis2;
216 // unspecified axes revert to the global system
217 tensor::operator=(sphericalTensor::I);
221 calcTransform(axis1, axis2, order);
225 // ************************************************************************* //