1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
25 Foam::coordinateSystem
28 A cartesian coordinate system and the base class for other coordinate
29 system specifications.
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
49 - if an axes specification (eg, e3/e1) is used, the coordinateRotation
50 sub-dictionary can be dropped.
53 flipped // the same, specified as axes
63 flipped // the same, using all the shortcuts
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:
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);
99 - additionally, if the coordinateSystem points to a plain entry,
100 it can be used to reference one of the global coordinateSystems
107 coordinateSystem system_10;
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);
117 For this to work correctly, the coordinateSystem constructor must be
118 supplied with both a dictionary and an objectRegistry.
121 coordinateSystems and coordinateSystems::New
125 newCoordinateSystem.C
126 \*---------------------------------------------------------------------------*/
128 #ifndef coordinateSystem_H
129 #define coordinateSystem_H
134 #include "vectorField.H"
135 #include "pointField.H"
137 #include "coordinateRotation.H"
138 #include "objectRegistry.H"
140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145 /*---------------------------------------------------------------------------*\
146 Class coordinateSystem Declaration
147 \*---------------------------------------------------------------------------*/
149 class coordinateSystem
153 //- Name of coordinate system
157 mutable string note_;
160 mutable point origin_;
162 //- Local-to-Global transformation tensor
163 coordinateRotation R_;
165 //- Global-to-Local transformation tensor
170 // Protected Member Functions
172 //- Convert from local coordinate system to the global Cartesian system
173 // with optional translation for the origin
174 virtual vector localToGlobal(const vector&, bool translate) const;
176 //- Convert from local coordinate system to the global Cartesian system
177 // with optional translation for the origin
178 virtual tmp<vectorField> localToGlobal
184 //- Convert from global Cartesian system to the local coordinate system
185 // with optional translation for the origin
186 virtual vector globalToLocal(const vector&, bool translate) const;
188 //- Convert from global Cartesian system to the local coordinate system
189 // with optional translation for the origin
190 virtual tmp<vectorField> globalToLocal
198 //- Runtime type information
199 TypeName("coordinateSystem");
204 //- Construct null. This is equivalent to an identity coordinateSystem
207 //- Construct copy with a different name
211 const coordinateSystem&
214 //- Construct from origin and rotation
219 const coordinateRotation&
222 //- Construct from origin and 2 axes
231 //- Construct from dictionary with a given name
232 coordinateSystem(const word& name, const dictionary&);
234 //- Construct from dictionary with default name
235 coordinateSystem(const dictionary&);
237 //- Construct from dictionary (default name)
238 // With the ability to reference global coordinateSystems
239 coordinateSystem(const dictionary&, const objectRegistry&);
241 //- Construct from Istream
242 // The Istream contains a word followed by a dictionary
243 coordinateSystem(Istream&);
246 autoPtr<coordinateSystem> clone() const
248 return autoPtr<coordinateSystem>(new coordinateSystem(*this));
251 // Declare run-time constructor selection table
253 declareRunTimeSelectionTable
260 const dictionary& dict
265 declareRunTimeSelectionTable
273 const coordinateRotation& cr
280 //- Select constructed from dictionary
281 static autoPtr<coordinateSystem> New
287 //- Select constructed from origin and rotation
288 static autoPtr<coordinateSystem> New
290 const word& coordType,
293 const coordinateRotation&
296 //- Select constructed from Istream
297 static autoPtr<coordinateSystem> New(Istream& is);
301 virtual ~coordinateSystem();
309 const word& name() const
314 //- Return non-constant access to the optional note
320 //- Return the optional note
321 const string& note() const
327 const point& origin() const
332 //- Return coordinate rotation
333 const coordinateRotation& rotation() const
338 //- Return local-to-global transformation tensor
339 const tensor& R() const
344 //- Return local Cartesian x-axis
345 const vector e1() const
350 //- Return local Cartesian y-axis
351 const vector e2() const
356 //- Return local Cartesian z-axis
357 const vector e3() const
362 //- Return axis (e3: local Cartesian z-axis)
363 // @deprecated method e3 is preferred
364 const vector axis() const
369 //- Return direction (e1: local Cartesian x-axis)
370 // @deprecated method e1 is preferred
371 const vector direction() const
376 //- Return as dictionary of entries
377 // @param [in] ignoreType drop type (cartesian, cylindrical, etc)
378 // when generating the dictionary
379 virtual dictionary dict(bool ignoreType=false) const;
385 virtual void rename(const word& newName)
390 //- Edit access to origin
399 virtual void write(Ostream&) const;
402 virtual void writeDict(Ostream&, bool subDict=true) const;
406 //- Convert from position in local coordinate system to global Cartesian position
407 point globalPosition(const point& local) const
409 return localToGlobal(local, true);
412 //- Convert from position in local coordinate system to global Cartesian position
413 tmp<pointField> globalPosition(const pointField& local) const
415 return localToGlobal(local, true);
418 //- Convert from vector components in local coordinate system to global Cartesian vector
419 vector globalVector(const vector& local) const
421 return localToGlobal(local, false);
424 //- Convert from vector components in local coordinate system to global Cartesian vector
425 tmp<vectorField> globalVector(const vectorField& local) const
427 return localToGlobal(local, false);
430 //- Convert from global Cartesian position to position in local coordinate system
431 point localPosition(const point& global) const
433 return globalToLocal(global, true);
436 //- Convert from global Cartesian position to position in local coordinate system
437 tmp<pointField> localPosition(const pointField& global) const
439 return globalToLocal(global, true);
442 //- Convert from global Cartesian vector to components in local coordinate system
443 vector localVector(const vector& global) const
445 return globalToLocal(global, false);
448 //- Convert from global Cartesian vector to components in local coordinate system
449 tmp<vectorField> localVector(const vectorField& global) const
451 return globalToLocal(global, false);
457 //- assign from dictionary
458 void operator=(const dictionary&);
463 friend bool operator!=
465 const coordinateSystem&,
466 const coordinateSystem&
469 // IOstream Operators
471 friend Ostream& operator<<(Ostream&, const coordinateSystem&);
475 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
477 } // End namespace Foam
479 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
483 // ************************************************************************* //