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-2020 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  //- Construct and return a clone
164  virtual autoPtr<coordinateSystem> clone() const
165  {
166  return autoPtr<coordinateSystem>(new coordinateSystem(*this));
167  }
168 
169 
170  // Declare run-time constructor selection table
172  (
173  autoPtr,
175  dictionary,
176  (
177  const word& name,
178  const dictionary& dict
179  ),
180  (name, dict)
181  );
182 
183 
184  // Selectors
185 
186  //- Select constructed from dictionary and objectRegistry
188  (
189  const objectRegistry& obr,
190  const dictionary& dict
191  );
192 
193  //- Select constructed from name and dictionary
195  (
196  const word& name,
197  const dictionary& dict
198  );
199 
200 
201  //- Destructor
202  virtual ~coordinateSystem();
203 
204 
205  // Member Functions
206 
207  // Access
208 
209  //- Return name
210  const word& name() const
211  {
212  return name_;
213  }
214 
215  //- Return keyword
216  const word& keyword() const
217  {
218  return name_;
219  }
220 
221  //- Return origin
222  const point& origin() const
223  {
224  return origin_;
225  }
226 
227  //- Return const reference to co-ordinate rotation
228  const coordinateRotation& R() const
229  {
230  return R_();
231  }
232 
233  //- Update and return the co-ordinate rotation for a list of points
234  const coordinateRotation& R(const UList<vector>& points) const
235  {
236  R_->updatePoints(points);
237  return R_();
238  }
239 
240 
241  // Write
242 
243  //- Write
244  virtual void write(Ostream&) const;
245 
246  //- Write dictionary
247  void writeDict(Ostream&, bool subDict=true) const;
248 
249 
250  // Transformations
251 
252  //- Convert from position in local coordinate system to global
253  // Cartesian position
254  point globalPosition(const point& local) const
255  {
256  return localToGlobal(local, true);
257  }
258 
259  //- Convert from position in local coordinate system to global
260  // Cartesian position
261  tmp<pointField> globalPosition(const pointField& local) const
262  {
263  return localToGlobal(local, true);
264  }
265 
266  //- Convert from vector components in local coordinate system to
267  // global Cartesian vector
268  vector globalVector(const vector& local) const
269  {
270  return localToGlobal(local, false);
271  }
272 
273  //- Convert from vector components in local coordinate system to
274  // global Cartesian vector
275  tmp<vectorField> globalVector(const vectorField& local) const
276  {
277  return localToGlobal(local, false);
278  }
279 
280  //- Convert from global Cartesian position to position in local
281  // coordinate system
282  point localPosition(const point& global) const
283  {
284  return globalToLocal(global, true);
285  }
286 
287  //- Convert from global Cartesian position to position in local
288  // coordinate system
289  tmp<pointField> localPosition(const pointField& global) const
290  {
291  return globalToLocal(global, true);
292  }
293 
294  //- Convert from global Cartesian vector to components in local
295  // coordinate system
296  vector localVector(const vector& global) const
297  {
298  return globalToLocal(global, false);
299  }
300 
301  //- Convert from global Cartesian vector to components in local
302  // coordinate system
303  tmp<vectorField> localVector(const vectorField& global) const
304  {
305  return globalToLocal(global, false);
306  }
307 
308 
309  // IOstream Operators
310 
311  friend Ostream& operator<<(Ostream&, const coordinateSystem&);
312 };
313 
314 
315 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
316 
317 } // End namespace Foam
318 
319 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
320 
321 #endif
322 
323 // ************************************************************************* //
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:1205
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.