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