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 -------------------------------------------------------------------------------
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  // 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
249 
250  friend Istream& operator>> <Form, Cmpt, Ncmpts>
251  (
252  Istream&,
253  VectorSpace<Form, Cmpt, Ncmpts>&
254  );
255 
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
267 template<class Form, class Cmpt, direction Ncmpts>
268 word 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 // ************************************************************************* //
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:87
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
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::end
iterator end() noexcept
Return an iterator to end of VectorSpace.
Definition: VectorSpaceI.H:206
Foam::VectorSpace::VectorSpace
VectorSpace()=default
Default construct.
Foam::VectorSpace::begin
iterator begin() noexcept
Return an iterator to begin of VectorSpace.
Definition: VectorSpaceI.H:199
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
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::VectorSpace::nCols
static constexpr direction nCols
Definition: VectorSpace.H:108
Foam::VectorSpace::cbegin
const_iterator cbegin() const noexcept
Return const_iterator to begin of VectorSpace.
Definition: VectorSpaceI.H:213
zero.H
Foam::VectorSpace::replace
void replace(const direction, const Cmpt &)
Definition: VectorSpaceI.H:145
Foam::VectorSpace::vsType
VectorSpace< Form, Cmpt, Ncmpts > vsType
VectorSpace type.
Definition: VectorSpace.H:86
scalar.H
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::VectorSpace::rootMin
static const Form rootMin
Definition: VectorSpace.H:120
Foam::VectorSpace::cend
const_iterator cend() const noexcept
Return const_iterator to end of VectorSpace.
Definition: VectorSpaceI.H:221
direction.H
Direction is an 8-bit unsigned integer type used to represent Cartesian directions,...
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::Vector< scalar >
Foam::direction
uint8_t direction
Definition: direction.H:52
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
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::size
static constexpr direction size() noexcept
The number of elements in the VectorSpace = Ncmpts.
Definition: VectorSpace.H:176
Foam::VectorSpace::const_iterator
const typedef Cmpt * const_iterator
Random access iterator for traversing VectorSpace.
Definition: VectorSpace.H:220
Foam::VectorSpace::ConstBlock::operator[]
const Cmpt & operator[](const direction i) const
[i] const element access operator
Definition: VectorSpaceI.H:289
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:55
VectorSpace.C
Foam::VectorSpace::ConstBlock::ConstBlock
ConstBlock(const vsType &vs)
Construct for a given vector.
Definition: VectorSpaceI.H:69
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:192
Foam::VectorSpace::typeName
static const char *const typeName
Definition: VectorSpace.H:113
Foam::zero
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:62