1 /*---------------------------------------------------------------------------*\
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 -------------------------------------------------------------------------------
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"
30 #include "addToRunTimeSelectionTable.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 defineTypeNameAndDebug(cylindricalCS, 0);
37 addToRunTimeSelectionTable(coordinateSystem, cylindricalCS, dictionary);
38 addToRunTimeSelectionTable(coordinateSystem, cylindricalCS, origRotation);
42 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
44 Foam::cylindricalCS::cylindricalCS(const bool inDegrees)
51 Foam::cylindricalCS::cylindricalCS
53 const coordinateSystem& cs,
62 Foam::cylindricalCS::cylindricalCS
65 const coordinateSystem& cs,
69 coordinateSystem(name, cs),
74 Foam::cylindricalCS::cylindricalCS
78 const coordinateRotation& cr,
82 coordinateSystem(name, origin, cr),
87 Foam::cylindricalCS::cylindricalCS
96 coordinateSystem(name, origin, axis, dirn),
101 Foam::cylindricalCS::cylindricalCS
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);
122 b[2] = Pair<bool>(false, false);
128 Foam::boundBox Foam::cylindricalCS::spanBounds() const
135 ( inDegrees_ ? -180.0 : -mathematicalConstant::pi ),
141 ( inDegrees_ ? 180.0 : mathematicalConstant::pi ),
148 bool Foam::cylindricalCS::inDegrees() const
154 Foam::Switch& Foam::cylindricalCS::inDegrees()
160 Foam::vector Foam::cylindricalCS::localToGlobal
168 local.y() * ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
171 return coordinateSystem::localToGlobal
173 vector(local.x()*cos(theta), local.x()*sin(theta), local.z()),
179 Foam::tmp<Foam::vectorField> Foam::cylindricalCS::localToGlobal
181 const vectorField& local,
187 local.component(vector::Y)
188 * ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
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,
207 const vector lc = coordinateSystem::globalToLocal(global, translate);
211 sqrt(sqr(lc.x()) + sqr(lc.y())),
216 ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 ),
222 Foam::tmp<Foam::vectorField> Foam::cylindricalCS::globalToLocal
224 const vectorField& global,
228 const vectorField lc =
229 coordinateSystem::globalToLocal(global, translate);
231 tmp<vectorField> tresult(new vectorField(lc.size()));
232 vectorField& result = tresult();
237 sqrt(sqr(lc.component(vector::X)) + sqr(lc.component(vector::Y)))
245 lc.component(vector::Y),
246 lc.component(vector::X)
247 ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 )
250 result.replace(vector::Z, lc.component(vector::Z));
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
268 << indent << token::BEGIN_BLOCK << incrIndent << nl;
271 coordinateSystem::writeDict(os, false);
272 os.writeKeyword("inDegrees") << inDegrees_ << token::END_STATEMENT << nl;
276 os << decrIndent << indent << token::END_BLOCK << endl;
281 // ************************************************************************* //