cylindricalCS.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "cylindricalCS.H"
27 
28 #include "one.H"
29 #include "mathematicalConstants.H"
31 
32 
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 
36 :
38  inDegrees_(inDegrees)
39 {}
40 
41 
43 (
44  const coordinateSystem& cs,
45  const bool inDegrees
46 )
47 :
48  coordinateSystem(cs),
49  inDegrees_(inDegrees)
50 {}
51 
52 
54 (
55  const word& name,
56  const coordinateSystem& cs,
57  const bool inDegrees
58 )
59 :
60  coordinateSystem(name, cs),
61  inDegrees_(inDegrees)
62 {}
63 
64 
66 (
67  const word& name,
68  const point& origin,
69  const coordinateRotation& cr,
70  const bool inDegrees
71 )
72 :
73  coordinateSystem(name, origin, cr),
74  inDegrees_(inDegrees)
75 {}
76 
77 
79 (
80  const word& name,
81  const point& origin,
82  const vector& axis,
83  const vector& dirn,
84  const bool inDegrees
85 )
86 :
87  coordinateSystem(name, origin, axis, dirn),
88  inDegrees_(inDegrees)
89 {}
90 
91 
93 (
94  const word& name,
95  const dictionary& dict
96 )
97 :
98  coordinateSystem(name, dict),
99  inDegrees_(dict.lookupOrDefault("degrees", true))
100 {}
101 
102 
104 (
105  const objectRegistry& obr,
106  const dictionary& dict
107 )
108 :
109  coordinateSystem(obr, dict),
110  inDegrees_(dict.lookupOrDefault("degrees", true))
111 {}
112 
113 
114 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
115 
117 {}
118 
119 
120 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
121 
123 {
124  return inDegrees_;
125 }
126 
127 
129 {
130  return inDegrees_;
131 }
132 
133 
135 (
136  const vector& local,
137  bool translate
138 ) const
139 {
140  scalar theta
141  (
142  local.y()*(inDegrees_ ? constant::mathematical::pi/180.0 : 1.0)
143  );
144 
146  (
147  vector(local.x()*cos(theta), local.x()*sin(theta), local.z()),
148  translate
149  );
150 }
151 
152 
154 (
155  const vectorField& local,
156  bool translate
157 ) const
158 {
159  scalarField theta
160  (
161  local.component(vector::Y)
162  *(inDegrees_ ? constant::mathematical::pi/180.0 : 1.0)
163  );
164 
165 
166  vectorField lc(local.size());
167  lc.replace(vector::X, local.component(vector::X)*cos(theta));
168  lc.replace(vector::Y, local.component(vector::X)*sin(theta));
169  lc.replace(vector::Z, local.component(vector::Z));
170 
171  return coordinateSystem::localToGlobal(lc, translate);
172 }
173 
174 
176 (
177  const vector& global,
178  bool translate
179 ) const
180 {
181  const vector lc
182  (
183  coordinateSystem::globalToLocal(global, translate)
184  );
185 
186  return vector
187  (
188  sqrt(sqr(lc.x()) + sqr(lc.y())),
189  atan2
190  (
191  lc.y(),
192  lc.x()
193  )*(inDegrees_ ? 180.0/constant::mathematical::pi : 1.0),
194  lc.z()
195  );
196 }
197 
198 
200 (
201  const vectorField& global,
202  bool translate
203 ) const
204 {
205  const vectorField lc
206  (
207  coordinateSystem::globalToLocal(global, translate)
208  );
209 
210  tmp<vectorField> tresult(new vectorField(lc.size()));
211  vectorField& result = tresult();
212 
213  result.replace
214  (
215  vector::X,
217  );
218 
219  result.replace
220  (
221  vector::Y,
222  atan2
223  (
224  lc.component(vector::Y),
225  lc.component(vector::X)
226  )*(inDegrees_ ? 180.0/constant::mathematical::pi : 1.0)
227  );
228 
229  result.replace(vector::Z, lc.component(vector::Z));
230 
231  return tresult;
232 }
233 
234 
235 // ************************************************************************* //
dimensionedScalar sqrt(const dimensionedScalar &ds)
virtual vector globalToLocal(const vector &, bool translate) const
Convert from global Cartesian system to the local coordinate system.
tmp< Field< cmptType > > component(const direction) const
Return a component field of the field.
Definition: Field.C:578
Base class for other coordinate system specifications.
dimensionedScalar atan2(const dimensionedScalar &x, const dimensionedScalar &y)
virtual ~cylindricalCS()
Destructor.
A class for handling words, derived from string.
Definition: word.H:59
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
const Cmpt & y() const
Definition: VectorI.H:71
Abstract base class for coordinate rotation.
Field< vector > vectorField
Specialisation of Field<T> for vector.
dimensionedScalar cos(const dimensionedScalar &ds)
const Cmpt & x() const
Definition: VectorI.H:65
Macros for easy insertion into run-time selection tables.
const Cmpt & z() const
Definition: VectorI.H:77
coordinateSystem()
Construct null. This is equivalent to an identity coordinateSystem.
bool inDegrees() const
Are angles in degrees?
cylindricalCS(const bool inDegrees=true)
Construct null.
Definition: cylindricalCS.C:35
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
Registry of regIOobjects.
virtual vector globalToLocal(const vector &, bool translate) const
Convert from global Cartesian system to the local coordinate system.
virtual vector localToGlobal(const vector &, bool translate) const
Convert from local coordinate system to the global Cartesian system.
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
void replace(const direction, const UList< cmptType > &)
Replace a component field of the field.
Definition: Field.C:590
dimensionedSymmTensor sqr(const dimensionedVector &dv)
virtual vector localToGlobal(const vector &, bool translate) const
Convert from local coordinate system to the global Cartesian system.
A class for managing temporary objects.
Definition: PtrList.H:118
dimensionedScalar sin(const dimensionedScalar &ds)