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-2022 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 Foam_MatrixSpace_H
45 #define Foam_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  }
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  (
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  (
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 noexcept;
242 
243  //- Fast element access using compile-time addressing
244  template<direction Row, direction Col>
245  inline Cmpt& elmt() noexcept;
246 
247 
248  // Const element access functions for a 3x3
249  // Compile-time errors are generated for inappropriate use
250 
251  const Cmpt& xx() const noexcept { return elmt<0,0>(); }
252  const Cmpt& xy() const noexcept { return elmt<0,1>(); }
253  const Cmpt& xz() const noexcept { return elmt<0,2>(); }
254  const Cmpt& yx() const noexcept { return elmt<1,0>(); }
255  const Cmpt& yy() const noexcept { return elmt<1,1>(); }
256  const Cmpt& yz() const noexcept { return elmt<1,2>(); }
257  const Cmpt& zx() const noexcept { return elmt<2,0>(); }
258  const Cmpt& zy() const noexcept { return elmt<2,1>(); }
259  const Cmpt& zz() const noexcept { return elmt<2,2>(); }
260 
261 
262  // Element access functions for a 3x3
263  // Compile-time errors are generated for inappropriate use
264 
265  Cmpt& xx() noexcept { return elmt<0,0>(); }
266  Cmpt& xy() noexcept { return elmt<0,1>(); }
267  Cmpt& xz() noexcept { return elmt<0,2>(); }
268  Cmpt& yx() noexcept { return elmt<1,0>(); }
269  Cmpt& yy() noexcept { return elmt<1,1>(); }
270  Cmpt& yz() noexcept { return elmt<1,2>(); }
271  Cmpt& zx() noexcept { return elmt<2,0>(); }
272  Cmpt& zy() noexcept { return elmt<2,1>(); }
273  Cmpt& zz() noexcept { return elmt<2,2>(); }
274 
275 
276  //- Return the transpose of the matrix
277  inline typename typeOfTranspose<Cmpt, Form>::type T() const;
278 
279  //- Return a const sub-block corresponding to the specified type
280  // starting at the specified row and column
281  template<class SubTensor, direction BRowStart, direction BColStart>
282  inline ConstBlock<SubTensor, BRowStart, BColStart> block() const;
283 
284  //- Return a sub-block corresponding to the specified type
285  // starting at the specified row and column
286  template<class SubTensor, direction BRowStart, direction BColStart>
287  inline Block<SubTensor, BRowStart, BColStart> block();
288 
289  //- (i, j) const element access operator
290  inline const Cmpt& operator()
291  (
292  const direction& i,
293  const direction& j
294  ) const;
295 
296  //- (i, j) element access operator
297  inline Cmpt& operator()(const direction& i, const direction& j);
298 
299 
300  // Member Operators
301 
302  //- Assignment to zero
303  inline void operator=(const Foam::zero);
305  //- Assignment to a block of another matrix space
306  template
307  <
308  template<class, direction, direction> class Block2,
309  direction BRowStart,
310  direction BColStart
311  >
312  inline void operator=
313  (
314  const Block2<Form, BRowStart, BColStart>& block
315  );
317  //- Inner product with a compatible square matrix
318  template<class Form2>
319  inline void operator&=
320  (
322  );
323 };
325 
326 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
327 
328 } // End namespace Foam
329 
330 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
331 
332 #include "MatrixSpaceI.H"
333 
334 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
335 
336 #endif
337 
338 // ************************************************************************* //
static direction m()
Return the number of rows in the block.
Definition: MatrixSpace.H:119
type
Types of root.
Definition: Roots.H:52
static direction n() noexcept
The number of columns.
Definition: MatrixSpace.H:87
uint8_t direction
Definition: direction.H:46
Block(msType &matrix)
Construct for the given matrix.
Definition: MatrixSpaceI.H:100
const Cmpt & operator()(const direction &i, const direction &j) const
(i, j) const element access operator
Definition: MatrixSpaceI.H:208
ConstBlock(const msType &matrix)
Construct for the given matrix.
Definition: MatrixSpaceI.H:79
const Cmpt & xy() const noexcept
Definition: MatrixSpace.H:303
static const direction nCols
Definition: MatrixSpace.H:172
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
SubTensor operator()() const
Construct and return the sub-tensor corresponding to this block.
Definition: MatrixSpaceI.H:251
Templated vector space.
Definition: VectorSpace.H:52
MatrixSpace< Form, Cmpt, Mrows, Ncols > msType
MatrixSpace type.
Definition: MatrixSpace.H:65
void operator=(const Foam::zero)
Assignment to zero.
Definition: MatrixSpaceI.H:313
typeOfTranspose< Cmpt, Form >::type T() const
Return the transpose of the matrix.
Definition: MatrixSpaceI.H:157
Templated matrix space.
Definition: MatrixSpace.H:54
const Cmpt & zy() const noexcept
Definition: MatrixSpace.H:309
static direction n()
Return the number of columns in the block.
Definition: MatrixSpace.H:127
static const direction mRows
Definition: MatrixSpace.H:113
const Cmpt & zx() const noexcept
Definition: MatrixSpace.H:308
static constexpr direction nCols
Definition: MatrixSpace.H:71
static direction m() noexcept
The number of rows.
Definition: MatrixSpace.H:79
const Cmpt & yx() const noexcept
Definition: MatrixSpace.H:305
static constexpr direction mRows
Definition: MatrixSpace.H:70
const Cmpt & xz() const noexcept
Definition: MatrixSpace.H:304
static const direction mRows
Definition: MatrixSpace.H:171
static const direction nCols
Definition: MatrixSpace.H:114
ConstBlock< SubTensor, BRowStart, BColStart > block() const
Return a const sub-block corresponding to the specified type.
Creates a single block of cells from point coordinates, numbers of cells in each direction and an exp...
Definition: block.H:54
const Cmpt & elmt() const noexcept
Fast const element access using compile-time addressing.
Definition: MatrixSpaceI.H:121
const direction noexcept
Definition: Scalar.H:258
const Cmpt & yy() const noexcept
Definition: MatrixSpace.H:306
Sub-block type.
Definition: MatrixSpace.H:162
friend Ostream & operator(Ostream &, const VectorSpace< Form, Cmpt, Ncmpts > &)
static direction m()
The number of rows in the block.
Definition: MatrixSpace.H:177
const Cmpt & zz() const noexcept
Definition: MatrixSpace.H:310
MatrixSpace()=default
Default construct.
SubTensor operator()() const
Construct and return the sub-tensor corresponding to this block.
Definition: MatrixSpaceI.H:273
const Cmpt & xx() const noexcept
Definition: MatrixSpace.H:302
const Cmpt & yz() const noexcept
Definition: MatrixSpace.H:307
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
static direction n()
The number of columns in the block.
Definition: MatrixSpace.H:185
static msType identity()
An identity matrix for square matrix-spaces.
Definition: MatrixSpaceI.H:141
Namespace for OpenFOAM.