MatrixSpace.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2016-2023 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::MatrixSpace
26 
27 Description
28  Templated matrix space.
29 
30  Template arguments are the Form the matrix space will be used to create,
31  the type of the elements and the number of rows and columns of the matrix.
32 
33 SourceFiles
34  MatrixSpaceI.H
35 
36 See also
37  Foam::VectorSpace
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef MatrixSpace_H
42 #define MatrixSpace_H
43 
44 #include "VectorSpace.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 /*---------------------------------------------------------------------------*\
52  Class MatrixSpace Declaration
53 \*---------------------------------------------------------------------------*/
54 
55 template<class Form, class Cmpt, direction Mrows, direction Ncols>
56 class MatrixSpace
57 :
58  public VectorSpace<Form, Cmpt, Mrows*Ncols>
59 {
60 
61 public:
62 
63  //- MatrixSpace type
65 
66 
67  // Member constants
68 
69  static const direction mRows = Mrows;
70  static const direction nCols = Ncols;
71 
72 
73  // Static member functions
74 
75  //- Return the number of rows
76  static direction m()
77  {
78  return Mrows;
79  }
80 
81  //- Return the number of columns
82  static direction n()
83  {
84  return Ncols;
85  }
86 
87  //- Return the identity matrix for square matrix spaces
88  inline static msType identityMap();
89 
90 
91  // Sub-Block Classes
92 
93  //- Const sub-block type
94  template<class SubTensor, direction BRowStart, direction BColStart>
95  class ConstBlock
96  {
97  //- Reference to parent matrix
98  const msType& matrix_;
99 
100  public:
101 
102  static const direction mRows = SubTensor::mRows;
103  static const direction nCols = SubTensor::nCols;
104 
105  //- Return the number of rows in the block
106  static direction m()
107  {
108  return mRows;
109  }
110 
111  //- Return the number of columns in the block
112  static direction n()
113  {
114  return nCols;
115  }
116 
117  //- Construct for the given matrix
118  inline ConstBlock(const msType& matrix);
119 
120  //- Construct and return the sub-ensor corresponding to this block
121  inline SubTensor operator()() const;
122 
123  //- (i, j) const element access operator
124  inline const Cmpt& operator()
125  (
126  const direction i,
127  const direction j
128  ) const;
129  };
130 
131 
132  //- Sub-block type
133  template
134  <
135  class SubTensor,
136  direction BRowStart,
137  direction BColStart
138  >
139  class Block
140  {
141  //- Reference to parent matrix
142  msType& matrix_;
143 
144  public:
145 
146  static const direction mRows = SubTensor::mRows;
147  static const direction nCols = SubTensor::nCols;
148 
149  //- Return the number of rows in the block
150  static direction m()
151  {
152  return mRows;
153  }
154 
155  //- Return the number of columns in the block
156  static direction n()
157  {
158  return nCols;
159  }
160 
161  //- Construct for the given matrix
162  inline Block(msType& matrix);
163 
164  //- Assignment to a matrix
165  template<class Form2>
166  inline void operator=
167  (
168  const MatrixSpace
169  <
170  Form2,
171  Cmpt,
172  SubTensor::mRows,
173  SubTensor::nCols
174  >& matrix
175  );
176 
177  //- Assignment to a column vector
178  template<class VSForm>
179  inline void operator=
180  (
182  );
183 
184  //- Construct and return the sub-tensor corresponding to this block
185  inline SubTensor operator()() const;
186 
187  //- (i, j) const element access operator
188  inline const Cmpt& operator()
189  (
190  const direction i,
191  const direction j
192  ) const;
193 
194  //- (i, j) element access operator
195  inline Cmpt& operator()(const direction i, const direction j);
196  };
197 
198 
199  // Constructors
200 
201  //- Construct null
202  inline MatrixSpace();
203 
204  //- Construct initialised to zero
205  inline MatrixSpace(const Foam::zero);
206 
207  //- Construct as copy of a VectorSpace with the same size
208  template<class Form2, class Cmpt2>
209  inline explicit MatrixSpace
210  (
212  );
213 
214  //- Construct from a block of another matrix space
215  template
216  <
217  template<class, direction, direction> class Block2,
218  direction BRowStart,
219  direction BColStart
220  >
221  inline MatrixSpace
222  (
223  const Block2<Form, BRowStart, BColStart>& block
224  );
225 
226  //- Construct from Istream
228 
229 
230  // Member Functions
231 
232  //- Fast const element access using compile-time addressing
233  template<direction Row, direction Col>
234  inline const Cmpt& elmt() const;
235 
236  //- Fast element access using compile-time addressing
237  template<direction Row, direction Col>
238  inline Cmpt& elmt();
239 
240  // Const element access functions for a 3x3
241  // Compile-time errors are generated for inappropriate use
242 
243  inline const Cmpt& xx() const;
244  inline const Cmpt& xy() const;
245  inline const Cmpt& xz() const;
246  inline const Cmpt& yx() const;
247  inline const Cmpt& yy() const;
248  inline const Cmpt& yz() const;
249  inline const Cmpt& zx() const;
250  inline const Cmpt& zy() const;
251  inline const Cmpt& zz() const;
252 
253  // Element access functions for a 3x3
254  // Compile-time errors are generated for inappropriate use
255 
256  inline Cmpt& xx();
257  inline Cmpt& xy();
258  inline Cmpt& xz();
259  inline Cmpt& yx();
260  inline Cmpt& yy();
261  inline Cmpt& yz();
262  inline Cmpt& zx();
263  inline Cmpt& zy();
264  inline Cmpt& zz();
265 
266  //- Return the transpose of the matrix
267  inline typename typeOfTranspose<Cmpt, Form>::type T() const;
268 
269  //- Return a const sub-block corresponding to the specified type
270  // starting at the specified row and column
271  template<class SubTensor, direction BRowStart, direction BColStart>
273 
274  //- Return a sub-block corresponding to the specified type
275  // starting at the specified row and column
276  template<class SubTensor, direction BRowStart, direction BColStart>
278 
279  //- (i, j) const element access operator
280  inline const Cmpt& operator()
281  (
282  const direction& i,
283  const direction& j
284  ) const;
285 
286  //- (i, j) element access operator
287  inline Cmpt& operator()(const direction& i, const direction& j);
288 
289 
290  // Member Operators
291 
292  //- Assignment to zero
293  inline void operator=(const Foam::zero);
294 
295  //- Assignment to a block of another matrix space
296  template
297  <
298  template<class, direction, direction> class Block2,
299  direction BRowStart,
300  direction BColStart
301  >
302  inline void operator=
303  (
304  const Block2<Form, BRowStart, BColStart>& block
305  );
306 
307  //- Inner product with a compatible square matrix
308  template<class Form2>
309  inline void operator&=
310  (
312  );
313 };
314 
315 
316 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
317 
318 } // End namespace Foam
319 
320 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
321 
322 #include "MatrixSpaceI.H"
323 
324 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
325 
326 #endif
327 
328 // ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
static direction n()
Return the number of columns in the block.
Definition: MatrixSpace.H:155
static direction m()
Return the number of rows in the block.
Definition: MatrixSpace.H:149
Block(msType &matrix)
Construct for the given matrix.
Definition: MatrixSpaceI.H:110
SubTensor operator()() const
Construct and return the sub-tensor corresponding to this block.
Definition: MatrixSpaceI.H:405
static const direction nCols
Definition: MatrixSpace.H:146
static const direction mRows
Definition: MatrixSpace.H:145
Const sub-block type.
Definition: MatrixSpace.H:95
ConstBlock(const msType &matrix)
Construct for the given matrix.
Definition: MatrixSpaceI.H:89
static direction n()
Return the number of columns in the block.
Definition: MatrixSpace.H:111
static direction m()
Return the number of rows in the block.
Definition: MatrixSpace.H:105
SubTensor operator()() const
Construct and return the sub-ensor corresponding to this block.
Definition: MatrixSpaceI.H:383
static const direction nCols
Definition: MatrixSpace.H:102
static const direction mRows
Definition: MatrixSpace.H:101
Templated matrix space.
Definition: MatrixSpace.H:58
typeOfTranspose< Cmpt, Form >::type T() const
Return the transpose of the matrix.
Definition: MatrixSpaceI.H:289
MatrixSpace()
Construct null.
Definition: MatrixSpaceI.H:31
const Cmpt & xx() const
Definition: MatrixSpaceI.H:148
const Cmpt & yx() const
Definition: MatrixSpaceI.H:190
MatrixSpace< Form, Cmpt, Mrows, Ncols > msType
MatrixSpace type.
Definition: MatrixSpace.H:63
static msType identityMap()
Return the identity matrix for square matrix spaces.
Definition: MatrixSpaceI.H:273
const Cmpt & yz() const
Definition: MatrixSpaceI.H:218
static direction n()
Return the number of columns.
Definition: MatrixSpace.H:81
static direction m()
Return the number of rows.
Definition: MatrixSpace.H:75
const Cmpt & xz() const
Definition: MatrixSpaceI.H:176
const Cmpt & zz() const
Definition: MatrixSpaceI.H:260
const Cmpt & elmt() const
Fast const element access using compile-time addressing.
Definition: MatrixSpaceI.H:131
const Cmpt & xy() const
Definition: MatrixSpaceI.H:162
const Cmpt & zx() const
Definition: MatrixSpaceI.H:232
const Cmpt & zy() const
Definition: MatrixSpaceI.H:246
const Cmpt & operator()(const direction &i, const direction &j) const
(i, j) const element access operator
Definition: MatrixSpaceI.H:340
const Cmpt & yy() const
Definition: MatrixSpaceI.H:204
ConstBlock< SubTensor, BRowStart, BColStart > block() const
Return a const sub-block corresponding to the specified type.
static const direction nCols
Definition: MatrixSpace.H:69
static const direction mRows
Definition: MatrixSpace.H:68
void operator=(const Foam::zero)
Assignment to zero.
Definition: MatrixSpaceI.H:445
Templated vector space.
Definition: VectorSpace.H:85
friend Ostream & operator(Ostream &, const VectorSpace< Form, Cmpt, Ncmpts > &)
Creates a single block of cells from point coordinates, numbers of cells in each direction and an exp...
Definition: block.H:66
Abstract template class to provide the transpose form of a form.
Definition: products.H:59
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:50
Namespace for OpenFOAM.
uint8_t direction
Definition: direction.H:45