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