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-2021 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 void writeEntry(Ostream& os, const VectorSpace<Form, Cmpt, Ncmpts>& value);
58 
59 template<class Form, class Cmpt, direction Ncmpts>
60 Istream& operator>>
61 (
62  Istream&,
64 );
65 
66 template<class Form, class Cmpt, direction Ncmpts>
67 Ostream& operator<<
68 (
69  Ostream&,
71 );
72 
73 
74 /*---------------------------------------------------------------------------*\
75  Class VectorSpace Declaration
76 \*---------------------------------------------------------------------------*/
77 
78 template<class Form, class Cmpt, direction Ncmpts>
79 class VectorSpace
80 {
81 
82 public:
83 
84  //- The components of this vector space
85  Cmpt v_[Ncmpts];
86 
87  //- VectorSpace type
89 
90  //- Component type
91  typedef Cmpt cmptType;
92 
93 
94  // Static constants
95 
96  //- Dimensionality of space
97  static const direction dim = 3;
98 
99  //- Number of components in this vector space
100  static const direction nComponents = Ncmpts;
101 
102 
103  // VectorSpace currently defaults to a column-vector
104  // This will be removed when column-vector is introduced
105  // as a specialisation
106  static const direction mRows = Ncmpts;
107  static const direction nCols = 1;
108 
109 
110  // Static Data Members
112  static const char* const typeName;
113  static const char* const componentNames[];
114  static const Form zero;
115  static const Form one;
116  static const Form max;
117  static const Form min;
118  static const Form rootMax;
119  static const Form rootMin;
120 
121 
122  // Sub-Block Classes
123 
124  //- Const sub-block type
125  template
126  <
127  class SubVector,
128  direction BStart
129  >
130  class ConstBlock
131  {
132  const vsType& vs_;
133 
134  public:
135 
136  //- Number of components in this vector space
137  static const direction nComponents = SubVector::nComponents;
138 
139  //- Construct for a given vector
140  inline ConstBlock(const vsType& vs);
141 
142  //- [i] const element access operator
143  inline const Cmpt& operator[](const direction i) const;
144 
145  //- (i, 0) const element access operator
146  inline const Cmpt& operator()
147  (
148  const direction i,
149  const direction
150  ) const;
151  };
152 
153 
154  // Constructors
155 
156  //- Construct null
157  inline VectorSpace();
158 
159  //- Construct initialised to zero
160  inline VectorSpace(const Foam::zero);
161 
162  //- Construct from Istream
163  VectorSpace(Istream&);
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 
196  inline void operator=(const Foam::zero);
197  inline void operator*=(const scalar);
198  inline void operator/=(const scalar);
199 
200 
201  // IOstream Operators
202 
203  friend Istream& operator>> <Form, Cmpt, Ncmpts>
204  (
205  Istream&,
207  );
208 
209  friend Ostream& operator<< <Form, Cmpt, Ncmpts>
210  (
211  Ostream&,
213  );
214 };
215 
216 
217 // * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * * //
218 
219 //- Return a string representation of a VectorSpace
220 template<class Form, class Cmpt, direction Ncmpts>
222 
223 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
224 
225 } // End namespace Foam
226 
227 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
228 
229 #include "VectorSpaceI.H"
230 
231 #ifdef NoRepository
232  #include "VectorSpace.C"
233 #endif
234 
235 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
236 
237 #endif
238 
239 // ************************************************************************* //
static const direction nCols
Definition: VectorSpace.H:106
static const char *const typeName
Definition: VectorSpace.H:111
Const sub-block type.
Definition: VectorSpace.H:129
static const Form max
Definition: VectorSpace.H:115
static const direction mRows
Definition: VectorSpace.H:105
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:112
static const Form rootMin
Definition: VectorSpace.H:118
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:116
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:99
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:54
static direction size()
Return the number of elements in the VectorSpace = Ncmpts.
Definition: VectorSpaceI.H:83
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
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:117
Direction is an 8-bit unsigned integer type used to represent the Cartesian directions etc...
Cmpt cmptType
Component type.
Definition: VectorSpace.H:90
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:114
VectorSpace< Form, Cmpt, Ncmpts > vsType
VectorSpace type.
Definition: VectorSpace.H:87
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:96
static const Form zero
Definition: VectorSpace.H:113
Cmpt v_[Ncmpts]
The components of this vector space.
Definition: VectorSpace.H:84
Namespace for OpenFOAM.
const Cmpt & operator[](const direction i) const
[i] const element access operator
Definition: VectorSpaceI.H:231