initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / meshTools / coordinateSystems / coordinateSystem.H
blob5bff54e52311078a96aea9736d7e87df385048ce
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 Class
26     Foam::coordinateSystem
28 Description
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
36       is implicit
38     @verbatim
39         flipped
40         {
41             origin  (0 0 0);
42             coordinateRotation
43             {
44                 type        STARCDRotation;
45                 rotation    (0 0 90);
46             }
47         }
48     @endverbatim
50     - if an axes specification (eg, e3/e1) is used, the coordinateRotation
51       sub-dictionary can be dropped.
53     @verbatim
54         flipped     // the same, specified as axes
55         {
56             origin  (0 0 0);
57             coordinateRotation
58             {
59                 type    axes;
60                 e3      (1 0 0);
61                 e1      (0 0 -1);
62             }
63         }
64         flipped     // the same, using all the shortcuts
65         {
66             e3      (1 0 0);
67             e1      (0 0 -1);
68         }
69     @endverbatim
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:
76     @verbatim
77         1
78         (
79         cat1
80         {
81             coordinateSystem
82             {
83                 origin  (0 0 0);
84                 coordinateRotation
85                 {
86                     type        STARCDRotation;
87                     rotation    (0 0 90);
88                 }
89             }
90             porosity        0.781;
91             Darcy
92             {
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);
95             }
96         }
97         )
98     @endverbatim
100     - additionally, if the coordinateSystem points to a plain entry,
101       it can be used to reference one of the global coordinateSystems
103     @verbatim
104         1
105         (
106         cat1
107         {
108             coordinateSystem  system_10;
109             porosity        0.781;
110             Darcy
111             {
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);
114             }
115         }
116         )
117     @endverbatim
118     For this to work correctly, the coordinateSystem constructor must be
119     supplied with both a dictionary and an objectRegistry.
121 See Also
122     coordinateSystems and coordinateSystems::New
124 SourceFiles
125     coordinateSystem.C
126     newCoordinateSystem.C
127 \*---------------------------------------------------------------------------*/
129 #ifndef coordinateSystem_H
130 #define coordinateSystem_H
132 #include "vector.H"
133 #include "point.H"
134 #include "tensor.H"
135 #include "vectorField.H"
136 #include "pointField.H"
137 #include "tmp.H"
138 #include "coordinateRotation.H"
139 #include "objectRegistry.H"
141 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
143 namespace Foam
146 /*---------------------------------------------------------------------------*\
147                      Class coordinateSystem Declaration
148 \*---------------------------------------------------------------------------*/
150 class coordinateSystem
152     // Private data
154         //- Name of coordinate system
155         mutable word name_;
157         //- Optional note
158         mutable string note_;
160         //- Origin
161         mutable point origin_;
163         //- Local-to-Global transformation tensor
164         coordinateRotation R_;
166         //- Global-to-Local transformation tensor
167         tensor Rtr_;
169 protected:
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
180         (
181             const vectorField&,
182             bool translate
183         ) const;
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
192         (
193             const vectorField&,
194             bool translate
195         ) const;
197 public:
199     //- Runtime type information
200     TypeName("coordinateSystem");
203     // Constructors
205         //- Construct null. This is equivalent to an identity coordinateSystem
206         coordinateSystem();
208         //- Construct copy with a different name
209         coordinateSystem
210         (
211             const word& name,
212             const coordinateSystem&
213         );
215         //- Construct from origin and rotation
216         coordinateSystem
217         (
218             const word& name,
219             const point& origin,
220             const coordinateRotation&
221         );
223         //- Construct from origin and 2 axes
224         coordinateSystem
225         (
226             const word& name,
227             const point& origin,
228             const vector& axis,
229             const vector& dirn
230         );
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&);
246         //- Return clone
247         autoPtr<coordinateSystem> clone() const
248         {
249             return autoPtr<coordinateSystem>(new coordinateSystem(*this));
250         }
252     // Declare run-time constructor selection table
254         declareRunTimeSelectionTable
255         (
256             autoPtr,
257             coordinateSystem,
258             dictionary,
259             (
260                 const word& name,
261                 const dictionary& dict
262             ),
263             (name, dict)
264         );
266         declareRunTimeSelectionTable
267         (
268             autoPtr,
269             coordinateSystem,
270             origRotation,
271             (
272                 const word& name,
273                 const point& origin,
274                 const coordinateRotation& cr
275             ),
276             (name, origin, cr)
277         );
279     // Selectors
281         //- Select constructed from dictionary
282         static autoPtr<coordinateSystem> New
283         (
284             const word& name,
285             const dictionary&
286         );
288         //- Select constructed from origin and rotation
289         static autoPtr<coordinateSystem> New
290         (
291             const word& coordType,
292             const word& name,
293             const point& origin,
294             const coordinateRotation&
295         );
297         //- Select constructed from Istream
298         static autoPtr<coordinateSystem> New(Istream& is);
300     // Destructor
302         virtual ~coordinateSystem();
305     // Member Functions
307       // Access
309         //- Return name
310         const word& name() const
311         {
312             return name_;
313         }
315         //- Return non-constant access to the optional note
316         string& note()
317         {
318             return note_;
319         }
321         //- Return the optional note
322         const string& note() const
323         {
324             return note_;
325         }
327         //- Return origin
328         const point& origin() const
329         {
330             return origin_;
331         }
333         //- Return coordinate rotation
334         const coordinateRotation& rotation() const
335         {
336             return R_;
337         }
339         //- Return local-to-global transformation tensor
340         const tensor& R() const
341         {
342             return R_;
343         }
345         //- Return local Cartesian x-axis
346         const vector& e1() const
347         {
348            return Rtr_.x();
349         }
351         //- Return local Cartesian y-axis
352         const vector& e2() const
353         {
354            return Rtr_.y();
355         }
357         //- Return local Cartesian z-axis
358         const vector& e3() const
359         {
360            return Rtr_.z();
361         }
363         //- Return axis (e3: local Cartesian z-axis)
364         // @deprecated method e3 is preferred
365         const vector& axis() const
366         {
367            return Rtr_.z();
368         }
370         //- Return direction (e1: local Cartesian x-axis)
371         // @deprecated method e1 is preferred
372         const vector& direction() const
373         {
374             return Rtr_.x();
375         }
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;
383       // Edit
385         //- Rename
386         virtual void rename(const word& newName)
387         {
388             name_ = newName;
389         }
391         //- Edit access to origin
392         point& origin()
393         {
394             return origin_;
395         }
397       // Write
399         //- Write
400         virtual void write(Ostream&) const;
402         //- Write dictionary
403         virtual void writeDict(Ostream&, bool subDict=true) const;
405       // Transformations
407         //- Convert from position in local coordinate system to global Cartesian position
408         point globalPosition(const point& local) const
409         {
410             return localToGlobal(local, true);
411         }
413         //- Convert from position in local coordinate system to global Cartesian position
414         tmp<pointField> globalPosition(const pointField& local) const
415         {
416             return localToGlobal(local, true);
417         }
419         //- Convert from vector components in local coordinate system to global Cartesian vector
420         vector globalVector(const vector& local) const
421         {
422             return localToGlobal(local, false);
423         }
425         //- Convert from vector components in local coordinate system to global Cartesian vector
426         tmp<vectorField> globalVector(const vectorField& local) const
427         {
428             return localToGlobal(local, false);
429         }
431         //- Convert from global Cartesian position to position in local coordinate system
432         point localPosition(const point& global) const
433         {
434             return globalToLocal(global, true);
435         }
437         //- Convert from global Cartesian position to position in local coordinate system
438         tmp<pointField> localPosition(const pointField& global) const
439         {
440             return globalToLocal(global, true);
441         }
443         //- Convert from global Cartesian vector to components in local coordinate system
444         vector localVector(const vector& global) const
445         {
446             return globalToLocal(global, false);
447         }
449         //- Convert from global Cartesian vector to components in local coordinate system
450         tmp<vectorField> localVector(const vectorField& global) const
451         {
452             return globalToLocal(global, false);
453         }
456     // Member Operators
458         //- assign from dictionary
459         void operator=(const dictionary&);
462     // friend Operators
464         friend bool operator!=
465         (
466             const coordinateSystem&,
467             const coordinateSystem&
468         );
470     // IOstream Operators
472         friend Ostream& operator<<(Ostream&, const coordinateSystem&);
476 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
478 } // End namespace Foam
480 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
482 #endif
484 // ************************************************************************* //