1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
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
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 "sphericalCS.H"
29 #include "mathematicalConstants.H"
30 #include "addToRunTimeSelectionTable.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 defineTypeNameAndDebug(sphericalCS, 0);
37 addToRunTimeSelectionTable(coordinateSystem, sphericalCS, dictionary);
38 addToRunTimeSelectionTable(coordinateSystem, sphericalCS, origRotation);
42 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
44 Foam::sphericalCS::sphericalCS(const bool inDegrees)
51 Foam::sphericalCS::sphericalCS
53 const coordinateSystem& cs,
62 Foam::sphericalCS::sphericalCS
65 const coordinateSystem& cs,
69 coordinateSystem(name, cs),
74 Foam::sphericalCS::sphericalCS
78 const coordinateRotation& cr,
82 coordinateSystem(name, origin, cr),
87 Foam::sphericalCS::sphericalCS
96 coordinateSystem(name, origin, axis, dirn),
101 Foam::sphericalCS::sphericalCS
104 const dictionary& dict
107 coordinateSystem(name, dict),
108 inDegrees_(dict.lookupOrDefault("degrees", true))
112 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
114 bool Foam::sphericalCS::inDegrees() const
120 bool& Foam::sphericalCS::inDegrees()
126 Foam::vector Foam::sphericalCS::localToGlobal
132 scalar r = local.x();
136 *(inDegrees_ ? constant::mathematical::pi/180.0 : 1.0)
141 *(inDegrees_ ? constant::mathematical::pi/180.0 : 1.0)
144 return coordinateSystem::localToGlobal
146 vector(r*cos(theta)*sin(phi), r*sin(theta)*sin(phi), r*cos(phi)),
152 Foam::tmp<Foam::vectorField> Foam::sphericalCS::localToGlobal
154 const vectorField& local,
158 const scalarField r(local.component(vector::X));
159 const scalarField theta
161 local.component(vector::Y)
162 *(inDegrees_ ? constant::mathematical::pi/180.0 : 1.0)
164 const scalarField phi
166 local.component(vector::Z)
167 *(inDegrees_ ? constant::mathematical::pi/180.0 : 1.0)
170 vectorField lc(local.size());
171 lc.replace(vector::X, r*cos(theta)*sin(phi));
172 lc.replace(vector::Y, r*sin(theta)*sin(phi));
173 lc.replace(vector::Z, r*cos(phi));
175 return coordinateSystem::localToGlobal(lc, translate);
179 Foam::vector Foam::sphericalCS::globalToLocal
181 const vector& global,
185 const vector lc = coordinateSystem::globalToLocal(global, translate);
186 const scalar r = mag(lc);
194 )*(inDegrees_ ? 180.0/constant::mathematical::pi : 1.0),
198 )*(inDegrees_ ? 180.0/constant::mathematical::pi : 1.0)
203 Foam::tmp<Foam::vectorField> Foam::sphericalCS::globalToLocal
205 const vectorField& global,
209 const vectorField lc(coordinateSystem::globalToLocal(global, translate));
210 const scalarField r(mag(lc));
212 tmp<vectorField> tresult(new vectorField(lc.size()));
213 vectorField& result = tresult();
226 lc.component(vector::Y),
227 lc.component(vector::X)
228 )*(inDegrees_ ? 180.0/constant::mathematical::pi : 1.0)
236 lc.component(vector::Z)/(r + SMALL)
237 )*(inDegrees_ ? 180.0/constant::mathematical::pi : 1.0)
244 // ************************************************************************* //