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-------------------------------------------------------------------------------
11License
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
35namespace Foam
36{
37namespace coordSystem
38{
41}
42}
43
44
46
47
48// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
49
50namespace Foam
51{
52
53// Issue warning if 'degrees' keyword was specified and true.
54// Compatibility change after 1806.
55
56static 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)
70static 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)
77static 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:
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,
148 coordinateRotations::cylindrical(axis)
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 ax2.removeCollinear(ax1);
239
240 const scalar magAxis2(mag(ax2));
241
242 // Trap zero size and colinearity
243 if (magAxis2 < SMALL)
244 {
245 return rotTensor;
246 }
247
248 ax2 /= magAxis2; // normalise
249
250 // Replace with updated local axes
251
252 rotTensor.col<0>(ax2);
253 rotTensor.col<1>(ax1^ax2);
254
255 return rotTensor;
256}
257
258
260(
261 const vector& local,
262 bool translate
263) const
264{
266 (
267 toCartesian(local),
268 translate
269 );
270}
271
272
274(
275 const vectorField& local,
276 bool translate
277) const
278{
279 const label len = local.size();
280
281 auto tresult = tmp<vectorField>::New(len);
282 auto& result = tresult.ref();
283
284 for (label i=0; i<len; ++i)
285 {
286 result[i] =
288 (
289 toCartesian(local[i]),
290 translate
291 );
292 }
293
294 return tresult;
295}
296
297
299(
300 const vector& global,
301 bool translate
302) const
303{
304 return fromCartesian
305 (
306 coordinateSystem::globalToLocal(global, translate)
307 );
308}
309
310
312(
313 const vectorField& global,
314 bool translate
315) const
316{
317 const label len = global.size();
318
319 tmp<vectorField> tresult
320 (
321 coordinateSystem::globalToLocal(global, translate)
322 );
323 auto& result = tresult.ref();
324
325 for (label i=0; i<len; ++i)
326 {
327 result[i] = fromCartesian(result[i]);
328 }
329
330 return tresult;
331}
332
333
334
335// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Vector< Cmpt > col() const
Extract vector for given column: compile-time check of index.
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
const Cmpt & z() const
Access to the vector z component.
Definition: VectorI.H:85
const Cmpt & y() const
Access to the vector y component.
Definition: VectorI.H:79
const Cmpt & x() const
Access to the vector x component.
Definition: VectorI.H:73
Vector< Cmpt > & removeCollinear(const Vector< Cmpt > &unitVec)
Definition: VectorI.H:142
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A cylindrical coordinate system (r-theta-z). The coordinate system angle theta is always in radians.
Definition: cylindricalCS.H:74
virtual vector globalToLocal(const vector &global, bool translate) const
virtual vector localToGlobal(const vector &local, bool translate) const
static const cylindrical null
Global (identity) cylindrical coordinate system.
cylindrical()
Default construct. This is an identity coordinate system.
Definition: cylindricalCS.C:87
virtual const tensor & R() const
Position-dependent rotation tensors at multiple points.
User specification of a coordinate rotation.
Base class for coordinate system specification, the default coordinate system type is cartesian .
virtual vector globalToLocal(const vector &global, bool translate) const
virtual vector localToGlobal(const vector &local, bool translate) const
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:460
fileName relativeName(const bool caseTag=false) const
The dictionary name relative to the case.
Definition: dictionary.C:186
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
splitCell * master() const
Definition: splitCell.H:113
A class for managing temporary objects.
Definition: tmp.H:65
T & ref() const
Definition: tmpI.H:227
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeName(Type)
Define the typeName.
Definition: className.H:96
const word dictName("faMeshDefinition")
Namespace for OpenFOAM.
static vector toCartesian(const vector &v)
Convert to Cartesian (from Cylindrical)
Definition: cylindricalCS.C:77
dimensionedScalar sin(const dimensionedScalar &ds)
static void warnCompatDegrees(const Foam::dictionary &dict)
Definition: cylindricalCS.C:56
dimensionedScalar atan2(const dimensionedScalar &x, const dimensionedScalar &y)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
dimensionedScalar hypot(const dimensionedScalar &x, const dimensionedScalar &y)
static vector fromCartesian(const vector &v)
Convert from Cartesian (to Cylindrical)
Definition: cylindricalCS.C:70
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Vector< scalar > vector
Definition: vector.H:61
dimensionedScalar cos(const dimensionedScalar &ds)
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict