FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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  A cartesian coordinate system and the base class for other coordinate
29  system specifications.
30 
31  All systems are defined by an origin point and a coordinateRotation.
32  For convenience, the dictionary constructor forms allow a few shortcuts:
33  - the default origin corresponds to <em>(0 0 0)</em>
34  - if the @c type is not otherwise specified, a Cartesian coordinateSystem
35  is implicit
36 
37  @verbatim
38  flipped
39  {
40  origin (0 0 0);
41  coordinateRotation
42  {
43  type STARCDRotation;
44  rotation (0 0 90);
45  }
46  }
47  @endverbatim
48 
49  - if an axes specification (eg, e3/e1) is used, the coordinateRotation
50  sub-dictionary can be dropped.
51 
52  @verbatim
53  flipped // the same, specified as axes
54  {
55  origin (0 0 0);
56  coordinateRotation
57  {
58  type axes;
59  e3 (1 0 0);
60  e1 (0 0 -1);
61  }
62  }
63  flipped // the same, using all the shortcuts
64  {
65  e3 (1 0 0);
66  e1 (0 0 -1);
67  }
68  @endverbatim
69 
70  - if a sub-dictionary coordinateSystem is found within the dictionary, it
71  will be used. This provides a convenient means of embedding
72  coordinateSystem information in another dictionary.
73  This is used, for example, in the porousZones:
74 
75  @verbatim
76  1
77  (
78  cat1
79  {
80  coordinateSystem
81  {
82  origin (0 0 0);
83  coordinateRotation
84  {
85  type STARCDRotation;
86  rotation (0 0 90);
87  }
88  }
89  porosity 0.781;
90  Darcy
91  {
92  d d [0 -2 0 0 0] (-1000 -1000 0.50753e+08);
93  f f [0 -1 0 0 0] (-1000 -1000 12.83);
94  }
95  }
96  )
97  @endverbatim
98 
99  - additionally, if the coordinateSystem points to a plain entry,
100  it can be used to reference one of the global coordinateSystems
101 
102  @verbatim
103  1
104  (
105  cat1
106  {
107  coordinateSystem system_10;
108  porosity 0.781;
109  Darcy
110  {
111  d d [0 -2 0 0 0] (-1000 -1000 0.50753e+08);
112  f f [0 -1 0 0 0] (-1000 -1000 12.83);
113  }
114  }
115  )
116  @endverbatim
117  For this to work correctly, the coordinateSystem constructor must be
118  supplied with both a dictionary and an objectRegistry.
119 
120 See Also
121  coordinateSystems and coordinateSystems::New
122 
123 SourceFiles
124  coordinateSystem.C
125  newCoordinateSystem.C
126 
127 \*---------------------------------------------------------------------------*/
128 
129 #ifndef coordinateSystem_H
130 #define coordinateSystem_H
131 
132 #include <OpenFOAM/vector.H>
133 #include <OpenFOAM/point.H>
134 #include <OpenFOAM/tensor.H>
135 #include <OpenFOAM/vectorField.H>
136 #include <OpenFOAM/pointField.H>
137 #include <OpenFOAM/tmp.H>
139 #include <OpenFOAM/objectRegistry.H>
140 
141 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
142 
143 namespace Foam
144 {
145 
146 /*---------------------------------------------------------------------------*\
147  Class coordinateSystem Declaration
148 \*---------------------------------------------------------------------------*/
149 
151 {
152  // Private data
153 
154  //- Name of coordinate system
155  mutable word name_;
156 
157  //- Optional note
158  mutable string note_;
159 
160  //- Origin
161  mutable point origin_;
162 
163  //- Local-to-Global transformation tensor
165 
166  //- Global-to-Local transformation tensor
167  tensor Rtr_;
168 
169 protected:
170 
171  // Protected Member Functions
172 
173  //- Convert from local coordinate system to the global Cartesian system
174  // with optional translation for the origin
175  virtual vector localToGlobal(const vector&, bool translate) const;
176 
177  //- Convert from local coordinate system to the global Cartesian system
178  // with optional translation for the origin
180  (
181  const vectorField&,
182  bool translate
183  ) const;
184 
185  //- Convert from global Cartesian system to the local coordinate system
186  // with optional translation for the origin
187  virtual vector globalToLocal(const vector&, bool translate) const;
188 
189  //- Convert from global Cartesian system to the local coordinate system
190  // with optional translation for the origin
192  (
193  const vectorField&,
194  bool translate
195  ) const;
196 
197 public:
198 
199  //- Runtime type information
200  TypeName("coordinateSystem");
201 
202 
203  // Constructors
204 
205  //- Construct null. This is equivalent to an identity coordinateSystem
207 
208  //- Construct copy with a different name
210  (
211  const word& name,
212  const coordinateSystem&
213  );
214 
215  //- Construct from origin and rotation
217  (
218  const word& name,
219  const point& origin,
220  const coordinateRotation&
221  );
222 
223  //- Construct from origin and 2 axes
225  (
226  const word& name,
227  const point& origin,
228  const vector& axis,
229  const vector& dirn
230  );
231 
232  //- Construct from dictionary with a given name
233  coordinateSystem(const word& name, const dictionary&);
234 
235  //- Construct from dictionary with default name
237 
238  //- Construct from dictionary (default name)
239  // With the ability to reference global coordinateSystems
241 
242  //- Construct from Istream
243  // The Istream contains a word followed by a dictionary
245 
246  //- Return clone
248  {
249  return autoPtr<coordinateSystem>(new coordinateSystem(*this));
250  }
251 
252  // Declare run-time constructor selection table
253 
255  (
256  autoPtr,
258  dictionary,
259  (
260  const word& name,
261  const dictionary& dict
262  ),
263  (name, dict)
264  );
265 
267  (
268  autoPtr,
270  origRotation,
271  (
272  const word& name,
273  const point& origin,
274  const coordinateRotation& cr
275  ),
276  (name, origin, cr)
277  );
278 
279  // Selectors
280 
281  //- Select constructed from dictionary
283  (
284  const word& name,
285  const dictionary&
286  );
287 
288  //- Select constructed from origin and rotation
290  (
291  const word& coordType,
292  const word& name,
293  const point& origin,
294  const coordinateRotation&
295  );
296 
297  //- Select constructed from Istream
299 
300  // Destructor
301 
302  virtual ~coordinateSystem();
303 
304 
305  // Member Functions
306 
307  // Access
308 
309  //- Return name
310  const word& name() const
311  {
312  return name_;
313  }
314 
315  //- Return non-constant access to the optional note
316  string& note()
317  {
318  return note_;
319  }
320 
321  //- Return the optional note
322  const string& note() const
323  {
324  return note_;
325  }
326 
327  //- Return origin
328  const point& origin() const
329  {
330  return origin_;
331  }
332 
333  //- Return coordinate rotation
335  {
336  return R_;
337  }
338 
339  //- Return local-to-global transformation tensor
340  const tensor& R() const
341  {
342  return R_;
343  }
344 
345  //- Return local Cartesian x-axis
346  const vector e1() const
347  {
348  return Rtr_.x();
349  }
350 
351  //- Return local Cartesian y-axis
352  const vector e2() const
353  {
354  return Rtr_.y();
355  }
356 
357  //- Return local Cartesian z-axis
358  const vector e3() const
359  {
360  return Rtr_.z();
361  }
362 
363  //- Return axis (e3: local Cartesian z-axis)
364  // @deprecated method e3 is preferred
365  const vector axis() const
366  {
367  return Rtr_.z();
368  }
369 
370  //- Return direction (e1: local Cartesian x-axis)
371  // @deprecated method e1 is preferred
372  const vector direction() const
373  {
374  return Rtr_.x();
375  }
376 
377  //- Return as dictionary of entries
378  // @param [in] ignoreType drop type (cartesian, cylindrical, etc)
379  // when generating the dictionary
380  virtual dictionary dict(bool ignoreType=false) const;
381 
382 
383  // Edit
384 
385  //- Rename
386  virtual void rename(const word& newName)
387  {
388  name_ = newName;
389  }
390 
391  //- Edit access to origin
393  {
394  return origin_;
395  }
396 
397  // Write
398 
399  //- Write
400  virtual void write(Ostream&) const;
401 
402  //- Write dictionary
403  virtual void writeDict(Ostream&, bool subDict=true) const;
404 
405  // Transformations
406 
407  //- Convert from position in local coordinate system to global Cartesian position
408  point globalPosition(const point& local) const
409  {
410  return localToGlobal(local, true);
411  }
412 
413  //- Convert from position in local coordinate system to global Cartesian position
415  {
416  return localToGlobal(local, true);
417  }
418 
419  //- Convert from vector components in local coordinate system to global Cartesian vector
420  vector globalVector(const vector& local) const
421  {
422  return localToGlobal(local, false);
423  }
424 
425  //- Convert from vector components in local coordinate system to global Cartesian vector
427  {
428  return localToGlobal(local, false);
429  }
430 
431  //- Convert from global Cartesian position to position in local coordinate system
432  point localPosition(const point& global) const
433  {
434  return globalToLocal(global, true);
435  }
436 
437  //- Convert from global Cartesian position to position in local coordinate system
439  {
440  return globalToLocal(global, true);
441  }
442 
443  //- Convert from global Cartesian vector to components in local coordinate system
444  vector localVector(const vector& global) const
445  {
446  return globalToLocal(global, false);
447  }
448 
449  //- Convert from global Cartesian vector to components in local coordinate system
451  {
452  return globalToLocal(global, false);
453  }
454 
455 
456  // Member Operators
457 
458  //- assign from dictionary
459  void operator=(const dictionary&);
460 
461 
462  // friend Operators
463 
464  friend bool operator!=
465  (
466  const coordinateSystem&,
467  const coordinateSystem&
468  );
469 
470  // IOstream Operators
471 
472  friend Ostream& operator<<(Ostream&, const coordinateSystem&);
473 };
474 
475 
476 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
477 
478 } // End namespace Foam
479 
480 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
481 
482 #endif
483 
484 // ************************ vim: set sw=4 sts=4 et: ************************ //