coordinateSystem.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2016 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 "vector.H"
65 #include "point.H"
66 #include "tensor.H"
67 #include "vectorField.H"
68 #include "pointField.H"
69 #include "tmp.H"
70 #include "coordinateRotation.H"
71 #include "objectRegistry.H"
72 #include "autoPtr.H"
73 
74 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
75 
76 namespace Foam
77 {
78 
79 // Forward declaration of friend functions and operators
80 
81 class coordinateSystem;
82 
83 bool operator!=(const coordinateSystem&, const coordinateSystem&);
84 Ostream& operator<<(Ostream&, const coordinateSystem&);
85 
86 
87 /*---------------------------------------------------------------------------*\
88  Class coordinateSystem Declaration
89 \*---------------------------------------------------------------------------*/
90 
91 class coordinateSystem
92 {
93  // Private data
94 
95  //- Name of coordinate system
96  word name_;
97 
98  //- Optional note
99  string note_;
100 
101  //- Origin
102  point origin_;
103 
104  //- Local-to-Global transformation tensor
106 
107 
108 protected:
109 
110  // Protected Member Functions
111 
112  //- Convert from local coordinate system to the global Cartesian system
113  // with optional translation for the origin
114  virtual vector localToGlobal(const vector&, bool translate) const;
115 
116  //- Convert from local coordinate system to the global Cartesian system
117  // with optional translation for the origin
119  (
120  const vectorField&,
121  bool translate
122  ) const;
123 
124  //- Convert from global Cartesian system to the local coordinate system
125  // with optional translation for the origin
126  virtual vector globalToLocal(const vector&, bool translate) const;
127 
128  //- Convert from global Cartesian system to the local coordinate system
129  // with optional translation for the origin
131  (
132  const vectorField&,
133  bool translate
134  ) const;
135 
136  //- Init from dict and obr
137  void init(const dictionary&);
138 
139  //- Init from dictionary
140  void init(const dictionary&, const objectRegistry&);
141 
142 
143 public:
144 
145  //- Runtime type information
146  TypeName("coordinateSystem");
147 
148 
149  // Constructors
150 
151  //- Construct null. This is equivalent to an identity coordinateSystem
153 
154  //- Construct copy with a different name
156  (
157  const word& name,
158  const coordinateSystem&
159  );
160 
161  //- Construct from origin and rotation
163  (
164  const word& name,
165  const point& origin,
166  const coordinateRotation&
167  );
168 
169  //- Construct from origin and 2 axes
171  (
172  const word& name,
173  const point& origin,
174  const vector& axis,
175  const vector& dirn
176  );
177 
178  //- Construct from dictionary with a given name
179  coordinateSystem(const word& name, const dictionary&);
180 
181  //- Construct from dictionary with default name
183 
184  //- Construct from dictionary (default name)
185  // With the ability to reference global coordinateSystems
187 
188  //- Construct from Istream
189  // The Istream contains a word followed by a dictionary
191 
192 
193  //- Return clone
195  {
196  return autoPtr<coordinateSystem>(new coordinateSystem(*this));
197  }
198 
199 
200  // Declare run-time constructor selection table
202  (
203  autoPtr,
205  dictionary,
206  (
207  const objectRegistry& obr,
208  const dictionary& dict
209  ),
210  (obr, dict)
211  );
212 
213 
214  // Selectors
215 
216  //- Select constructed from dictionary and objectRegistry
218  (
219  const objectRegistry& obr,
220  const dictionary& dict
221  );
222 
223  //- Select constructed from dictionary
225  (
226  const dictionary& dict
227  );
228 
229  //- Select constructed from Istream
231 
232 
233  //- Destructor
234  virtual ~coordinateSystem();
235 
236 
237  // Member Functions
238 
239  // Access
240 
241  //- Return name
242  const word& name() const
243  {
244  return name_;
245  }
246 
247  //- Return non-constant access to the optional note
248  string& note()
249  {
250  return note_;
251  }
252 
253  //- Return the optional note
254  const string& note() const
255  {
256  return note_;
257  }
258 
259  //- Return origin
260  const point& origin() const
261  {
262  return origin_;
263  }
264 
265  //- Return const reference to co-ordinate rotation
266  const coordinateRotation& R() const
267  {
268  return R_();
269  }
270 
271  //- Return non const reference to co-ordinate rotation
273  {
274  return R_();
275  }
276 
277  //- Update and return the co-ordinate roation for a list of cells
279  (
280  const polyMesh& mesh,
281  const labelList& cells
282  )
283  {
284  R_->updateCells(mesh, cells);
285  return R_();
286  }
287 
288  //- Return as dictionary of entries
289  // \param[in] ignoreType drop type (cartesian, cylindrical, etc)
290  // when generating the dictionary
291  virtual dictionary dict(bool ignoreType=false) const;
292 
293 
294  // Edit
295 
296  //- Rename
297  void rename(const word& newName)
298  {
299  name_ = newName;
300  }
301 
302  //- Edit access to origin
303  point& origin()
304  {
305  return origin_;
306  }
307 
308  //- Reset origin and rotation to an identity coordinateSystem
309  // Also resets the note
310  virtual void clear();
311 
312 
313  // Write
314 
315  //- Write
316  virtual void write(Ostream&) const;
317 
318  //- Write dictionary
319  void writeDict(Ostream&, bool subDict=true) const;
320 
321 
322  // Transformations
323 
324  //- Convert from position in local coordinate system to global
325  // Cartesian position
326  point globalPosition(const point& local) const
327  {
328  return localToGlobal(local, true);
329  }
330 
331  //- Convert from position in local coordinate system to global
332  // Cartesian position
333  tmp<pointField> globalPosition(const pointField& local) const
334  {
335  return localToGlobal(local, true);
336  }
337 
338  //- Convert from vector components in local coordinate system to
339  // global Cartesian vector
340  vector globalVector(const vector& local) const
341  {
342  return localToGlobal(local, false);
343  }
344 
345  //- Convert from vector components in local coordinate system to
346  // global Cartesian vector
347  tmp<vectorField> globalVector(const vectorField& local) const
348  {
349  return localToGlobal(local, false);
350  }
351 
352  //- Convert from global Cartesian position to position in local
353  // coordinate system
354  point localPosition(const point& global) const
355  {
356  return globalToLocal(global, true);
357  }
358 
359  //- Convert from global Cartesian position to position in local
360  // coordinate system
361  tmp<pointField> localPosition(const pointField& global) const
362  {
363  return globalToLocal(global, true);
364  }
365 
366  //- Convert from global Cartesian vector to components in local
367  // coordinate system
368  vector localVector(const vector& global) const
369  {
370  return globalToLocal(global, false);
371  }
372 
373  //- Convert from global Cartesian vector to components in local
374  // coordinate system
375  tmp<vectorField> localVector(const vectorField& global) const
376  {
377  return globalToLocal(global, false);
378  }
379 
380 
381  // Member Operators
382 
383  // friend Operators
384 
385  friend bool operator!=
386  (
387  const coordinateSystem&,
388  const coordinateSystem&
389  );
390 
391 
392  // IOstream Operators
393 
394  friend Ostream& operator<<(Ostream&, const coordinateSystem&);
395 };
396 
397 
398 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
399 
400 } // End namespace Foam
401 
402 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
403 
404 #endif
405 
406 // ************************************************************************* //
Base class for other coordinate system specifications.
TypeName("coordinateSystem")
Runtime type information.
Abstract base class for coordinate rotation.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
void writeDict(Ostream &, bool subDict=true) const
Write dictionary.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
vector globalVector(const vector &local) const
Convert from vector components in local coordinate system to.
virtual void write(Ostream &) const
Write.
autoPtr< coordinateSystem > clone() const
Return clone.
point globalPosition(const point &local) const
Convert from position in local coordinate system to global.
virtual ~coordinateSystem()
Destructor.
declareRunTimeSelectionTable(autoPtr, coordinateSystem, dictionary,(const objectRegistry &obr, const dictionary &dict),(obr, dict))
const coordinateRotation & R() const
Return const reference to co-ordinate rotation.
virtual void clear()
Reset origin and rotation to an identity coordinateSystem.
coordinateSystem()
Construct null. This is equivalent to an identity coordinateSystem.
string & note()
Return non-constant access to the optional note.
virtual vector globalToLocal(const vector &, bool translate) const
Convert from global Cartesian system to the local coordinate system.
dynamicFvMesh & mesh
const cellShapeList & cells
A class for handling words, derived from string.
Definition: word.H:59
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
const word & name() const
Return name.
virtual vector localToGlobal(const vector &, bool translate) const
Convert from local coordinate system to the global Cartesian system.
static autoPtr< coordinateSystem > New(const objectRegistry &obr, const dictionary &dict)
Select constructed from dictionary and objectRegistry.
void rename(const word &newName)
Rename.
Ostream & operator<<(Ostream &, const ensightPart &)
vector localVector(const vector &global) const
Convert from global Cartesian vector to components in local.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:53
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
point localPosition(const point &global) const
Convert from global Cartesian position to position in local.
A class for managing temporary objects.
Definition: PtrList.H:54
Registry of regIOobjects.
friend Ostream & operator<<(Ostream &, const coordinateSystem &)
bool operator!=(const particle &, const particle &)
Definition: particle.C:145
const point & origin() const
Return origin.
void init(const dictionary &)
Init from dict and obr.
Namespace for OpenFOAM.
virtual dictionary dict(bool ignoreType=false) const
Return as dictionary of entries.