Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / foam / coordinateSystems / toroidalCS.C
blobab4286782e82daa0002ff320080d8e3939f1e91c
1 /*---------------------------------------------------------------------------*\
2   =========                 |
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 -------------------------------------------------------------------------------
8 License
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"
28 #include "boundBox.H"
29 #include "addToRunTimeSelectionTable.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,
48     const bool inDegrees
51     coordinateSystem(name, origin, cr),
52     radius_(radius),
53     inDegrees_(inDegrees)
57 Foam::toroidalCS::toroidalCS
59     const word& name,
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);
78     return b;
82 Foam::boundBox Foam::toroidalCS::spanBounds() const
84     return boundBox
85     (
86         vector
87         (
88             0,
89             ( inDegrees_ ? -180.0 : -mathematicalConstant::pi ),
90             ( inDegrees_ ? -180.0 : -mathematicalConstant::pi )
91         ),
92         vector
93         (
94             GREAT,
95             ( inDegrees_ ? 180.0 : mathematicalConstant::pi ),
96             ( inDegrees_ ? 180.0 : mathematicalConstant::pi )
97         )
98     );
102 bool Foam::toroidalCS::inDegrees() const
104     return inDegrees_;
108 Foam::Switch& Foam::toroidalCS::inDegrees()
110     return inDegrees_;
114 Foam::vector Foam::toroidalCS::localToGlobal
116     const vector& local,
117     bool translate
118 ) const
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_))
127     {
128         FatalErrorIn("toroidalCS::toGlobal(vector) const")
129             << "Badly defined toroidal coordinates"
130             << abort(FatalError);
131     }
133     return coordinateSystem::localToGlobal
134     (
135         vector(rprime*cos(theta), rprime*sin(theta), local.x()*cos(phi)),
136         translate
137     );
141 Foam::tmp<Foam::vectorField> Foam::toroidalCS::localToGlobal
143     const vectorField& local,
144     bool translate
145 ) const
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,
169     bool translate
170 ) const
172     notImplemented
173     (
174         "toroidalCS::globalToLocal(const vector&, bool) const"
175     );
177     return vector::zero;
181 Foam::tmp<Foam::vectorField> Foam::toroidalCS::globalToLocal
183     const vectorField& global,
184     bool translate
185 ) const
187     notImplemented
188     (
189         "toroidalCS::globalToLocal(const vectorField&, bool) const"
190     );
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
205     if (subDict)
206     {
207         os  << indent << nl
208             << indent << token::BEGIN_BLOCK << incrIndent << nl;
209     }
211     coordinateSystem::writeDict(os, false);
212     os.writeKeyword("radius") << radius() << token::END_STATEMENT << nl;
214     if (subDict)
215     {
216         os << decrIndent << indent << token::END_BLOCK << endl;
217     }
221 // ************************************************************************* //