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-2021 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 (error::master())
59  {
60  std::cerr
61  << "--> FOAM IOWarning :" << nl
62  << " Found [v1806] 'degrees' keyword in dictionary \""
63  << dict.relativeName() << "\" 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  coordinateSystem(crot)
114 {}
115 
116 
118 (
119  const point& origin,
120  const coordinateRotation& crot
121 )
122 :
123  coordinateSystem(origin, crot)
124 {}
125 
126 
128 (
129  const point& origin,
130  const vector& axis
131 )
132 :
133  cylindrical(word::null, origin, axis)
134 {}
135 
136 
138 (
139  const word& name,
140  const point& origin,
141  const vector& axis
142 )
143 :
145  (
146  name,
147  origin,
149  )
150 {}
151 
152 
154 (
155  const point& origin,
156  const vector& axis,
157  const vector& dirn
158 )
159 :
160  cylindrical(word::null, origin, axis, dirn)
161 {}
162 
163 
165 (
166  const word& name,
167  const point& origin,
168  const vector& axis,
169  const vector& dirn
170 )
171 :
172  coordinateSystem(name, origin, axis, dirn)
173 {}
174 
175 
177 (
178  const word& name,
179  const dictionary& dict
180 )
181 :
183 {
184  if (dict.getOrDefault("degrees", false))
185  {
187  }
188 }
189 
190 
192 :
194 {
195  if (dict.getOrDefault("degrees", false))
196  {
198  }
199 }
200 
201 
203 (
204  const dictionary& dict,
205  const word& dictName
206 )
207 :
209 {
210  const dictionary* dictPtr =
211  (
212  dictName.size()
213  ? &(dict.subDict(dictName))
214  : &(dict)
215  );
216 
217  if (dictPtr->getOrDefault("degrees", false))
218  {
220  }
221 }
222 
223 
224 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
225 
227 {
228  // Robuster version of coordinateRotations::axes::rotation()
229  // using an E3_E1 order and falling back to the top-level rotation
230  // tensor if the directional input is borderline.
231 
232  tensor rotTensor(rot_);
233 
234  const vector ax1 = rotTensor.col<2>(); // == e3 (already normalized)
235 
236  vector ax2(global - origin_);
237 
238  // Remove colinear component
239  ax2 -= ((ax1 & ax2) * ax1);
240 
241  const scalar magAxis2(mag(ax2));
242 
243  // Trap zero size and colinearity
244  if (magAxis2 < SMALL)
245  {
246  return rotTensor;
247  }
248 
249  ax2 /= magAxis2; // normalise
250 
251  // Replace with updated local axes
252 
253  rotTensor.col<0>(ax2);
254  rotTensor.col<1>(ax1^ax2);
255 
256  return rotTensor;
257 }
258 
259 
261 (
262  const vector& local,
263  bool translate
264 ) const
265 {
267  (
268  toCartesian(local),
269  translate
270  );
271 }
272 
273 
275 (
276  const vectorField& local,
277  bool translate
278 ) const
279 {
280  const label len = local.size();
281 
282  auto tresult = tmp<vectorField>::New(len);
283  auto& result = tresult.ref();
284 
285  for (label i=0; i<len; ++i)
286  {
287  result[i] =
289  (
290  toCartesian(local[i]),
291  translate
292  );
293  }
294 
295  return tresult;
296 }
297 
298 
300 (
301  const vector& global,
302  bool translate
303 ) const
304 {
305  return fromCartesian
306  (
307  coordinateSystem::globalToLocal(global, translate)
308  );
309 }
310 
311 
313 (
314  const vectorField& global,
315  bool translate
316 ) const
317 {
318  const label len = global.size();
319 
320  tmp<vectorField> tresult
321  (
322  coordinateSystem::globalToLocal(global, translate)
323  );
324  auto& result = tresult.ref();
325 
326  for (label i=0; i<len; ++i)
327  {
328  result[i] = fromCartesian(result[i]);
329  }
330 
331  return tresult;
332 }
333 
334 
335 
336 // ************************************************************************* //
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:65
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
dictName
const word dictName("faMeshDefinition")
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
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::tmp::ref
T & ref() const
Definition: tmpI.H:227
Foam::Field< vector >
Foam::coordSystem::cylindrical::cylindrical
cylindrical()
Default construct. This is an identity coordinate system.
Definition: cylindricalCS.C:87
Foam::dictionary::relativeName
fileName relativeName(const bool caseTag=false) const
The dictionary name relative to the case.
Definition: dictionary.C:186
Foam::coordinateRotation
User specification of a coordinate rotation.
Definition: coordinateRotation.H:78
Foam::coordSystem::cylindrical::localToGlobal
virtual vector localToGlobal(const vector &local, bool translate) const
Definition: cylindricalCS.C:261
Foam::coordSystem::cylindrical::globalToLocal
virtual vector globalToLocal(const vector &global, bool translate) const
Definition: cylindricalCS.C:300
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:123
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:368
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:404
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::error::master
static bool master(const label communicator=-1)
Definition: error.C:41
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:80
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::coordinateSystem::localToGlobal
virtual vector localToGlobal(const vector &local, bool translate) const
Definition: coordinateSystem.C:338
Foam::dictionary::getOrDefault
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:148
Foam::Tensor::col
Vector< Cmpt > col() const
Extract vector for given column.
Foam::coordSystem::addToRunTimeSelectionTable
addToRunTimeSelectionTable(coordinateSystem, cartesian, dictionary)
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:132
Foam::coordinateSystem::R
virtual const tensor & R() const
Return const reference to the rotation tensor.
Definition: coordinateSystem.H:475
Foam::cos
dimensionedScalar cos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:265