Remove trailing whitespace systematically
[foam-extend-3.2.git] / src / foam / coordinateSystems / toroidalCS.C
blob4101496bd55ad876c68b199ed3c2ed791ed09d49
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     |
5     \\  /    A nd           | For copyright notice see file Copyright
6      \\/     M anipulation  |
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 "Switch.H"
29 #include "boundBox.H"
30 #include "addToRunTimeSelectionTable.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 namespace Foam
36     defineTypeNameAndDebug(toroidalCS, 0);
37     addToRunTimeSelectionTable(coordinateSystem, toroidalCS, dictionary);
40 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
43 Foam::toroidalCS::toroidalCS
45     const word& name,
46     const point& origin,
47     const coordinateRotation& cr,
48     const scalar radius,
49     const bool inDegrees
52     coordinateSystem(name, origin, cr),
53     radius_(radius),
54     inDegrees_(inDegrees)
58 Foam::toroidalCS::toroidalCS
60     const word& name,
61     const dictionary& dict
64     coordinateSystem(name, dict),
65     radius_(readScalar(dict.lookup("radius"))),
66     inDegrees_(dict.lookupOrDefault<Switch>("degrees", true))
70 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
72 Foam::coordinateSystem::spanInfo Foam::toroidalCS::spanLimited() const
74     spanInfo b(Pair<bool>(true, true));
76     // Upper bound or r is unlimited
77     b[0] = Pair<bool>(true, false);
79     return b;
83 Foam::boundBox Foam::toroidalCS::spanBounds() const
85     return boundBox
86     (
87         vector
88         (
89             0,
90             ( inDegrees_ ? -180.0 : -mathematicalConstant::pi ),
91             ( inDegrees_ ? -180.0 : -mathematicalConstant::pi )
92         ),
93         vector
94         (
95             GREAT,
96             ( inDegrees_ ? 180.0 : mathematicalConstant::pi ),
97             ( inDegrees_ ? 180.0 : mathematicalConstant::pi )
98         )
99     );
103 bool Foam::toroidalCS::inDegrees() const
105     return inDegrees_;
109 bool& Foam::toroidalCS::inDegrees()
111     return inDegrees_;
115 Foam::vector Foam::toroidalCS::localToGlobal
117     const vector& local,
118     bool translate
119 ) const
121     // Notation: r = local.x()
122     scalar theta = local.y()*mathematicalConstant::pi/180.0;
123     scalar phi = local.z()*mathematicalConstant::pi/180.0;
125     scalar rprime = radius_ + local.x()*sin(phi);
127     if ((local.x()*sin(phi)) > (radius_))
128     {
129         FatalErrorIn("toroidalCS::toGlobal(vector) const")
130             << "Badly defined toroidal coordinates"
131             << abort(FatalError);
132     }
134     return coordinateSystem::localToGlobal
135     (
136         vector(rprime*cos(theta), rprime*sin(theta), local.x()*cos(phi)),
137         translate
138     );
142 Foam::tmp<Foam::vectorField> Foam::toroidalCS::localToGlobal
144     const vectorField& local,
145     bool translate
146 ) const
148     const scalarField r = local.component(vector::X);
150     const scalarField theta =
151         local.component(vector::Y)*mathematicalConstant::pi/180.0;
153     const scalarField phi =
154         local.component(vector::Z)*mathematicalConstant::pi/180.0;
156     const scalarField rprime = radius_ + r*sin(phi);
158     vectorField lc(local.size());
159     lc.replace(vector::X, rprime*cos(theta));
160     lc.replace(vector::Y, rprime*sin(theta));
161     lc.replace(vector::Z, r*cos(phi));
163     return coordinateSystem::localToGlobal(lc, translate);
167 Foam::vector Foam::toroidalCS::globalToLocal
169     const vector& global,
170     bool translate
171 ) const
173     notImplemented
174     (
175         "toroidalCS::globalToLocal(const vector&, bool) const"
176     );
178     return vector::zero;
182 Foam::tmp<Foam::vectorField> Foam::toroidalCS::globalToLocal
184     const vectorField& global,
185     bool translate
186 ) const
188     notImplemented
189     (
190         "toroidalCS::globalToLocal(const vectorField&, bool) const"
191     );
193     return tmp<vectorField>(vectorField::null());
197 void Foam::toroidalCS::write(Ostream& os) const
199     coordinateSystem::write(os);
200     os << "radius: " << radius() << endl;
204 void Foam::toroidalCS::writeDict(Ostream& os, bool subDict) const
206     if (subDict)
207     {
208         os  << indent << name() << nl
209             << indent << token::BEGIN_BLOCK << incrIndent << nl;
210     }
212     coordinateSystem::writeDict(os, false);
213     os.writeKeyword("radius") << radius() << token::END_STATEMENT << nl;
215     if (subDict)
216     {
217         os << decrIndent << indent << token::END_BLOCK << endl;
218     }
221 // ************************************************************************* //