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

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