1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
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"
30 #include "mathematicalConstants.H"
31 #include "addToRunTimeSelectionTable.H"
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 defineTypeNameAndDebug(sphericalCS, 0);
38 addToRunTimeSelectionTable(coordinateSystem, sphericalCS, dictionary);
39 addToRunTimeSelectionTable(coordinateSystem, sphericalCS, origRotation);
43 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
45 Foam::sphericalCS::sphericalCS(const bool inDegrees)
52 Foam::sphericalCS::sphericalCS
54 const coordinateSystem& cs,
63 Foam::sphericalCS::sphericalCS
66 const coordinateSystem& cs,
70 coordinateSystem(name, cs),
75 Foam::sphericalCS::sphericalCS
79 const coordinateRotation& cr,
83 coordinateSystem(name, origin, cr),
88 Foam::sphericalCS::sphericalCS
97 coordinateSystem(name, origin, axis, dirn),
102 Foam::sphericalCS::sphericalCS
105 const dictionary& dict
108 coordinateSystem(name, dict),
109 inDegrees_(dict.lookupOrDefault<Switch>("degrees", true))
113 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
115 bool Foam::sphericalCS::inDegrees() const
121 bool& Foam::sphericalCS::inDegrees()
127 Foam::vector Foam::sphericalCS::localToGlobal
133 scalar r = local.x();
137 * ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
142 * ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
145 return coordinateSystem::localToGlobal
147 vector(r*cos(theta)*sin(phi), r*sin(theta)*sin(phi), r*cos(phi)),
153 Foam::tmp<Foam::vectorField> Foam::sphericalCS::localToGlobal
155 const vectorField& local,
159 const scalarField r = local.component(vector::X);
160 const scalarField theta
162 local.component(vector::Y)
163 * ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
165 const scalarField phi
167 local.component(vector::Z)
168 * ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
171 vectorField lc(local.size());
172 lc.replace(vector::X, r*cos(theta)*sin(phi));
173 lc.replace(vector::Y, r*sin(theta)*sin(phi));
174 lc.replace(vector::Z, r*cos(phi));
176 return coordinateSystem::localToGlobal(lc, translate);
180 Foam::vector Foam::sphericalCS::globalToLocal
182 const vector& global,
186 const vector lc = coordinateSystem::globalToLocal(global, translate);
187 const scalar r = mag(lc);
195 ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 ),
199 ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 )
204 Foam::tmp<Foam::vectorField> Foam::sphericalCS::globalToLocal
206 const vectorField& global,
210 const vectorField lc = coordinateSystem::globalToLocal(global, translate);
211 const scalarField r = mag(lc);
213 tmp<vectorField> tresult(new vectorField(lc.size()));
214 vectorField& result = tresult();
227 lc.component(vector::Y),
228 lc.component(vector::X)
229 ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 )
237 lc.component(vector::Z)/(r + SMALL)
238 ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 )
245 // ************************************************************************* //