1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 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
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"
31 #include "mathematicalConstants.H"
32 #include "addToRunTimeSelectionTable.H"
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 defineTypeNameAndDebug(sphericalCS, 0);
39 addToRunTimeSelectionTable(coordinateSystem, sphericalCS, dictionary);
40 addToRunTimeSelectionTable(coordinateSystem, sphericalCS, origRotation);
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 Foam::sphericalCS::sphericalCS(const bool inDegrees)
53 Foam::sphericalCS::sphericalCS
55 const coordinateSystem& cs,
64 Foam::sphericalCS::sphericalCS
67 const coordinateSystem& cs,
71 coordinateSystem(name, cs),
76 Foam::sphericalCS::sphericalCS
80 const coordinateRotation& cr,
84 coordinateSystem(name, origin, cr),
89 Foam::sphericalCS::sphericalCS
98 coordinateSystem(name, origin, axis, dirn),
103 Foam::sphericalCS::sphericalCS
106 const dictionary& dict
109 coordinateSystem(name, dict),
110 inDegrees_(dict.lookupOrDefault<Switch>("degrees", true))
114 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
116 bool Foam::sphericalCS::inDegrees() const
122 bool& Foam::sphericalCS::inDegrees()
128 Foam::vector Foam::sphericalCS::localToGlobal
134 scalar r = local.x();
138 *( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
143 *( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
146 return coordinateSystem::localToGlobal
148 vector(r*cos(theta)*sin(phi), r*sin(theta)*sin(phi), r*cos(phi)),
154 Foam::tmp<Foam::vectorField> Foam::sphericalCS::localToGlobal
156 const vectorField& local,
160 const scalarField r = local.component(vector::X);
161 const scalarField theta
163 local.component(vector::Y)
164 * ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
166 const scalarField phi
168 local.component(vector::Z)
169 * ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
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,
187 const vector lc = coordinateSystem::globalToLocal(global, translate);
188 const scalar r = mag(lc);
196 ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 ),
200 ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 )
205 Foam::tmp<Foam::vectorField> Foam::sphericalCS::globalToLocal
207 const vectorField& global,
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();
228 lc.component(vector::Y),
229 lc.component(vector::X)
230 ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 )
238 lc.component(vector::Z)/(r + SMALL)
239 ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 )
246 // ************************************************************************* //