Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / meshTools / coordinateSystems / cylindricalCS.C
blob5e229863093e585bc110c5eb66b26fba4ea05504
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2010 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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "cylindricalCS.H"
28 #include "one.H"
29 #include "mathematicalConstants.H"
30 #include "addToRunTimeSelectionTable.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 namespace Foam
36     defineTypeNameAndDebug(cylindricalCS, 0);
37     addToRunTimeSelectionTable(coordinateSystem, cylindricalCS, dictionary);
38     addToRunTimeSelectionTable(coordinateSystem, cylindricalCS, origRotation);
42 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
44 Foam::cylindricalCS::cylindricalCS(const bool inDegrees)
46     coordinateSystem(),
47     inDegrees_(inDegrees)
51 Foam::cylindricalCS::cylindricalCS
53     const coordinateSystem& cs,
54     const bool inDegrees
57     coordinateSystem(cs),
58     inDegrees_(inDegrees)
62 Foam::cylindricalCS::cylindricalCS
64     const word& name,
65     const coordinateSystem& cs,
66     const bool inDegrees
69     coordinateSystem(name, cs),
70     inDegrees_(inDegrees)
74 Foam::cylindricalCS::cylindricalCS
76     const word& name,
77     const point& origin,
78     const coordinateRotation& cr,
79     const bool inDegrees
82     coordinateSystem(name, origin, cr),
83     inDegrees_(inDegrees)
87 Foam::cylindricalCS::cylindricalCS
89     const word& name,
90     const point& origin,
91     const vector& axis,
92     const vector& dirn,
93     const bool inDegrees
96     coordinateSystem(name, origin, axis, dirn),
97     inDegrees_(inDegrees)
101 Foam::cylindricalCS::cylindricalCS
103     const word& name,
104     const dictionary& dict
107     coordinateSystem(name, dict),
108     inDegrees_(dict.lookupOrDefault("degrees", true))
112 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
114 bool Foam::cylindricalCS::inDegrees() const
116     return inDegrees_;
120 bool& Foam::cylindricalCS::inDegrees()
122     return inDegrees_;
126 Foam::vector Foam::cylindricalCS::localToGlobal
128     const vector& local,
129     bool translate
130 ) const
132     scalar theta
133     (
134         local.y()*(inDegrees_ ? constant::mathematical::pi/180.0 : 1.0)
135     );
137     return coordinateSystem::localToGlobal
138     (
139         vector(local.x()*cos(theta), local.x()*sin(theta), local.z()),
140         translate
141     );
145 Foam::tmp<Foam::vectorField> Foam::cylindricalCS::localToGlobal
147     const vectorField& local,
148     bool translate
149 ) const
151     scalarField theta
152     (
153         local.component(vector::Y)
154        *(inDegrees_ ? constant::mathematical::pi/180.0 : 1.0)
155     );
158     vectorField lc(local.size());
159     lc.replace(vector::X, local.component(vector::X)*cos(theta));
160     lc.replace(vector::Y, local.component(vector::X)*sin(theta));
161     lc.replace(vector::Z, local.component(vector::Z));
163     return coordinateSystem::localToGlobal(lc, translate);
167 Foam::vector Foam::cylindricalCS::globalToLocal
169     const vector& global,
170     bool translate
171 ) const
173     const vector lc
174     (
175         coordinateSystem::globalToLocal(global, translate)
176     );
178     return vector
179     (
180         sqrt(sqr(lc.x()) + sqr(lc.y())),
181         atan2
182         (
183             lc.y(),
184             lc.x()
185         )*(inDegrees_ ? 180.0/constant::mathematical::pi : 1.0),
186         lc.z()
187     );
191 Foam::tmp<Foam::vectorField> Foam::cylindricalCS::globalToLocal
193     const vectorField& global,
194     bool translate
195 ) const
197     const vectorField lc
198     (
199         coordinateSystem::globalToLocal(global, translate)
200     );
202     tmp<vectorField> tresult(new vectorField(lc.size()));
203     vectorField& result = tresult();
205     result.replace
206     (
207         vector::X,
208         sqrt(sqr(lc.component(vector::X)) + sqr(lc.component(vector::Y)))
209     );
211     result.replace
212     (
213         vector::Y,
214         atan2
215         (
216             lc.component(vector::Y),
217             lc.component(vector::X)
218         )*(inDegrees_ ? 180.0/constant::mathematical::pi : 1.0)
219     );
221     result.replace(vector::Z, lc.component(vector::Z));
223     return tresult;
227 // ************************************************************************* //