Loading...
Searching...
No Matches
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-2025 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.txx
39
40\*---------------------------------------------------------------------------*/
41
42#ifndef Foam_VectorSpace_H
43#define Foam_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(
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;
92 //- Magnitude type
93 typedef Cmpt magType;
94
95 //- The type to represent the size of a VectorSpace
97
98
99 // Static Constants
100
101 //- Dimensionality of space
102 static constexpr direction dim = 3;
103
104 //- Number of components in this vector space
105 static constexpr direction nComponents = Ncmpts;
106
107
108 // VectorSpace currently defaults to a column-vector
109 // This will be removed when column-vector is introduced
110 // as a specialization
111 static constexpr direction mRows = Ncmpts;
112 static constexpr direction nCols = 1;
113
115 // Static Data Members
116
117 static const char* const typeName;
118 static const char* const componentNames[];
119 static const Form zero;
120 static const Form one;
121 static const Form max;
122 static const Form min;
123 static const Form rootMax;
124 static const Form rootMin;
125
127 // Sub-Block Classes
129 //- Const sub-block type
130 template<class SubVector, direction BStart>
131 class ConstBlock
133 const vsType& vs_;
134
135 public:
136
137 //- Number of components in this vector space
138 static const direction nComponents = SubVector::nComponents;
139
140 //- Construct for a given vector
141 inline ConstBlock(const vsType& vs);
143 //- [i] const element access operator
144 inline const Cmpt& operator[](const direction i) const;
145
146 //- (i, 0) const element access operator
147 inline const Cmpt& operator()
148 (
149 const direction i,
150 const direction
151 ) const;
152 };
153
154
155 // Generated Methods
156
157 //- Default construct
158 VectorSpace() = default;
159
160
161 // Constructors
162
163 //- Construct initialized to zero
164 inline VectorSpace(Foam::zero);
165
166 //- Copy construct
168
169 //- Copy construct of a VectorSpace with the same size
170 template<class Form2, class Cmpt2>
171 inline explicit VectorSpace(const VectorSpace<Form2, Cmpt2, Ncmpts>&);
172
173 //- Construct from Istream
174 explicit VectorSpace(Istream& is);
175
176
177 // Member Functions
178
179 //- The number of elements in the VectorSpace = Ncmpts.
180 static constexpr direction size() noexcept { return Ncmpts; }
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&);
188 //- Return const pointer to the first data element
189 const Cmpt* cdata() const noexcept { return v_; }
190
191 //- Return pointer to the first data element
192 Cmpt* data() noexcept { return v_; }
193
194 //- Assign all components to given value
195 inline void fill(const Cmpt& s);
196
197 //- Return a VectorSpace with all elements = s
198 inline static Form uniform(const Cmpt& s);
199
200 template<class SubVector, direction BStart>
201 inline const ConstBlock<SubVector, BStart> block() const;
202
204 // Member Operators
205
206 inline const Cmpt& operator[](const direction) const;
207 inline Cmpt& operator[](const direction);
208
209 inline void operator=(const VectorSpace<Form, Cmpt, Ncmpts>&);
212
213 //- Copy assign from a VectorSpace with the same size
214 template<class Form2, class Cmpt2>
217 inline void operator=(Foam::zero);
218 inline void operator*=(const scalar);
219 inline void operator/=(const scalar);
220
221
222 // Iterators
223
224 //- Random access iterator for traversing VectorSpace
225 typedef Cmpt* iterator;
226
227 //- Random access iterator for traversing VectorSpace
228 typedef const Cmpt* const_iterator;
229
230
231 // Random access iterators (const and non-const)
233 //- Return an iterator (pointer) to begin of VectorSpace
234 iterator begin() noexcept { return v_; }
235
236 //- Return const_iterator (const pointer) to begin of VectorSpace
237 const_iterator begin() const noexcept { return v_; }
238
239 //- Return const_iterator (const pointer) to begin of VectorSpace
240 const_iterator cbegin() const noexcept { return v_; }
241
242 //- Return an iterator (pointer) to end of VectorSpace
243 iterator end() noexcept { return (v_ + Ncmpts); }
244
245 //- Return const_iterator (const pointer) to end of VectorSpace
246 const_iterator end() const noexcept { return (v_ + Ncmpts); }
247
248 //- Return const_iterator (const pointer) to end of VectorSpace
249 const_iterator cend() const noexcept { return (v_ + Ncmpts); }
251
252 // IOstream Operators
253
254 friend Istream& operator>> <Form, Cmpt, Ncmpts>
255 (
258 );
261 (
262 Ostream&,
264 );
265};
266
267
268// * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
269
270//- A word representation of a VectorSpace
271template<class Form, class Cmpt, direction Ncmpts>
274// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
275
276} // End namespace Foam
277
278// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
279
280#include "VectorSpaceI.H"
282#ifdef NoRepository
283 #include "VectorSpace.txx"
284#endif
285
286// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
287
288#endif
289
290// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
ConstBlock(const vsType &vs)
Construct for a given vector.
static const direction nComponents
Number of components in this vector space.
const Cmpt & operator[](const direction i) const
[i] const element access operator
Templated vector space.
Definition VectorSpace.H:75
void operator=(Foam::zero)
VectorSpace(Istream &is)
Construct from Istream.
VectorSpace(Foam::zero)
Construct initialized to zero.
void fill(const Cmpt &s)
Assign all components to given value.
const_iterator begin() const noexcept
Return const_iterator (const pointer) to begin of VectorSpace.
const Cmpt & component(const direction) const
Cmpt * data() noexcept
Return pointer to the first data element.
void operator=(const VectorSpace< Form, Cmpt, Ncmpts > &)
Cmpt & component(const direction)
void replace(const direction, const Cmpt &)
const_iterator end() const noexcept
Return const_iterator (const pointer) to end of VectorSpace.
const ConstBlock< SubVector, BStart > block() const
VectorSpace(const VectorSpace< Form2, Cmpt2, Ncmpts > &)
Copy construct of a VectorSpace with the same size.
static constexpr direction size() noexcept
The number of elements in the VectorSpace = Ncmpts.
VectorSpace(const VectorSpace< Form, Cmpt, Ncmpts > &vs)
Copy construct.
void component(Cmpt &, const direction) const
const Cmpt * cdata() const noexcept
Return const pointer to the first data element.
void operator/=(const scalar)
iterator begin() noexcept
Return an iterator (pointer) to begin of VectorSpace.
const_iterator cend() const noexcept
Return const_iterator (const pointer) to end of VectorSpace.
VectorSpace< Vector< scalar >, scalar, Ncmpts > vsType
Definition VectorSpace.H:86
void operator+=(const VectorSpace< Form, Cmpt, Ncmpts > &)
const Cmpt & operator[](const direction) const
void operator=(const VectorSpace< Form2, Cmpt2, Ncmpts > &)
Copy assign from a VectorSpace with the same size.
void operator-=(const VectorSpace< Form, Cmpt, Ncmpts > &)
const_iterator cbegin() const noexcept
Return const_iterator (const pointer) to begin of VectorSpace.
static Form uniform(const Cmpt &s)
Return a VectorSpace with all elements = s.
friend Ostream & operator(Ostream &, const VectorSpace< Form, Cmpt, Ncmpts > &)
VectorSpace()=default
Default construct.
void operator*=(const scalar)
Cmpt & operator[](const direction)
iterator end() noexcept
Return an iterator (pointer) to end of VectorSpace.
A class for handling words, derived from Foam::string.
Definition word.H:66
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition zero.H:58
Direction is an 8-bit unsigned integer type used to represent Cartesian directions,...
OBJstream os(runTime.globalPath()/outputName)
auto & name
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:49
const direction noexcept
Definition scalarImpl.H:265