ENH: RASModel.C: clipping input to log
[OpenFOAM-1.7.x.git] / src / meshTools / coordinateSystems / coordinateSystem.H
blob85991ba15b1dde8b3368fbf11818a2b28ad503ce
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2010 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
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
19     for more details.
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/>.
24 Class
25     Foam::coordinateSystem
27 Description
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
35       is implicit
37     @verbatim
38         flipped
39         {
40             origin  (0 0 0);
41             coordinateRotation
42             {
43                 type        STARCDRotation;
44                 rotation    (0 0 90);
45             }
46         }
47     @endverbatim
49     - if an axes specification (eg, e3/e1) is used, the coordinateRotation
50       sub-dictionary can be dropped.
52     @verbatim
53         flipped     // the same, specified as axes
54         {
55             origin  (0 0 0);
56             coordinateRotation
57             {
58                 type    axes;
59                 e3      (1 0 0);
60                 e1      (0 0 -1);
61             }
62         }
63         flipped     // the same, using all the shortcuts
64         {
65             e3      (1 0 0);
66             e1      (0 0 -1);
67         }
68     @endverbatim
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:
75     @verbatim
76         1
77         (
78         cat1
79         {
80             coordinateSystem
81             {
82                 origin  (0 0 0);
83                 coordinateRotation
84                 {
85                     type        STARCDRotation;
86                     rotation    (0 0 90);
87                 }
88             }
89             porosity        0.781;
90             Darcy
91             {
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);
94             }
95         }
96         )
97     @endverbatim
99     - additionally, if the coordinateSystem points to a plain entry,
100       it can be used to reference one of the global coordinateSystems
102     @verbatim
103         1
104         (
105         cat1
106         {
107             coordinateSystem  system_10;
108             porosity        0.781;
109             Darcy
110             {
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);
113             }
114         }
115         )
116     @endverbatim
117     For this to work correctly, the coordinateSystem constructor must be
118     supplied with both a dictionary and an objectRegistry.
120 See Also
121     coordinateSystems and coordinateSystems::New
123 SourceFiles
124     coordinateSystem.C
125     newCoordinateSystem.C
126 \*---------------------------------------------------------------------------*/
128 #ifndef coordinateSystem_H
129 #define coordinateSystem_H
131 #include "vector.H"
132 #include "point.H"
133 #include "tensor.H"
134 #include "vectorField.H"
135 #include "pointField.H"
136 #include "tmp.H"
137 #include "coordinateRotation.H"
138 #include "objectRegistry.H"
140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
142 namespace Foam
145 /*---------------------------------------------------------------------------*\
146                      Class coordinateSystem Declaration
147 \*---------------------------------------------------------------------------*/
149 class coordinateSystem
151     // Private data
153         //- Name of coordinate system
154         mutable word name_;
156         //- Optional note
157         mutable string note_;
159         //- Origin
160         mutable point origin_;
162         //- Local-to-Global transformation tensor
163         coordinateRotation R_;
165         //- Global-to-Local transformation tensor
166         tensor Rtr_;
168 protected:
170     // Protected Member Functions
172         //- Convert from local coordinate system to the global Cartesian system
173         //  with optional translation for the origin
174         virtual vector localToGlobal(const vector&, bool translate) const;
176         //- Convert from local coordinate system to the global Cartesian system
177         //  with optional translation for the origin
178         virtual tmp<vectorField> localToGlobal
179         (
180             const vectorField&,
181             bool translate
182         ) const;
184         //- Convert from global Cartesian system to the local coordinate system
185         //  with optional translation for the origin
186         virtual vector globalToLocal(const vector&, bool translate) const;
188         //- Convert from global Cartesian system to the local coordinate system
189         //  with optional translation for the origin
190         virtual tmp<vectorField> globalToLocal
191         (
192             const vectorField&,
193             bool translate
194         ) const;
196 public:
198     //- Runtime type information
199     TypeName("coordinateSystem");
202     // Constructors
204         //- Construct null. This is equivalent to an identity coordinateSystem
205         coordinateSystem();
207         //- Construct copy with a different name
208         coordinateSystem
209         (
210             const word& name,
211             const coordinateSystem&
212         );
214         //- Construct from origin and rotation
215         coordinateSystem
216         (
217             const word& name,
218             const point& origin,
219             const coordinateRotation&
220         );
222         //- Construct from origin and 2 axes
223         coordinateSystem
224         (
225             const word& name,
226             const point& origin,
227             const vector& axis,
228             const vector& dirn
229         );
231         //- Construct from dictionary with a given name
232         coordinateSystem(const word& name, const dictionary&);
234         //- Construct from dictionary with default name
235         coordinateSystem(const dictionary&);
237         //- Construct from dictionary (default name)
238         //  With the ability to reference global coordinateSystems
239         coordinateSystem(const dictionary&, const objectRegistry&);
241         //- Construct from Istream
242         //  The Istream contains a word followed by a dictionary
243         coordinateSystem(Istream&);
245         //- Return clone
246         autoPtr<coordinateSystem> clone() const
247         {
248             return autoPtr<coordinateSystem>(new coordinateSystem(*this));
249         }
251     // Declare run-time constructor selection table
253         declareRunTimeSelectionTable
254         (
255             autoPtr,
256             coordinateSystem,
257             dictionary,
258             (
259                 const word& name,
260                 const dictionary& dict
261             ),
262             (name, dict)
263         );
265         declareRunTimeSelectionTable
266         (
267             autoPtr,
268             coordinateSystem,
269             origRotation,
270             (
271                 const word& name,
272                 const point& origin,
273                 const coordinateRotation& cr
274             ),
275             (name, origin, cr)
276         );
278     // Selectors
280         //- Select constructed from dictionary
281         static autoPtr<coordinateSystem> New
282         (
283             const word& name,
284             const dictionary&
285         );
287         //- Select constructed from origin and rotation
288         static autoPtr<coordinateSystem> New
289         (
290             const word& coordType,
291             const word& name,
292             const point& origin,
293             const coordinateRotation&
294         );
296         //- Select constructed from Istream
297         static autoPtr<coordinateSystem> New(Istream& is);
299     // Destructor
301         virtual ~coordinateSystem();
304     // Member Functions
306       // Access
308         //- Return name
309         const word& name() const
310         {
311             return name_;
312         }
314         //- Return non-constant access to the optional note
315         string& note()
316         {
317             return note_;
318         }
320         //- Return the optional note
321         const string& note() const
322         {
323             return note_;
324         }
326         //- Return origin
327         const point& origin() const
328         {
329             return origin_;
330         }
332         //- Return coordinate rotation
333         const coordinateRotation& rotation() const
334         {
335             return R_;
336         }
338         //- Return local-to-global transformation tensor
339         const tensor& R() const
340         {
341             return R_;
342         }
344         //- Return local Cartesian x-axis
345         const vector e1() const
346         {
347            return Rtr_.x();
348         }
350         //- Return local Cartesian y-axis
351         const vector e2() const
352         {
353            return Rtr_.y();
354         }
356         //- Return local Cartesian z-axis
357         const vector e3() const
358         {
359            return Rtr_.z();
360         }
362         //- Return axis (e3: local Cartesian z-axis)
363         // @deprecated method e3 is preferred
364         const vector axis() const
365         {
366            return Rtr_.z();
367         }
369         //- Return direction (e1: local Cartesian x-axis)
370         // @deprecated method e1 is preferred
371         const vector direction() const
372         {
373             return Rtr_.x();
374         }
376         //- Return as dictionary of entries
377         //  @param [in] ignoreType drop type (cartesian, cylindrical, etc)
378         //  when generating the dictionary
379         virtual dictionary dict(bool ignoreType=false) const;
382       // Edit
384         //- Rename
385         virtual void rename(const word& newName)
386         {
387             name_ = newName;
388         }
390         //- Edit access to origin
391         point& origin()
392         {
393             return origin_;
394         }
396       // Write
398         //- Write
399         virtual void write(Ostream&) const;
401         //- Write dictionary
402         virtual void writeDict(Ostream&, bool subDict=true) const;
404       // Transformations
406         //- Convert from position in local coordinate system to global Cartesian position
407         point globalPosition(const point& local) const
408         {
409             return localToGlobal(local, true);
410         }
412         //- Convert from position in local coordinate system to global Cartesian position
413         tmp<pointField> globalPosition(const pointField& local) const
414         {
415             return localToGlobal(local, true);
416         }
418         //- Convert from vector components in local coordinate system to global Cartesian vector
419         vector globalVector(const vector& local) const
420         {
421             return localToGlobal(local, false);
422         }
424         //- Convert from vector components in local coordinate system to global Cartesian vector
425         tmp<vectorField> globalVector(const vectorField& local) const
426         {
427             return localToGlobal(local, false);
428         }
430         //- Convert from global Cartesian position to position in local coordinate system
431         point localPosition(const point& global) const
432         {
433             return globalToLocal(global, true);
434         }
436         //- Convert from global Cartesian position to position in local coordinate system
437         tmp<pointField> localPosition(const pointField& global) const
438         {
439             return globalToLocal(global, true);
440         }
442         //- Convert from global Cartesian vector to components in local coordinate system
443         vector localVector(const vector& global) const
444         {
445             return globalToLocal(global, false);
446         }
448         //- Convert from global Cartesian vector to components in local coordinate system
449         tmp<vectorField> localVector(const vectorField& global) const
450         {
451             return globalToLocal(global, false);
452         }
455     // Member Operators
457         //- assign from dictionary
458         void operator=(const dictionary&);
461     // friend Operators
463         friend bool operator!=
464         (
465             const coordinateSystem&,
466             const coordinateSystem&
467         );
469     // IOstream Operators
471         friend Ostream& operator<<(Ostream&, const coordinateSystem&);
475 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
477 } // End namespace Foam
479 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
481 #endif
483 // ************************************************************************* //