1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-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 "unitConversion.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 = degToRad(local.y());
75 scalar phi = degToRad(local.z());
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,
102 local.component(vector::X)
105 const scalarField theta
107 local.component(vector::Y)*constant::mathematical::pi/180.0
110 const scalarField phi
112 local.component(vector::Z)*constant::mathematical::pi/180.0
115 const scalarField rprime
120 vectorField lc(local.size());
121 lc.replace(vector::X, rprime*cos(theta));
122 lc.replace(vector::Y, rprime*sin(theta));
123 lc.replace(vector::Z, r*cos(phi));
125 return coordinateSystem::localToGlobal(lc, translate);
129 Foam::vector Foam::toroidalCS::globalToLocal
131 const vector& global,
137 "toroidalCS::globalToLocal(const vector&, bool) const"
144 Foam::tmp<Foam::vectorField> Foam::toroidalCS::globalToLocal
146 const vectorField& global,
152 "toroidalCS::globalToLocal(const vectorField&, bool) const"
155 return tmp<vectorField>(vectorField::null());
159 void Foam::toroidalCS::write(Ostream& os) const
161 coordinateSystem::write(os);
162 os << "radius: " << radius() << endl;
166 void Foam::toroidalCS::writeDict(Ostream& os, bool subDict) const
170 os << indent << name() << nl
171 << indent << token::BEGIN_BLOCK << incrIndent << nl;
174 coordinateSystem::writeDict(os, false);
175 os.writeKeyword("radius") << radius() << token::END_STATEMENT << nl;
179 os << decrIndent << indent << token::END_BLOCK << endl;
184 // ************************************************************************* //