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

EulerCoordinateRotation.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 "EulerCoordinateRotation.H"
00028 
00029 #include "Switch.H"
00030 #include "mathematicalConstants.H"
00031 #include "addToRunTimeSelectionTable.H"
00032 
00033 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00034 
00035 namespace Foam
00036 {
00037     defineTypeNameAndDebug(EulerCoordinateRotation, 0);
00038     addToRunTimeSelectionTable
00039     (
00040         coordinateRotation,
00041         EulerCoordinateRotation,
00042         dictionary
00043     );
00044 }
00045 
00046 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00047 
00048 void Foam::EulerCoordinateRotation::calcTransform
00049 (
00050     const scalar phiAngle,
00051     const scalar thetaAngle,
00052     const scalar psiAngle,
00053     const bool inDegrees
00054 )
00055 {
00056     scalar phi   = phiAngle;
00057     scalar theta = thetaAngle;
00058     scalar psi   = psiAngle;
00059 
00060     if (inDegrees)
00061     {
00062         phi   *= mathematicalConstant::pi/180.0;
00063         theta *= mathematicalConstant::pi/180.0;
00064         psi   *= mathematicalConstant::pi/180.0;
00065     }
00066 
00067     tensor::operator=
00068     (
00069         tensor
00070         (
00071             cos(phi)*cos(psi) - sin(phi)*sin(psi)*cos(theta),
00072             -sin(phi)*cos(psi)*cos(theta) - cos(phi)*sin(psi),
00073             sin(phi)*sin(theta),
00074 
00075             cos(phi)*sin(psi)*cos(theta) + sin(phi)*cos(psi),
00076             cos(phi)*cos(psi)*cos(theta) - sin(phi)*sin(psi),
00077             -cos(phi)*sin(theta),
00078 
00079             sin(psi)*sin(theta),
00080             cos(psi)*sin(theta),
00081             cos(theta)
00082         )
00083     );
00084 }
00085 
00086 
00087 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00088 
00089 Foam::EulerCoordinateRotation::EulerCoordinateRotation()
00090 :
00091     coordinateRotation()
00092 {}
00093 
00094 
00095 Foam::EulerCoordinateRotation::EulerCoordinateRotation
00096 (
00097     const vector& phiThetaPsi,
00098     const bool inDegrees
00099 )
00100 :
00101     coordinateRotation()
00102 {
00103     calcTransform
00104     (
00105         phiThetaPsi.component(vector::X),
00106         phiThetaPsi.component(vector::Y),
00107         phiThetaPsi.component(vector::Z),
00108         inDegrees
00109     );
00110 }
00111 
00112 
00113 Foam::EulerCoordinateRotation::EulerCoordinateRotation
00114 (
00115     const scalar phiAngle,
00116     const scalar thetaAngle,
00117     const scalar psiAngle,
00118     const bool inDegrees
00119 )
00120 :
00121     coordinateRotation()
00122 {
00123     calcTransform(phiAngle, thetaAngle, psiAngle, inDegrees);
00124 }
00125 
00126 
00127 Foam::EulerCoordinateRotation::EulerCoordinateRotation
00128 (
00129     const dictionary& dict
00130 )
00131 :
00132     coordinateRotation()
00133 {
00134     vector rotation(dict.lookup("rotation"));
00135 
00136     calcTransform
00137     (
00138         rotation.component(vector::X),
00139         rotation.component(vector::Y),
00140         rotation.component(vector::Z),
00141         dict.lookupOrDefault<Switch>("degrees", true)
00142     );
00143 }
00144 
00145 
00146 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Copyright © 2000-2009 OpenCFD Ltd