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-2022 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
54 // Compatibility change after 1806.
55 
56 static inline void warnCompatDegrees(const Foam::dictionary& dict)
57 {
58  if (dict.found("degrees", keyType::LITERAL) && 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 :
89  coordinateSystem(csys)
90 {}
91 
92 
94 :
95  coordinateSystem(std::move(csys))
96 {}
97 
98 
100 :
101  coordinateSystem(std::move(csys))
102 {}
103 
104 
106 :
107  coordinateSystem(crot)
108 {}
110 
112 (
113  const point& origin,
114  const coordinateRotation& crot
115 )
116 :
117  coordinateSystem(origin, crot)
118 {}
120 
122 (
123  const point& origin,
124  const vector& axis
125 )
126 :
127  cylindrical(word::null, origin, axis)
128 {}
130 
132 (
133  const word& name,
134  const point& origin,
135  const vector& axis
136 )
137 :
139  (
140  name,
141  origin,
142  coordinateRotations::cylindrical(axis)
143  )
144 {}
146 
148 (
149  const point& origin,
150  const vector& axis,
151  const vector& dirn
152 )
153 :
154  cylindrical(word::null, origin, axis, dirn)
155 {}
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 {}
169 
171 (
172  const dictionary& dict,
173  IOobjectOption::readOption readOrigin
174 )
175 :
176  coordinateSystem(dict, readOrigin)
177 {
179 }
181 
183 (
184  const dictionary& dict,
185  const word& dictName,
186  IOobjectOption::readOption readOrigin
187 )
188 :
189  coordinateSystem(dict, dictName, readOrigin)
190 {
191  if (dictName.size())
192  {
193  warnCompatDegrees(dict.subDict(dictName));
194  }
195  else
196  {
198  }
199 }
200 
202 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
203 
205 {
206  // Robuster version of coordinateRotations::axes::rotation()
207  // using an E3_E1 order and falling back to the top-level rotation
208  // tensor if the directional input is borderline.
209 
210  tensor rotTensor(rot_);
211 
212  const vector ax1 = rotTensor.col<2>(); // == e3 (already normalized)
213 
214  vector ax2(global - origin_);
215 
216  ax2.removeCollinear(ax1);
217 
218  const scalar magAxis2(mag(ax2));
219 
220  // Trap zero size and colinearity
221  if (magAxis2 < SMALL)
222  {
223  return rotTensor;
224  }
225 
226  ax2 /= magAxis2; // normalise
227 
228  // Replace with updated local axes
229 
230  rotTensor.col<0>(ax2);
231  rotTensor.col<1>(ax1^ax2);
232 
233  return rotTensor;
234 }
236 
238 (
239  const vector& local,
240  bool translate
241 ) const
242 {
244  (
246  translate
247  );
248 }
250 
252 (
253  const vectorField& local,
254  bool translate
255 ) const
256 {
257  const label len = local.size();
258 
259  auto tresult = tmp<vectorField>::New(len);
260  auto& result = tresult.ref();
261 
262  for (label i=0; i<len; ++i)
263  {
264  result[i] =
266  (
267  toCartesian(local[i]),
268  translate
269  );
270  }
271 
272  return tresult;
273 }
275 
277 (
278  const vector& global,
279  bool translate
280 ) const
281 {
282  return fromCartesian
283  (
284  coordinateSystem::globalToLocal(global, translate)
285  );
286 }
288 
290 (
291  const vectorField& global,
292  bool translate
293 ) const
294 {
295  const label len = global.size();
296 
297  tmp<vectorField> tresult
298  (
299  coordinateSystem::globalToLocal(global, translate)
300  );
301  auto& result = tresult.ref();
302 
303  for (label i=0; i<len; ++i)
304  {
305  result[i] = fromCartesian(result[i]);
306  }
307 
308  return tresult;
309 }
310 
311 
312 // ************************************************************************* //
virtual vector globalToLocal(const vector &global, bool translate) const
From global Cartesian system to the local coordinate system with optional translation for the origin...
Base class for coordinate system specification, the default coordinate system type is cartesian ...
User specification of a coordinate rotation.
dictionary dict
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
static const cylindrical null
Global (identity) cylindrical coordinate system.
A cylindrical coordinate system (r-theta-z). The coordinate system angle theta is always in radians...
Definition: cylindricalCS.H:67
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
T & ref() const
Return non-const reference to the contents of a non-null managed pointer.
Definition: tmpI.H:235
virtual vector localToGlobal(const vector &local, bool translate) const
From local coordinate system to the global Cartesian system with optional translation for the origin...
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
const word dictName("faMeshDefinition")
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
cylindrical()=default
Default construct. Identity coordinate system.
static vector toCartesian(const vector &v)
Convert to Cartesian (from Cylindrical)
Definition: cylindricalCS.C:74
Macros for easy insertion into run-time selection tables.
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
Definition: dictionaryI.H:104
virtual const tensor & R() const
Return const reference to the rotation tensor.
virtual vector globalToLocal(const vector &global, bool translate) const
From global Cartesian system to the local coordinate system with optional translation for the origin...
dimensionedScalar cos(const dimensionedScalar &ds)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
static bool master(const label communicator=-1)
Like Pstream::master but with a Pstream::parRun guard in case Pstream has not yet been initialised...
Definition: error.C:53
A class for handling words, derived from Foam::string.
Definition: word.H:63
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
Definition: tmp.H:206
bool local
Definition: EEqn.H:20
Vector< scalar > vector
Definition: vector.H:57
String literal.
Definition: keyType.H:82
virtual vector localToGlobal(const vector &local, bool translate) const
From local coordinate system to the global Cartesian system with optional translation for the origin...
dimensionedScalar sin(const dimensionedScalar &ds)
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
dimensionedScalar atan2(const dimensionedScalar &x, const dimensionedScalar &y)
fileName relativeName(const bool caseTag=false) const
The dictionary name relative to the case.
Definition: dictionary.C:179
static vector fromCartesian(const vector &v)
Convert from Cartesian (to Cylindrical)
Definition: cylindricalCS.C:65
static void warnCompatDegrees(const Foam::dictionary &dict)
Definition: cylindricalCS.C:49
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
defineTypeName(cartesian)
A class for managing temporary objects.
Definition: HashPtrTable.H:50
addToRunTimeSelectionTable(coordinateSystem, cartesian, dictionary)
Tensor of scalars, i.e. Tensor<scalar>.
dimensionedScalar hypot(const dimensionedScalar &x, const dimensionedScalar &y)
Namespace for OpenFOAM.
readOption
Enumeration defining read preferences.