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-2024 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  const scalar theta = local.y();
51 
53  (
54  vector(local.x()*cos(theta), local.x()*sin(theta), local.z()),
55  translate
56  );
57 }
58 
59 
60 Foam::tmp<Foam::vectorField> Foam::coordinateSystems::cylindrical::localToGlobal
61 (
62  const vectorField& local,
63  bool translate
64 ) const
65 {
66  const scalarField theta(local.component(vector::Y));
67 
68  vectorField lc(local.size());
69  lc.replace(vector::X, local.component(vector::X)*cos(theta));
70  lc.replace(vector::Y, local.component(vector::X)*sin(theta));
71  lc.replace(vector::Z, local.component(vector::Z));
72 
73  return coordinateSystem::localToGlobal(lc, translate);
74 }
75 
76 
77 Foam::vector Foam::coordinateSystems::cylindrical::globalToLocal
78 (
79  const vector& global,
80  bool translate
81 ) const
82 {
83  const vector lc
84  (
85  coordinateSystem::globalToLocal(global, translate)
86  );
87 
88  return vector
89  (
90  sqrt(sqr(lc.x()) + sqr(lc.y())),
91  atan2(lc.y(), lc.x()),
92  lc.z()
93  );
94 }
95 
96 
97 Foam::tmp<Foam::vectorField> Foam::coordinateSystems::cylindrical::globalToLocal
98 (
99  const vectorField& global,
100  bool translate
101 ) const
102 {
103  const vectorField lc
104  (
105  coordinateSystem::globalToLocal(global, translate)
106  );
107 
108  tmp<vectorField> tresult(new vectorField(lc.size()));
109  vectorField& result = tresult.ref();
110 
111  result.replace
112  (
113  vector::X,
114  sqrt(sqr(lc.component(vector::X)) + sqr(lc.component(vector::Y)))
115  );
116 
117  result.replace
118  (
119  vector::Y,
120  atan2(lc.component(vector::Y), lc.component(vector::X))
121  );
122 
123  result.replace(vector::Z, lc.component(vector::Z));
124 
125  return tresult;
126 }
127 
128 
129 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
130 
132 (
133  const word& name,
134  const point& origin,
135  const coordinateRotation& cr
136 )
137 :
138  coordinateSystem(name, origin, cr)
139 {}
140 
141 
143 (
144  const word& name,
145  const point& origin,
146  const vector& axis,
147  const vector& dirn
148 )
149 :
150  coordinateSystem(name, origin, axis, dirn)
151 {}
152 
153 
155 (
156  const word& name,
157  const dictionary& dict
158 )
159 :
161 {}
162 
163 
164 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
165 
167 {}
168 
169 
170 // ************************************************************************* //
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:491
const Cmpt & y() const
Definition: VectorI.H:81
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 &)
Construct from origin and rotation.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
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