DUNE-FEM (unstable)

fmatrix.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5#ifndef DUNE_FMATRIX_HH
6#define DUNE_FMATRIX_HH
7
8#include <cmath>
9#include <cstddef>
10#include <iostream>
11#include <algorithm>
12#include <initializer_list>
13#include <type_traits>
14
22#include <dune/common/matrixconcepts.hh>
23
24namespace Dune
25{
26
27 namespace Impl
28 {
29
30 template<class M>
31 class ColumnVectorView
32 {
33 public:
34
35 using value_type = typename M::value_type;
36 using size_type = typename M::size_type;
37
38 constexpr ColumnVectorView(M& matrix, size_type col) :
39 matrix_(matrix),
40 col_(col)
41 {}
42
43 constexpr size_type N () const {
44 return matrix_.N();
45 }
46
47 template<class M_ = M,
48 std::enable_if_t<std::is_same_v<M_,M> and not std::is_const_v<M_>, int> = 0>
49 constexpr value_type& operator[] (size_type row) {
50 return matrix_[row][col_];
51 }
52
53 constexpr const value_type& operator[] (size_type row) const {
54 return matrix_[row][col_];
55 }
56
57 protected:
58 M& matrix_;
59 const size_type col_;
60 };
61
62 }
63
64 template<typename M>
65 struct FieldTraits< Impl::ColumnVectorView<M> >
66 {
67 using field_type = typename FieldTraits<M>::field_type;
68 using real_type = typename FieldTraits<M>::real_type;
69 };
70
82 template< class K, int ROWS, int COLS = ROWS > class FieldMatrix;
83
84
85 template< class K, int ROWS, int COLS >
86 struct DenseMatVecTraits< FieldMatrix<K,ROWS,COLS> >
87 {
88 typedef FieldMatrix<K,ROWS,COLS> derived_type;
89
90 // each row is implemented by a field vector
91 typedef FieldVector<K,COLS> row_type;
92
93 typedef row_type &row_reference;
94 typedef const row_type &const_row_reference;
95
96 typedef std::array<row_type,ROWS> container_type;
97 typedef K value_type;
98 typedef typename container_type::size_type size_type;
99 };
100
101 template< class K, int ROWS, int COLS >
102 struct FieldTraits< FieldMatrix<K,ROWS,COLS> >
103 {
104 typedef typename FieldTraits<K>::field_type field_type;
105 typedef typename FieldTraits<K>::real_type real_type;
106 };
107
108
119 template<class M, int ROWS, int COLS>
121 : std::true_type {};
122
123 template<class K, int ROWS, int COLS>
124 struct IsFieldMatrixShapeCorrect<FieldMatrix<K,ROWS,COLS>,ROWS,COLS>
125 : std::true_type {};
126
127 template<class K, int ROWS, int COLS, int ROWS1, int COLS1>
128 struct IsFieldMatrixShapeCorrect<FieldMatrix<K,ROWS1,COLS1>,ROWS,COLS>
129 : std::false_type {};
130
131
140 template<class K, int ROWS, int COLS>
141 class FieldMatrix : public DenseMatrix< FieldMatrix<K,ROWS,COLS> >
142 {
143 template<class,int,int> friend class FieldMatrix;
145
147 std::array< FieldVector<K,COLS>, ROWS > _data;
148
149 public:
150
152 static constexpr std::integral_constant<int, ROWS> rows = {};
153
155 static constexpr std::integral_constant<int, COLS> cols = {};
156
158 using size_type = typename Base::size_type;
159
161 using value_type = typename Base::value_type;
162
165
168
170 using row_type = typename Base::row_type;
171
174
177
178 public:
179
182
184 constexpr FieldMatrix ()
185 noexcept(std::is_nothrow_default_constructible_v<K>)
186 : _data{}
187 {}
188
190 constexpr FieldMatrix (std::initializer_list<Dune::FieldVector<K, cols> > const &l)
191 : _data{}
192 {
193 DUNE_ASSERT_BOUNDS(l.size() == rows);
194 for (size_type i = 0; i < rows; ++i)
195 _data[i] = std::data(l)[i];
196 }
197
199 template <class OtherK, int otherRows, int otherCols>
200 requires (otherRows != ROWS || otherCols != COLS)
202
204 template <class OtherMatrix>
205 requires (HasDenseMatrixAssigner<FieldMatrix, OtherMatrix>::value)
206 constexpr FieldMatrix (const OtherMatrix& rhs)
207 : _data{}
208 {
210 }
211
213
215 template <class OtherK, int otherRows, int otherCols>
216 requires (otherRows != ROWS || otherCols != COLS)
217 constexpr FieldMatrix& operator= (const FieldMatrix<OtherK, otherRows, otherCols>&) = delete;
218
220 using Base::operator=;
221
224 {
226 for( int i = 0; i < ROWS; ++i )
227 for( int j = 0; j < COLS; ++j )
228 AT[j][i] = (*this)[i][j];
229 return AT;
230 }
231
232
235
237 template <class OtherK>
238 friend constexpr auto operator+ (const FieldMatrix& matrixA,
239 const FieldMatrix<OtherK,ROWS,COLS>& matrixB)
240 {
242 for (size_type i = 0; i < ROWS; ++i)
243 for (size_type j = 0; j < COLS; ++j)
244 result[i][j] = matrixA[i][j] + matrixB[i][j];
245 return result;
246 }
247
249 template <Concept::Number S>
250 [[deprecated("Please use 1x1 FieldMatrix objects like matrices, not like scalars!")]]
251 friend constexpr auto operator+ (const FieldMatrix& a, const S& b) noexcept
252 requires(ROWS*COLS == 1)
253 {
254 using ResultValueType = typename PromotionTraits<K,S>::PromotedType;
255 return FieldMatrix<ResultValueType,1,1>{a[0][0] + b};
256 }
257
259 template <Concept::Number S>
260 [[deprecated("Please use 1x1 FieldMatrix objects like matrices, not like scalars!")]]
261 friend constexpr auto operator+ (const S& a, const FieldMatrix& b) noexcept
262 requires(ROWS*COLS == 1)
263 {
264 using ResultValueType = typename PromotionTraits<K,S>::PromotedType;
265 return FieldMatrix<ResultValueType,1,1>{a + b[0][0]};
266 }
267
269 template <Concept::Number S>
270 [[deprecated("Please use 1x1 FieldMatrix objects like matrices, not like scalars!")]]
271 constexpr FieldMatrix& operator+= (const S& scalar)
272 requires(ROWS*COLS == 1)
273 {
274 _data[0][0] += scalar;
275 return *this;
276 }
277
278 using Base::operator+=;
279
281 template <class OtherK>
282 friend constexpr auto operator- (const FieldMatrix& matrixA,
283 const FieldMatrix<OtherK,ROWS,COLS>& matrixB)
284 {
286 for (size_type i = 0; i < ROWS; ++i)
287 for (size_type j = 0; j < COLS; ++j)
288 result[i][j] = matrixA[i][j] - matrixB[i][j];
289 return result;
290 }
291
293 template<Concept::Number S>
294 [[deprecated("Please use 1x1 FieldMatrix objects like matrices, not like scalars!")]]
295 friend constexpr auto operator- (const FieldMatrix& a, const S& b) noexcept
296 requires(ROWS*COLS == 1)
297 {
298 using ResultValueType = typename PromotionTraits<K,S>::PromotedType;
299 return FieldMatrix<ResultValueType,1,1>{a[0][0] - b};
300 }
301
303 template<Concept::Number S>
304 [[deprecated("Please use 1x1 FieldMatrix objects like matrices, not like scalars!")]]
305 friend constexpr auto operator- (const S& a, const FieldMatrix& b) noexcept
306 requires(ROWS*COLS == 1)
307 {
308 using ResultValueType = typename PromotionTraits<K,S>::PromotedType;
309 return FieldMatrix<ResultValueType,1,1>{a - b[0][0]};
310 }
311
313 template <Concept::Number S>
314 [[deprecated("Please use 1x1 FieldMatrix objects like matrices, not like scalars!")]]
315 constexpr FieldMatrix& operator-= (const S& scalar)
316 requires(ROWS*COLS == 1)
317 {
318 _data[0][0] -= scalar;
319 return *this;
320 }
321
322 using Base::operator-=;
323
325 template <Concept::Number S>
326 friend constexpr auto operator* (const FieldMatrix& matrix, const S& scalar)
327 {
329 for (size_type i = 0; i < ROWS; ++i)
330 for (size_type j = 0; j < COLS; ++j)
331 result[i][j] = matrix[i][j] * scalar;
332 return result;
333 }
334
336 template <Concept::Number S>
337 friend constexpr auto operator* (const S& scalar, const FieldMatrix& matrix)
338 {
340 for (size_type i = 0; i < ROWS; ++i)
341 for (size_type j = 0; j < COLS; ++j)
342 result[i][j] = scalar * matrix[i][j];
343 return result;
344 }
345
354 template <Concept::Number S>
355 constexpr FieldMatrix& operator*= (const S& scalar)
356 requires(ROWS*COLS == 1)
357 {
358 _data[0][0] *= scalar;
359 return *this;
360 }
361
362 using Base::operator*=;
363
365 template <Concept::Number S>
366 friend constexpr auto operator/ (const FieldMatrix& matrix, const S& scalar)
367 {
369 for (size_type i = 0; i < ROWS; ++i)
370 for (size_type j = 0; j < COLS; ++j)
371 result[i][j] = matrix[i][j] / scalar;
372 return result;
373 }
374
376 template<Concept::Number S>
377 [[deprecated("Please use 1x1 FieldMatrix objects like matrices, not like scalars!")]]
378 friend constexpr FieldMatrix operator/ (const S& a, const FieldMatrix& b) noexcept
379 requires(ROWS*COLS == 1)
380 {
381 return FieldMatrix{a / b[0][0]};
382 }
383
392 template <Concept::Number S>
393 constexpr FieldMatrix& operator/= (const S& scalar)
394 requires(ROWS*COLS == 1)
395 {
396 _data[0][0] /= scalar;
397 return *this;
398 }
399
400 using Base::operator/=;
401
403
404
407
409 template <class OtherK, int otherCols>
410 friend constexpr auto operator* (const FieldMatrix& matrixA,
412 {
414
415 for (size_type i = 0; i < matrixA.mat_rows(); ++i)
416 for (size_type j = 0; j < matrixB.mat_cols(); ++j)
417 {
418 result[i][j] = 0;
419 for (size_type k = 0; k < matrixA.mat_cols(); ++k)
420 result[i][j] += matrixA[i][k] * matrixB[k][j];
421 }
422
423 return result;
424 }
425
432 template <class OtherMatrix>
433 requires (Impl::IsStaticSizeMatrix_v<OtherMatrix> and not Impl::IsFieldMatrix_v<OtherMatrix>)
434 friend constexpr auto operator* (const FieldMatrix& matrixA,
435 const OtherMatrix& matrixB)
436 {
437 using Field = typename PromotionTraits<K, typename OtherMatrix::field_type>::PromotedType;
439 for (size_type j = 0; j < rows; ++j)
440 matrixB.mtv(matrixA[j], result[j]);
441 return result;
442 }
443
450 template <class OtherMatrix>
451 requires (Impl::IsStaticSizeMatrix_v<OtherMatrix> and not Impl::IsFieldMatrix_v<OtherMatrix>)
452 friend constexpr auto operator* (const OtherMatrix& matrixA,
453 const FieldMatrix& matrixB)
454 {
455 using Field = typename PromotionTraits<K, typename OtherMatrix::field_type>::PromotedType;
457 for (size_type j = 0; j < cols; ++j)
458 {
459 auto B_j = Impl::ColumnVectorView(matrixB, j);
460 auto result_j = Impl::ColumnVectorView(result, j);
461 matrixA.mv(B_j, result_j);
462 }
463 return result;
464 }
465
467 template<int l>
469 {
470 return M * (*this);
471 }
472
474
476 template <int r, int c>
478 {
479 static_assert(r == c, "Cannot rightmultiply with non-square matrix");
480 static_assert(r == cols, "Size mismatch");
482
483 for (size_type i=0; i<rows; i++)
484 for (size_type j=0; j<cols; j++) {
485 (*this)[i][j] = 0;
486 for (size_type k=0; k<cols; k++)
487 (*this)[i][j] += C[i][k]*M[k][j];
488 }
489 return *this;
490 }
491
493 template<int l>
495 {
496 return (*this) * M;
497 }
498
500
501
504
505 // internal: return the number of rows
506 static constexpr size_type mat_rows() { return ROWS; }
507
508 // internal: return the number of columns
509 static constexpr size_type mat_cols() { return COLS; }
510
512
513
516
517 // internal: return a reference to the ith row
518 constexpr row_reference mat_access (size_type i)
519 {
520 DUNE_ASSERT_BOUNDS(i < ROWS);
521 return _data[i];
522 }
523
524 // internal: return a const reference to the ith row
525 constexpr const_row_reference mat_access (size_type i) const
526 {
527 DUNE_ASSERT_BOUNDS(i < ROWS);
528 return _data[i];
529 }
530
532 [[deprecated("Please use 1x1 FieldMatrix objects like matrices, not like scalars!")]]
533 constexpr operator const_reference () const noexcept
534 requires(ROWS*COLS == 1)
535 {
536 return _data[0][0];
537 }
538
540 [[deprecated("Please use 1x1 FieldMatrix objects like matrices, not like scalars!")]]
541 constexpr operator reference () noexcept
542 requires(ROWS*COLS == 1)
543 {
544 return _data[0][0];
545 }
546
548
549
552
554 template<Concept::Number S>
555 [[deprecated("Please use 1x1 FieldMatrix objects like matrices, not like scalars!")]]
556 friend constexpr bool operator== (const FieldMatrix& a, const S& b) noexcept
557 requires(ROWS*COLS == 1)
558 {
559 return a._data[0] == b;
560 }
561
563 template<Concept::Number S>
564 [[deprecated("Please use 1x1 FieldMatrix objects like matrices, not like scalars!")]]
565 friend constexpr bool operator== (const S& a, const FieldMatrix& b) noexcept
566 requires(ROWS*COLS == 1)
567 {
568 return a == b._data[0];
569 }
570
572 template<class OtherK>
574 friend constexpr auto operator<=> (const FieldMatrix& a, const FieldMatrix<OtherK,ROWS,COLS>& b) noexcept
575 {
576#if __cpp_lib_three_way_comparison
577 return a._data <=> b._data;
578#else
579 return Std::lexicographical_compare_three_way(a.begin(), a.end(), b.begin(), b.end());
580#endif
581 }
582
584 template<Concept::Number S>
585 [[deprecated("Please use 1x1 FieldMatrix objects like matrices, not like scalars!")]]
586 friend constexpr auto operator<=> (const FieldMatrix& a, const S& b) noexcept
587 requires(ROWS*COLS == 1)
588 {
589 return a._data[0] <=> b;
590 }
591
593 template<Concept::Number S>
594 [[deprecated("Please use 1x1 FieldMatrix objects like matrices, not like scalars!")]]
595 friend constexpr auto operator<=> (const S& a, const FieldMatrix& b) noexcept
596 requires(ROWS*COLS == 1)
597 {
598 return a <=> b._data[0];
599 }
600
602 };
603
611 template<typename K>
612 std::ostream& operator<< (std::ostream& s, const FieldMatrix<K,1,1>& a)
613 {
614 s << a[0][0];
615 return s;
616 }
617
618 namespace FMatrixHelp {
619
621 template <typename K>
622 static constexpr K invertMatrix (const FieldMatrix<K,1,1> &matrix, FieldMatrix<K,1,1> &inverse)
623 {
624 using real_type = typename FieldTraits<K>::real_type;
625 inverse[0][0] = real_type(1.0)/matrix[0][0];
626 return matrix[0][0];
627 }
628
630 template <typename K>
631 static constexpr K invertMatrix_retTransposed (const FieldMatrix<K,1,1> &matrix, FieldMatrix<K,1,1> &inverse)
632 {
633 return invertMatrix(matrix,inverse);
634 }
635
636
638 template <typename K>
639 static constexpr K invertMatrix (const FieldMatrix<K,2,2> &matrix, FieldMatrix<K,2,2> &inverse)
640 {
641 using real_type = typename FieldTraits<K>::real_type;
642 // code generated by maple
643 K det = (matrix[0][0]*matrix[1][1] - matrix[0][1]*matrix[1][0]);
644 K det_1 = real_type(1.0)/det;
645 inverse[0][0] = matrix[1][1] * det_1;
646 inverse[0][1] = - matrix[0][1] * det_1;
647 inverse[1][0] = - matrix[1][0] * det_1;
648 inverse[1][1] = matrix[0][0] * det_1;
649 return det;
650 }
651
654 template <typename K>
655 static constexpr K invertMatrix_retTransposed (const FieldMatrix<K,2,2> &matrix, FieldMatrix<K,2,2> &inverse)
656 {
657 using real_type = typename FieldTraits<K>::real_type;
658 // code generated by maple
659 K det = (matrix[0][0]*matrix[1][1] - matrix[0][1]*matrix[1][0]);
660 K det_1 = real_type(1.0)/det;
661 inverse[0][0] = matrix[1][1] * det_1;
662 inverse[1][0] = - matrix[0][1] * det_1;
663 inverse[0][1] = - matrix[1][0] * det_1;
664 inverse[1][1] = matrix[0][0] * det_1;
665 return det;
666 }
667
669 template <typename K>
670 static constexpr K invertMatrix (const FieldMatrix<K,3,3> &matrix, FieldMatrix<K,3,3> &inverse)
671 {
672 using real_type = typename FieldTraits<K>::real_type;
673 // code generated by maple
674 K t4 = matrix[0][0] * matrix[1][1];
675 K t6 = matrix[0][0] * matrix[1][2];
676 K t8 = matrix[0][1] * matrix[1][0];
677 K t10 = matrix[0][2] * matrix[1][0];
678 K t12 = matrix[0][1] * matrix[2][0];
679 K t14 = matrix[0][2] * matrix[2][0];
680
681 K det = (t4*matrix[2][2]-t6*matrix[2][1]-t8*matrix[2][2]+
682 t10*matrix[2][1]+t12*matrix[1][2]-t14*matrix[1][1]);
683 K t17 = real_type(1.0)/det;
684
685 inverse[0][0] = (matrix[1][1] * matrix[2][2] - matrix[1][2] * matrix[2][1])*t17;
686 inverse[0][1] = -(matrix[0][1] * matrix[2][2] - matrix[0][2] * matrix[2][1])*t17;
687 inverse[0][2] = (matrix[0][1] * matrix[1][2] - matrix[0][2] * matrix[1][1])*t17;
688 inverse[1][0] = -(matrix[1][0] * matrix[2][2] - matrix[1][2] * matrix[2][0])*t17;
689 inverse[1][1] = (matrix[0][0] * matrix[2][2] - t14) * t17;
690 inverse[1][2] = -(t6-t10) * t17;
691 inverse[2][0] = (matrix[1][0] * matrix[2][1] - matrix[1][1] * matrix[2][0]) * t17;
692 inverse[2][1] = -(matrix[0][0] * matrix[2][1] - t12) * t17;
693 inverse[2][2] = (t4-t8) * t17;
694
695 return det;
696 }
697
699 template <typename K>
700 static constexpr K invertMatrix_retTransposed (const FieldMatrix<K,3,3> &matrix, FieldMatrix<K,3,3> &inverse)
701 {
702 using real_type = typename FieldTraits<K>::real_type;
703 // code generated by maple
704 K t4 = matrix[0][0] * matrix[1][1];
705 K t6 = matrix[0][0] * matrix[1][2];
706 K t8 = matrix[0][1] * matrix[1][0];
707 K t10 = matrix[0][2] * matrix[1][0];
708 K t12 = matrix[0][1] * matrix[2][0];
709 K t14 = matrix[0][2] * matrix[2][0];
710
711 K det = (t4*matrix[2][2]-t6*matrix[2][1]-t8*matrix[2][2]+
712 t10*matrix[2][1]+t12*matrix[1][2]-t14*matrix[1][1]);
713 K t17 = real_type(1.0)/det;
714
715 inverse[0][0] = (matrix[1][1] * matrix[2][2] - matrix[1][2] * matrix[2][1])*t17;
716 inverse[1][0] = -(matrix[0][1] * matrix[2][2] - matrix[0][2] * matrix[2][1])*t17;
717 inverse[2][0] = (matrix[0][1] * matrix[1][2] - matrix[0][2] * matrix[1][1])*t17;
718 inverse[0][1] = -(matrix[1][0] * matrix[2][2] - matrix[1][2] * matrix[2][0])*t17;
719 inverse[1][1] = (matrix[0][0] * matrix[2][2] - t14) * t17;
720 inverse[2][1] = -(t6-t10) * t17;
721 inverse[0][2] = (matrix[1][0] * matrix[2][1] - matrix[1][1] * matrix[2][0]) * t17;
722 inverse[1][2] = -(matrix[0][0] * matrix[2][1] - t12) * t17;
723 inverse[2][2] = (t4-t8) * t17;
724
725 return det;
726 }
727
729 template< class K, int m, int n, int p >
730 static constexpr void multMatrix ( const FieldMatrix< K, m, n > &A,
731 const FieldMatrix< K, n, p > &B,
733 {
734 typedef typename FieldMatrix< K, m, p > :: size_type size_type;
735
736 for( size_type i = 0; i < m; ++i )
737 {
738 for( size_type j = 0; j < p; ++j )
739 {
740 ret[ i ][ j ] = K( 0 );
741 for( size_type k = 0; k < n; ++k )
742 ret[ i ][ j ] += A[ i ][ k ] * B[ k ][ j ];
743 }
744 }
745 }
746
748 template <typename K, int rows, int cols>
750 {
751 typedef typename FieldMatrix<K,rows,cols>::size_type size_type;
752
753 for(size_type i=0; i<cols; i++)
754 for(size_type j=0; j<cols; j++)
755 {
756 ret[i][j]=0.0;
757 for(size_type k=0; k<rows; k++)
758 ret[i][j]+=matrix[k][i]*matrix[k][j];
759 }
760 }
761
762 using Dune::DenseMatrixHelp::multAssign;
763
765 template <typename K, int rows, int cols>
766 static constexpr void multAssignTransposed( const FieldMatrix<K,rows,cols> &matrix, const FieldVector<K,rows> & x, FieldVector<K,cols> & ret)
767 {
768 typedef typename FieldMatrix<K,rows,cols>::size_type size_type;
769
770 for(size_type i=0; i<cols; ++i)
771 {
772 ret[i] = 0.0;
773 for(size_type j=0; j<rows; ++j)
774 ret[i] += matrix[j][i]*x[j];
775 }
776 }
777
779 template <typename K, int rows, int cols>
780 static constexpr FieldVector<K,rows> mult(const FieldMatrix<K,rows,cols> &matrix, const FieldVector<K,cols> & x)
781 {
783 multAssign(matrix,x,ret);
784 return ret;
785 }
786
788 template <typename K, int rows, int cols>
790 {
792 multAssignTransposed( matrix, x, ret );
793 return ret;
794 }
795
796 } // end namespace FMatrixHelp
797
800} // end namespace
801
802#include "fmatrixev.hh"
803#endif
Macro for wrapping boundary checks.
A dense n x m matrix.
Definition: densematrix.hh:145
constexpr size_type M() const
number of columns
Definition: densematrix.hh:708
FieldMatrix< K, ROWS, COLS > & rightmultiply(const DenseMatrix< M2 > &M)
Multiplies M from the right to this matrix.
Definition: densematrix.hh:650
Traits::value_type value_type
export the type representing the field
Definition: densematrix.hh:162
constexpr Iterator end()
end iterator
Definition: densematrix.hh:227
constexpr derived_type operator-() const
Matrix negation.
Definition: densematrix.hh:303
constexpr void mtv(const X &x, Y &y) const
y = A^T x
Definition: densematrix.hh:392
Traits::row_type row_type
The type used to represent a row (must fulfill the Dune::DenseVector interface)
Definition: densematrix.hh:174
Traits::size_type size_type
The type used for the index access and size operation.
Definition: densematrix.hh:171
Traits::const_row_reference const_row_reference
The type used to represent a reference to a constant row (usually const row_type &)
Definition: densematrix.hh:180
Traits::row_reference row_reference
The type used to represent a reference to a row (usually row_type &)
Definition: densematrix.hh:177
constexpr Iterator begin()
begin iterator
Definition: densematrix.hh:221
A dense n x m matrix.
Definition: fmatrix.hh:142
typename Base::size_type size_type
The type used for the index access and size operation.
Definition: fmatrix.hh:158
constexpr FieldMatrix & operator/=(const S &scalar)
division by scalar
Definition: fmatrix.hh:393
constexpr FieldMatrix< K, rows, l > rightmultiplyany(const FieldMatrix< K, cols, l > &M) const
Multiplies M from the right to this matrix, this matrix is not modified.
Definition: fmatrix.hh:494
constexpr FieldMatrix() noexcept(std::is_nothrow_default_constructible_v< K >)
Default constructor, making value-initialized matrix with all components set to zero.
Definition: fmatrix.hh:184
static constexpr std::integral_constant< int, ROWS > rows
The number of rows.
Definition: fmatrix.hh:152
static constexpr std::integral_constant< int, COLS > cols
The number of columns.
Definition: fmatrix.hh:155
constexpr FieldMatrix & rightmultiply(const FieldMatrix< K, r, c > &M)
Multiplies M from the right to this matrix.
Definition: fmatrix.hh:477
constexpr FieldMatrix & operator+=(const S &scalar)
add scalar
Definition: fmatrix.hh:271
constexpr FieldMatrix & operator-=(const S &scalar)
subtract scalar
Definition: fmatrix.hh:315
friend constexpr auto operator*(const FieldMatrix &matrix, const S &scalar)
vector space multiplication with scalar
Definition: fmatrix.hh:326
constexpr FieldMatrix(std::initializer_list< Dune::FieldVector< K, cols > > const &l)
Constructor initializing the matrix from a nested list of values.
Definition: fmatrix.hh:190
friend constexpr auto operator<=>(const FieldMatrix &a, const FieldMatrix< OtherK, ROWS, COLS > &b) noexcept
three-way comparison of FieldMatrix
Definition: fmatrix.hh:574
typename Base::row_type row_type
The type the rows of the matrix are represented by.
Definition: fmatrix.hh:170
friend constexpr auto operator+(const FieldMatrix &matrixA, const FieldMatrix< OtherK, ROWS, COLS > &matrixB)
vector space addition
Definition: fmatrix.hh:238
typename Base::const_row_reference const_row_reference
The type used for const references to the rows of the matrix.
Definition: fmatrix.hh:176
constexpr FieldMatrix & operator*=(const S &scalar)
multiplication with scalar
Definition: fmatrix.hh:355
friend constexpr bool operator==(const FieldMatrix &a, const S &b) noexcept
comparing FieldMatrix<1,1> with scalar for equality
Definition: fmatrix.hh:556
typename Base::value_type value_type
The type of the elements stored in the matrix.
Definition: fmatrix.hh:161
const value_type & const_reference
The type used for const references to the matrix entries.
Definition: fmatrix.hh:167
constexpr FieldMatrix< K, COLS, ROWS > transposed() const
Return transposed of the matrix as FieldMatrix.
Definition: fmatrix.hh:223
friend constexpr auto operator/(const FieldMatrix &matrix, const S &scalar)
vector space division by scalar
Definition: fmatrix.hh:366
constexpr FieldMatrix< K, l, cols > leftmultiplyany(const FieldMatrix< K, l, rows > &M) const
Multiplies M from the left to this matrix, this matrix is not modified.
Definition: fmatrix.hh:468
typename Base::row_reference row_reference
The type used for references to the rows of the matrix.
Definition: fmatrix.hh:173
value_type & reference
The type used for references to the matrix entries.
Definition: fmatrix.hh:164
vector space out of a tensor product of fields.
Definition: fvector.hh:97
The concept std::three_way_comparable_with specifies that the three way comparison operator <=> on (p...
Definition: compare.hh:100
Implements a matrix constructed from a given type representing a field and a compile-time given numbe...
A few common exception classes.
static constexpr void multAssignTransposed(const FieldMatrix< K, rows, cols > &matrix, const FieldVector< K, rows > &x, FieldVector< K, cols > &ret)
calculates ret = matrix^T * x
Definition: fmatrix.hh:766
static constexpr FieldVector< K, cols > multTransposed(const FieldMatrix< K, rows, cols > &matrix, const FieldVector< K, rows > &x)
calculates ret = matrix^T * x
Definition: fmatrix.hh:789
static constexpr K invertMatrix_retTransposed(const FieldMatrix< K, 1, 1 > &matrix, FieldMatrix< K, 1, 1 > &inverse)
invert scalar without changing the original matrix
Definition: fmatrix.hh:631
static constexpr void multTransposedMatrix(const FieldMatrix< K, rows, cols > &matrix, FieldMatrix< K, cols, cols > &ret)
calculates ret= A_t*A
Definition: fmatrix.hh:749
static constexpr void multMatrix(const FieldMatrix< K, m, n > &A, const FieldMatrix< K, n, p > &B, FieldMatrix< K, m, p > &ret)
calculates ret = A * B
Definition: fmatrix.hh:730
static constexpr K invertMatrix(const FieldMatrix< K, 1, 1 > &matrix, FieldMatrix< K, 1, 1 > &inverse)
invert scalar without changing the original matrix
Definition: fmatrix.hh:622
static constexpr FieldVector< K, rows > mult(const FieldMatrix< K, rows, cols > &matrix, const FieldVector< K, cols > &x)
calculates ret = matrix * x
Definition: fmatrix.hh:780
Eigenvalue computations for the FieldMatrix class.
Implements a vector constructed from a given type representing a field and a compile-time given size.
#define DUNE_ASSERT_BOUNDS(cond)
If DUNE_CHECK_BOUNDS is defined: check if condition cond holds; otherwise, do nothing.
Definition: boundschecking.hh:30
std::ostream & operator<<(std::ostream &s, const FieldMatrix< K, 1, 1 > &a)
Sends the matrix to an output stream.
Definition: fmatrix.hh:612
constexpr auto lexicographical_compare_three_way(I1 f1, I1 l1, I2 f2, I2 l2, Cmp comp={}) -> decltype(comp(*f1, *f2))
Lexicographically compares two ranges [first1, last1) and [first2, last2) using three-way comparison ...
Definition: algorithm.hh:37
Dune namespace
Definition: alignedallocator.hh:13
STL namespace.
Various precision settings for calculations with FieldMatrix and FieldVector.
Compute type of the result of an arithmetic operation involving two different number types.
you have to specialize this structure for any type that should be assignable to a DenseMatrix
Definition: densematrix.hh:61
TMP to check the shape of a DenseMatrix statically, if possible.
Definition: fmatrix.hh:121
Traits for type conversions and type information.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Mar 31, 22:41, 2026)