ENH: RASModel.C: clipping input to log
[OpenFOAM-1.7.x.git] / src / meshTools / coordinateSystems / cylindricalCS.C
blobb990523cc0a5db826cfc1e7e69540e860b7f4aad
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "cylindricalCS.H"
28 #include "one.H"
29 #include "Switch.H"
30 #include "mathematicalConstants.H"
31 #include "addToRunTimeSelectionTable.H"
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 namespace Foam
37     defineTypeNameAndDebug(cylindricalCS, 0);
38     addToRunTimeSelectionTable(coordinateSystem, cylindricalCS, dictionary);
39     addToRunTimeSelectionTable(coordinateSystem, cylindricalCS, origRotation);
43 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
45 Foam::cylindricalCS::cylindricalCS(const bool inDegrees)
47     coordinateSystem(),
48     inDegrees_(inDegrees)
52 Foam::cylindricalCS::cylindricalCS
54     const coordinateSystem& cs,
55     const bool inDegrees
58     coordinateSystem(cs),
59     inDegrees_(inDegrees)
63 Foam::cylindricalCS::cylindricalCS
65     const word& name,
66     const coordinateSystem& cs,
67     const bool inDegrees
70     coordinateSystem(name, cs),
71     inDegrees_(inDegrees)
75 Foam::cylindricalCS::cylindricalCS
77     const word& name,
78     const point& origin,
79     const coordinateRotation& cr,
80     const bool inDegrees
83     coordinateSystem(name, origin, cr),
84     inDegrees_(inDegrees)
88 Foam::cylindricalCS::cylindricalCS
90     const word& name,
91     const point& origin,
92     const vector& axis,
93     const vector& dirn,
94     const bool inDegrees
97     coordinateSystem(name, origin, axis, dirn),
98     inDegrees_(inDegrees)
102 Foam::cylindricalCS::cylindricalCS
104     const word& name,
105     const dictionary& dict
108     coordinateSystem(name, dict),
109     inDegrees_(dict.lookupOrDefault<Switch>("degrees", true))
113 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
115 bool Foam::cylindricalCS::inDegrees() const
117     return inDegrees_;
121 bool& Foam::cylindricalCS::inDegrees()
123     return inDegrees_;
127 Foam::vector Foam::cylindricalCS::localToGlobal
129     const vector& local,
130     bool translate
131 ) const
133     scalar theta
134     (
135         local.y() * ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )  
136     );
138     return coordinateSystem::localToGlobal
139     (
140         vector(local.x()*cos(theta), local.x()*sin(theta), local.z()),
141         translate
142     );
146 Foam::tmp<Foam::vectorField> Foam::cylindricalCS::localToGlobal
148     const vectorField& local,
149     bool translate
150 ) const
152     scalarField theta =
153     (
154         local.component(vector::Y)
155       * ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
156     );
159     vectorField lc(local.size());
160     lc.replace(vector::X, local.component(vector::X)*cos(theta));
161     lc.replace(vector::Y, local.component(vector::X)*sin(theta));
162     lc.replace(vector::Z, local.component(vector::Z));
164     return coordinateSystem::localToGlobal(lc, translate);
168 Foam::vector Foam::cylindricalCS::globalToLocal
170     const vector& global,
171     bool translate
172 ) const
174     const vector lc = coordinateSystem::globalToLocal(global, translate);
176     return vector
177     (
178         sqrt(sqr(lc.x()) + sqr(lc.y())),
179         atan2
180         (
181             lc.y(),
182             lc.x()
183         ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 ),
184         lc.z()
185     );
189 Foam::tmp<Foam::vectorField> Foam::cylindricalCS::globalToLocal
191     const vectorField& global,
192     bool translate
193 ) const
195     const vectorField lc =
196         coordinateSystem::globalToLocal(global, translate);
198     tmp<vectorField> tresult(new vectorField(lc.size()));
199     vectorField& result = tresult();
201     result.replace
202     (
203         vector::X,
204         sqrt(sqr(lc.component(vector::X)) + sqr(lc.component(vector::Y)))
205     );
207     result.replace
208     (
209         vector::Y,
210         atan2
211         (
212             lc.component(vector::Y),
213             lc.component(vector::X)
214         ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 )
215     );
217     result.replace(vector::Z, lc.component(vector::Z));
219     return tresult;
223 // ************************************************************************* //