initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / meshTools / coordinateSystems / cylindricalCS.C
blob33a7455cc2d66819a6a2ccf6c707905863c5fa71
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "cylindricalCS.H"
29 #include "one.H"
30 #include "Switch.H"
31 #include "mathematicalConstants.H"
32 #include "addToRunTimeSelectionTable.H"
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 namespace Foam
38     defineTypeNameAndDebug(cylindricalCS, 0);
39     addToRunTimeSelectionTable(coordinateSystem, cylindricalCS, dictionary);
40     addToRunTimeSelectionTable(coordinateSystem, cylindricalCS, origRotation);
44 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
46 Foam::cylindricalCS::cylindricalCS(const bool inDegrees)
48     coordinateSystem(),
49     inDegrees_(inDegrees)
53 Foam::cylindricalCS::cylindricalCS
55     const coordinateSystem& cs,
56     const bool inDegrees
59     coordinateSystem(cs),
60     inDegrees_(inDegrees)
64 Foam::cylindricalCS::cylindricalCS
66     const word& name,
67     const coordinateSystem& cs,
68     const bool inDegrees
71     coordinateSystem(name, cs),
72     inDegrees_(inDegrees)
76 Foam::cylindricalCS::cylindricalCS
78     const word& name,
79     const point& origin,
80     const coordinateRotation& cr,
81     const bool inDegrees
84     coordinateSystem(name, origin, cr),
85     inDegrees_(inDegrees)
89 Foam::cylindricalCS::cylindricalCS
91     const word& name,
92     const point& origin,
93     const vector& axis,
94     const vector& dirn,
95     const bool inDegrees
98     coordinateSystem(name, origin, axis, dirn),
99     inDegrees_(inDegrees)
103 Foam::cylindricalCS::cylindricalCS
105     const word& name,
106     const dictionary& dict
109     coordinateSystem(name, dict),
110     inDegrees_(dict.lookupOrDefault<Switch>("degrees", true))
114 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
116 bool Foam::cylindricalCS::inDegrees() const
118     return inDegrees_;
122 bool& Foam::cylindricalCS::inDegrees()
124     return inDegrees_;
128 Foam::vector Foam::cylindricalCS::localToGlobal
130     const vector& local,
131     bool translate
132 ) const
134     scalar theta
135     (
136         local.y() * ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )  
137     );
139     return coordinateSystem::localToGlobal
140     (
141         vector(local.x()*cos(theta), local.x()*sin(theta), local.z()),
142         translate
143     );
147 Foam::tmp<Foam::vectorField> Foam::cylindricalCS::localToGlobal
149     const vectorField& local,
150     bool translate
151 ) const
153     scalarField theta =
154     (
155         local.component(vector::Y)
156       * ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
157     );
160     vectorField lc(local.size());
161     lc.replace(vector::X, local.component(vector::X)*cos(theta));
162     lc.replace(vector::Y, local.component(vector::X)*sin(theta));
163     lc.replace(vector::Z, local.component(vector::Z));
165     return coordinateSystem::localToGlobal(lc, translate);
169 Foam::vector Foam::cylindricalCS::globalToLocal
171     const vector& global,
172     bool translate
173 ) const
175     const vector lc = coordinateSystem::globalToLocal(global, translate);
177     return vector
178     (
179         sqrt(sqr(lc.x()) + sqr(lc.y())),
180         atan2
181         (
182             lc.y(),
183             lc.x()
184         ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 ),
185         lc.z()
186     );
190 Foam::tmp<Foam::vectorField> Foam::cylindricalCS::globalToLocal
192     const vectorField& global,
193     bool translate
194 ) const
196     const vectorField lc =
197         coordinateSystem::globalToLocal(global, translate);
199     tmp<vectorField> tresult(new vectorField(lc.size()));
200     vectorField& result = tresult();
202     result.replace
203     (
204         vector::X,
205         sqrt(sqr(lc.component(vector::X)) + sqr(lc.component(vector::Y)))
206     );
208     result.replace
209     (
210         vector::Y,
211         atan2
212         (
213             lc.component(vector::Y),
214             lc.component(vector::X)
215         ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 )
216     );
218     result.replace(vector::Z, lc.component(vector::Z));
220     return tresult;
224 // ************************************************************************* //