1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
5 \\ / A nd | 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 "toroidalCS.H"
27 #include "mathematicalConstants.H"
30 #include "addToRunTimeSelectionTable.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 defineTypeNameAndDebug(toroidalCS, 0);
37 addToRunTimeSelectionTable(coordinateSystem, toroidalCS, dictionary);
40 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43 Foam::toroidalCS::toroidalCS
47 const coordinateRotation& cr,
52 coordinateSystem(name, origin, cr),
58 Foam::toroidalCS::toroidalCS
61 const dictionary& dict
64 coordinateSystem(name, dict),
65 radius_(readScalar(dict.lookup("radius"))),
66 inDegrees_(dict.lookupOrDefault<Switch>("degrees", true))
70 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
72 Foam::coordinateSystem::spanInfo Foam::toroidalCS::spanLimited() const
74 spanInfo b(Pair<bool>(true, true));
76 // Upper bound or r is unlimited
77 b[0] = Pair<bool>(true, false);
83 Foam::boundBox Foam::toroidalCS::spanBounds() const
90 ( inDegrees_ ? -180.0 : -mathematicalConstant::pi ),
91 ( inDegrees_ ? -180.0 : -mathematicalConstant::pi )
96 ( inDegrees_ ? 180.0 : mathematicalConstant::pi ),
97 ( inDegrees_ ? 180.0 : mathematicalConstant::pi )
103 bool Foam::toroidalCS::inDegrees() const
109 bool& Foam::toroidalCS::inDegrees()
115 Foam::vector Foam::toroidalCS::localToGlobal
121 // Notation: r = local.x()
122 scalar theta = local.y()*mathematicalConstant::pi/180.0;
123 scalar phi = local.z()*mathematicalConstant::pi/180.0;
125 scalar rprime = radius_ + local.x()*sin(phi);
127 if ((local.x()*sin(phi)) > (radius_))
129 FatalErrorIn("toroidalCS::toGlobal(vector) const")
130 << "Badly defined toroidal coordinates"
131 << abort(FatalError);
134 return coordinateSystem::localToGlobal
136 vector(rprime*cos(theta), rprime*sin(theta), local.x()*cos(phi)),
142 Foam::tmp<Foam::vectorField> Foam::toroidalCS::localToGlobal
144 const vectorField& local,
148 const scalarField r = local.component(vector::X);
150 const scalarField theta =
151 local.component(vector::Y)*mathematicalConstant::pi/180.0;
153 const scalarField phi =
154 local.component(vector::Z)*mathematicalConstant::pi/180.0;
156 const scalarField rprime = radius_ + r*sin(phi);
158 vectorField lc(local.size());
159 lc.replace(vector::X, rprime*cos(theta));
160 lc.replace(vector::Y, rprime*sin(theta));
161 lc.replace(vector::Z, r*cos(phi));
163 return coordinateSystem::localToGlobal(lc, translate);
167 Foam::vector Foam::toroidalCS::globalToLocal
169 const vector& global,
175 "toroidalCS::globalToLocal(const vector&, bool) const"
182 Foam::tmp<Foam::vectorField> Foam::toroidalCS::globalToLocal
184 const vectorField& global,
190 "toroidalCS::globalToLocal(const vectorField&, bool) const"
193 return tmp<vectorField>(vectorField::null());
197 void Foam::toroidalCS::write(Ostream& os) const
199 coordinateSystem::write(os);
200 os << "radius: " << radius() << endl;
204 void Foam::toroidalCS::writeDict(Ostream& os, bool subDict) const
208 os << indent << name() << nl
209 << indent << token::BEGIN_BLOCK << incrIndent << nl;
212 coordinateSystem::writeDict(os, false);
213 os.writeKeyword("radius") << radius() << token::END_STATEMENT << nl;
217 os << decrIndent << indent << token::END_BLOCK << endl;
221 // ************************************************************************* //