initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / meshTools / coordinateSystems / coordinateSystem.H
blobf61c6412d2afcda5cd3fefb3372996067ebd590c
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 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
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
36       is implicit
38     @verbatim
39         flipped
40         {
41             type    cartesian;
42             origin  (0 0 0);
43             coordinateRotation
44             {
45                 type        STARCDRotation;
46                 rotation    (0 0 90);
47             }
48         }
49     @endverbatim
51     - if an axes specification (eg, e3/e1) is used, the coordinateRotation
52       sub-dictionary can be dropped.
54     @verbatim
55         flipped     // the same, specified as axes
56         {
57             type    cartesian;
58             origin  (0 0 0);
59             coordinateRotation
60             {
61                 type    axes;
62                 e3      (1 0 0);
63                 e1      (0 0 -1);
64             }
65         }
66         flipped     // the same, using all the shortcuts
67         {
68             e3      (1 0 0);
69             e1      (0 0 -1);
70         }
71     @endverbatim
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:
78     @verbatim
79         1
80         (
81         cat1
82         {
83             coordinateSystem
84             {
85                 origin  (0 0 0);
86                 coordinateRotation
87                 {
88                     type        STARCDRotation;
89                     rotation    (0 0 90);
90                 }
91             }
92             porosity        0.781;
93             Darcy
94             {
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);
97             }
98         }
99         )
100     @endverbatim
102 SourceFiles
103     coordinateSystem.C
104     newCoordinateSystem.C
105 \*---------------------------------------------------------------------------*/
107 #ifndef coordinateSystem_H
108 #define coordinateSystem_H
110 #include "vector.H"
111 #include "point.H"
112 #include "tensor.H"
113 #include "vectorField.H"
114 #include "pointField.H"
115 #include "tmp.H"
116 #include "coordinateRotation.H"
117 #include "objectRegistry.H"
119 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
121 namespace Foam
124 /*---------------------------------------------------------------------------*\
125                      Class coordinateSystem Declaration
126 \*---------------------------------------------------------------------------*/
128 class coordinateSystem
130     // Private data
132         //- Name of coordinate system
133         mutable word name_;
135         //- Origin
136         mutable point origin_;
138         //- Local-to-Global transformation tensor
139         coordinateRotation R_;
141         //- Global-to-Local transformation tensor
142         tensor Rtr_;
144 protected:
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
155         (
156             const vectorField&,
157             bool translate
158         ) const;
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
167         (
168             const vectorField&,
169             bool translate
170         ) const;
172 public:
174     //- Runtime type information
175     TypeName("coordinateSystem");
178     // Constructors
180         //- Construct null
181         coordinateSystem();
183         //- Construct from origin and 2 axes
184         coordinateSystem
185         (
186             const word& name,
187             const point& origin,
188             const vector& axis,
189             const vector& dir
190         );
192         //- Construct from origin and rotation angles
193         coordinateSystem
194         (
195             const word& name,
196             const point& origin,
197             const coordinateRotation&
198         );
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&);
210         //- Return clone
211         autoPtr<coordinateSystem> clone() const
212         {
213             return autoPtr<coordinateSystem>
214             (
215                 new coordinateSystem
216                 (
217                     name(),
218                     origin(),
219                     rotation()
220                 )
221             );
222         }
224     // Declare run-time constructor selection table
226         declareRunTimeSelectionTable
227         (
228             autoPtr,
229             coordinateSystem,
230             origAxisDir,
231             (
232                 const word& name,
233                 const point& origin,
234                 const vector& axis,
235                 const vector& dir
236             ),
237             (name, origin, axis, dir)
238         );
240         declareRunTimeSelectionTable
241         (
242             autoPtr,
243             coordinateSystem,
244             origRotation,
245             (
246                 const word& name,
247                 const point& origin,
248                 const coordinateRotation& cr
249             ),
250             (name, origin, cr)
251         );
253         declareRunTimeSelectionTable
254         (
255             autoPtr,
256             coordinateSystem,
257             dictionary,
258             (
259                 const word& name,
260                 const dictionary& dict
261             ),
262             (name, dict)
263         );
266     // Selectors
268         //- Select constructed from origin and 2 axes
269         static autoPtr<coordinateSystem> New
270         (
271             const word& coordType,
272             const word& name,
273             const point& origin,
274             const vector& axis,
275             const vector& dir
276         );
278         //- Select constructed from origin and rotation
279         static autoPtr<coordinateSystem> New
280         (
281             const word& coordType,
282             const word& name,
283             const point& origin,
284             const coordinateRotation& cr
285         );
287         //- Select constructed from dictionary
288         static autoPtr<coordinateSystem> New
289         (
290             const word& name,
291             const dictionary& dict
292         );
294         //- Select constructed from Istream
295         static autoPtr<coordinateSystem> New(Istream& is);
297     // Destructor
299         virtual ~coordinateSystem();
302     // Member Functions
304       // Access
306         //- Return name
307         const word& name() const
308         {
309             return name_;
310         }
312         //- Return origin
313         const point& origin() const
314         {
315             return origin_;
316         }
318         //- Return coordinate rotation
319         const coordinateRotation& rotation() const
320         {
321             return R_;
322         }
324         //- Return local-to-global transformation tensor
325         const tensor& R() const
326         {
327             return R_;
328         }
330         //- Return local Cartesian x-axis
331         const vector& e1() const
332         {
333            return Rtr_.x();
334         }
336         //- Return local Cartesian y-axis
337         const vector& e2() const
338         {
339            return Rtr_.y();
340         }
342         //- Return local Cartesian z-axis
343         const vector& e3() const
344         {
345            return Rtr_.z();
346         }
348         //- Return axis (e3: local Cartesian z-axis)
349         // @deprecated method e3 is preferred
350         const vector& axis() const
351         {
352            return Rtr_.z();
353         }
355         //- Return direction (e1: local Cartesian x-axis)
356         // @deprecated method e1 is preferred
357         const vector& direction() const
358         {
359             return Rtr_.x();
360         }
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;
368       // Edit
370         //- Rename
371         virtual void rename(const word& newName)
372         {
373             name_ = newName;
374         }
376         //- Edit access to origin
377         point& origin()
378         {
379             return origin_;
380         }
382       // Write
384         //- Write
385         virtual void write(Ostream&) const;
387         //- Write dictionary
388         virtual void writeDict(Ostream&, bool subDict = true) const;
390       // Transformations
392         //- Convert from position in local coordinate system to global Cartesian position
393         point globalPosition(const point& local) const
394         {
395             return localToGlobal(local, true);
396         }
398         //- Convert from position in local coordinate system to global Cartesian position
399         tmp<pointField> globalPosition(const pointField& local) const
400         {
401             return localToGlobal(local, true);
402         }
404         //- Convert from vector components in local coordinate system to global Cartesian vector
405         vector globalVector(const vector& local) const
406         {
407             return localToGlobal(local, false);
408         }
410         //- Convert from vector components in local coordinate system to global Cartesian vector
411         tmp<vectorField> globalVector(const vectorField& local) const
412         {
413             return localToGlobal(local, false);
414         }
416         //- Convert from global Cartesian position to position in local coordinate system
417         point localPosition(const point& global) const
418         {
419             return globalToLocal(global, true);
420         }
422         //- Convert from global Cartesian position to position in local coordinate system
423         tmp<pointField> localPosition(const pointField& global) const
424         {
425             return globalToLocal(global, true);
426         }
428         //- Convert from global Cartesian vector to components in local coordinate system
429         vector localVector(const vector& global) const
430         {
431             return globalToLocal(global, false);
432         }
434         //- Convert from global Cartesian vector to components in local coordinate system
435         tmp<vectorField> localVector(const vectorField& global) const
436         {
437             return globalToLocal(global, false);
438         }
441     // Member Operators
443         //- assign from dictionary
444         void operator=(const dictionary&);
447     // friend Operators
449         friend bool operator!=(const coordinateSystem&, const coordinateSystem&);
451     // IOstream Operators
453         friend Ostream& operator<<(Ostream&, const coordinateSystem&);
457 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
459 } // End namespace Foam
461 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
463 #endif
465 // ************************************************************************* //