MatrixSpace.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) 2016 OpenFOAM Foundation
9  Copyright (C) 2019-2020 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::MatrixSpace
29 
30 Description
31  Templated matrix space.
32 
33  Template arguments are the Form the matrix space will be used to create,
34  the type of the elements and the number of rows and columns of the matrix.
35 
36 SourceFiles
37  MatrixSpaceI.H
38 
39 See also
40  Foam::VectorSpace
41 
42 \*---------------------------------------------------------------------------*/
43 
44 #ifndef MatrixSpace_H
45 #define MatrixSpace_H
46 
47 #include "VectorSpace.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 /*---------------------------------------------------------------------------*\
55  Class MatrixSpace Declaration
56 \*---------------------------------------------------------------------------*/
57 
58 template<class Form, class Cmpt, direction Mrows, direction Ncols>
59 class MatrixSpace
60 :
61  public VectorSpace<Form, Cmpt, Mrows*Ncols>
62 {
63 public:
64 
65  // Typedefs
66 
67  //- MatrixSpace type
69 
70 
71  // Member Constants
72 
73  static constexpr direction mRows = Mrows;
74  static constexpr direction nCols = Ncols;
75 
76 
77  // Static Member Functions
78 
79  //- The number of rows
80  static direction m() noexcept
81  {
82  return Mrows;
83  }
84 
85  //- The number of columns
86  static direction n() noexcept
87  {
88  return Ncols;
89  }
90 
91  //- An identity matrix for square matrix-spaces
92  inline static msType identity();
93 
94 
95  // Sub-Block Classes
96 
97  //- Const sub-block type
98  template<class SubTensor, direction BRowStart, direction BColStart>
99  class ConstBlock
100  {
101  //- Reference to parent matrix
102  const msType& matrix_;
103 
104  public:
105 
106  static const direction mRows = SubTensor::mRows;
107  static const direction nCols = SubTensor::nCols;
108 
109  //- Return the number of rows in the block
110  static direction m()
111  {
112  return mRows;
113  }
114 
115  //- Return the number of columns in the block
116  static direction n()
117  {
118  return nCols;
119  }
120 
121  //- Construct for the given matrix
122  inline ConstBlock(const msType& matrix);
123 
124  //- Construct and return the sub-tensor corresponding to this block
125  inline SubTensor operator()() const;
126 
127  //- (i, j) const element access operator
128  inline const Cmpt& operator()
129  (
130  const direction i,
131  const direction j
132  ) const;
133  };
134 
135 
136  //- Sub-block type
137  template
138  <
139  class SubTensor,
140  direction BRowStart,
141  direction BColStart
142  >
143  class Block
144  {
145  //- Reference to parent matrix
146  msType& matrix_;
147 
148  public:
149 
150  static const direction mRows = SubTensor::mRows;
151  static const direction nCols = SubTensor::nCols;
152 
153  //- The number of rows in the block
154  static direction m()
155  {
156  return mRows;
157  }
158 
159  //- The number of columns in the block
160  static direction n()
161  {
162  return nCols;
163  }
164 
165  //- Construct for the given matrix
166  inline Block(msType& matrix);
167 
168  //- Assignment to a matrix
169  template<class Form2>
170  inline void operator=
171  (
172  const MatrixSpace
173  <
174  Form2,
175  Cmpt,
176  SubTensor::mRows,
177  SubTensor::nCols
178  >& matrix
179  );
180 
181  //- Assignment to a column vector
182  template<class VSForm>
183  inline void operator=
184  (
186  );
187 
188  //- Construct and return the sub-tensor corresponding to this block
189  inline SubTensor operator()() const;
190 
191  //- (i, j) const element access operator
192  inline const Cmpt& operator()
193  (
194  const direction i,
195  const direction j
196  ) const;
197 
198  //- (i, j) element access operator
199  inline Cmpt& operator()(const direction i, const direction j);
200  };
201 
202 
203  // Generated Methods
204 
205  //- Default construct
206  MatrixSpace() = default;
207 
208 
209  // Constructors
210 
211  //- Construct initialized to zero
212  inline MatrixSpace(const Foam::zero);
213 
214  //- Construct as copy of a VectorSpace with the same size
215  template<class Form2, class Cmpt2>
216  inline explicit MatrixSpace
217  (
218  const VectorSpace<Form2, Cmpt2, Mrows*Ncols>&
219  );
220 
221  //- Construct from a block of another matrix space
222  template
223  <
224  template<class, direction, direction> class Block2,
225  direction BRowStart,
226  direction BColStart
227  >
228  inline MatrixSpace
229  (
230  const Block2<Form, BRowStart, BColStart>& block
231  );
232 
233  //- Construct from Istream
234  explicit MatrixSpace(Istream& is);
235 
236 
237  // Member Functions
238 
239  //- Fast const element access using compile-time addressing
240  template<direction Row, direction Col>
241  inline const Cmpt& elmt() const;
242 
243  //- Fast element access using compile-time addressing
244  template<direction Row, direction Col>
245  inline Cmpt& elmt();
246 
247  // Const element access functions for a 3x3
248  // Compile-time errors are generated for inappropriate use
249 
250  inline const Cmpt& xx() const;
251  inline const Cmpt& xy() const;
252  inline const Cmpt& xz() const;
253  inline const Cmpt& yx() const;
254  inline const Cmpt& yy() const;
255  inline const Cmpt& yz() const;
256  inline const Cmpt& zx() const;
257  inline const Cmpt& zy() const;
258  inline const Cmpt& zz() const;
259 
260  // Element access functions for a 3x3
261  // Compile-time errors are generated for inappropriate use
262 
263  inline Cmpt& xx();
264  inline Cmpt& xy();
265  inline Cmpt& xz();
266  inline Cmpt& yx();
267  inline Cmpt& yy();
268  inline Cmpt& yz();
269  inline Cmpt& zx();
270  inline Cmpt& zy();
271  inline Cmpt& zz();
272 
273  //- Return the transpose of the matrix
274  inline typename typeOfTranspose<Cmpt, Form>::type T() const;
275 
276  //- Return a const sub-block corresponding to the specified type
277  // starting at the specified row and column
278  template<class SubTensor, direction BRowStart, direction BColStart>
279  inline ConstBlock<SubTensor, BRowStart, BColStart> block() const;
280 
281  //- Return a sub-block corresponding to the specified type
282  // starting at the specified row and column
283  template<class SubTensor, direction BRowStart, direction BColStart>
284  inline Block<SubTensor, BRowStart, BColStart> block();
285 
286  //- (i, j) const element access operator
287  inline const Cmpt& operator()
288  (
289  const direction& i,
290  const direction& j
291  ) const;
292 
293  //- (i, j) element access operator
294  inline Cmpt& operator()(const direction& i, const direction& j);
295 
296 
297  // Member Operators
298 
299  //- Assignment to zero
300  inline void operator=(const Foam::zero);
301 
302  //- Assignment to a block of another matrix space
303  template
304  <
305  template<class, direction, direction> class Block2,
306  direction BRowStart,
307  direction BColStart
308  >
309  inline void operator=
310  (
311  const Block2<Form, BRowStart, BColStart>& block
312  );
313 
314  //- Inner product with a compatible square matrix
315  template<class Form2>
316  inline void operator&=
317  (
318  const MatrixSpace<Form, Cmpt, Ncols, Ncols>& matrix
319  );
320 };
321 
322 
323 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
324 
325 } // End namespace Foam
326 
327 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
328 
329 #include "MatrixSpaceI.H"
330 
331 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
332 
333 #endif
334 
335 // ************************************************************************* //
Foam::MatrixSpace::MatrixSpace
MatrixSpace()=default
VectorSpace.H
Foam::block
Creates a single block of cells from point coordinates, numbers of cells in each direction and an exp...
Definition: block.H:54
Foam::MatrixSpace::elmt
const Cmpt & elmt() const
Definition: MatrixSpaceI.H:121
Foam::typeOfTranspose
Definition: products.H:62
Foam::MatrixSpace::T
typeOfTranspose< Cmpt, Form >::type T() const
Definition: MatrixSpaceI.H:279
Foam::MatrixSpace::Block::nCols
static const direction nCols
Definition: MatrixSpace.H:146
Foam::MatrixSpace::ConstBlock::n
static direction n()
Definition: MatrixSpace.H:111
Foam::MatrixSpace::ConstBlock::mRows
static const direction mRows
Definition: MatrixSpace.H:101
Foam::MatrixSpace::ConstBlock::ConstBlock
ConstBlock(const msType &matrix)
Definition: MatrixSpaceI.H:79
Foam::MatrixSpace::mRows
static constexpr direction mRows
Definition: MatrixSpace.H:68
Foam::MatrixSpace::zy
const Cmpt & zy() const
Definition: MatrixSpaceI.H:236
Foam::MatrixSpace::ConstBlock::nCols
static const direction nCols
Definition: MatrixSpace.H:102
Foam::MatrixSpace::operator=
void operator=(const Foam::zero)
Definition: MatrixSpaceI.H:435
Foam::VectorSpace
Templated vector space.
Definition: VectorSpace.H:52
Foam::MatrixSpace::nCols
static constexpr direction nCols
Definition: MatrixSpace.H:69
Foam::MatrixSpace
Templated matrix space.
Definition: MatrixSpace.H:54
Foam::MatrixSpace::yz
const Cmpt & yz() const
Definition: MatrixSpaceI.H:208
Foam::MatrixSpace::ConstBlock::operator()
SubTensor operator()() const
Definition: MatrixSpaceI.H:373
Foam::MatrixSpace::Block::Block
Block(msType &matrix)
Definition: MatrixSpaceI.H:100
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::MatrixSpace::Block
Definition: MatrixSpace.H:138
Foam::MatrixSpace::xz
const Cmpt & xz() const
Definition: MatrixSpaceI.H:166
Foam::MatrixSpace::msType
MatrixSpace< Form, Cmpt, Mrows, Ncols > msType
Definition: MatrixSpace.H:63
Foam::MatrixSpace::yx
const Cmpt & yx() const
Definition: MatrixSpaceI.H:180
Foam::MatrixSpace::zx
const Cmpt & zx() const
Definition: MatrixSpaceI.H:222
Foam::MatrixSpace::ConstBlock
Definition: MatrixSpace.H:94
Foam::MatrixSpace::xy
const Cmpt & xy() const
Definition: MatrixSpaceI.H:152
Foam
Definition: atmBoundaryLayer.C:26
Foam::MatrixSpace::Block::operator()
SubTensor operator()() const
Definition: MatrixSpaceI.H:395
Foam::MatrixSpace::yy
const Cmpt & yy() const
Definition: MatrixSpaceI.H:194
Foam::MatrixSpace::block
ConstBlock< SubTensor, BRowStart, BColStart > block() const
Foam::MatrixSpace::ConstBlock::m
static direction m()
Definition: MatrixSpace.H:105
MatrixSpaceI.H
Foam::direction
uint8_t direction
Definition: direction.H:46
Foam::MatrixSpace::operator()
const Cmpt & operator()(const direction &i, const direction &j) const
Definition: MatrixSpaceI.H:330
Foam::roots::type
type
Definition: Roots.H:52
Foam::MatrixSpace::identity
static msType identity()
Definition: MatrixSpaceI.H:263
Foam::MatrixSpace::Block::n
static direction n()
Definition: MatrixSpace.H:155
Foam::MatrixSpace::Block::mRows
static const direction mRows
Definition: MatrixSpace.H:145
Foam::MatrixSpace::xx
const Cmpt & xx() const
Definition: MatrixSpaceI.H:138
Foam::VectorSpace< Form, Cmpt, Mrows *Ncols >::operator
friend Ostream & operator(Ostream &, const VectorSpace< Form, Cmpt, Ncmpts > &)
Foam::MatrixSpace::Block::m
static direction m()
Definition: MatrixSpace.H:149
Foam::MatrixSpace::zz
const Cmpt & zz() const
Definition: MatrixSpaceI.H:250
Foam::MatrixSpace::m
static direction m() noexcept
Definition: MatrixSpace.H:75
Foam::MatrixSpace::n
static direction n() noexcept
Definition: MatrixSpace.H:81
Foam::zero
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:58