OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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