1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 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 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
30 other coordinate 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
51 - if an axes specification (eg, e3/e1) is used, the coordinateRotation
52 sub-dictionary can be dropped.
55 flipped // the same, specified as axes
66 flipped // the same, using all the shortcuts
73 - if a sub-dictionary coordinateSystem is found within the dictionary, it
74 will be used. This provides a convenient means of embedding the
75 coordinateSystem information in another dictionary.
76 This is used, for example, in the porousZones:
95 d d [0 -2 0 0 0] (-1000 -1000 0.50753e+08);
96 f f [0 -1 0 0 0] (-1000 -1000 12.83);
104 newCoordinateSystem.C
105 \*---------------------------------------------------------------------------*/
107 #ifndef coordinateSystem_H
108 #define coordinateSystem_H
113 #include "vectorField.H"
114 #include "pointField.H"
116 #include "coordinateRotation.H"
117 #include "objectRegistry.H"
119 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
124 /*---------------------------------------------------------------------------*\
125 Class coordinateSystem Declaration
126 \*---------------------------------------------------------------------------*/
128 class coordinateSystem
132 //- Name of coordinate system
136 mutable point origin_;
138 //- Local-to-Global transformation tensor
139 coordinateRotation R_;
141 //- Global-to-Local transformation tensor
146 // Protected Member Functions
148 //- Convert from local coordinate system to the global Cartesian system
149 // with optional translation for the origin
150 virtual vector localToGlobal(const vector&, bool translate) const;
152 //- Convert from local coordinate system to the global Cartesian system
153 // with optional translation for the origin
154 virtual tmp<vectorField> localToGlobal
160 //- Convert from global Cartesian system to the local coordinate system
161 // with optional translation for the origin
162 virtual vector globalToLocal(const vector&, bool translate) const;
164 //- Convert from global Cartesian system to the local coordinate system
165 // with optional translation for the origin
166 virtual tmp<vectorField> globalToLocal
174 //- Runtime type information
175 TypeName("coordinateSystem");
183 //- Construct from origin and 2 axes
192 //- Construct from origin and rotation angles
197 const coordinateRotation&
200 //- Construct from dictionary with default name
201 coordinateSystem(const dictionary&);
203 //- Construct from dictionary
204 coordinateSystem(const word& name, const dictionary&);
206 //- Construct from Istream
207 // The Istream contains a word followed by a dictionary
208 coordinateSystem(Istream&);
211 autoPtr<coordinateSystem> clone() const
213 return autoPtr<coordinateSystem>
224 // Declare run-time constructor selection table
226 declareRunTimeSelectionTable
237 (name, origin, axis, dir)
240 declareRunTimeSelectionTable
248 const coordinateRotation& cr
253 declareRunTimeSelectionTable
260 const dictionary& dict
268 //- Select constructed from origin and 2 axes
269 static autoPtr<coordinateSystem> New
271 const word& coordType,
278 //- Select constructed from origin and rotation
279 static autoPtr<coordinateSystem> New
281 const word& coordType,
284 const coordinateRotation& cr
287 //- Select constructed from dictionary
288 static autoPtr<coordinateSystem> New
291 const dictionary& dict
294 //- Select constructed from Istream
295 static autoPtr<coordinateSystem> New(Istream& is);
299 virtual ~coordinateSystem();
307 const word& name() const
313 const point& origin() const
318 //- Return coordinate rotation
319 const coordinateRotation& rotation() const
324 //- Return local-to-global transformation tensor
325 const tensor& R() const
330 //- Return local Cartesian x-axis
331 const vector& e1() const
336 //- Return local Cartesian y-axis
337 const vector& e2() const
342 //- Return local Cartesian z-axis
343 const vector& e3() const
348 //- Return axis (e3: local Cartesian z-axis)
349 // @deprecated method e3 is preferred
350 const vector& axis() const
355 //- Return direction (e1: local Cartesian x-axis)
356 // @deprecated method e1 is preferred
357 const vector& direction() const
362 //- Return as dictionary of entries
363 // @param [in] ignoreType drop type (cartesian, cylindrical, etc)
364 // when generating the dictionary
365 virtual dictionary dict(bool ignoreType = false) const;
371 virtual void rename(const word& newName)
376 //- Edit access to origin
385 virtual void write(Ostream&) const;
388 virtual void writeDict(Ostream&, bool subDict = true) const;
392 //- Convert from position in local coordinate system to global Cartesian position
393 point globalPosition(const point& local) const
395 return localToGlobal(local, true);
398 //- Convert from position in local coordinate system to global Cartesian position
399 tmp<pointField> globalPosition(const pointField& local) const
401 return localToGlobal(local, true);
404 //- Convert from vector components in local coordinate system to global Cartesian vector
405 vector globalVector(const vector& local) const
407 return localToGlobal(local, false);
410 //- Convert from vector components in local coordinate system to global Cartesian vector
411 tmp<vectorField> globalVector(const vectorField& local) const
413 return localToGlobal(local, false);
416 //- Convert from global Cartesian position to position in local coordinate system
417 point localPosition(const point& global) const
419 return globalToLocal(global, true);
422 //- Convert from global Cartesian position to position in local coordinate system
423 tmp<pointField> localPosition(const pointField& global) const
425 return globalToLocal(global, true);
428 //- Convert from global Cartesian vector to components in local coordinate system
429 vector localVector(const vector& global) const
431 return globalToLocal(global, false);
434 //- Convert from global Cartesian vector to components in local coordinate system
435 tmp<vectorField> localVector(const vectorField& global) const
437 return globalToLocal(global, false);
443 //- assign from dictionary
444 void operator=(const dictionary&);
449 friend bool operator!=(const coordinateSystem&, const coordinateSystem&);
451 // IOstream Operators
453 friend Ostream& operator<<(Ostream&, const coordinateSystem&);
457 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
459 } // End namespace Foam
461 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
465 // ************************************************************************* //