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-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::VectorSpace
29
30Description
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
36SourceFiles
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
52namespace Foam
53{
54
55// Forward Declarations
56
57template<class Form, class Cmpt, direction Ncmpts> class VectorSpace;
58
59template<class Form, class Cmpt, direction Ncmpts>
60Istream& operator>>
61(
62 Istream& is,
64);
65
66template<class Form, class Cmpt, direction Ncmpts>
67Ostream& operator<<
68(
69 Ostream& os,
71);
72
73
74/*---------------------------------------------------------------------------*\
75 Class VectorSpace Declaration
76\*---------------------------------------------------------------------------*/
77
78template<class Form, class Cmpt, direction Ncmpts>
79class VectorSpace
80{
81public:
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
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 // Generated Methods
153
154 //- Default construct
155 VectorSpace() = default;
156
157
158 // Constructors
159
160 //- Construct initialized to zero
161 inline VectorSpace(const Foam::zero);
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 //- Construct from Istream
171 explicit VectorSpace(Istream& is);
172
173
174 // Member Functions
175
176 //- The number of elements in the VectorSpace = Ncmpts.
177 static constexpr direction size() noexcept
178 {
179 return Ncmpts;
180 }
181
182 inline const Cmpt& component(const direction) const;
183 inline Cmpt& component(const direction);
184
185 inline void component(Cmpt&, const direction) const;
186 inline void replace(const direction, const Cmpt&);
187
188 //- Return const pointer to the first data element
189 inline const Cmpt* cdata() const noexcept;
190
191 //- Return pointer to the first data element
192 inline Cmpt* data() noexcept;
193
194 //- Return a VectorSpace with all elements = s
195 inline static Form uniform(const Cmpt& s);
196
197 template<class SubVector, direction BStart>
198 inline const ConstBlock<SubVector, BStart> block() const;
199
200
201 // Member Operators
202
203 inline const Cmpt& operator[](const direction) const;
204 inline Cmpt& operator[](const direction);
205
206 inline void operator=(const VectorSpace<Form, Cmpt, Ncmpts>&);
207 inline void operator+=(const VectorSpace<Form, Cmpt, Ncmpts>&);
208 inline void operator-=(const VectorSpace<Form, Cmpt, Ncmpts>&);
209
210 inline void operator=(const Foam::zero);
211 inline void operator*=(const scalar);
212 inline void operator/=(const scalar);
213
214
215 // Iterators
216
217 //- Random access iterator for traversing VectorSpace
218 typedef Cmpt* iterator;
219
220 //- Random access iterator for traversing VectorSpace
221 typedef const Cmpt* const_iterator;
222
223
224 // Random access iterator (non-const)
225
226 //- Return an iterator to begin of VectorSpace
227 inline iterator begin() noexcept;
228
229 //- Return an iterator to end of VectorSpace
230 inline iterator end() noexcept;
231
232
233 // Random access iterator (const)
234
235 //- Return const_iterator to begin of VectorSpace
236 inline const_iterator cbegin() const noexcept;
237
238 //- Return const_iterator to end of VectorSpace
239 inline const_iterator cend() const noexcept;
240
241 //- Return const_iterator to begin of VectorSpace
242 inline const_iterator begin() const noexcept;
243
244 //- Return const_iterator to end of VectorSpace
245 inline const_iterator end() const noexcept;
246
247
248 // IOstream Operators
250 friend Istream& operator>> <Form, Cmpt, Ncmpts>
251 (
252 Istream&,
253 VectorSpace<Form, Cmpt, Ncmpts>&
254 );
256 friend Ostream& operator<< <Form, Cmpt, Ncmpts>
257 (
258 Ostream&,
259 const VectorSpace<Form, Cmpt, Ncmpts>&
260 );
261};
262
263
264// * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
265
266//- A word representation of a VectorSpace
267template<class Form, class Cmpt, direction Ncmpts>
268word name(const VectorSpace<Form, Cmpt, Ncmpts>& vs);
269
270// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
271
272} // End namespace Foam
273
274// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
275
276#include "VectorSpaceI.H"
277
278#ifdef NoRepository
279 #include "VectorSpace.C"
280#endif
281
282// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
283
284#endif
285
286// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Const sub-block type.
Definition: VectorSpace.H:128
static const direction nComponents
Number of components in this vector space.
Definition: VectorSpace.H:134
const Cmpt & operator[](const direction i) const
[i] const element access operator
Definition: VectorSpaceI.H:289
Templated vector space.
Definition: VectorSpace.H:79
static constexpr direction nCols
Definition: VectorSpace.H:108
static const Form zero
Definition: VectorSpace.H:115
static const char *const componentNames[]
Definition: VectorSpace.H:114
const Cmpt & component(const direction) const
Definition: VectorSpaceI.H:87
void replace(const direction, const Cmpt &)
Definition: VectorSpaceI.H:145
static const Form one
Definition: VectorSpace.H:116
static constexpr direction nComponents
Number of components in this vector space.
Definition: VectorSpace.H:101
static constexpr direction size() noexcept
The number of elements in the VectorSpace = Ncmpts.
Definition: VectorSpace.H:176
static constexpr direction dim
Dimensionality of space.
Definition: VectorSpace.H:98
Cmpt magType
Magnitude type.
Definition: VectorSpace.H:92
Cmpt * iterator
Random access iterator for traversing VectorSpace.
Definition: VectorSpace.H:217
const Cmpt * cdata() const noexcept
Return const pointer to the first data element.
Definition: VectorSpaceI.H:192
static const Form rootMax
Definition: VectorSpace.H:119
static constexpr direction mRows
Definition: VectorSpace.H:107
VectorSpace< Form, Cmpt, Ncmpts > vsType
VectorSpace type.
Definition: VectorSpace.H:86
static const Form max
Definition: VectorSpace.H:117
iterator end() noexcept
Return an iterator to end of VectorSpace.
Definition: VectorSpaceI.H:206
static const Form rootMin
Definition: VectorSpace.H:120
Cmpt v_[Ncmpts]
The components of this vector space.
Definition: VectorSpace.H:83
Cmpt cmptType
Component type.
Definition: VectorSpace.H:89
friend Ostream & operator(Ostream &, const VectorSpace< Form, Cmpt, Ncmpts > &)
const_iterator cend() const noexcept
Return const_iterator to end of VectorSpace.
Definition: VectorSpaceI.H:221
VectorSpace()=default
Default construct.
static const Form min
Definition: VectorSpace.H:118
iterator begin() noexcept
Return an iterator to begin of VectorSpace.
Definition: VectorSpaceI.H:199
const Cmpt * const_iterator
Random access iterator for traversing VectorSpace.
Definition: VectorSpace.H:220
const_iterator cbegin() const noexcept
Return const_iterator to begin of VectorSpace.
Definition: VectorSpaceI.H:213
static const char *const typeName
Definition: VectorSpace.H:113
Creates a single block of cells from point coordinates, numbers of cells in each direction and an exp...
Definition: block.H:61
Database for solution data, solver performance and other reduced data.
Definition: data.H:58
A class for handling words, derived from Foam::string.
Definition: word.H:68
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:63
Direction is an 8-bit unsigned integer type used to represent Cartesian directions,...
OBJstream os(runTime.globalPath()/outputName)
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))
Namespace for OpenFOAM.
uint8_t direction
Definition: direction.H:56
const direction noexcept
Definition: Scalar.H:223
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59