VectorSpace.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 Class
25  Foam::VectorSpace
26 
27 Description
28  Templated vector space.
29 
30  Template arguments are the Form the vector space will be used to create,
31  the type of the elements and the number of elements.
32 
33 SourceFiles
34  VectorSpaceI.H
35  VectorSpace.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef VectorSpace_H
40 #define VectorSpace_H
41 
42 #include "direction.H"
43 #include "scalar.H"
44 #include "word.H"
45 #include "zero.H"
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 // Forward declaration of friend functions and operators
53 
54 template<class Form, class Cmpt, direction Ncmpts> class VectorSpace;
55 
56 template<class Form, class Cmpt, direction Ncmpts>
57 Istream& operator>>
58 (
59  Istream&,
61 );
62 
63 template<class Form, class Cmpt, direction Ncmpts>
64 Ostream& operator<<
65 (
66  Ostream&,
68 );
69 
70 
71 /*---------------------------------------------------------------------------*\
72  Class VectorSpace Declaration
73 \*---------------------------------------------------------------------------*/
74 
75 template<class Form, class Cmpt, direction Ncmpts>
76 class VectorSpace
77 {
78 
79 public:
80 
81  //- The components of this vector space
82  Cmpt v_[Ncmpts];
83 
84  //- VectorSpace type
86 
87  //- Component type
88  typedef Cmpt cmptType;
89 
90 
91  // Static constants
92 
93  //- Dimensionality of space
94  static const direction dim = 3;
95 
96  //- Number of components in this vector space
97  static const direction nComponents = Ncmpts;
98 
99 
100  // VectorSpace currently defaults to a column-vector
101  // This will be removed when column-vector is introduced
102  // as a specialization
103  static const direction mRows = Ncmpts;
104  static const direction nCols = 1;
105 
106 
107  // Static data members
109  static const char* const typeName;
110  static const char* const componentNames[];
111  static const Form zero;
112  static const Form one;
113  static const Form max;
114  static const Form min;
115  static const Form rootMax;
116  static const Form rootMin;
117 
118 
119  // Sub-Block Classes
120 
121  //- Const sub-block type
122  template
123  <
124  class SubVector,
125  direction BStart
126  >
127  class ConstBlock
128  {
129  const vsType& vs_;
130 
131  public:
132 
133  //- Number of components in this vector space
134  static const direction nComponents = SubVector::nComponents;
135 
136  //- Construct for a given vector
137  inline ConstBlock(const vsType& vs);
138 
139  //- [i] const element access operator
140  inline const Cmpt& operator[](const direction i) const;
141 
142  //- (i, 0) const element access operator
143  inline const Cmpt& operator()
144  (
145  const direction i,
146  const direction
147  ) const;
148  };
149 
150 
151  // Constructors
152 
153  //- Construct null
154  inline VectorSpace();
155 
156  //- Construct initialized to zero
157  inline VectorSpace(const Foam::zero);
158 
159  //- Construct from Istream
160  VectorSpace(Istream&);
161 
162  //- Construct as copy
164 
165  //- Construct as copy of a VectorSpace with the same size
166  template<class Form2, class Cmpt2>
167  inline explicit VectorSpace(const VectorSpace<Form2, Cmpt2, Ncmpts>&);
168 
169 
170  // Member Functions
171 
172  //- Return the number of elements in the VectorSpace = Ncmpts.
173  inline static direction size();
174 
175  inline const Cmpt& component(const direction) const;
176  inline Cmpt& component(const direction);
177 
178  inline void component(Cmpt&, const direction) const;
179  inline void replace(const direction, const Cmpt&);
180 
181  //- Return a VectorSpace with all elements = s
182  inline static Form uniform(const Cmpt& s);
183 
184  template<class SubVector, direction BStart>
185  inline const ConstBlock<SubVector, BStart> block() const;
186 
187 
188  // Member Operators
189 
190  inline const Cmpt& operator[](const direction) const;
191  inline Cmpt& operator[](const direction);
192 
193  inline void operator=(const VectorSpace<Form, Cmpt, Ncmpts>&);
194  inline void operator+=(const VectorSpace<Form, Cmpt, Ncmpts>&);
195  inline void operator-=(const VectorSpace<Form, Cmpt, Ncmpts>&);
196 
197  inline void operator=(const Foam::zero);
198  inline void operator*=(const scalar);
199  inline void operator/=(const scalar);
200 
201 
202  // IOstream Operators
203 
204  friend Istream& operator>> <Form, Cmpt, Ncmpts>
205  (
206  Istream&,
208  );
209 
210  friend Ostream& operator<< <Form, Cmpt, Ncmpts>
211  (
212  Ostream&,
214  );
215 };
216 
217 
218 // * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * * //
219 
220 //- Return a string representation of a VectorSpace
221 template<class Form, class Cmpt, direction Ncmpts>
223 
224 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
225 
226 } // End namespace Foam
227 
228 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
229 
230 #include "VectorSpaceI.H"
231 
232 #ifdef NoRepository
233  #include "VectorSpace.C"
234 #endif
235 
236 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
237 
238 #endif
239 
240 // ************************************************************************* //
static const direction nCols
Definition: VectorSpace.H:103
static const char *const typeName
Definition: VectorSpace.H:108
Const sub-block type.
Definition: VectorSpace.H:126
static const Form max
Definition: VectorSpace.H:112
static const direction mRows
Definition: VectorSpace.H:102
void operator=(const VectorSpace< Form, Cmpt, Ncmpts > &)
Definition: VectorSpaceI.H:290
uint8_t direction
Definition: direction.H:45
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
VectorSpace()
Construct null.
Definition: VectorSpaceI.H:40
static const char *const componentNames[]
Definition: VectorSpace.H:109
static const Form rootMin
Definition: VectorSpace.H:115
Templated vector space.
Definition: VectorSpace.H:53
ConstBlock(const vsType &vs)
Construct for a given vector.
Definition: VectorSpaceI.H:76
void replace(const direction, const Cmpt &)
Definition: VectorSpaceI.H:159
static const Form min
Definition: VectorSpace.H:113
void operator-=(const VectorSpace< Form, Cmpt, Ncmpts > &)
Definition: VectorSpaceI.H:310
static const direction nComponents
Number of components in this vector space.
Definition: VectorSpace.H:96
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
A class for handling words, derived from string.
Definition: word.H:59
void operator+=(const VectorSpace< Form, Cmpt, Ncmpts > &)
Definition: VectorSpaceI.H:300
const ConstBlock< SubVector, BStart > block() const
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
static direction size()
Return the number of elements in the VectorSpace = Ncmpts.
Definition: VectorSpaceI.H:93
friend Ostream & operator(Ostream &, const VectorSpace< Form, Cmpt, Ncmpts > &)
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
static const Form rootMax
Definition: VectorSpace.H:114
Direction is an 8-bit unsigned integer type used to represent the Cartesian directions etc...
Cmpt cmptType
Component type.
Definition: VectorSpace.H:87
void operator*=(const scalar)
Definition: VectorSpaceI.H:327
const Cmpt & component(const direction) const
Definition: VectorSpaceI.H:101
static const Form one
Definition: VectorSpace.H:111
VectorSpace< Form, Cmpt, Ncmpts > vsType
VectorSpace type.
Definition: VectorSpace.H:84
static Form uniform(const Cmpt &s)
Return a VectorSpace with all elements = s.
Definition: VectorSpaceI.H:178
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:49
void operator/=(const scalar)
Definition: VectorSpaceI.H:337
static const direction dim
Dimensionality of space.
Definition: VectorSpace.H:93
static const Form zero
Definition: VectorSpace.H:110
Cmpt v_[Ncmpts]
The components of this vector space.
Definition: VectorSpace.H:81
Namespace for OpenFOAM.
const Cmpt & operator[](const direction i) const
[i] const element access operator
Definition: VectorSpaceI.H:241