named regIOobject for dictionary
[OpenFOAM-1.6.x.git] / src / meshTools / coordinateSystems / sphericalCS.C
blob0e3f2663e5b6799c9fe42e61ef7758216c41616e
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 "sphericalCS.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(sphericalCS, 0);
39     addToRunTimeSelectionTable(coordinateSystem, sphericalCS, dictionary);
40     addToRunTimeSelectionTable(coordinateSystem, sphericalCS, origRotation);
44 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
46 Foam::sphericalCS::sphericalCS(const bool inDegrees)
48     coordinateSystem(),
49     inDegrees_(inDegrees)
53 Foam::sphericalCS::sphericalCS
55     const coordinateSystem& cs,
56     const bool inDegrees
59     coordinateSystem(cs),
60     inDegrees_(inDegrees)
64 Foam::sphericalCS::sphericalCS
66     const word& name,
67     const coordinateSystem& cs,
68     const bool inDegrees
71     coordinateSystem(name, cs),
72     inDegrees_(inDegrees)
76 Foam::sphericalCS::sphericalCS
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::sphericalCS::sphericalCS
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::sphericalCS::sphericalCS
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::sphericalCS::inDegrees() const
118     return inDegrees_;
122 bool& Foam::sphericalCS::inDegrees()
124     return inDegrees_;
128 Foam::vector Foam::sphericalCS::localToGlobal
130     const vector& local,
131     bool translate
132 ) const
134     scalar r = local.x();
135     const scalar theta
136     (
137         local.y()
138       * ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
139     );
140     const scalar phi
141     (
142         local.z()
143       * ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
144     );
146     return coordinateSystem::localToGlobal
147     (
148         vector(r*cos(theta)*sin(phi), r*sin(theta)*sin(phi), r*cos(phi)),
149         translate
150     );
154 Foam::tmp<Foam::vectorField> Foam::sphericalCS::localToGlobal
156     const vectorField& local,
157     bool translate
158 ) const
160     const scalarField r = local.component(vector::X);
161     const scalarField theta
162     (
163         local.component(vector::Y)
164       * ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
165     );
166     const scalarField phi
167     (
168         local.component(vector::Z)
169       * ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
170     );
172     vectorField lc(local.size());
173     lc.replace(vector::X, r*cos(theta)*sin(phi));
174     lc.replace(vector::Y, r*sin(theta)*sin(phi));
175     lc.replace(vector::Z, r*cos(phi));
177     return coordinateSystem::localToGlobal(lc, translate);
181 Foam::vector Foam::sphericalCS::globalToLocal
183     const vector& global,
184     bool translate
185 ) const
187     const vector lc = coordinateSystem::globalToLocal(global, translate);
188     const scalar r = mag(lc);
190     return vector
191     (
192         r,
193         atan2
194         (
195             lc.y(), lc.x()
196         ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 ),
197         acos
198         (
199             lc.z()/(r + SMALL)
200         ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 )
201     );
205 Foam::tmp<Foam::vectorField> Foam::sphericalCS::globalToLocal
207     const vectorField& global,
208     bool translate
209 ) const
211     const vectorField lc = coordinateSystem::globalToLocal(global, translate);
212     const scalarField r = mag(lc);
214     tmp<vectorField> tresult(new vectorField(lc.size()));
215     vectorField& result = tresult();
217     result.replace
218     (
219         vector::X, r
221     );
223     result.replace
224     (
225         vector::Y,
226         atan2
227         (
228             lc.component(vector::Y),
229             lc.component(vector::X)
230         ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 )
231     );
233     result.replace
234     (
235         vector::Z,
236         acos
237         (
238             lc.component(vector::Z)/(r + SMALL)
239         ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 )
240     );
242     return tresult;
246 // ************************************************************************* //