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 "toroidalCS.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "mathematicalConstants.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 defineTypeNameAndDebug(toroidalCS, 0);
36 addToRunTimeSelectionTable(coordinateSystem, toroidalCS, dictionary);
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42 Foam::toroidalCS::toroidalCS
46 const coordinateRotation& cr,
50 coordinateSystem(name, origin, cr),
55 Foam::toroidalCS::toroidalCS
58 const dictionary& dict
61 coordinateSystem(name, dict),
62 radius_(readScalar(dict.lookup("radius")))
66 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
68 Foam::vector Foam::toroidalCS::localToGlobal
74 // Notation: r = local.x()
75 scalar theta = local.y()*mathematicalConstant::pi/180.0;
76 scalar phi = local.z()*mathematicalConstant::pi/180.0;
78 scalar rprime = radius_ + local.x()*sin(phi);
80 if ((local.x()*sin(phi)) > (radius_))
82 FatalErrorIn("toroidalCS::toGlobal(vector) const")
83 << "Badly defined toroidal coordinates"
87 return coordinateSystem::localToGlobal
89 vector(rprime*cos(theta), rprime*sin(theta), local.x()*cos(phi)),
95 Foam::tmp<Foam::vectorField> Foam::toroidalCS::localToGlobal
97 const vectorField& local,
101 const scalarField r = local.component(vector::X);
103 const scalarField theta =
104 local.component(vector::Y)*mathematicalConstant::pi/180.0;
106 const scalarField phi =
107 local.component(vector::Z)*mathematicalConstant::pi/180.0;
109 const scalarField rprime = radius_ + r*sin(phi);
111 vectorField lc(local.size());
112 lc.replace(vector::X, rprime*cos(theta));
113 lc.replace(vector::Y, rprime*sin(theta));
114 lc.replace(vector::Z, r*cos(phi));
116 return coordinateSystem::localToGlobal(lc, translate);
120 Foam::vector Foam::toroidalCS::globalToLocal
122 const vector& global,
128 "toroidalCS::globalToLocal(const vector&, bool) const"
135 Foam::tmp<Foam::vectorField> Foam::toroidalCS::globalToLocal
137 const vectorField& global,
143 "toroidalCS::globalToLocal(const vectorField&, bool) const"
146 return tmp<vectorField>(vectorField::null());
150 void Foam::toroidalCS::write(Ostream& os) const
152 coordinateSystem::write(os);
153 os << "radius: " << radius() << endl;
157 void Foam::toroidalCS::writeDict(Ostream& os, bool subDict) const
161 os << indent << name() << nl
162 << indent << token::BEGIN_BLOCK << incrIndent << nl;
165 coordinateSystem::writeDict(os, false);
166 os.writeKeyword("radius") << radius() << token::END_STATEMENT << nl;
170 os << decrIndent << indent << token::END_BLOCK << endl;
174 // ************************************************************************* //