FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

coordinateSystem.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 Class
00025     Foam::coordinateSystem
00026 
00027 Description
00028     A cartesian coordinate system and the base class for other coordinate
00029     system specifications.
00030 
00031     All systems are defined by an origin point and a coordinateRotation.
00032     For convenience, the dictionary constructor forms allow a few shortcuts:
00033     - the default origin corresponds to <em>(0 0 0)</em>
00034     - if the @c type is not otherwise specified, a Cartesian coordinateSystem
00035       is implicit
00036 
00037     @verbatim
00038         flipped
00039         {
00040             origin  (0 0 0);
00041             coordinateRotation
00042             {
00043                 type        STARCDRotation;
00044                 rotation    (0 0 90);
00045             }
00046         }
00047     @endverbatim
00048 
00049     - if an axes specification (eg, e3/e1) is used, the coordinateRotation
00050       sub-dictionary can be dropped.
00051 
00052     @verbatim
00053         flipped     // the same, specified as axes
00054         {
00055             origin  (0 0 0);
00056             coordinateRotation
00057             {
00058                 type    axes;
00059                 e3      (1 0 0);
00060                 e1      (0 0 -1);
00061             }
00062         }
00063         flipped     // the same, using all the shortcuts
00064         {
00065             e3      (1 0 0);
00066             e1      (0 0 -1);
00067         }
00068     @endverbatim
00069 
00070     - if a sub-dictionary coordinateSystem is found within the dictionary, it
00071       will be used. This provides a convenient means of embedding
00072       coordinateSystem information in another dictionary.
00073       This is used, for example, in the porousZones:
00074 
00075     @verbatim
00076         1
00077         (
00078         cat1
00079         {
00080             coordinateSystem
00081             {
00082                 origin  (0 0 0);
00083                 coordinateRotation
00084                 {
00085                     type        STARCDRotation;
00086                     rotation    (0 0 90);
00087                 }
00088             }
00089             porosity        0.781;
00090             Darcy
00091             {
00092                 d   d [0 -2 0 0 0]  (-1000 -1000 0.50753e+08);
00093                 f   f [0 -1 0 0 0]  (-1000 -1000 12.83);
00094             }
00095         }
00096         )
00097     @endverbatim
00098 
00099     - additionally, if the coordinateSystem points to a plain entry,
00100       it can be used to reference one of the global coordinateSystems
00101 
00102     @verbatim
00103         1
00104         (
00105         cat1
00106         {
00107             coordinateSystem  system_10;
00108             porosity        0.781;
00109             Darcy
00110             {
00111                 d   d [0 -2 0 0 0]  (-1000 -1000 0.50753e+08);
00112                 f   f [0 -1 0 0 0]  (-1000 -1000 12.83);
00113             }
00114         }
00115         )
00116     @endverbatim
00117     For this to work correctly, the coordinateSystem constructor must be
00118     supplied with both a dictionary and an objectRegistry.
00119 
00120 See Also
00121     coordinateSystems and coordinateSystems::New
00122 
00123 SourceFiles
00124     coordinateSystem.C
00125     newCoordinateSystem.C
00126 
00127 \*---------------------------------------------------------------------------*/
00128 
00129 #ifndef coordinateSystem_H
00130 #define coordinateSystem_H
00131 
00132 #include <OpenFOAM/vector.H>
00133 #include <OpenFOAM/point.H>
00134 #include <OpenFOAM/tensor.H>
00135 #include <OpenFOAM/vectorField.H>
00136 #include <OpenFOAM/pointField.H>
00137 #include <OpenFOAM/tmp.H>
00138 #include <meshTools/coordinateRotation.H>
00139 #include <OpenFOAM/objectRegistry.H>
00140 
00141 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00142 
00143 namespace Foam
00144 {
00145 
00146 /*---------------------------------------------------------------------------*\
00147                      Class coordinateSystem Declaration
00148 \*---------------------------------------------------------------------------*/
00149 
00150 class coordinateSystem
00151 {
00152     // Private data
00153 
00154         //- Name of coordinate system
00155         mutable word name_;
00156 
00157         //- Optional note
00158         mutable string note_;
00159 
00160         //- Origin
00161         mutable point origin_;
00162 
00163         //- Local-to-Global transformation tensor
00164         coordinateRotation R_;
00165 
00166         //- Global-to-Local transformation tensor
00167         tensor Rtr_;
00168 
00169 protected:
00170 
00171     // Protected Member Functions
00172 
00173         //- Convert from local coordinate system to the global Cartesian system
00174         //  with optional translation for the origin
00175         virtual vector localToGlobal(const vector&, bool translate) const;
00176 
00177         //- Convert from local coordinate system to the global Cartesian system
00178         //  with optional translation for the origin
00179         virtual tmp<vectorField> localToGlobal
00180         (
00181             const vectorField&,
00182             bool translate
00183         ) const;
00184 
00185         //- Convert from global Cartesian system to the local coordinate system
00186         //  with optional translation for the origin
00187         virtual vector globalToLocal(const vector&, bool translate) const;
00188 
00189         //- Convert from global Cartesian system to the local coordinate system
00190         //  with optional translation for the origin
00191         virtual tmp<vectorField> globalToLocal
00192         (
00193             const vectorField&,
00194             bool translate
00195         ) const;
00196 
00197 public:
00198 
00199     //- Runtime type information
00200     TypeName("coordinateSystem");
00201 
00202 
00203     // Constructors
00204 
00205         //- Construct null. This is equivalent to an identity coordinateSystem
00206         coordinateSystem();
00207 
00208         //- Construct copy with a different name
00209         coordinateSystem
00210         (
00211             const word& name,
00212             const coordinateSystem&
00213         );
00214 
00215         //- Construct from origin and rotation
00216         coordinateSystem
00217         (
00218             const word& name,
00219             const point& origin,
00220             const coordinateRotation&
00221         );
00222 
00223         //- Construct from origin and 2 axes
00224         coordinateSystem
00225         (
00226             const word& name,
00227             const point& origin,
00228             const vector& axis,
00229             const vector& dirn
00230         );
00231 
00232         //- Construct from dictionary with a given name
00233         coordinateSystem(const word& name, const dictionary&);
00234 
00235         //- Construct from dictionary with default name
00236         coordinateSystem(const dictionary&);
00237 
00238         //- Construct from dictionary (default name)
00239         //  With the ability to reference global coordinateSystems
00240         coordinateSystem(const dictionary&, const objectRegistry&);
00241 
00242         //- Construct from Istream
00243         //  The Istream contains a word followed by a dictionary
00244         coordinateSystem(Istream&);
00245 
00246         //- Return clone
00247         autoPtr<coordinateSystem> clone() const
00248         {
00249             return autoPtr<coordinateSystem>(new coordinateSystem(*this));
00250         }
00251 
00252     // Declare run-time constructor selection table
00253 
00254         declareRunTimeSelectionTable
00255         (
00256             autoPtr,
00257             coordinateSystem,
00258             dictionary,
00259             (
00260                 const word& name,
00261                 const dictionary& dict
00262             ),
00263             (name, dict)
00264         );
00265 
00266         declareRunTimeSelectionTable
00267         (
00268             autoPtr,
00269             coordinateSystem,
00270             origRotation,
00271             (
00272                 const word& name,
00273                 const point& origin,
00274                 const coordinateRotation& cr
00275             ),
00276             (name, origin, cr)
00277         );
00278 
00279     // Selectors
00280 
00281         //- Select constructed from dictionary
00282         static autoPtr<coordinateSystem> New
00283         (
00284             const word& name,
00285             const dictionary&
00286         );
00287 
00288         //- Select constructed from origin and rotation
00289         static autoPtr<coordinateSystem> New
00290         (
00291             const word& coordType,
00292             const word& name,
00293             const point& origin,
00294             const coordinateRotation&
00295         );
00296 
00297         //- Select constructed from Istream
00298         static autoPtr<coordinateSystem> New(Istream& is);
00299 
00300     // Destructor
00301 
00302         virtual ~coordinateSystem();
00303 
00304 
00305     // Member Functions
00306 
00307       // Access
00308 
00309         //- Return name
00310         const word& name() const
00311         {
00312             return name_;
00313         }
00314 
00315         //- Return non-constant access to the optional note
00316         string& note()
00317         {
00318             return note_;
00319         }
00320 
00321         //- Return the optional note
00322         const string& note() const
00323         {
00324             return note_;
00325         }
00326 
00327         //- Return origin
00328         const point& origin() const
00329         {
00330             return origin_;
00331         }
00332 
00333         //- Return coordinate rotation
00334         const coordinateRotation& rotation() const
00335         {
00336             return R_;
00337         }
00338 
00339         //- Return local-to-global transformation tensor
00340         const tensor& R() const
00341         {
00342             return R_;
00343         }
00344 
00345         //- Return local Cartesian x-axis
00346         const vector e1() const
00347         {
00348            return Rtr_.x();
00349         }
00350 
00351         //- Return local Cartesian y-axis
00352         const vector e2() const
00353         {
00354            return Rtr_.y();
00355         }
00356 
00357         //- Return local Cartesian z-axis
00358         const vector e3() const
00359         {
00360            return Rtr_.z();
00361         }
00362 
00363         //- Return axis (e3: local Cartesian z-axis)
00364         // @deprecated method e3 is preferred
00365         const vector axis() const
00366         {
00367            return Rtr_.z();
00368         }
00369 
00370         //- Return direction (e1: local Cartesian x-axis)
00371         // @deprecated method e1 is preferred
00372         const vector direction() const
00373         {
00374             return Rtr_.x();
00375         }
00376 
00377         //- Return as dictionary of entries
00378         //  @param [in] ignoreType drop type (cartesian, cylindrical, etc)
00379         //  when generating the dictionary
00380         virtual dictionary dict(bool ignoreType=false) const;
00381 
00382 
00383       // Edit
00384 
00385         //- Rename
00386         virtual void rename(const word& newName)
00387         {
00388             name_ = newName;
00389         }
00390 
00391         //- Edit access to origin
00392         point& origin()
00393         {
00394             return origin_;
00395         }
00396 
00397       // Write
00398 
00399         //- Write
00400         virtual void write(Ostream&) const;
00401 
00402         //- Write dictionary
00403         virtual void writeDict(Ostream&, bool subDict=true) const;
00404 
00405       // Transformations
00406 
00407         //- Convert from position in local coordinate system to global Cartesian position
00408         point globalPosition(const point& local) const
00409         {
00410             return localToGlobal(local, true);
00411         }
00412 
00413         //- Convert from position in local coordinate system to global Cartesian position
00414         tmp<pointField> globalPosition(const pointField& local) const
00415         {
00416             return localToGlobal(local, true);
00417         }
00418 
00419         //- Convert from vector components in local coordinate system to global Cartesian vector
00420         vector globalVector(const vector& local) const
00421         {
00422             return localToGlobal(local, false);
00423         }
00424 
00425         //- Convert from vector components in local coordinate system to global Cartesian vector
00426         tmp<vectorField> globalVector(const vectorField& local) const
00427         {
00428             return localToGlobal(local, false);
00429         }
00430 
00431         //- Convert from global Cartesian position to position in local coordinate system
00432         point localPosition(const point& global) const
00433         {
00434             return globalToLocal(global, true);
00435         }
00436 
00437         //- Convert from global Cartesian position to position in local coordinate system
00438         tmp<pointField> localPosition(const pointField& global) const
00439         {
00440             return globalToLocal(global, true);
00441         }
00442 
00443         //- Convert from global Cartesian vector to components in local coordinate system
00444         vector localVector(const vector& global) const
00445         {
00446             return globalToLocal(global, false);
00447         }
00448 
00449         //- Convert from global Cartesian vector to components in local coordinate system
00450         tmp<vectorField> localVector(const vectorField& global) const
00451         {
00452             return globalToLocal(global, false);
00453         }
00454 
00455 
00456     // Member Operators
00457 
00458         //- assign from dictionary
00459         void operator=(const dictionary&);
00460 
00461 
00462     // friend Operators
00463 
00464         friend bool operator!=
00465         (
00466             const coordinateSystem&,
00467             const coordinateSystem&
00468         );
00469 
00470     // IOstream Operators
00471 
00472         friend Ostream& operator<<(Ostream&, const coordinateSystem&);
00473 };
00474 
00475 
00476 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00477 
00478 } // End namespace Foam
00479 
00480 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00481 
00482 #endif
00483 
00484 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines