OpenFOAM logo
The Open Source CFD Toolbox
  Programmer’s C++ Doxygen OpenCFD Solutions Contact OpenFOAM

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-2007 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     coordinateSystem
00027 
00028 Description
00029     Base class for coordinate systems.
00030     All systems are defined by an origin and a coordinate rotation.
00031 
00032 SourceFiles
00033     coordinateSystem.C
00034 
00035 \*---------------------------------------------------------------------------*/
00036 
00037 #ifndef coordinateSystem_H
00038 #define coordinateSystem_H
00039 
00040 #include "vector.H"
00041 #include "point.H"
00042 #include "tensor.H"
00043 #include "vectorField.H"
00044 #include "pointField.H"
00045 #include "tmp.H"
00046 #include "coordinateRotation.H"
00047 #include "objectRegistry.H"
00048 
00049 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00050 
00051 namespace Foam
00052 {
00053 
00054 /*---------------------------------------------------------------------------*\
00055                      Class coordinateSystem Declaration
00056 \*---------------------------------------------------------------------------*/
00057 
00058 class coordinateSystem
00059 {
00060     // Private data
00061 
00062         //- Name of coordinate system
00063         mutable word name_;
00064 
00065         //- Origin
00066         mutable point origin_;
00067 
00068         //- Local-to-Global transformation tensor
00069         coordinateRotation R_;
00070 
00071         //- Global-to-Local transformation tensor
00072         tensor Rtr_;
00073 
00074 protected:
00075 
00076     // Protected Member Functions
00077 
00078         //- Convert from local coordinate system to the global Cartesian system
00079         //  with optional translation for the origin
00080         virtual vector localToGlobal(const vector&, bool translate) const;
00081 
00082         //- Convert from local coordinate system to the global Cartesian system
00083         //  with optional translation for the origin
00084         virtual tmp<vectorField> localToGlobal
00085         (
00086             const vectorField&,
00087             bool translate
00088         ) const;
00089 
00090         //- Convert from global Cartesian system to the local coordinate system
00091         //  with optional translation for the origin
00092         virtual vector globalToLocal(const vector&, bool translate) const;
00093 
00094         //- Convert from global Cartesian system to the local coordinate system
00095         //  with optional translation for the origin
00096         virtual tmp<vectorField> globalToLocal
00097         (
00098             const vectorField&,
00099             bool translate
00100         ) const;
00101 
00102 public:
00103 
00104     //- Runtime type information
00105     TypeName("coordinateSystem");
00106 
00107 
00108     // Constructors
00109 
00110         //- Construct null
00111         coordinateSystem();
00112 
00113         //- Construct from origin and 2 axes
00114         coordinateSystem
00115         (
00116             const word& name,
00117             const point& origin,
00118             const vector& axis,
00119             const vector& dir
00120         );
00121 
00122         //- Construct from origin and rotation angles
00123         coordinateSystem
00124         (
00125             const word& name,
00126             const point& origin,
00127             const coordinateRotation&
00128         );
00129 
00130         //- Construct from dictionary with default name
00131         coordinateSystem(const dictionary&);
00132 
00133         //- Construct from dictionary
00134         coordinateSystem(const word& name, const dictionary&);
00135 
00136         //- Construct from Istream
00137         coordinateSystem(Istream&);
00138 
00139         //- Return clone
00140         autoPtr<coordinateSystem> clone() const
00141         {
00142             return autoPtr<coordinateSystem>
00143             (
00144                 new coordinateSystem
00145                 (
00146                     name(),
00147                     origin(),
00148                     rotation()
00149                 )
00150             );
00151         }
00152 
00153     // Declare run-time constructor selection table
00154 
00155         declareRunTimeSelectionTable
00156         (
00157             autoPtr,
00158             coordinateSystem,
00159             origAxisDir,
00160             (
00161                 const word& name,
00162                 const point& origin,
00163                 const vector& axis,
00164                 const vector& dir
00165             ),
00166             (name, origin, axis, dir)
00167         );
00168 
00169         declareRunTimeSelectionTable
00170         (
00171             autoPtr,
00172             coordinateSystem,
00173             origRotation,
00174             (
00175                 const word& name,
00176                 const point& origin,
00177                 const coordinateRotation& cr
00178             ),
00179             (name, origin, cr)
00180         );
00181 
00182         declareRunTimeSelectionTable
00183         (
00184             autoPtr,
00185             coordinateSystem,
00186             dictionary,
00187             (
00188                 const word& name,
00189                 const dictionary& dict
00190             ),
00191             (name, dict)
00192         );
00193 
00194 
00195     // Selectors
00196 
00197         //- Select constructed from origin and 2 axes
00198         static autoPtr<coordinateSystem> New
00199         (
00200             const word& coordType,
00201             const word& name,
00202             const point& origin,
00203             const vector& axis,
00204             const vector& dir
00205         );
00206 
00207         //- Select constructed from origin and rotation
00208         static autoPtr<coordinateSystem> New
00209         (
00210             const word& coordType,
00211             const word& name,
00212             const point& origin,
00213             const coordinateRotation& cr
00214         );
00215 
00216         //- Select constructed from dictionary
00217         static autoPtr<coordinateSystem> New
00218         (
00219             const word& name,
00220             const dictionary& dict
00221         );
00222 
00223         //- Select constructed from Istream
00224         static autoPtr<coordinateSystem> New(Istream& is);
00225 
00226     // Destructor
00227 
00228         virtual ~coordinateSystem();
00229 
00230 
00231     // Member Functions
00232 
00233       // Access
00234 
00235         //- Return name
00236         const word& name() const
00237         {
00238             return name_;
00239         }
00240 
00241         //- Return origin
00242         const point& origin() const
00243         {
00244             return origin_;
00245         }
00246 
00247         //- Return coordinate rotation
00248         const coordinateRotation& rotation() const
00249         {
00250             return R_;
00251         }
00252 
00253         //- Return local-to-global transformation tensor
00254         const tensor& R() const
00255         {
00256             return R_;
00257         }
00258 
00259         //- Return local Cartesian x-axis
00260         const vector& e1() const
00261         {
00262            return Rtr_.x();
00263         }
00264 
00265         //- Return local Cartesian y-axis
00266         const vector& e2() const
00267         {
00268            return Rtr_.y();
00269         }
00270 
00271         //- Return local Cartesian z-axis
00272         const vector& e3() const
00273         {
00274            return Rtr_.z();
00275         }
00276    
00277         //- Return axis (e3: local Cartesian z-axis)
00278         const vector& axis() const
00279         {
00280            return Rtr_.z();
00281         }
00282 
00283         //- Return direction (e1: local Cartesian x-axis)
00284         const vector& direction() const
00285         {
00286             return Rtr_.x();
00287         }
00288 
00289         //- Return as dictionary of entries
00290         virtual dictionary dict(bool ignoreType = false) const;
00291 
00292 
00293       // Edit
00294 
00295         //- Rename
00296         virtual void rename(const word& newName)
00297         {
00298             name_ = newName;
00299         }
00300 
00301         //- Edit access to origin
00302         point& origin()
00303         {
00304             return origin_;
00305         }
00306 
00307       // Write
00308 
00309         //- Write
00310         virtual void write(Ostream&) const;
00311 
00312         //- Write dictionary
00313         virtual void writeDict(Ostream&, bool subDict = true) const;
00314 
00315       // Transformations
00316 
00317         //- Convert from position in local coordinate system to global Cartesian position
00318         point globalPosition(const point& local) const
00319         {
00320             return localToGlobal(local, true);
00321         }
00322 
00323         //- Convert from position in local coordinate system to global Cartesian position
00324         tmp<pointField> globalPosition(const pointField& local) const
00325         {
00326             return localToGlobal(local, true);
00327         }
00328 
00329         //- Convert from vector components in local coordinate system to global Cartesian vector
00330         vector globalVector(const vector& local) const
00331         {
00332             return localToGlobal(local, false);
00333         }
00334 
00335         //- Convert from vector components in local coordinate system to global Cartesian vector
00336         tmp<vectorField> globalVector(const vectorField& local) const
00337         {
00338             return localToGlobal(local, false);
00339         }
00340 
00341         //- Convert from global Cartesian position to position in local coordinate system
00342         point localPosition(const point& global) const
00343         {
00344             return globalToLocal(global, true);
00345         }
00346 
00347         //- Convert from global Cartesian position to position in local coordinate system
00348         tmp<pointField> localPosition(const pointField& global) const
00349         {
00350             return globalToLocal(global, true);
00351         }
00352 
00353         //- Convert from global Cartesian vector to components in local coordinate system
00354         vector localVector(const vector& global) const
00355         {
00356             return globalToLocal(global, false);
00357         }
00358 
00359         //- Convert from global Cartesian vector to components in local coordinate system
00360         tmp<vectorField> localVector(const vectorField& global) const
00361         {
00362             return globalToLocal(global, false);
00363         }
00364 
00365 
00366     // Member Operators
00367 
00368         //- assign from dictionary
00369         void operator=(const dictionary&);
00370 
00371 
00372     // friend Operators
00373 
00374         friend bool operator!=(const coordinateSystem&, const coordinateSystem&);
00375 
00376     // IOstream Operators
00377 
00378         friend Ostream& operator<<(Ostream&, const coordinateSystem&);
00379 };
00380 
00381 
00382 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00383 
00384 } // End namespace Foam
00385 
00386 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00387 
00388 #endif
00389 
00390 // ************************************************************************* //
Copyright © 2000-2007 OpenCFD Ltd