cylindricalCS.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "cylindricalCS.H"
27 #include "mathematicalConstants.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace coordinateSystems
35 {
38 }
39 }
40 
41 
42 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43 
44 Foam::vector Foam::coordinateSystems::cylindrical::localToGlobal
45 (
46  const vector& local,
47  bool translate
48 ) const
49 {
50  scalar theta
51  (
52  local.y()*(inDegrees_ ? constant::mathematical::pi/180.0 : 1.0)
53  );
54 
56  (
57  vector(local.x()*cos(theta), local.x()*sin(theta), local.z()),
58  translate
59  );
60 }
61 
62 
63 Foam::tmp<Foam::vectorField> Foam::coordinateSystems::cylindrical::localToGlobal
64 (
65  const vectorField& local,
66  bool translate
67 ) const
68 {
69  scalarField theta
70  (
71  local.component(vector::Y)
72  *(inDegrees_ ? constant::mathematical::pi/180.0 : 1.0)
73  );
74 
75  vectorField lc(local.size());
76  lc.replace(vector::X, local.component(vector::X)*cos(theta));
77  lc.replace(vector::Y, local.component(vector::X)*sin(theta));
78  lc.replace(vector::Z, local.component(vector::Z));
79 
80  return coordinateSystem::localToGlobal(lc, translate);
81 }
82 
83 
84 Foam::vector Foam::coordinateSystems::cylindrical::globalToLocal
85 (
86  const vector& global,
87  bool translate
88 ) const
89 {
90  const vector lc
91  (
92  coordinateSystem::globalToLocal(global, translate)
93  );
94 
95  return vector
96  (
97  sqrt(sqr(lc.x()) + sqr(lc.y())),
98  atan2
99  (
100  lc.y(),
101  lc.x()
102  )*(inDegrees_ ? 180.0/constant::mathematical::pi : 1.0),
103  lc.z()
104  );
105 }
106 
107 
108 Foam::tmp<Foam::vectorField> Foam::coordinateSystems::cylindrical::globalToLocal
109 (
110  const vectorField& global,
111  bool translate
112 ) const
113 {
114  const vectorField lc
115  (
116  coordinateSystem::globalToLocal(global, translate)
117  );
118 
119  tmp<vectorField> tresult(new vectorField(lc.size()));
120  vectorField& result = tresult.ref();
121 
122  result.replace
123  (
124  vector::X,
125  sqrt(sqr(lc.component(vector::X)) + sqr(lc.component(vector::Y)))
126  );
127 
128  result.replace
129  (
130  vector::Y,
131  atan2
132  (
133  lc.component(vector::Y),
134  lc.component(vector::X)
135  )*(inDegrees_ ? 180.0/constant::mathematical::pi : 1.0)
136  );
137 
138  result.replace(vector::Z, lc.component(vector::Z));
139 
140  return tresult;
141 }
142 
143 
144 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
145 
147 (
148  const word& name,
149  const point& origin,
150  const coordinateRotation& cr,
151  const bool inDegrees
152 )
153 :
154  coordinateSystem(name, origin, cr),
155  inDegrees_(inDegrees)
156 {}
157 
158 
160 (
161  const word& name,
162  const point& origin,
163  const vector& axis,
164  const vector& dirn,
165  const bool inDegrees
166 )
167 :
168  coordinateSystem(name, origin, axis, dirn),
169  inDegrees_(inDegrees)
170 {}
171 
172 
174 (
175  const word& name,
176  const dictionary& dict
177 )
178 :
180  inDegrees_(dict.lookupOrDefault("degrees", true))
181 {}
182 
183 
184 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
185 
187 {}
188 
189 
190 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
void replace(const direction, const UList< cmptType > &)
Replace a component field of the field.
Definition: Field.C:467
Abstract base class for coordinate rotation.
Base class for other coordinate system specifications.
virtual vector globalToLocal(const vector &, bool translate) const
Convert from global Cartesian system to the local coordinate system.
virtual vector localToGlobal(const vector &, bool translate) const
Convert from local coordinate system to the global Cartesian system.
Cylindrical coordinate system.
Definition: cylindricalCS.H:53
cylindrical(const word &name, const point &origin, const coordinateRotation &, const bool inDegrees=true)
Construct from origin and rotation.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
defineTypeNameAndDebug(cartesian, 0)
addToRunTimeSelectionTable(coordinateSystem, cartesian, dictionary)
Namespace for OpenFOAM.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
dimensionedScalar sin(const dimensionedScalar &ds)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
dimensionedScalar atan2(const dimensionedScalar &x, const dimensionedScalar &y)
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
dimensionedScalar sqrt(const dimensionedScalar &ds)
Field< vector > vectorField
Specialisation of Field<T> for vector.
dimensionedScalar cos(const dimensionedScalar &ds)
dictionary dict