1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "sphericalCS.H"
29 #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 Foam::coordinateSystem::spanInfo Foam::sphericalCS::spanLimited() const
117 spanInfo b(Pair<bool>(true, true));
119 // Upper bound or r is unlimited
120 b[0] = Pair<bool>(true, false);
126 Foam::boundBox Foam::sphericalCS::spanBounds() const
133 ( inDegrees_ ? -180.0 : -mathematicalConstant::pi ),
134 ( inDegrees_ ? -90.0 : -mathematicalConstant::pi/2 )
139 ( inDegrees_ ? 180.0 : mathematicalConstant::pi ),
140 ( inDegrees_ ? 90.0 : mathematicalConstant::pi/2 )
146 bool Foam::sphericalCS::inDegrees() const
152 Foam::Switch& Foam::sphericalCS::inDegrees()
158 Foam::vector Foam::sphericalCS::localToGlobal
164 scalar r = local.x();
168 *( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
173 *( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
176 return coordinateSystem::localToGlobal
178 vector(r*cos(theta)*sin(phi), r*sin(theta)*sin(phi), r*cos(phi)),
184 Foam::tmp<Foam::vectorField> Foam::sphericalCS::localToGlobal
186 const vectorField& local,
190 const scalarField r = local.component(vector::X);
191 const scalarField theta
193 local.component(vector::Y)
194 * ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
196 const scalarField phi
198 local.component(vector::Z)
199 * ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
202 vectorField lc(local.size());
203 lc.replace(vector::X, r*cos(theta)*sin(phi));
204 lc.replace(vector::Y, r*sin(theta)*sin(phi));
205 lc.replace(vector::Z, r*cos(phi));
207 return coordinateSystem::localToGlobal(lc, translate);
211 Foam::vector Foam::sphericalCS::globalToLocal
213 const vector& global,
217 const vector lc = coordinateSystem::globalToLocal(global, translate);
218 const scalar r = mag(lc);
226 ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 ),
230 ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 )
235 Foam::tmp<Foam::vectorField> Foam::sphericalCS::globalToLocal
237 const vectorField& global,
241 const vectorField lc = coordinateSystem::globalToLocal(global, translate);
242 const scalarField r = mag(lc);
244 tmp<vectorField> tresult(new vectorField(lc.size()));
245 vectorField& result = tresult();
258 lc.component(vector::Y),
259 lc.component(vector::X)
260 ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 )
268 lc.component(vector::Z)/(r + SMALL)
269 ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 )
276 void Foam::sphericalCS::write(Ostream& os) const
278 coordinateSystem::write(os);
279 os << "inDegrees: " << inDegrees() << endl;
283 void Foam::sphericalCS::writeDict(Ostream& os, bool subDict) const
288 << indent << token::BEGIN_BLOCK << incrIndent << nl;
291 coordinateSystem::writeDict(os, false);
292 os.writeKeyword("inDegrees") << inDegrees_ << token::END_STATEMENT << nl;
296 os << decrIndent << indent << token::END_BLOCK << endl;
301 // ************************************************************************* //