coordinateSystem.H
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-2021 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 Class
25  Foam::coordinateSystem
26 
27 Description
28  Base class for other coordinate system specifications.
29 
30  All systems are defined by an origin point and a co-ordinate rotation.
31 
32  \verbatim
33  coordinateSystem
34  {
35  type cartesian;
36  origin (0 0 0);
37  coordinateRotation
38  {
39  type cylindrical;
40  e3 (0 0 1);
41  }
42  }
43  \endverbatim
44 
45  Types of coordinateRotation:
46  -# axesRotation
47  -# \link STARCDCoordinateRotation STARCDRotation \endlink
48  -# cylindricalCS cylindrical
49  -# EulerCoordinateRotation
50 
51  Type of co-ordinates:
52  -# \link cartesianCS cartesian \endlink
53 
54 
55 SourceFiles
56  coordinateSystem.C
57  coordinateSystemNew.C
58 
59 \*---------------------------------------------------------------------------*/
60 
61 #ifndef coordinateSystem_H
62 #define coordinateSystem_H
63 
64 #include "coordinateRotation.H"
65 #include "objectRegistry.H"
66 
67 
68 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
69 
70 namespace Foam
71 {
72 
73 // Forward declaration of friend functions and operators
74 
75 class coordinateSystem;
76 
77 bool operator!=(const coordinateSystem&, const coordinateSystem&);
78 Ostream& operator<<(Ostream&, const coordinateSystem&);
79 
80 
81 /*---------------------------------------------------------------------------*\
82  Class coordinateSystem Declaration
83 \*---------------------------------------------------------------------------*/
84 
85 class coordinateSystem
86 {
87  // Private Data
88 
89  //- Name of coordinate system
90  word name_;
91 
92  //- Origin
93  point origin_;
94 
95  //- Local-to-Global transformation tensor
96  mutable autoPtr<coordinateRotation> R_;
97 
98 
99 protected:
100 
101  // Protected Member Functions
102 
103  //- Convert from local coordinate system to the global Cartesian system
104  // with optional translation for the origin
105  virtual vector localToGlobal(const vector&, bool translate) const;
106 
107  //- Convert from local coordinate system to the global Cartesian system
108  // with optional translation for the origin
110  (
111  const vectorField&,
112  bool translate
113  ) const;
114 
115  //- Convert from global Cartesian system to the local coordinate system
116  // with optional translation for the origin
117  virtual vector globalToLocal(const vector&, bool translate) const;
118 
119  //- Convert from global Cartesian system to the local coordinate system
120  // with optional translation for the origin
122  (
123  const vectorField&,
124  bool translate
125  ) const;
126 
127 
128 public:
129 
130  //- Runtime type information
131  TypeName("coordinateSystem");
132 
133 
134  // Constructors
135 
136  //- Construct from origin
138  (
139  const word& name,
140  const point& origin
141  );
142 
143  //- Construct from origin and rotation
145  (
146  const word& name,
147  const point& origin,
148  const coordinateRotation&
149  );
150 
151  //- Construct from origin and 2 axes
153  (
154  const word& name,
155  const point& origin,
156  const vector& axis,
157  const vector& dirn
158  );
159 
160  //- Construct from dictionary with a given name
161  coordinateSystem(const word& name, const dictionary&);
162 
163  //- Copy constructor
165 
166  //- Construct and return a clone
167  virtual autoPtr<coordinateSystem> clone() const
168  {
169  return autoPtr<coordinateSystem>(new coordinateSystem(*this));
170  }
171 
172 
173  // Declare run-time constructor selection table
175  (
176  autoPtr,
178  dictionary,
179  (
180  const word& name,
181  const dictionary& dict
182  ),
183  (name, dict)
184  );
185 
186 
187  // Selectors
188 
189  //- Select constructed from dictionary and objectRegistry
191  (
192  const objectRegistry& obr,
193  const dictionary& dict
194  );
195 
196  //- Select constructed from name and dictionary
198  (
199  const word& name,
200  const dictionary& dict
201  );
202 
203 
204  //- Destructor
205  virtual ~coordinateSystem();
206 
207 
208  // Member Functions
209 
210  // Access
211 
212  //- Return name
213  const word& name() const
214  {
215  return name_;
216  }
217 
218  //- Return keyword
219  const word& keyword() const
220  {
221  return name_;
222  }
223 
224  //- Return origin
225  const point& origin() const
226  {
227  return origin_;
228  }
229 
230  //- Return const reference to co-ordinate rotation
231  const coordinateRotation& R() const
232  {
233  return R_();
234  }
235 
236  //- Update and return the co-ordinate rotation for a list of points
237  const coordinateRotation& R(const UList<vector>& points) const
238  {
239  R_->updatePoints(points);
240  return R_();
241  }
242 
243 
244  // Write
245 
246  //- Write
247  virtual void write(Ostream&) const;
248 
249  //- Write dictionary
250  void writeDict(Ostream&, bool subDict=true) const;
251 
252 
253  // Transformations
254 
255  //- Convert from position in local coordinate system to global
256  // Cartesian position
257  point globalPosition(const point& local) const
258  {
259  return localToGlobal(local, true);
260  }
261 
262  //- Convert from position in local coordinate system to global
263  // Cartesian position
264  tmp<pointField> globalPosition(const pointField& local) const
265  {
266  return localToGlobal(local, true);
267  }
268 
269  //- Convert from vector components in local coordinate system to
270  // global Cartesian vector
271  vector globalVector(const vector& local) const
272  {
273  return localToGlobal(local, false);
274  }
275 
276  //- Convert from vector components in local coordinate system to
277  // global Cartesian vector
278  tmp<vectorField> globalVector(const vectorField& local) const
279  {
280  return localToGlobal(local, false);
281  }
282 
283  //- Convert from global Cartesian position to position in local
284  // coordinate system
285  point localPosition(const point& global) const
286  {
287  return globalToLocal(global, true);
288  }
289 
290  //- Convert from global Cartesian position to position in local
291  // coordinate system
292  tmp<pointField> localPosition(const pointField& global) const
293  {
294  return globalToLocal(global, true);
295  }
296 
297  //- Convert from global Cartesian vector to components in local
298  // coordinate system
299  vector localVector(const vector& global) const
300  {
301  return globalToLocal(global, false);
302  }
303 
304  //- Convert from global Cartesian vector to components in local
305  // coordinate system
306  tmp<vectorField> localVector(const vectorField& global) const
307  {
308  return globalToLocal(global, false);
309  }
310 
311 
312  // Member Operators
313 
314  //- Assignment operator
315  void operator=(const coordinateSystem&);
316 
317 
318  // IOstream Operators
319 
320  friend Ostream& operator<<(Ostream&, const coordinateSystem&);
321 };
322 
323 
324 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
325 
326 } // End namespace Foam
327 
328 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
329 
330 #endif
331 
332 // ************************************************************************* //
Base class for other coordinate system specifications.
TypeName("coordinateSystem")
Runtime type information.
Abstract base class for coordinate rotation.
dictionary dict
point globalPosition(const point &local) const
Convert from position in local coordinate system to global.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
const word & keyword() const
Return keyword.
const word & name() const
Return name.
const point & origin() const
Return origin.
virtual ~coordinateSystem()
Destructor.
virtual vector localToGlobal(const vector &, bool translate) const
Convert from local coordinate system to the global Cartesian system.
point localPosition(const point &global) const
Convert from global Cartesian position to position in local.
const pointField & points
virtual autoPtr< coordinateSystem > clone() const
Construct and return a clone.
A class for handling words, derived from string.
Definition: word.H:59
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
vector localVector(const vector &global) const
Convert from global Cartesian vector to components in local.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
virtual vector globalToLocal(const vector &, bool translate) const
Convert from global Cartesian system to the local coordinate system.
declareRunTimeSelectionTable(autoPtr, coordinateSystem, dictionary,(const word &name, const dictionary &dict),(name, dict))
static autoPtr< coordinateSystem > New(const objectRegistry &obr, const dictionary &dict)
Select constructed from dictionary and objectRegistry.
Ostream & operator<<(Ostream &, const ensightPart &)
vector globalVector(const vector &local) const
Convert from vector components in local coordinate system to.
coordinateSystem(const word &name, const point &origin)
Construct from origin.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
A class for managing temporary objects.
Definition: PtrList.H:53
Registry of regIOobjects.
friend Ostream & operator<<(Ostream &, const coordinateSystem &)
bool operator!=(const particle &, const particle &)
Definition: particle.C:1282
void writeDict(Ostream &, bool subDict=true) const
Write dictionary.
virtual void write(Ostream &) const
Write.
Namespace for OpenFOAM.
const coordinateRotation & R() const
Return const reference to co-ordinate rotation.
void operator=(const coordinateSystem &)
Assignment operator.