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 "toroidalCS.H"
27 #include "mathematicalConstants.H"
29 #include "addToRunTimeSelectionTable.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 defineTypeNameAndDebug(toroidalCS, 0);
36 addToRunTimeSelectionTable(coordinateSystem, toroidalCS, dictionary);
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42 Foam::toroidalCS::toroidalCS
46 const coordinateRotation& cr,
51 coordinateSystem(name, origin, cr),
57 Foam::toroidalCS::toroidalCS
60 const dictionary& dict
63 coordinateSystem(name, dict),
64 radius_(readScalar(dict.lookup("radius"))),
65 inDegrees_(dict.lookupOrDefault<Switch>("degrees", true))
69 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
71 Foam::coordinateSystem::spanInfo Foam::toroidalCS::spanLimited() const
73 spanInfo b(Pair<bool>(true, true));
75 // Upper bound or r is unlimited
76 b[0] = Pair<bool>(true, false);
82 Foam::boundBox Foam::toroidalCS::spanBounds() const
89 ( inDegrees_ ? -180.0 : -mathematicalConstant::pi ),
90 ( inDegrees_ ? -180.0 : -mathematicalConstant::pi )
95 ( inDegrees_ ? 180.0 : mathematicalConstant::pi ),
96 ( inDegrees_ ? 180.0 : mathematicalConstant::pi )
102 bool Foam::toroidalCS::inDegrees() const
108 Foam::Switch& Foam::toroidalCS::inDegrees()
114 Foam::vector Foam::toroidalCS::localToGlobal
120 // Notation: r = local.x()
121 scalar theta = local.y()*mathematicalConstant::pi/180.0;
122 scalar phi = local.z()*mathematicalConstant::pi/180.0;
124 scalar rprime = radius_ + local.x()*sin(phi);
126 if ((local.x()*sin(phi)) > (radius_))
128 FatalErrorIn("toroidalCS::toGlobal(vector) const")
129 << "Badly defined toroidal coordinates"
130 << abort(FatalError);
133 return coordinateSystem::localToGlobal
135 vector(rprime*cos(theta), rprime*sin(theta), local.x()*cos(phi)),
141 Foam::tmp<Foam::vectorField> Foam::toroidalCS::localToGlobal
143 const vectorField& local,
147 const scalarField r = local.component(vector::X);
149 const scalarField theta =
150 local.component(vector::Y)*mathematicalConstant::pi/180.0;
152 const scalarField phi =
153 local.component(vector::Z)*mathematicalConstant::pi/180.0;
155 const scalarField rprime = radius_ + r*sin(phi);
157 vectorField lc(local.size());
158 lc.replace(vector::X, rprime*cos(theta));
159 lc.replace(vector::Y, rprime*sin(theta));
160 lc.replace(vector::Z, r*cos(phi));
162 return coordinateSystem::localToGlobal(lc, translate);
166 Foam::vector Foam::toroidalCS::globalToLocal
168 const vector& global,
174 "toroidalCS::globalToLocal(const vector&, bool) const"
181 Foam::tmp<Foam::vectorField> Foam::toroidalCS::globalToLocal
183 const vectorField& global,
189 "toroidalCS::globalToLocal(const vectorField&, bool) const"
192 return tmp<vectorField>(vectorField::null());
196 void Foam::toroidalCS::write(Ostream& os) const
198 coordinateSystem::write(os);
199 os << "radius: " << radius() << endl;
203 void Foam::toroidalCS::writeDict(Ostream& os, bool subDict) const
208 << indent << token::BEGIN_BLOCK << incrIndent << nl;
211 coordinateSystem::writeDict(os, false);
212 os.writeKeyword("radius") << radius() << token::END_STATEMENT << nl;
216 os << decrIndent << indent << token::END_BLOCK << endl;
221 // ************************************************************************* //