initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / meshTools / coordinateSystems / coordinateRotation / coordinateRotation.C
blobf3c95afc910c1bc73415cd483e6147c18ce40b1a
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 * * * * * * * * * * * * * //
33 namespace Foam
35     defineTypeNameAndDebug(coordinateRotation, 0);
36     defineRunTimeSelectionTable(coordinateRotation, dictionary);
39 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
41 void Foam::coordinateRotation::calcTransform
43     const vector& axis1,
44     const vector& axis2,
45     const axisOrder& order
48     vector a = axis1 / mag(axis1);
49     vector b = axis2;
51     // Absorb minor nonorthogonality into axis2
52     b = b - (b & a)*a;
54     if (mag(b) < SMALL)
55     {
56         FatalErrorIn("coordinateRotation::calcTransform()")
57             << "axis1, axis2 appear co-linear: "
58             << axis1 << ", " << axis2 << endl
59             << abort(FatalError);
60     }
62     b = b / mag(b);
63     vector c = a ^ b;
65     // the global -> local transformation
66     tensor Rtr;
67     switch (order)
68     {
69         case e1e2:
70             Rtr.x() = a;
71             Rtr.y() = b;
72             Rtr.z() = c;
73             break;
75         case e2e3:
76             Rtr.x() = c;
77             Rtr.y() = a;
78             Rtr.z() = b;
79             break;
81         case e3e1:
82             Rtr.x() = b;
83             Rtr.y() = c;
84             Rtr.z() = a;
85             break;
87         default:
88             FatalErrorIn("coordinateRotation::calcTransform()")
89                 << "programmer error" << endl
90                 << abort(FatalError);
91             break;
92     }
94     // the local -> global transformation
95     tensor::operator=( Rtr.T() );
99 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
101 Foam::coordinateRotation::coordinateRotation()
103     tensor(sphericalTensor::I)
107 Foam::coordinateRotation::coordinateRotation
109     const vector& axis,
110     const vector& dir
113     tensor(sphericalTensor::I)
115     calcTransform(axis, dir, e3e1);
119 Foam::coordinateRotation::coordinateRotation
121     const dictionary& dict
124     tensor(sphericalTensor::I)
126     operator=(dict);
129 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
131 Foam::autoPtr<Foam::coordinateRotation> Foam::coordinateRotation::New
133     const dictionary& dict
136     if (debug)
137     {
138         Pout<< "coordinateRotation::New(const dictionary&) : "
139             << "constructing coordinateRotation"
140             << endl;
141     }
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")
149     {
150         return autoPtr<coordinateRotation>(new coordinateRotation(dict));
151     }
154     dictionaryConstructorTable::iterator cstrIter =
155         dictionaryConstructorTablePtr_->find(rotType);
157     if (cstrIter == dictionaryConstructorTablePtr_->end())
158     {
159         FatalIOErrorIn
160         (
161             "coordinateRotation::New(const dictionary&)",
162             dict
163         )   << "Unknown coordinateRotation type " << rotType << nl << nl
164             << "Valid coordinateRotation types are :" <<  nl
165             << "[default: axes " << typeName_() << "]"
166             << dictionaryConstructorTablePtr_->toc()
167             << exit(FatalIOError);
168     }
170     return autoPtr<coordinateRotation>(cstrIter()(dict));
174 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
176 void Foam::coordinateRotation::operator=(const dictionary& rhs)
178     if (debug)
179     {
180         Pout<< "coordinateRotation::operator=(const dictionary&) : "
181             << "assign from " << rhs << endl;
182     }
184     // allow as embedded sub-dictionary "coordinateRotation"
185     const dictionary& dict =
186     (
187         rhs.found(typeName_())
188       ? rhs.subDict(typeName_())
189       : rhs
190     );
192     vector axis1, axis2;
193     axisOrder order(e3e1);
195     if (dict.readIfPresent("e1", axis1) && dict.readIfPresent("e2", axis2))
196     {
197         order = e1e2;
198     }
199     else if (dict.readIfPresent("e2", axis1) && dict.readIfPresent("e3", axis2))
200     {
201         order = e2e3;
202     }
203     else if (dict.readIfPresent("e3", axis1) && dict.readIfPresent("e1", axis2))
204     {
205         order = e3e1;
206     }
207     else if (dict.found("axis") || dict.found("direction"))
208     {
209         // let it bomb if only one of axis/direction is defined
210         order = e3e1;
211         dict.lookup("axis") >> axis1;
212         dict.lookup("direction") >> axis2;
213     }
214     else
215     {
216         // unspecified axes revert to the global system
217         tensor::operator=(sphericalTensor::I);
218         return;
219     }
221     calcTransform(axis1, axis2, order);
225 // ************************************************************************* //