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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2018-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "cylindricalCS.H"
30 #include "cylindricalRotation.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 namespace coordSystem
38 {
39  defineTypeName(cylindrical);
40  addToRunTimeSelectionTable(coordinateSystem, cylindrical, dictionary);
41 }
42 }
43 
44 
46 
47 
48 // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 // Issue warning if 'degrees' keyword was specified and true.
54 // Compatibility change after 1806.
55 
56 static inline void warnCompatDegrees(const Foam::dictionary& dict)
57 {
58  if (Pstream::parRun() ? Pstream::master() : true)
59  {
60  std::cerr
61  << "--> FOAM IOWarning :" << nl
62  << " Found [v1806] 'degrees' keyword in dictionary \""
63  << dict.name().c_str() << "\" Ignored, now radians only." << nl
64  << std::endl;
65  }
66 }
67 
68 
69 //- Convert from Cartesian (to Cylindrical)
70 static inline vector fromCartesian(const vector& v)
71 {
72  return vector(hypot(v.x(), v.y()), atan2(v.y(), v.x()), v.z());
73 }
74 
75 
76 //- Convert to Cartesian (from Cylindrical)
77 static inline vector toCartesian(const vector& v)
78 {
79  return vector(v.x()*cos(v.y()), v.x()*sin(v.y()), v.z());
80 }
81 
82 } // End namespace Foam
83 
84 
85 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
86 
88 :
90 {}
91 
92 
94 :
95  coordinateSystem(csys)
96 {}
97 
98 
100 :
101  coordinateSystem(std::move(csys))
102 {}
103 
104 
106 :
107  coordinateSystem(std::move(csys))
108 {}
109 
110 
112 (
113  const point& origin,
114  const coordinateRotation& crot
115 )
116 :
117  coordinateSystem(origin, crot)
118 {}
119 
120 
122 (
123  const point& origin,
124  const vector& axis
125 )
126 :
127  cylindrical(word::null, origin, axis)
128 {}
129 
130 
132 (
133  const word& name,
134  const point& origin,
135  const vector& axis
136 )
137 :
139  (
140  name,
141  origin,
143  )
144 {}
145 
146 
148 (
149  const point& origin,
150  const vector& axis,
151  const vector& dirn
152 )
153 :
154  cylindrical(word::null, origin, axis, dirn)
155 {}
156 
157 
159 (
160  const word& name,
161  const point& origin,
162  const vector& axis,
163  const vector& dirn
164 )
165 :
166  coordinateSystem(name, origin, axis, dirn)
167 {}
168 
169 
171 (
172  const word& name,
173  const dictionary& dict
174 )
175 :
177 {
178  if (dict.getOrDefault("degrees", false))
179  {
181  }
182 }
183 
184 
186 :
188 {
189  if (dict.getOrDefault("degrees", false))
190  {
192  }
193 }
194 
195 
197 (
198  const dictionary& dict,
199  const word& dictName
200 )
201 :
203 {
204  const dictionary* dictPtr =
205  (
206  dictName.size()
207  ? &(dict.subDict(dictName))
208  : &(dict)
209  );
210 
211  if (dictPtr->getOrDefault("degrees", false))
212  {
214  }
215 }
216 
217 
218 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
219 
221 {
222  // Robuster version of coordinateRotations::axes::rotation()
223  // using an E3_E1 order and falling back to the top-level rotation
224  // tensor if the directional input is borderline.
225 
226  tensor rotTensor(rot_);
227 
228  const vector ax1 = rotTensor.col<2>(); // == e3 (already normalized)
229 
230  vector ax2(global - origin_);
231 
232  // Remove colinear component
233  ax2 -= ((ax1 & ax2) * ax1);
234 
235  const scalar magAxis2(mag(ax2));
236 
237  // Trap zero size and colinearity
238  if (magAxis2 < SMALL)
239  {
240  return rotTensor;
241  }
242 
243  ax2 /= magAxis2; // normalise
244 
245  // Replace with updated local axes
246 
247  rotTensor.col<0>(ax2);
248  rotTensor.col<1>(ax1^ax2);
249 
250  return rotTensor;
251 }
252 
253 
255 (
256  const vector& local,
257  bool translate
258 ) const
259 {
261  (
262  toCartesian(local),
263  translate
264  );
265 }
266 
267 
269 (
270  const vectorField& local,
271  bool translate
272 ) const
273 {
274  const label len = local.size();
275 
276  auto tresult = tmp<vectorField>::New(len);
277  auto& result = tresult.ref();
278 
279  for (label i=0; i<len; ++i)
280  {
281  result[i] =
283  (
284  toCartesian(local[i]),
285  translate
286  );
287  }
288 
289  return tresult;
290 }
291 
292 
294 (
295  const vector& global,
296  bool translate
297 ) const
298 {
299  return fromCartesian
300  (
301  coordinateSystem::globalToLocal(global, translate)
302  );
303 }
304 
305 
307 (
308  const vectorField& global,
309  bool translate
310 ) const
311 {
312  const label len = global.size();
313 
314  tmp<vectorField> tresult
315  (
316  coordinateSystem::globalToLocal(global, translate)
317  );
318  auto& result = tresult.ref();
319 
320  for (label i=0; i<len; ++i)
321  {
322  result[i] = fromCartesian(result[i]);
323  }
324 
325  return tresult;
326 }
327 
328 
329 
330 // ************************************************************************* //
Foam::Tensor< scalar >
Foam::Vector::x
const Cmpt & x() const
Access to the vector x component.
Definition: VectorI.H:73
Foam::fromCartesian
static vector fromCartesian(const vector &v)
Convert from Cartesian (to Cylindrical)
Definition: cylindricalCS.C:70
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::coordinateRotations::cylindrical
A special purpose coordinateRotation that is generally for use in combination with a cylindricalCS wh...
Definition: cylindricalRotation.H:83
Foam::coordSystem::cylindrical::null
static const cylindrical null
Global (identity) cylindrical coordinate system.
Definition: cylindricalCS.H:121
Foam::sin
dimensionedScalar sin(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:264
Foam::atan2
dimensionedScalar atan2(const dimensionedScalar &x, const dimensionedScalar &y)
Definition: dimensionedScalar.C:312
Foam::UPstream::parRun
static bool & parRun()
Test if this a parallel run, or allow modify access.
Definition: UPstream.H:434
dictName
const word dictName("blockMeshDict")
Foam::UPstream::master
static bool master(const label communicator=worldComm)
Am I the master process.
Definition: UPstream.H:458
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::Vector::z
const Cmpt & z() const
Access to the vector z component.
Definition: VectorI.H:85
Foam::hypot
dimensionedScalar hypot(const dimensionedScalar &x, const dimensionedScalar &y)
Definition: dimensionedScalar.C:327
Foam::warnCompatDegrees
static void warnCompatDegrees(const Foam::dictionary &dict)
Definition: cylindricalCS.C:56
Foam::dictionary::name
const fileName & name() const
The dictionary name.
Definition: dictionary.H:446
Foam::tmp::ref
T & ref() const
Definition: tmpI.H:228
Foam::Field< vector >
Foam::coordSystem::cylindrical::cylindrical
cylindrical()
Construct null (identity coordinateSystem)
Definition: cylindricalCS.C:87
Foam::coordinateRotation
User specification of a coordinate rotation.
Definition: coordinateRotation.H:77
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::coordSystem::cylindrical::localToGlobal
virtual vector localToGlobal(const vector &local, bool translate) const
Definition: cylindricalCS.C:255
Foam::coordSystem::cylindrical::globalToLocal
virtual vector globalToLocal(const vector &global, bool translate) const
Definition: cylindricalCS.C:294
cylindricalCS.H
Foam::coordSystem::cylindrical
A cylindrical coordinate system (r-theta-z). The coordinate system angle theta is always in radians.
Definition: cylindricalCS.H:71
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::coordinateSystem::globalToLocal
virtual vector globalToLocal(const vector &global, bool translate) const
Definition: coordinateSystem.C:364
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:51
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::Vector::y
const Cmpt & y() const
Access to the vector y component.
Definition: VectorI.H:79
Foam::coordSystem::defineTypeName
defineTypeName(cartesian)
cylindricalRotation.H
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::Vector
Templated 3D Vector derived from VectorSpace adding construction from 3 components,...
Definition: Vector.H:62
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::tmp::New
static tmp< T > New(Args &&... args)
Construct tmp of T with forwarding arguments.
Foam::word::null
static const word null
An empty word.
Definition: word.H:77
Foam::coordinateSystem::localToGlobal
virtual vector localToGlobal(const vector &local, bool translate) const
Definition: coordinateSystem.C:334
Foam::dictionary::getOrDefault
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:122
Foam::Tensor::col
Vector< Cmpt > col() const
Extract vector for given column.
Foam::coordSystem::addToRunTimeSelectionTable
addToRunTimeSelectionTable(coordinateSystem, cartesian, dictionary)
Foam::coordSystem::cylindrical::cylindrical
cylindrical(const point &origin, const vector &axis, const vector &dirn)
Construct from origin and two axes.
Definition: cylindricalCS.C:148
Foam::toCartesian
static vector toCartesian(const vector &v)
Convert to Cartesian (from Cylindrical)
Definition: cylindricalCS.C:77
Foam::coordinateSystem
Base class for coordinate system specification, the default coordinate system type is cartesian .
Definition: coordinateSystem.H:122
Foam::coordinateSystem::R
virtual const tensor & R() const
Return const reference to the rotation tensor.
Definition: coordinateSystem.H:465
Foam::cos
dimensionedScalar cos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:265