FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "coordinateRotation.H"
00027 #include <OpenFOAM/dictionary.H>
00028 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00029 
00030 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00031 
00032 namespace Foam
00033 {
00034     defineTypeNameAndDebug(coordinateRotation, 0);
00035     defineRunTimeSelectionTable(coordinateRotation, dictionary);
00036 }
00037 
00038 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00039 
00040 void Foam::coordinateRotation::calcTransform
00041 (
00042     const vector& axis1,
00043     const vector& axis2,
00044     const axisOrder& order
00045 )
00046 {
00047     vector a = axis1 / mag(axis1);
00048     vector b = axis2;
00049 
00050     // Absorb minor nonorthogonality into axis2
00051     b = b - (b & a)*a;
00052 
00053     if (mag(b) < SMALL)
00054     {
00055         FatalErrorIn("coordinateRotation::calcTransform()")
00056             << "axis1, axis2 appear co-linear: "
00057             << axis1 << ", " << axis2 << endl
00058             << abort(FatalError);
00059     }
00060 
00061     b = b / mag(b);
00062     vector c = a ^ b;
00063 
00064     // the global -> local transformation
00065     tensor Rtr;
00066     switch (order)
00067     {
00068         case e1e2:
00069             Rtr = tensor(a, b, c);
00070             break;
00071 
00072         case e2e3:
00073             Rtr = tensor(c, a, b);
00074             break;
00075 
00076         case e3e1:
00077             Rtr = tensor(b, c, a);
00078             break;
00079 
00080         default:
00081             FatalErrorIn("coordinateRotation::calcTransform()")
00082                 << "programmer error" << endl
00083                 << abort(FatalError);
00084             // To satisfy compiler warnings
00085             Rtr = tensor::zero;
00086             break;
00087     }
00088 
00089     // the local -> global transformation
00090     tensor::operator=( Rtr.T() );
00091 }
00092 
00093 
00094 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00095 
00096 Foam::coordinateRotation::coordinateRotation()
00097 :
00098     tensor(sphericalTensor::I)
00099 {}
00100 
00101 
00102 Foam::coordinateRotation::coordinateRotation
00103 (
00104     const vector& axis,
00105     const vector& dir
00106 )
00107 :
00108     tensor(sphericalTensor::I)
00109 {
00110     calcTransform(axis, dir, e3e1);
00111 }
00112 
00113 
00114 Foam::coordinateRotation::coordinateRotation
00115 (
00116     const dictionary& dict
00117 )
00118 :
00119     tensor(sphericalTensor::I)
00120 {
00121     operator=(dict);
00122 }
00123 
00124 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
00125 
00126 Foam::autoPtr<Foam::coordinateRotation> Foam::coordinateRotation::New
00127 (
00128     const dictionary& dict
00129 )
00130 {
00131     if (debug)
00132     {
00133         Pout<< "coordinateRotation::New(const dictionary&) : "
00134             << "constructing coordinateRotation"
00135             << endl;
00136     }
00137 
00138     // default type is self (alias: "axes")
00139     word rotType(typeName_());
00140     dict.readIfPresent("type", rotType);
00141 
00142     // can (must) construct base class directly
00143     if (rotType == typeName_() || rotType == "axes")
00144     {
00145         return autoPtr<coordinateRotation>(new coordinateRotation(dict));
00146     }
00147 
00148 
00149     dictionaryConstructorTable::iterator cstrIter =
00150         dictionaryConstructorTablePtr_->find(rotType);
00151 
00152     if (cstrIter == dictionaryConstructorTablePtr_->end())
00153     {
00154         FatalIOErrorIn
00155         (
00156             "coordinateRotation::New(const dictionary&)",
00157             dict
00158         )   << "Unknown coordinateRotation type "
00159             << rotType << nl << nl
00160             << "Valid coordinateRotation types are :" <<  nl
00161             << "[default: axes " << typeName_() << "]"
00162             << dictionaryConstructorTablePtr_->sortedToc()
00163             << exit(FatalIOError);
00164     }
00165 
00166     return autoPtr<coordinateRotation>(cstrIter()(dict));
00167 }
00168 
00169 
00170 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00171 
00172 void Foam::coordinateRotation::operator=(const dictionary& rhs)
00173 {
00174     if (debug)
00175     {
00176         Pout<< "coordinateRotation::operator=(const dictionary&) : "
00177             << "assign from " << rhs << endl;
00178     }
00179 
00180     // allow as embedded sub-dictionary "coordinateRotation"
00181     const dictionary& dict =
00182     (
00183         rhs.found(typeName_())
00184       ? rhs.subDict(typeName_())
00185       : rhs
00186     );
00187 
00188     vector axis1, axis2;
00189     axisOrder order(e3e1);
00190 
00191     if (dict.readIfPresent("e1", axis1) && dict.readIfPresent("e2", axis2))
00192     {
00193         order = e1e2;
00194     }
00195     else if (dict.readIfPresent("e2", axis1) && dict.readIfPresent("e3", axis2))
00196     {
00197         order = e2e3;
00198     }
00199     else if (dict.readIfPresent("e3", axis1) && dict.readIfPresent("e1", axis2))
00200     {
00201         order = e3e1;
00202     }
00203     else if (dict.found("axis") || dict.found("direction"))
00204     {
00205         // let it bomb if only one of axis/direction is defined
00206         order = e3e1;
00207         dict.lookup("axis") >> axis1;
00208         dict.lookup("direction") >> axis2;
00209     }
00210     else
00211     {
00212         // unspecified axes revert to the global system
00213         tensor::operator=(sphericalTensor::I);
00214         return;
00215     }
00216 
00217     calcTransform(axis1, axis2, order);
00218 }
00219 
00220 
00221 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines