VectorSpace.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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 of a VectorSpace with the same size
163  template<class Form2, class Cmpt2>
164  inline explicit VectorSpace(const VectorSpace<Form2, Cmpt2, Ncmpts>&);
165 
166 
167  // Member Functions
168 
169  //- Return the number of elements in the VectorSpace = Ncmpts.
170  inline static direction size();
171 
172  inline const Cmpt& component(const direction) const;
173  inline Cmpt& component(const direction);
174 
175  inline void component(Cmpt&, const direction) const;
176  inline void replace(const direction, const Cmpt&);
177 
178  //- Return a VectorSpace with all elements = s
179  inline static Form uniform(const Cmpt& s);
180 
181  template<class SubVector, direction BStart>
182  inline const ConstBlock<SubVector, BStart> block() const;
183 
184 
185  // Member Operators
186 
187  inline const Cmpt& operator[](const direction) const;
188  inline Cmpt& operator[](const direction);
189 
190  inline void operator+=(const VectorSpace<Form, Cmpt, Ncmpts>&);
191  inline void operator-=(const VectorSpace<Form, Cmpt, Ncmpts>&);
192 
193  inline void operator=(const Foam::zero);
194  inline void operator*=(const scalar);
195  inline void operator/=(const scalar);
196 
197 
198  // IOstream Operators
199 
200  friend Istream& operator>> <Form, Cmpt, Ncmpts>
201  (
202  Istream&,
204  );
205 
206  friend Ostream& operator<< <Form, Cmpt, Ncmpts>
207  (
208  Ostream&,
210  );
211 };
212 
213 
214 // * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * * //
215 
216 //- Return a string representation of a VectorSpace
217 template<class Form, class Cmpt, direction Ncmpts>
219 
220 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
221 
222 } // End namespace Foam
223 
224 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
225 
226 #include "VectorSpaceI.H"
227 
228 #ifdef NoRepository
229  #include "VectorSpace.C"
230 #endif
231 
232 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
233 
234 #endif
235 
236 // ************************************************************************* //
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
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:66
void replace(const direction, const Cmpt &)
Definition: VectorSpaceI.H:149
static const Form min
Definition: VectorSpace.H:113
void operator-=(const VectorSpace< Form, Cmpt, Ncmpts > &)
Definition: VectorSpaceI.H:290
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:280
void operator=(const Foam::zero)
Definition: VectorSpaceI.H:299
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:83
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:307
const Cmpt & component(const direction) const
Definition: VectorSpaceI.H:91
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:168
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:317
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:231