Loading...
Searching...
No Matches
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"
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34
35namespace Foam
36{
37namespace coordSystem
38{
41}
42}
43
44
46
47
48// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
50namespace Foam
51{
52
53// Issue warning if 'degrees' keyword was specified
54// Compatibility change after 1806.
55
56static 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)
70static inline vector fromCartesian(const vector& v)
71{
72 return vector(hypot(v.x(), v.y()), atan2(v.y(), v.x()), v.z());
73}
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
85// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
86
88:
94:
95 coordinateSystem(std::move(csys))
100:
101 coordinateSystem(std::move(csys))
106:
107 coordinateSystem(crot)
109
110
112(
113 const point& origin,
114 const coordinateRotation& crot
115)
116:
117 coordinateSystem(origin, crot)
119
120
122(
123 const point& origin,
124 const vector& axis
125)
126:
127 cylindrical(word::null, origin, axis)
129
130
132(
133 const word& name,
134 const point& origin,
135 const vector& axis
136)
137:
139 (
140 name,
141 origin,
143 )
145
146
148(
149 const point& origin,
150 const vector& axis,
151 const vector& dirn
152)
153:
154 cylindrical(word::null, origin, axis, dirn)
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)
168
169
171(
172 const dictionary& dict,
174)
175:
176 coordinateSystem(dict, readOrigin)
177{
180
181
183(
184 const dictionary& dict,
185 const word& dictName,
187)
188:
189 coordinateSystem(dict, dictName, readOrigin)
190{
191 if (dictName.size())
192 {
193 warnCompatDegrees(dict.subDict(dictName));
194 }
195 else
196 {
197 warnCompatDegrees(dict);
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;
235
236
238(
239 const vector& local,
240 bool translate
241) const
242{
244 (
246 translate
247 );
249
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;
274
275
277(
278 const vector& global,
279 bool translate
280) const
281{
282 return fromCartesian
283 (
284 coordinateSystem::globalToLocal(global, translate)
285 );
287
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// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
readOption
Enumeration defining read preferences.
Vector< Cmpt > col() const
Extract vector for given column: compile-time check of index.
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
const Cmpt & x() const noexcept
Access to the vector x component.
Definition Vector.H:135
const Cmpt & z() const noexcept
Access to the vector z component.
Definition Vector.H:145
const Cmpt & y() const noexcept
Access to the vector y component.
Definition Vector.H:140
Vector< Cmpt > & removeCollinear(const Vector< Cmpt > &unitVec)
Inplace removal of components that are collinear to the given unit vector.
Definition VectorI.H:136
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A cylindrical coordinate system (r-theta-z). The coordinate system angle theta is always in radians.
virtual vector globalToLocal(const vector &global, bool translate) const
From global Cartesian system to the local coordinate system with optional translation for the origin.
virtual vector localToGlobal(const vector &local, bool translate) const
From local coordinate system to the global Cartesian system with optional translation for the origin.
static const cylindrical null
Global (identity) cylindrical coordinate system.
virtual const tensor & R() const
Position-dependent rotation tensors at multiple points.
cylindrical()=default
Default construct. Identity coordinate system.
User specification of a coordinate rotation.
Base class for coordinate system specification, the default coordinate system type is cartesian .
virtual const word & name() const
Return the name.
coordinateSystem(std::nullptr_t)
Construct null, without allocating a coordinateRotation specification.
virtual vector globalToLocal(const vector &global, bool translate) const
From global Cartesian system to the local coordinate system with optional translation for the origin.
virtual vector localToGlobal(const vector &local, bool translate) const
From local coordinate system to the global Cartesian system with optional translation for the origin.
tensor rot_
The rotation tensor.
virtual const point & origin() const
Return origin.
point origin_
The coordinate system origin.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
static bool master(const int communicator=-1)
Like Pstream::master but with a Pstream::parRun guard in case Pstream has not yet been initialised.
Definition error.C:53
@ LITERAL
String literal.
Definition keyType.H:82
A class for managing temporary objects.
Definition tmp.H:75
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
Definition tmp.H:215
T & ref() const
Return non-const reference to the contents of a non-null managed pointer.
Definition tmpI.H:235
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeName(Type)
Define the typeName.
Definition className.H:113
bool local
Definition EEqn.H:20
const word dictName("faMeshDefinition")
Namespace for coordinate systems.
Definition cartesianCS.C:30
Namespace for coordinate system rotations.
Namespace for OpenFOAM.
static vector toCartesian(const vector &v)
Convert to Cartesian (from Cylindrical).
dimensionedScalar sin(const dimensionedScalar &ds)
static void warnCompatDegrees(const Foam::dictionary &dict)
Tensor< scalar > tensor
Definition symmTensor.H:57
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)
Field< vector > vectorField
Specialisation of Field<T> for vector.
vector point
Point is a vector.
Definition point.H:37
static vector fromCartesian(const vector &v)
Convert from Cartesian (to Cylindrical).
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
Vector< scalar > vector
Definition vector.H:57
dimensionedScalar cos(const dimensionedScalar &ds)
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict