1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
171 // Protected Member Functions
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;
177 //- Convert from local coordinate system to the global Cartesian system
178 // with optional translation for the origin
179 virtual tmp<vectorField> localToGlobal
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;
189 //- Convert from global Cartesian system to the local coordinate system
190 // with optional translation for the origin
191 virtual tmp<vectorField> globalToLocal
200 //- Runtime type information
201 TypeName("coordinateSystem");
206 //- Construct null. This is equivalent to an identity coordinateSystem
209 //- Construct copy with a different name
213 const coordinateSystem&
216 //- Construct from origin and rotation
221 const coordinateRotation&
224 //- Construct from origin and 2 axes
233 //- Construct from dictionary with a given name
234 coordinateSystem(const word& name, const dictionary&);
236 //- Construct from dictionary with default name
237 coordinateSystem(const dictionary&);
239 //- Construct from dictionary (default name)
240 // With the ability to reference global coordinateSystems
241 coordinateSystem(const dictionary&, const objectRegistry&);
243 //- Construct from Istream
244 // The Istream contains a word followed by a dictionary
245 coordinateSystem(Istream&);
248 autoPtr<coordinateSystem> clone() const
250 return autoPtr<coordinateSystem>(new coordinateSystem(*this));
254 // Declare run-time constructor selection table
256 declareRunTimeSelectionTable
263 const dictionary& dict
268 declareRunTimeSelectionTable
276 const coordinateRotation& cr
284 //- Select constructed from dictionary
285 static autoPtr<coordinateSystem> New
291 //- Select constructed from origin and rotation
292 static autoPtr<coordinateSystem> New
294 const word& coordType,
297 const coordinateRotation&
300 //- Select constructed from Istream
301 static autoPtr<coordinateSystem> New(Istream& is);
305 virtual ~coordinateSystem();
313 const word& name() const
318 //- Return non-constant access to the optional note
324 //- Return the optional note
325 const string& note() const
331 const point& origin() const
336 //- Return coordinate rotation
337 const coordinateRotation& rotation() const
342 //- Return local-to-global transformation tensor
343 const tensor& R() const
348 //- Return local Cartesian x-axis
349 const vector e1() const
354 //- Return local Cartesian y-axis
355 const vector e2() const
360 //- Return local Cartesian z-axis
361 const vector e3() const
366 //- Return axis (e3: local Cartesian z-axis)
367 // \deprecated method e3 is preferred (deprecated Apr 2008)
368 const vector axis() const
373 //- Return direction (e1: local Cartesian x-axis)
374 // \deprecated method e1 is preferred (deprecated Apr 2008)
375 const vector direction() const
380 //- Return as dictionary of entries
381 // \param [in] ignoreType drop type (cartesian, cylindrical, etc)
382 // when generating the dictionary
383 virtual dictionary dict(bool ignoreType=false) const;
389 virtual void rename(const word& newName)
394 //- Edit access to origin
400 //- Reset origin and rotation to an identity coordinateSystem
401 // Also resets the note
402 virtual void clear();
408 virtual void write(Ostream&) const;
411 virtual void writeDict(Ostream&, bool subDict=true) const;
416 //- Convert from position in local coordinate system to global
417 // Cartesian position
418 point globalPosition(const point& local) const
420 return localToGlobal(local, true);
423 //- Convert from position in local coordinate system to global
424 // Cartesian position
425 tmp<pointField> globalPosition(const pointField& local) const
427 return localToGlobal(local, true);
430 //- Convert from vector components in local coordinate system to
431 // global Cartesian vector
432 vector globalVector(const vector& local) const
434 return localToGlobal(local, false);
437 //- Convert from vector components in local coordinate system to
438 // global Cartesian vector
439 tmp<vectorField> globalVector(const vectorField& local) const
441 return localToGlobal(local, false);
444 //- Convert from global Cartesian position to position in local
446 point localPosition(const point& global) const
448 return globalToLocal(global, true);
451 //- Convert from global Cartesian position to position in local
453 tmp<pointField> localPosition(const pointField& global) const
455 return globalToLocal(global, true);
458 //- Convert from global Cartesian vector to components in local
460 vector localVector(const vector& global) const
462 return globalToLocal(global, false);
465 //- Convert from global Cartesian vector to components in local
467 tmp<vectorField> localVector(const vectorField& global) const
469 return globalToLocal(global, false);
475 //- assign from dictionary
476 void operator=(const dictionary&);
481 friend bool operator!=
483 const coordinateSystem&,
484 const coordinateSystem&
488 // IOstream Operators
490 friend Ostream& operator<<(Ostream&, const coordinateSystem&);
494 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
496 } // End namespace Foam
498 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
502 // ************************************************************************* //