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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::VectorSpace
29 
30 Description
31  Templated vector space.
32 
33  Template arguments are the Form the vector space will be used to create,
34  the type of the elements and the number of elements.
35 
36 SourceFiles
37  VectorSpaceI.H
38  VectorSpace.C
39 
40 \*---------------------------------------------------------------------------*/
41 
42 #ifndef VectorSpace_H
43 #define VectorSpace_H
44 
45 #include "direction.H"
46 #include "scalar.H"
47 #include "word.H"
48 #include "zero.H"
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace Foam
53 {
54 
55 // Forward declarations
56 
57 template<class Form, class Cmpt, direction Ncmpts> class VectorSpace;
58 
59 template<class Form, class Cmpt, direction Ncmpts>
60 Istream& operator>>
61 (
62  Istream& is,
64 );
65 
66 template<class Form, class Cmpt, direction Ncmpts>
67 Ostream& operator<<
68 (
69  Ostream& os,
71 );
72 
73 
74 /*---------------------------------------------------------------------------*\
75  Class VectorSpace Declaration
76 \*---------------------------------------------------------------------------*/
77 
78 template<class Form, class Cmpt, direction Ncmpts>
79 class VectorSpace
80 {
81 public:
82 
83  //- The components of this vector space
84  Cmpt v_[Ncmpts];
85 
86  //- VectorSpace type
88 
89  //- Component type
90  typedef Cmpt cmptType;
91 
92  //- Magnitude type
93  typedef Cmpt magType;
94 
95 
96  // Static Constants
97 
98  //- Dimensionality of space
99  static constexpr direction dim = 3;
100 
101  //- Number of components in this vector space
102  static constexpr direction nComponents = Ncmpts;
103 
104 
105  // VectorSpace currently defaults to a column-vector
106  // This will be removed when column-vector is introduced
107  // as a specialization
108  static constexpr direction mRows = Ncmpts;
109  static constexpr direction nCols = 1;
110 
111 
112  // Static Data Members
113 
114  static const char* const typeName;
115  static const char* const componentNames[];
116  static const Form zero;
117  static const Form one;
118  static const Form max;
119  static const Form min;
120  static const Form rootMax;
121  static const Form rootMin;
122 
123 
124  // Sub-Block Classes
125 
126  //- Const sub-block type
127  template<class SubVector, direction BStart>
128  class ConstBlock
129  {
130  const vsType& vs_;
131 
132  public:
133 
134  //- Number of components in this vector space
135  static const direction nComponents = SubVector::nComponents;
136 
137  //- Construct for a given vector
138  inline ConstBlock(const vsType& vs);
139 
140  //- [i] const element access operator
141  inline const Cmpt& operator[](const direction i) const;
142 
143  //- (i, 0) const element access operator
144  inline const Cmpt& operator()
145  (
146  const direction i,
147  const direction
148  ) const;
149  };
150 
151 
152  // Constructors
153 
154  //- Construct null
155  inline VectorSpace();
156 
157  //- Construct initialized to zero
158  inline VectorSpace(const Foam::zero);
159 
160  //- Construct from Istream
161  VectorSpace(Istream& is);
162 
163  //- Copy construct
165 
166  //- Copy construct of a VectorSpace with the same size
167  template<class Form2, class Cmpt2>
168  inline explicit VectorSpace(const VectorSpace<Form2, Cmpt2, Ncmpts>&);
169 
170 
171  // Member Functions
172 
173  //- Return the number of elements in the VectorSpace = Ncmpts.
174  inline static constexpr direction size();
175 
176  inline const Cmpt& component(const direction) const;
177  inline Cmpt& component(const direction);
178 
179  inline void component(Cmpt&, const direction) const;
180  inline void replace(const direction, const Cmpt&);
181 
182  //- Return const pointer to the first data element
183  inline const Cmpt* cdata() const noexcept;
184 
185  //- Return pointer to the first data element
186  inline Cmpt* data() noexcept;
187 
188  //- Return a VectorSpace with all elements = s
189  inline static Form uniform(const Cmpt& s);
190 
191  template<class SubVector, direction BStart>
192  inline const ConstBlock<SubVector, BStart> block() const;
193 
194 
195  // Member Operators
196 
197  inline const Cmpt& operator[](const direction) const;
198  inline Cmpt& operator[](const direction);
199 
200  inline void operator=(const VectorSpace<Form, Cmpt, Ncmpts>&);
201  inline void operator+=(const VectorSpace<Form, Cmpt, Ncmpts>&);
202  inline void operator-=(const VectorSpace<Form, Cmpt, Ncmpts>&);
203 
204  inline void operator=(const Foam::zero);
205  inline void operator*=(const scalar);
206  inline void operator/=(const scalar);
207 
208 
209  // Iterators
210 
211  //- Random access iterator for traversing VectorSpace
212  typedef Cmpt* iterator;
213 
214  //- Random access iterator for traversing VectorSpace
215  typedef const Cmpt* const_iterator;
216 
217 
218  // Random access iterator (non-const)
219 
220  //- Return an iterator to begin of VectorSpace
221  inline iterator begin();
222 
223  //- Return an iterator to end of VectorSpace
224  inline iterator end();
225 
226 
227  // Random access iterator (const)
228 
229  //- Return const_iterator to begin of VectorSpace
230  inline const_iterator cbegin() const;
231 
232  //- Return const_iterator to end of VectorSpace
233  inline const_iterator cend() const;
234 
235  //- Return const_iterator to begin of VectorSpace
236  inline const_iterator begin() const;
237 
238  //- Return const_iterator to end of VectorSpace
239  inline const_iterator end() const;
240 
241 
242  // IOstream Operators
243 
244  friend Istream& operator>> <Form, Cmpt, Ncmpts>
245  (
246  Istream&,
247  VectorSpace<Form, Cmpt, Ncmpts>&
248  );
249 
250  friend Ostream& operator<< <Form, Cmpt, Ncmpts>
251  (
252  Ostream&,
253  const VectorSpace<Form, Cmpt, Ncmpts>&
254  );
255 };
256 
257 
258 // * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * * //
259 
260 //- A word representation of a VectorSpace
261 template<class Form, class Cmpt, direction Ncmpts>
262 word name(const VectorSpace<Form, Cmpt, Ncmpts>& vs);
263 
264 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
265 
266 } // End namespace Foam
267 
268 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
269 
270 #include "VectorSpaceI.H"
271 
272 #ifdef NoRepository
273  #include "VectorSpace.C"
274 #endif
275 
276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
277 
278 #endif
279 
280 // ************************************************************************* //
Foam::VectorSpace::rootMax
static const Form rootMax
Definition: VectorSpace.H:119
Foam::block
Creates a single block of cells from point coordinates, numbers of cells in each direction and an exp...
Definition: block.H:58
Foam::VectorSpace::one
static const Form one
Definition: VectorSpace.H:116
Foam::VectorSpace::magType
Cmpt magType
Magnitude type.
Definition: VectorSpace.H:92
Foam::VectorSpace::component
const Cmpt & component(const direction) const
Definition: VectorSpaceI.H:100
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::VectorSpace::componentNames
static const char *const componentNames[]
Definition: VectorSpace.H:114
s
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.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))
Definition: gmvOutputSpray.H:25
Foam::VectorSpace::cend
const_iterator cend() const
Return const_iterator to end of VectorSpace.
Definition: VectorSpaceI.H:233
Foam::VectorSpace::size
static constexpr direction size()
Return the number of elements in the VectorSpace = Ncmpts.
Definition: VectorSpaceI.H:92
Foam::VectorSpace< DiagTensor< Cmpt >, Cmpt, 3 >::iterator
Cmpt * iterator
Random access iterator for traversing VectorSpace.
Definition: VectorSpace.H:211
Foam::VectorSpace::ConstBlock
Const sub-block type.
Definition: VectorSpace.H:127
Foam::VectorSpace::cmptType
Cmpt cmptType
Component type.
Definition: VectorSpace.H:89
Foam::VectorSpace::v_
Cmpt v_[Ncmpts]
The components of this vector space.
Definition: VectorSpace.H:83
Foam::VectorSpace::cbegin
const_iterator cbegin() const
Return const_iterator to begin of VectorSpace.
Definition: VectorSpaceI.H:226
Foam::VectorSpace
Templated vector space.
Definition: VectorSpace.H:56
Foam::uniform
Definition: uniform.H:50
Foam::VectorSpace::min
static const Form min
Definition: VectorSpace.H:118
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::VectorSpace::VectorSpace
VectorSpace()
Construct null.
Definition: VectorSpaceI.H:39
Foam::VectorSpace::nCols
static constexpr direction nCols
Definition: VectorSpace.H:108
zero.H
Foam::VectorSpace::replace
void replace(const direction, const Cmpt &)
Definition: VectorSpaceI.H:158
Foam::VectorSpace::vsType
VectorSpace< Form, Cmpt, Ncmpts > vsType
VectorSpace type.
Definition: VectorSpace.H:86
scalar.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::VectorSpace::begin
iterator begin()
Return an iterator to begin of VectorSpace.
Definition: VectorSpaceI.H:212
Foam::VectorSpace::rootMin
static const Form rootMin
Definition: VectorSpace.H:120
Foam::VectorSpace::end
iterator end()
Return an iterator to end of VectorSpace.
Definition: VectorSpaceI.H:219
direction.H
Direction is an 8-bit unsigned integer type used to represent the Cartesian directions etc.
Foam::VectorSpace::ConstBlock::nComponents
static const direction nComponents
Number of components in this vector space.
Definition: VectorSpace.H:134
Foam::VectorSpace::mRows
static constexpr direction mRows
Definition: VectorSpace.H:107
Foam::VectorSpace::max
static const Form max
Definition: VectorSpace.H:117
Foam::direction
uint8_t direction
Definition: direction.H:47
Foam::VectorSpace::zero
static const Form zero
Definition: VectorSpace.H:115
Foam::VectorSpace::dim
static constexpr direction dim
Dimensionality of space.
Definition: VectorSpace.H:98
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
word.H
Foam::VectorSpace::const_iterator
const typedef Cmpt * const_iterator
Random access iterator for traversing VectorSpace.
Definition: VectorSpace.H:214
Foam::VectorSpace::ConstBlock::operator[]
const Cmpt & operator[](const direction i) const
[i] const element access operator
Definition: VectorSpaceI.H:298
Foam::VectorSpace::operator
friend Ostream & operator(Ostream &, const VectorSpace< Form, Cmpt, Ncmpts > &)
Foam::data
Database for solution data, solver performance and other reduced data.
Definition: data.H:54
VectorSpace.C
Foam::VectorSpace::ConstBlock::ConstBlock
ConstBlock(const vsType &vs)
Construct for a given vector.
Definition: VectorSpaceI.H:75
Foam::VectorSpace::nComponents
static constexpr direction nComponents
Number of components in this vector space.
Definition: VectorSpace.H:101
Foam::VectorSpace::cdata
const Cmpt * cdata() const noexcept
Return const pointer to the first data element.
Definition: VectorSpaceI.H:205
Foam::VectorSpace::typeName
static const char *const typeName
Definition: VectorSpace.H:113
Foam::zero
A class representing the concept of 0 (zero), which can be used to avoid manipulating objects that ar...
Definition: zero.H:61