MatrixBlock.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-2020 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::MatrixBlock
26 
27 Description
28  A templated block of an (m x n) matrix of type <MatrixType>.
29 
30  Foam::ConstMatrixBlock: block of a const matrix
31  Foam::MatrixBlock: block of a non-const matrix
32 
33  The block may be assigned to a block of another matrix or to a VectorSpace
34  or MatrixSpace e.g. \c tensor. Conversion of a column block to a \c
35  Field<T> is also provide.
36 
37 SourceFiles
38  MatrixBlock.C
39  MatrixBlockI.H
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #ifndef MatrixBlock_H
44 #define MatrixBlock_H
45 
46 #include "Matrix.H"
47 #include "MatrixSpace.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 /*---------------------------------------------------------------------------*\
55  Class ConstMatrixBlock Declaration
56 \*---------------------------------------------------------------------------*/
57 
58 template<class MatrixType>
59 class ConstMatrixBlock
60 {
61  // Private Data
62 
63  //- Const reference to the parent matrix
64  const MatrixType& matrix_;
65 
66  // Block size
67  const label mRows_;
68  const label nCols_;
69 
70  // Block location in parent matrix
71  const label rowStart_;
72  const label colStart_;
73 
74 public:
75 
76  typedef typename MatrixType::cmptType cmptType;
77 
78  // Constructors
79 
80  //- Construct block for matrix, size and location
81  inline ConstMatrixBlock
82  (
83  const MatrixType& matrix,
84  const label m,
85  const label n,
86  const label mStart,
87  const label nStart
88  );
89 
90 
91  // Member Functions
92 
93  //- Return the number of rows in the block
94  inline label m() const;
95 
96  //- Return the number of columns in the block
97  inline label n() const;
98 
99  //- (i, j) const element access operator
100  inline const cmptType& operator()
101  (
102  const label i,
103  const label j
104  ) const;
105 
106  //- Convert a column of a matrix to a Field
107  operator Field<cmptType>() const;
108 };
109 
110 
111 /*---------------------------------------------------------------------------*\
112  Class MatrixBlock Declaration
113 \*---------------------------------------------------------------------------*/
114 
115 template<class MatrixType>
116 class MatrixBlock
117 {
118  // Private Data
119 
120  //- Reference to the parent matrix
121  MatrixType& matrix_;
122 
123  // Block size
124  const label mRows_;
125  const label nCols_;
126 
127  // Block location in parent matrix
128  const label rowStart_;
129  const label colStart_;
130 
131 public:
133  typedef typename MatrixType::cmptType cmptType;
134 
135  // Constructors
136 
137  //- Construct block for matrix, size and location
138  inline MatrixBlock
139  (
140  MatrixType& matrix,
141  const label m,
142  const label n,
143  const label mStart,
144  const label nStart
145  );
146 
147 
148  // Member Functions
149 
150  //- Return the number of rows in the block
151  inline label m() const;
152 
153  //- Return the number of columns in the block
154  inline label n() const;
155 
156  //- (i, j) const element access operator
157  inline const cmptType& operator()
158  (
159  const label i,
160  const label j
161  ) const;
162 
163  //- (i, j) element access operator
164  inline cmptType& operator()(const label i, const label j);
165 
166  //- Convert a column of a matrix to a Field
167  operator Field<cmptType>() const;
168 
169 
170  // Member Operators
171 
172  //- Assignment to a compatible matrix
173  template<class Form>
174  void operator=(const Matrix<Form, cmptType>&);
175 
176  //- Assignment to a compatible const block
177  void operator=(const ConstMatrixBlock<MatrixType>&);
178 
179  //- Assignment to a compatible block
180  void operator=(const MatrixBlock<MatrixType>&);
181 
182  //- Assignment to a compatible const block
183  template<class MatrixType2>
184  void operator=(const ConstMatrixBlock<MatrixType2>&);
185 
186  //- Assignment to a compatible block
187  template<class MatrixType2>
188  void operator=(const MatrixBlock<MatrixType2>&);
189 
190  //- Assignment to a compatible MatrixSpace
191  template<class MSForm, direction Nrows, direction Ncols>
192  void operator=(const MatrixSpace<MSForm, cmptType, Nrows, Ncols>&);
193 
194  //- Assignment to a compatible MatrixSpace block
195  template
196  <
197  template<class, direction, direction> class Block,
198  class SubTensor,
199  direction BRowStart,
200  direction BColStart
201  >
202  void operator=(const Block<SubTensor, BRowStart, BColStart>&);
203 
204  //- Assignment to a compatible VectorSpace (column-vector)
205  template<class VSForm, direction Ncmpts>
206  void operator=(const VectorSpace<VSForm, cmptType, Ncmpts>&);
207 
208  //- Assignment to a compatible VectorSpace (column-vector) block
209  template
210  <
211  template<class, direction> class Block,
212  class SubVector,
213  direction BStart
214  >
215  void operator=(const Block<SubVector, BStart>&);
216 
217  //- Assignment to a Field (column-vector)
218  void operator=(const Field<cmptType>&);
219 };
220 
221 
222 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
223 
224 } // End namespace Foam
225 
226 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
227 
228 #include "MatrixBlockI.H"
229 
230 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
231 
232 #ifdef NoRepository
233  #include "MatrixBlock.C"
234 #endif
235 
236 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
237 
238 #endif
239 
240 // ************************************************************************* //
label m() const
Return the number of rows in the block.
Definition: MatrixBlockI.H:93
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
uint8_t direction
Definition: direction.H:45
Templated vector space.
Definition: VectorSpace.H:53
A templated block of an (m x n) matrix of type <MatrixType>.
Definition: Matrix.H:71
Templated matrix space.
Definition: MatrixSpace.H:55
Pre-declare SubField and related Field type.
Definition: Field.H:56
const cmptType & operator()(const label i, const label j) const
(i, j) const element access operator
Definition: MatrixBlockI.H:125
ConstMatrixBlock(const MatrixType &matrix, const label m, const label n, const label mStart, const label nStart)
Construct block for matrix, size and location.
Definition: MatrixBlockI.H:30
A templated (m x n) matrix of objects of <T>.
label n() const
Return the number of columns in the block.
Definition: MatrixBlockI.H:100
MatrixType::cmptType cmptType
Definition: MatrixBlock.H:75
Namespace for OpenFOAM.