Fix tutorials: typo in tutorials/viscoelastic/viscoelasticFluidFoam/S-MDCPP/constant...
[OpenFOAM-1.6-ext.git] / src / OpenFOAM / coordinateSystems / toroidalCS.C
blob8f2c7cf7acd38d9e3cad5f93bcc6eda63faf6916
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 * * * * * * * * * * * * * //
33 namespace Foam
35     defineTypeNameAndDebug(toroidalCS, 0);
36     addToRunTimeSelectionTable(coordinateSystem, toroidalCS, dictionary);
39 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
42 Foam::toroidalCS::toroidalCS
44     const word& name,
45     const point& origin,
46     const coordinateRotation& cr,
47     const scalar radius
50     coordinateSystem(name, origin, cr),
51     radius_(radius)
55 Foam::toroidalCS::toroidalCS
57     const word& name,
58     const dictionary& dict
61     coordinateSystem(name, dict),
62     radius_(readScalar(dict.lookup("radius")))
66 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
68 Foam::vector Foam::toroidalCS::localToGlobal
70     const vector& local,
71     bool translate
72 ) const
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_))
81     {
82         FatalErrorIn("toroidalCS::toGlobal(vector) const")
83             << "Badly defined toroidal coordinates"
84             << abort(FatalError);
85     }
87     return coordinateSystem::localToGlobal
88     (
89         vector(rprime*cos(theta), rprime*sin(theta), local.x()*cos(phi)),
90         translate
91     );
95 Foam::tmp<Foam::vectorField> Foam::toroidalCS::localToGlobal
97     const vectorField& local,
98     bool translate
99 ) const
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,
123     bool translate
124 ) const
126     notImplemented
127     (
128         "toroidalCS::globalToLocal(const vector&, bool) const"
129     );
131     return vector::zero;
135 Foam::tmp<Foam::vectorField> Foam::toroidalCS::globalToLocal
137     const vectorField& global,
138     bool translate
139 ) const
141     notImplemented
142     (
143         "toroidalCS::globalToLocal(const vectorField&, bool) const"
144     );
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
159     if (subDict)
160     {
161         os  << indent << name() << nl
162             << indent << token::BEGIN_BLOCK << incrIndent << nl;
163     }
165     coordinateSystem::writeDict(os, false);
166     os.writeKeyword("radius") << radius() << token::END_STATEMENT << nl;
168     if (subDict)
169     {
170         os << decrIndent << indent << token::END_BLOCK << endl;
171     }
174 // ************************************************************************* //