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 "toroidalCS.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "mathematicalConstants.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 defineTypeNameAndDebug(toroidalCS, 0);
35 addToRunTimeSelectionTable(coordinateSystem, toroidalCS, dictionary);
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41 Foam::toroidalCS::toroidalCS
45 const coordinateRotation& cr,
49 coordinateSystem(name, origin, cr),
54 Foam::toroidalCS::toroidalCS
57 const dictionary& dict
60 coordinateSystem(name, dict),
61 radius_(readScalar(dict.lookup("radius")))
65 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
67 Foam::vector Foam::toroidalCS::localToGlobal
73 // Notation: r = local.x()
74 scalar theta = local.y()*mathematicalConstant::pi/180.0;
75 scalar phi = local.z()*mathematicalConstant::pi/180.0;
77 scalar rprime = radius_ + local.x()*sin(phi);
79 if ((local.x()*sin(phi)) > (radius_))
81 FatalErrorIn("toroidalCS::toGlobal(vector) const")
82 << "Badly defined toroidal coordinates"
86 return coordinateSystem::localToGlobal
88 vector(rprime*cos(theta), rprime*sin(theta), local.x()*cos(phi)),
94 Foam::tmp<Foam::vectorField> Foam::toroidalCS::localToGlobal
96 const vectorField& local,
100 const scalarField r = local.component(vector::X);
102 const scalarField theta =
103 local.component(vector::Y)*mathematicalConstant::pi/180.0;
105 const scalarField phi =
106 local.component(vector::Z)*mathematicalConstant::pi/180.0;
108 const scalarField rprime = radius_ + r*sin(phi);
110 vectorField lc(local.size());
111 lc.replace(vector::X, rprime*cos(theta));
112 lc.replace(vector::Y, rprime*sin(theta));
113 lc.replace(vector::Z, r*cos(phi));
115 return coordinateSystem::localToGlobal(lc, translate);
119 Foam::vector Foam::toroidalCS::globalToLocal
121 const vector& global,
127 "toroidalCS::globalToLocal(const vector&, bool) const"
134 Foam::tmp<Foam::vectorField> Foam::toroidalCS::globalToLocal
136 const vectorField& global,
142 "toroidalCS::globalToLocal(const vectorField&, bool) const"
145 return tmp<vectorField>(vectorField::null());
149 void Foam::toroidalCS::write(Ostream& os) const
151 coordinateSystem::write(os);
152 os << "radius: " << radius() << endl;
156 void Foam::toroidalCS::writeDict(Ostream& os, bool subDict) const
160 os << indent << name() << nl
161 << indent << token::BEGIN_BLOCK << incrIndent << nl;
164 coordinateSystem::writeDict(os, false);
165 os.writeKeyword("radius") << radius() << token::END_STATEMENT << nl;
169 os << decrIndent << indent << token::END_BLOCK << endl;
173 // ************************************************************************* //