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

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