OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

coordinateRotation.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "coordinateRotation.H"
00028 #include "dictionary.H"
00029 #include "addToRunTimeSelectionTable.H"
00030 
00031 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00032 
00033 namespace Foam
00034 {
00035     defineTypeNameAndDebug(coordinateRotation, 0);
00036     defineRunTimeSelectionTable(coordinateRotation, dictionary);
00037 }
00038 
00039 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00040 
00041 void Foam::coordinateRotation::calcTransform
00042 (
00043     const vector& axis1,
00044     const vector& axis2,
00045     const axisOrder& order
00046 )
00047 {
00048     vector a = axis1 / mag(axis1);
00049     vector b = axis2;
00050 
00051     // Absorb minor nonorthogonality into axis2
00052     b = b - (b & a)*a;
00053 
00054     if (mag(b) < SMALL)
00055     {
00056         FatalErrorIn("coordinateRotation::calcTransform()")
00057             << "axis1, axis2 appear co-linear: "
00058             << axis1 << ", " << axis2 << endl
00059             << abort(FatalError);
00060     }
00061 
00062     b = b / mag(b);
00063     vector c = a ^ b;
00064 
00065     // the global -> local transformation
00066     tensor Rtr;
00067     switch (order)
00068     {
00069         case e1e2:
00070             Rtr.x() = a;
00071             Rtr.y() = b;
00072             Rtr.z() = c;
00073             break;
00074 
00075         case e2e3:
00076             Rtr.x() = c;
00077             Rtr.y() = a;
00078             Rtr.z() = b;
00079             break;
00080 
00081         case e3e1:
00082             Rtr.x() = b;
00083             Rtr.y() = c;
00084             Rtr.z() = a;
00085             break;
00086 
00087         default:
00088             FatalErrorIn("coordinateRotation::calcTransform()")
00089                 << "programmer error" << endl
00090                 << abort(FatalError);
00091             break;
00092     }
00093 
00094     // the local -> global transformation
00095     tensor::operator=( Rtr.T() );
00096 }
00097 
00098 
00099 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00100 
00101 Foam::coordinateRotation::coordinateRotation()
00102 :
00103     tensor(sphericalTensor::I)
00104 {}
00105 
00106 
00107 Foam::coordinateRotation::coordinateRotation
00108 (
00109     const vector& axis,
00110     const vector& dir
00111 )
00112 :
00113     tensor(sphericalTensor::I)
00114 {
00115     calcTransform(axis, dir, e3e1);
00116 }
00117 
00118 
00119 Foam::coordinateRotation::coordinateRotation
00120 (
00121     const dictionary& dict
00122 )
00123 :
00124     tensor(sphericalTensor::I)
00125 {
00126     operator=(dict);
00127 }
00128 
00129 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
00130 
00131 Foam::autoPtr<Foam::coordinateRotation> Foam::coordinateRotation::New
00132 (
00133     const dictionary& dict
00134 )
00135 {
00136     if (debug)
00137     {
00138         Pout<< "coordinateRotation::New(const dictionary&) : "
00139             << "constructing coordinateRotation"
00140             << endl;
00141     }
00142 
00143     // default type is self (alias: "axes")
00144     word rotType(typeName_());
00145     dict.readIfPresent("type", rotType);
00146 
00147     // can (must) construct base class directly
00148     if (rotType == typeName_() || rotType == "axes")
00149     {
00150         return autoPtr<coordinateRotation>(new coordinateRotation(dict));
00151     }
00152 
00153 
00154     dictionaryConstructorTable::iterator cstrIter =
00155         dictionaryConstructorTablePtr_->find(rotType);
00156 
00157     if (cstrIter == dictionaryConstructorTablePtr_->end())
00158     {
00159         FatalIOErrorIn
00160         (
00161             "coordinateRotation::New(const dictionary&)",
00162             dict
00163         )   << "Unknown coordinateRotation type " << rotType << nl << nl
00164             << "Valid coordinateRotation types are :" <<  nl
00165             << "[default: axes " << typeName_() << "]"
00166             << dictionaryConstructorTablePtr_->toc()
00167             << exit(FatalIOError);
00168     }
00169 
00170     return autoPtr<coordinateRotation>(cstrIter()(dict));
00171 }
00172 
00173 
00174 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00175 
00176 void Foam::coordinateRotation::operator=(const dictionary& rhs)
00177 {
00178     if (debug)
00179     {
00180         Pout<< "coordinateRotation::operator=(const dictionary&) : "
00181             << "assign from " << rhs << endl;
00182     }
00183 
00184     // allow as embedded sub-dictionary "coordinateRotation"
00185     const dictionary& dict =
00186     (
00187         rhs.found(typeName_())
00188       ? rhs.subDict(typeName_())
00189       : rhs
00190     );
00191 
00192     vector axis1, axis2;
00193     axisOrder order(e3e1);
00194 
00195     if (dict.readIfPresent("e1", axis1) && dict.readIfPresent("e2", axis2))
00196     {
00197         order = e1e2;
00198     }
00199     else if (dict.readIfPresent("e2", axis1) && dict.readIfPresent("e3", axis2))
00200     {
00201         order = e2e3;
00202     }
00203     else if (dict.readIfPresent("e3", axis1) && dict.readIfPresent("e1", axis2))
00204     {
00205         order = e3e1;
00206     }
00207     else if (dict.found("axis") || dict.found("direction"))
00208     {
00209         // let it bomb if only one of axis/direction is defined
00210         order = e3e1;
00211         dict.lookup("axis") >> axis1;
00212         dict.lookup("direction") >> axis2;
00213     }
00214     else
00215     {
00216         // unspecified axes revert to the global system
00217         tensor::operator=(sphericalTensor::I);
00218         return;
00219     }
00220 
00221     calcTransform(axis1, axis2, order);
00222 }
00223 
00224 
00225 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd