1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 Foam::coordinateSystem
29 A cartesian coordinate system and the base class for other coordinate
30 system specifications.
32 All systems are defined by an origin point and a coordinateRotation.
33 For convenience, the dictionary constructor forms allow a few shortcuts:
34 - the default origin corresponds to <em>(0 0 0)</em>
35 - if the @c type is not otherwise specified, a Cartesian coordinateSystem
50 - if an axes specification (eg, e3/e1) is used, the coordinateRotation
51 sub-dictionary can be dropped.
54 flipped // the same, specified as axes
64 flipped // the same, using all the shortcuts
71 - if a sub-dictionary coordinateSystem is found within the dictionary, it
72 will be used. This provides a convenient means of embedding
73 coordinateSystem information in another dictionary.
74 This is used, for example, in the porousZones:
93 d d [0 -2 0 0 0] (-1000 -1000 0.50753e+08);
94 f f [0 -1 0 0 0] (-1000 -1000 12.83);
100 - additionally, if the coordinateSystem points to a plain entry,
101 it can be used to reference one of the global coordinateSystems
108 coordinateSystem system_10;
112 d d [0 -2 0 0 0] (-1000 -1000 0.50753e+08);
113 f f [0 -1 0 0 0] (-1000 -1000 12.83);
118 For this to work correctly, the coordinateSystem constructor must be
119 supplied with both a dictionary and an objectRegistry.
122 coordinateSystems and coordinateSystems::New
126 newCoordinateSystem.C
127 \*---------------------------------------------------------------------------*/
129 #ifndef coordinateSystem_H
130 #define coordinateSystem_H
135 #include "vectorField.H"
136 #include "pointField.H"
138 #include "coordinateRotation.H"
139 #include "objectRegistry.H"
141 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
146 /*---------------------------------------------------------------------------*\
147 Class coordinateSystem Declaration
148 \*---------------------------------------------------------------------------*/
150 class coordinateSystem
154 //- Name of coordinate system
158 mutable string note_;
161 mutable point origin_;
163 //- Local-to-Global transformation tensor
164 coordinateRotation R_;
166 //- 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
199 //- Runtime type information
200 TypeName("coordinateSystem");
205 //- Construct null. This is equivalent to an identity coordinateSystem
208 //- Construct copy with a different name
212 const coordinateSystem&
215 //- Construct from origin and rotation
220 const coordinateRotation&
223 //- Construct from origin and 2 axes
232 //- Construct from dictionary with a given name
233 coordinateSystem(const word& name, const dictionary&);
235 //- Construct from dictionary with default name
236 coordinateSystem(const dictionary&);
238 //- Construct from dictionary (default name)
239 // With the ability to reference global coordinateSystems
240 coordinateSystem(const dictionary&, const objectRegistry&);
242 //- Construct from Istream
243 // The Istream contains a word followed by a dictionary
244 coordinateSystem(Istream&);
247 autoPtr<coordinateSystem> clone() const
249 return autoPtr<coordinateSystem>(new coordinateSystem(*this));
252 // Declare run-time constructor selection table
254 declareRunTimeSelectionTable
261 const dictionary& dict
266 declareRunTimeSelectionTable
274 const coordinateRotation& cr
281 //- Select constructed from dictionary
282 static autoPtr<coordinateSystem> New
288 //- Select constructed from origin and rotation
289 static autoPtr<coordinateSystem> New
291 const word& coordType,
294 const coordinateRotation&
297 //- Select constructed from Istream
298 static autoPtr<coordinateSystem> New(Istream& is);
302 virtual ~coordinateSystem();
310 const word& name() const
315 //- Return non-constant access to the optional note
321 //- Return the optional note
322 const string& note() const
328 const point& origin() const
333 //- Return coordinate rotation
334 const coordinateRotation& rotation() const
339 //- Return local-to-global transformation tensor
340 const tensor& R() const
345 //- Return local Cartesian x-axis
346 const vector& e1() const
351 //- Return local Cartesian y-axis
352 const vector& e2() const
357 //- Return local Cartesian z-axis
358 const vector& e3() const
363 //- Return axis (e3: local Cartesian z-axis)
364 // @deprecated method e3 is preferred
365 const vector& axis() const
370 //- Return direction (e1: local Cartesian x-axis)
371 // @deprecated method e1 is preferred
372 const vector& direction() const
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;
386 virtual void rename(const word& newName)
391 //- Edit access to origin
400 virtual void write(Ostream&) const;
403 virtual void writeDict(Ostream&, bool subDict = true) const;
407 //- Convert from position in local coordinate system to
408 // global Cartesian position
409 point globalPosition(const point& local) const
411 return localToGlobal(local, true);
414 //- Convert from position in local coordinate system to
415 // global Cartesian position
416 tmp<pointField> globalPosition(const pointField& local) const
418 return localToGlobal(local, true);
421 //- Convert from vector components in local coordinate system
422 // to global Cartesian vector
423 vector globalVector(const vector& local) const
425 return localToGlobal(local, false);
428 //- Convert from vector components in local coordinate system
429 // to global Cartesian vector
430 tmp<vectorField> globalVector(const vectorField& local) const
432 return localToGlobal(local, false);
435 //- Convert from global Cartesian position to position in
436 // local coordinate system
437 point localPosition(const point& global) const
439 return globalToLocal(global, true);
442 //- Convert from global Cartesian position to position in
443 // local coordinate system
444 tmp<pointField> localPosition(const pointField& global) const
446 return globalToLocal(global, true);
449 //- Convert from global Cartesian vector to components in
450 // local coordinate system
451 vector localVector(const vector& global) const
453 return globalToLocal(global, false);
456 //- Convert from global Cartesian vector to components in
457 // local coordinate system
458 tmp<vectorField> localVector(const vectorField& global) const
460 return globalToLocal(global, false);
466 //- assign from dictionary
467 void operator=(const dictionary&);
472 friend bool operator!=
474 const coordinateSystem&,
475 const coordinateSystem&
478 // IOstream Operators
480 friend Ostream& operator<<(Ostream&, const coordinateSystem&);
484 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
486 } // End namespace Foam
488 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
492 // ************************************************************************* //