OpenFOAM logo
Open Source CFD Toolkit

VectorSpace.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-2005 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     VectorSpace
00027 
00028 Description
00029     Templated vector space.
00030     Template arguments are the Form the vector space will be used to create,
00031     the type of the elements and the number of elements.
00032 
00033 SourceFiles
00034     VectorSpaceI.H
00035     VectorSpace.C
00036 
00037 \*---------------------------------------------------------------------------*/
00038 
00039 #ifndef VectorSpace_H
00040 #define VectorSpace_H
00041 
00042 #include "direction.H"
00043 #include "scalar.H"
00044 #include "word.H"
00045 
00046 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00047 
00048 namespace Foam
00049 {
00050 
00051 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
00052 
00053 template<class Form, class Cmpt, int nCmpt> class VectorSpace;
00054 
00055 template<class Form, class Cmpt, int nCmpt>
00056 Istream& operator>>
00057 (
00058     Istream&,
00059     VectorSpace<Form, Cmpt, nCmpt>&
00060 );
00061 
00062 template<class Form, class Cmpt, int nCmpt>
00063 Ostream& operator<<
00064 (
00065     Ostream&,
00066     const VectorSpace<Form, Cmpt, nCmpt>&
00067 );
00068 
00069 
00070 /*---------------------------------------------------------------------------*\
00071                            Class VectorSpace Declaration
00072 \*---------------------------------------------------------------------------*/
00073 
00074 template<class Form, class Cmpt, int nCmpt>
00075 class VectorSpace
00076 {
00077 
00078 public:
00079 
00080     //- Component type
00081     typedef Cmpt cmptType;
00082 
00083 
00084     // Member constants
00085 
00086         enum
00087         {
00088             dim = 3,            // Dimensionality of space
00089             nComponents = nCmpt // Number of components in this vector space
00090         };
00091 
00092 
00093     // Static data members
00094 
00095         //- The components of this vector space
00096         Cmpt v_[nCmpt];
00097 
00098 
00099     // Constructors
00100 
00101         //- Construct null
00102         inline VectorSpace();
00103 
00104         //- Construct from Istream
00105         VectorSpace(Istream&);
00106 
00107         //- Construct as copy
00108         inline VectorSpace(const VectorSpace<Form, Cmpt, nCmpt>&);
00109 
00110 
00111     // Member Functions
00112 
00113         inline const Cmpt& component(const direction) const;
00114         inline Cmpt& component(const direction);
00115 
00116         inline void component(Cmpt&, const direction) const;
00117         inline void replace(const direction, const Cmpt&);
00118 
00119 
00120     // Member Operators
00121 
00122         inline const Cmpt& operator[](const direction) const;
00123         inline Cmpt& operator[](const direction);
00124 
00125         inline void operator=(const VectorSpace<Form, Cmpt, nCmpt>&);
00126         inline void operator+=(const VectorSpace<Form, Cmpt, nCmpt>&);
00127         inline void operator-=(const VectorSpace<Form, Cmpt, nCmpt>&);
00128 
00129         inline void operator*=(const scalar);
00130         inline void operator/=(const scalar);
00131 
00132 
00133     // IOstream Operators
00134 
00135         friend Istream& operator>> <Form, Cmpt, nCmpt>
00136         (
00137             Istream&,
00138             VectorSpace<Form, Cmpt, nCmpt>&
00139         );
00140 
00141         friend Ostream& operator<< <Form, Cmpt, nCmpt>
00142         (
00143             Ostream&,
00144             const VectorSpace<Form, Cmpt, nCmpt>&
00145         );
00146 };
00147 
00148 
00149 // * * * * * * * * * * * * * * Global functions  * * * * * * * * * * * * * * //
00150 
00151 //- Return a string representation of a VectorSpace
00152 template<class Form, class Cmpt, int nCmpt>
00153 word name(const VectorSpace<Form, Cmpt, nCmpt>&);
00154 
00155 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00156 
00157 } // End namespace Foam
00158 
00159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00160 
00161 #include "VectorSpaceI.H"
00162 
00163 #ifdef NoRepository
00164 #   include "VectorSpace.C"
00165 #endif
00166 
00167 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00168 
00169 #endif
00170 
00171 // ************************************************************************* //
For further information go to www.openfoam.org