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

cylindricalCS.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 "cylindricalCS.H"
00028 
00029 #include "one.H"
00030 #include "Switch.H"
00031 #include "mathematicalConstants.H"
00032 #include "addToRunTimeSelectionTable.H"
00033 
00034 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00035 
00036 namespace Foam
00037 {
00038     defineTypeNameAndDebug(cylindricalCS, 0);
00039     addToRunTimeSelectionTable(coordinateSystem, cylindricalCS, dictionary);
00040     addToRunTimeSelectionTable(coordinateSystem, cylindricalCS, origRotation);
00041 }
00042 
00043 
00044 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00045 
00046 Foam::cylindricalCS::cylindricalCS(const bool inDegrees)
00047 :
00048     coordinateSystem(),
00049     inDegrees_(inDegrees)
00050 {}
00051 
00052 
00053 Foam::cylindricalCS::cylindricalCS
00054 (
00055     const coordinateSystem& cs,
00056     const bool inDegrees
00057 )
00058 :
00059     coordinateSystem(cs),
00060     inDegrees_(inDegrees)
00061 {}
00062 
00063 
00064 Foam::cylindricalCS::cylindricalCS
00065 (
00066     const word& name,
00067     const coordinateSystem& cs,
00068     const bool inDegrees
00069 )
00070 :
00071     coordinateSystem(name, cs),
00072     inDegrees_(inDegrees)
00073 {}
00074 
00075 
00076 Foam::cylindricalCS::cylindricalCS
00077 (
00078     const word& name,
00079     const point& origin,
00080     const coordinateRotation& cr,
00081     const bool inDegrees
00082 )
00083 :
00084     coordinateSystem(name, origin, cr),
00085     inDegrees_(inDegrees)
00086 {}
00087 
00088 
00089 Foam::cylindricalCS::cylindricalCS
00090 (
00091     const word& name,
00092     const point& origin,
00093     const vector& axis,
00094     const vector& dirn,
00095     const bool inDegrees
00096 )
00097 :
00098     coordinateSystem(name, origin, axis, dirn),
00099     inDegrees_(inDegrees)
00100 {}
00101 
00102 
00103 Foam::cylindricalCS::cylindricalCS
00104 (
00105     const word& name,
00106     const dictionary& dict
00107 )
00108 :
00109     coordinateSystem(name, dict),
00110     inDegrees_(dict.lookupOrDefault<Switch>("degrees", true))
00111 {}
00112 
00113 
00114 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00115 
00116 bool Foam::cylindricalCS::inDegrees() const
00117 {
00118     return inDegrees_;
00119 }
00120 
00121 
00122 bool& Foam::cylindricalCS::inDegrees()
00123 {
00124     return inDegrees_;
00125 }
00126 
00127 
00128 Foam::vector Foam::cylindricalCS::localToGlobal
00129 (
00130     const vector& local,
00131     bool translate
00132 ) const
00133 {
00134     scalar theta
00135     (
00136         local.y() * ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )  
00137     );
00138 
00139     return coordinateSystem::localToGlobal
00140     (
00141         vector(local.x()*cos(theta), local.x()*sin(theta), local.z()),
00142         translate
00143     );
00144 }
00145 
00146 
00147 Foam::tmp<Foam::vectorField> Foam::cylindricalCS::localToGlobal
00148 (
00149     const vectorField& local,
00150     bool translate
00151 ) const
00152 {
00153     scalarField theta =
00154     (
00155         local.component(vector::Y)
00156       * ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
00157     );
00158 
00159 
00160     vectorField lc(local.size());
00161     lc.replace(vector::X, local.component(vector::X)*cos(theta));
00162     lc.replace(vector::Y, local.component(vector::X)*sin(theta));
00163     lc.replace(vector::Z, local.component(vector::Z));
00164 
00165     return coordinateSystem::localToGlobal(lc, translate);
00166 }
00167 
00168 
00169 Foam::vector Foam::cylindricalCS::globalToLocal
00170 (
00171     const vector& global,
00172     bool translate
00173 ) const
00174 {
00175     const vector lc = coordinateSystem::globalToLocal(global, translate);
00176 
00177     return vector
00178     (
00179         sqrt(sqr(lc.x()) + sqr(lc.y())),
00180         atan2
00181         (
00182             lc.y(),
00183             lc.x()
00184         ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 ),
00185         lc.z()
00186     );
00187 }
00188 
00189 
00190 Foam::tmp<Foam::vectorField> Foam::cylindricalCS::globalToLocal
00191 (
00192     const vectorField& global,
00193     bool translate
00194 ) const
00195 {
00196     const vectorField lc =
00197         coordinateSystem::globalToLocal(global, translate);
00198 
00199     tmp<vectorField> tresult(new vectorField(lc.size()));
00200     vectorField& result = tresult();
00201 
00202     result.replace
00203     (
00204         vector::X,
00205         sqrt(sqr(lc.component(vector::X)) + sqr(lc.component(vector::Y)))
00206     );
00207 
00208     result.replace
00209     (
00210         vector::Y,
00211         atan2
00212         (
00213             lc.component(vector::Y),
00214             lc.component(vector::X)
00215         ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 )
00216     );
00217 
00218     result.replace(vector::Z, lc.component(vector::Z));
00219 
00220     return tresult;
00221 }
00222 
00223 
00224 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd