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