1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2010 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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "coordinateRotation.H"
27 #include "dictionary.H"
28 #include "addToRunTimeSelectionTable.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 defineTypeNameAndDebug(coordinateRotation, 0);
35 defineRunTimeSelectionTable(coordinateRotation, dictionary);
38 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40 void Foam::coordinateRotation::calcTransform
44 const axisOrder& order
47 vector a = axis1 / mag(axis1);
50 // Absorb minor nonorthogonality into axis2
55 FatalErrorIn("coordinateRotation::calcTransform()")
56 << "axis1, axis2 appear co-linear: "
57 << axis1 << ", " << axis2 << endl
64 // the global -> local transformation
69 Rtr = tensor(a, b, c);
73 Rtr = tensor(c, a, b);
77 Rtr = tensor(b, c, a);
81 FatalErrorIn("coordinateRotation::calcTransform()")
82 << "programmer error" << endl
84 // To satisfy compiler warnings
89 // the local -> global transformation
90 tensor::operator=( Rtr.T() );
94 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
96 Foam::coordinateRotation::coordinateRotation()
98 tensor(sphericalTensor::I)
102 Foam::coordinateRotation::coordinateRotation
108 tensor(sphericalTensor::I)
110 calcTransform(axis, dir, e3e1);
114 Foam::coordinateRotation::coordinateRotation
116 const dictionary& dict
119 tensor(sphericalTensor::I)
124 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
126 Foam::autoPtr<Foam::coordinateRotation> Foam::coordinateRotation::New
128 const dictionary& dict
133 Pout<< "coordinateRotation::New(const dictionary&) : "
134 << "constructing coordinateRotation"
138 // default type is self (alias: "axes")
139 word rotType(typeName_());
140 dict.readIfPresent("type", rotType);
142 // can (must) construct base class directly
143 if (rotType == typeName_() || rotType == "axes")
145 return autoPtr<coordinateRotation>(new coordinateRotation(dict));
149 dictionaryConstructorTable::iterator cstrIter =
150 dictionaryConstructorTablePtr_->find(rotType);
152 if (cstrIter == dictionaryConstructorTablePtr_->end())
156 "coordinateRotation::New(const dictionary&)",
158 ) << "Unknown coordinateRotation type "
159 << rotType << nl << nl
160 << "Valid coordinateRotation types are :" << nl
161 << "[default: axes " << typeName_() << "]"
162 << dictionaryConstructorTablePtr_->sortedToc()
163 << exit(FatalIOError);
166 return autoPtr<coordinateRotation>(cstrIter()(dict));
170 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
172 void Foam::coordinateRotation::operator=(const dictionary& rhs)
176 Pout<< "coordinateRotation::operator=(const dictionary&) : "
177 << "assign from " << rhs << endl;
180 // allow as embedded sub-dictionary "coordinateRotation"
181 const dictionary& dict =
183 rhs.found(typeName_())
184 ? rhs.subDict(typeName_())
189 axisOrder order(e3e1);
191 if (dict.readIfPresent("e1", axis1) && dict.readIfPresent("e2", axis2))
195 else if (dict.readIfPresent("e2", axis1) && dict.readIfPresent("e3", axis2))
199 else if (dict.readIfPresent("e3", axis1) && dict.readIfPresent("e1", axis2))
203 else if (dict.found("axis") || dict.found("direction"))
205 // let it bomb if only one of axis/direction is defined
207 dict.lookup("axis") >> axis1;
208 dict.lookup("direction") >> axis2;
212 // unspecified axes revert to the global system
213 tensor::operator=(sphericalTensor::I);
217 calcTransform(axis1, axis2, order);
221 // ************************************************************************* //