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