Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / foam / coordinateSystems / cylindricalCS.C
blob6cc61273dbf7a8e45e8890f6c5a61f07b54133b3
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 "cylindricalCS.H"
28 #include "mathematicalConstants.H"
29 #include "boundBox.H"
30 #include "addToRunTimeSelectionTable.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 namespace Foam
36     defineTypeNameAndDebug(cylindricalCS, 0);
37     addToRunTimeSelectionTable(coordinateSystem, cylindricalCS, dictionary);
38     addToRunTimeSelectionTable(coordinateSystem, cylindricalCS, origRotation);
42 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
44 Foam::cylindricalCS::cylindricalCS(const bool inDegrees)
46     coordinateSystem(),
47     inDegrees_(inDegrees)
51 Foam::cylindricalCS::cylindricalCS
53     const coordinateSystem& cs,
54     const bool inDegrees
57     coordinateSystem(cs),
58     inDegrees_(inDegrees)
62 Foam::cylindricalCS::cylindricalCS
64     const word& name,
65     const coordinateSystem& cs,
66     const bool inDegrees
69     coordinateSystem(name, cs),
70     inDegrees_(inDegrees)
74 Foam::cylindricalCS::cylindricalCS
76     const word& name,
77     const point& origin,
78     const coordinateRotation& cr,
79     const bool inDegrees
82     coordinateSystem(name, origin, cr),
83     inDegrees_(inDegrees)
87 Foam::cylindricalCS::cylindricalCS
89     const word& name,
90     const point& origin,
91     const vector& axis,
92     const vector& dirn,
93     const bool inDegrees
96     coordinateSystem(name, origin, axis, dirn),
97     inDegrees_(inDegrees)
101 Foam::cylindricalCS::cylindricalCS
103     const word& name,
104     const dictionary& dict
107     coordinateSystem(name, dict),
108     inDegrees_(dict.lookupOrDefault<Switch>("degrees", true))
112 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
114 Foam::coordinateSystem::spanInfo Foam::cylindricalCS::spanLimited() const
116     spanInfo b(Pair<bool>(true, true));
118     // Upper bound or r is unlimited
119     b[0] = Pair<bool>(true, false);
121     // z is unlimited
122     b[2] = Pair<bool>(false, false);
124     return b;
128 Foam::boundBox Foam::cylindricalCS::spanBounds() const
130     return boundBox
131     (
132         vector
133         (
134             0,
135             ( inDegrees_ ? -180.0 : -mathematicalConstant::pi ),
136             -GREAT
137         ),
138         vector
139         (
140             GREAT,
141             ( inDegrees_ ? 180.0 : mathematicalConstant::pi ),
142             GREAT
143         )
144     );
148 bool Foam::cylindricalCS::inDegrees() const
150     return inDegrees_;
154 Foam::Switch& Foam::cylindricalCS::inDegrees()
156     return inDegrees_;
160 Foam::vector Foam::cylindricalCS::localToGlobal
162     const vector& local,
163     bool translate
164 ) const
166     scalar theta
167     (
168         local.y() * ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
169     );
171     return coordinateSystem::localToGlobal
172     (
173         vector(local.x()*cos(theta), local.x()*sin(theta), local.z()),
174         translate
175     );
179 Foam::tmp<Foam::vectorField> Foam::cylindricalCS::localToGlobal
181     const vectorField& local,
182     bool translate
183 ) const
185     scalarField theta =
186     (
187         local.component(vector::Y)
188       * ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
189     );
192     vectorField lc(local.size());
193     lc.replace(vector::X, local.component(vector::X)*cos(theta));
194     lc.replace(vector::Y, local.component(vector::X)*sin(theta));
195     lc.replace(vector::Z, local.component(vector::Z));
197     return coordinateSystem::localToGlobal(lc, translate);
201 Foam::vector Foam::cylindricalCS::globalToLocal
203     const vector& global,
204     bool translate
205 ) const
207     const vector lc = coordinateSystem::globalToLocal(global, translate);
209     return vector
210     (
211         sqrt(sqr(lc.x()) + sqr(lc.y())),
212         atan2
213         (
214             lc.y(),
215             lc.x()
216         ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 ),
217         lc.z()
218     );
222 Foam::tmp<Foam::vectorField> Foam::cylindricalCS::globalToLocal
224     const vectorField& global,
225     bool translate
226 ) const
228     const vectorField lc =
229         coordinateSystem::globalToLocal(global, translate);
231     tmp<vectorField> tresult(new vectorField(lc.size()));
232     vectorField& result = tresult();
234     result.replace
235     (
236         vector::X,
237         sqrt(sqr(lc.component(vector::X)) + sqr(lc.component(vector::Y)))
238     );
240     result.replace
241     (
242         vector::Y,
243         atan2
244         (
245             lc.component(vector::Y),
246             lc.component(vector::X)
247         ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 )
248     );
250     result.replace(vector::Z, lc.component(vector::Z));
252     return tresult;
256 void Foam::cylindricalCS::write(Ostream& os) const
258     coordinateSystem::write(os);
259     os << "inDegrees: " << inDegrees() << endl;
263 void Foam::cylindricalCS::writeDict(Ostream& os, bool subDict) const
265     if (subDict)
266     {
267         os  << indent << nl
268             << indent << token::BEGIN_BLOCK << incrIndent << nl;
269     }
271     coordinateSystem::writeDict(os, false);
272     os.writeKeyword("inDegrees") << inDegrees_ << token::END_STATEMENT << nl;
274     if (subDict)
275     {
276         os << decrIndent << indent << token::END_BLOCK << endl;
277     }
281 // ************************************************************************* //