Dune Core Modules (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
21#include <dune/common/matrixconcepts.hh>
22
23namespace Dune
24{
25
26 namespace Impl
27 {
28
29 template<class M>
30 class ColumnVectorView
31 {
32 public:
33
34 using value_type = typename M::value_type;
35 using size_type = typename M::size_type;
36
37 constexpr ColumnVectorView(M& matrix, size_type col) :
38 matrix_(matrix),
39 col_(col)
40 {}
41
42 constexpr size_type N () const {
43 return matrix_.N();
44 }
45
46 template<class M_ = M,
47 std::enable_if_t<std::is_same_v<M_,M> and not std::is_const_v<M_>, int> = 0>
48 constexpr value_type& operator[] (size_type row) {
49 return matrix_[row][col_];
50 }
51
52 constexpr const value_type& operator[] (size_type row) const {
53 return matrix_[row][col_];
54 }
55
56 protected:
57 M& matrix_;
58 const size_type col_;
59 };
60
61 }
62
63 template<typename M>
64 struct FieldTraits< Impl::ColumnVectorView<M> >
65 {
66 using field_type = typename FieldTraits<M>::field_type;
67 using real_type = typename FieldTraits<M>::real_type;
68 };
69
81 template< class K, int ROWS, int COLS = ROWS > class FieldMatrix;
82
83
84 template< class K, int ROWS, int COLS >
85 struct DenseMatVecTraits< FieldMatrix<K,ROWS,COLS> >
86 {
87 typedef FieldMatrix<K,ROWS,COLS> derived_type;
88
89 // each row is implemented by a field vector
90 typedef FieldVector<K,COLS> row_type;
91
92 typedef row_type &row_reference;
93 typedef const row_type &const_row_reference;
94
95 typedef std::array<row_type,ROWS> container_type;
96 typedef K value_type;
97 typedef typename container_type::size_type size_type;
98 };
99
100 template< class K, int ROWS, int COLS >
101 struct FieldTraits< FieldMatrix<K,ROWS,COLS> >
102 {
103 typedef typename FieldTraits<K>::field_type field_type;
104 typedef typename FieldTraits<K>::real_type real_type;
105 };
106
115 template<class K, int ROWS, int COLS>
116 class FieldMatrix : public DenseMatrix< FieldMatrix<K,ROWS,COLS> >
117 {
118 std::array< FieldVector<K,COLS>, ROWS > _data;
120 public:
121
123 constexpr static int rows = ROWS;
125 constexpr static int cols = COLS;
126
127 typedef typename Base::size_type size_type;
128 typedef typename Base::row_type row_type;
129
130 typedef typename Base::row_reference row_reference;
132
133 //===== constructors
136 constexpr FieldMatrix() = default;
137
140 constexpr FieldMatrix(std::initializer_list<Dune::FieldVector<K, cols> > const &l) {
141 assert(l.size() == rows); // Actually, this is not needed any more!
142 for(std::size_t i=0; i<std::min<std::size_t>(ROWS, l.size()); ++i)
143 _data[i] = std::data(l)[i];
144 }
145
147 FieldMatrix(const FieldMatrix&) = default;
148
150 template <class T,
151 typename = std::enable_if_t<HasDenseMatrixAssigner<FieldMatrix, T>::value>>
152 FieldMatrix(T const& rhs)
153 {
154 *this = rhs;
155 }
156
157 using Base::operator=;
158
161
163 template<typename T>
165 {
166 _data = x._data;
167 return *this;
168 }
169
171 template <typename T, int rows, int cols>
173
176 {
178 for( int i = 0; i < ROWS; ++i )
179 for( int j = 0; j < COLS; ++j )
180 AT[j][i] = (*this)[i][j];
181 return AT;
182 }
183
185 template <class OtherScalar>
186 friend auto operator+ ( const FieldMatrix& matrixA,
188 {
190
191 for (size_type i = 0; i < ROWS; ++i)
192 for (size_type j = 0; j < COLS; ++j)
193 result[i][j] = matrixA[i][j] + matrixB[i][j];
194
195 return result;
196 }
197
199 template <class OtherScalar>
200 friend auto operator- ( const FieldMatrix& matrixA,
202 {
204
205 for (size_type i = 0; i < ROWS; ++i)
206 for (size_type j = 0; j < COLS; ++j)
207 result[i][j] = matrixA[i][j] - matrixB[i][j];
208
209 return result;
210 }
211
213 template <class Scalar,
214 std::enable_if_t<IsNumber<Scalar>::value, int> = 0>
215 friend auto operator* ( const FieldMatrix& matrix, Scalar scalar)
216 {
218
219 for (size_type i = 0; i < ROWS; ++i)
220 for (size_type j = 0; j < COLS; ++j)
221 result[i][j] = matrix[i][j] * scalar;
222
223 return result;
224 }
225
227 template <class Scalar,
228 std::enable_if_t<IsNumber<Scalar>::value, int> = 0>
229 friend auto operator* ( Scalar scalar, const FieldMatrix& matrix)
230 {
232
233 for (size_type i = 0; i < ROWS; ++i)
234 for (size_type j = 0; j < COLS; ++j)
235 result[i][j] = scalar * matrix[i][j];
236
237 return result;
238 }
239
241 template <class Scalar,
242 std::enable_if_t<IsNumber<Scalar>::value, int> = 0>
243 friend auto operator/ ( const FieldMatrix& matrix, Scalar scalar)
244 {
246
247 for (size_type i = 0; i < ROWS; ++i)
248 for (size_type j = 0; j < COLS; ++j)
249 result[i][j] = matrix[i][j] / scalar;
250
251 return result;
252 }
253
256 template <class OtherScalar, int otherCols>
257 friend auto operator* ( const FieldMatrix& matrixA,
259 {
261
262 for (size_type i = 0; i < matrixA.mat_rows(); ++i)
263 for (size_type j = 0; j < matrixB.mat_cols(); ++j)
264 {
265 result[i][j] = 0;
266 for (size_type k = 0; k < matrixA.mat_cols(); ++k)
267 result[i][j] += matrixA[i][k] * matrixB[k][j];
268 }
269
270 return result;
271 }
272
279 template <class OtherMatrix, std::enable_if_t<
280 Impl::IsStaticSizeMatrix_v<OtherMatrix>
281 and not Impl::IsFieldMatrix_v<OtherMatrix>
282 , int> = 0>
283 friend auto operator* ( const FieldMatrix& matrixA,
284 const OtherMatrix& matrixB)
285 {
286 using Field = typename PromotionTraits<K, typename OtherMatrix::field_type>::PromotedType;
288 for (std::size_t j=0; j<rows; ++j)
289 matrixB.mtv(matrixA[j], result[j]);
290 return result;
291 }
292
299 template <class OtherMatrix, std::enable_if_t<
300 Impl::IsStaticSizeMatrix_v<OtherMatrix>
301 and not Impl::IsFieldMatrix_v<OtherMatrix>
302 , int> = 0>
303 friend auto operator* ( const OtherMatrix& matrixA,
304 const FieldMatrix& matrixB)
305 {
306 using Field = typename PromotionTraits<K, typename OtherMatrix::field_type>::PromotedType;
308 for (std::size_t j=0; j<cols; ++j)
309 {
310 auto B_j = Impl::ColumnVectorView(matrixB, j);
311 auto result_j = Impl::ColumnVectorView(result, j);
312 matrixA.mv(B_j, result_j);
313 }
314 return result;
315 }
316
318 template<int l>
320 {
322
323 for (size_type i=0; i<l; i++) {
324 for (size_type j=0; j<cols; j++) {
325 C[i][j] = 0;
326 for (size_type k=0; k<rows; k++)
327 C[i][j] += M[i][k]*(*this)[k][j];
328 }
329 }
330 return C;
331 }
332
334
336 template <int r, int c>
338 {
339 static_assert(r == c, "Cannot rightmultiply with non-square matrix");
340 static_assert(r == cols, "Size mismatch");
342
343 for (size_type i=0; i<rows; i++)
344 for (size_type j=0; j<cols; j++) {
345 (*this)[i][j] = 0;
346 for (size_type k=0; k<cols; k++)
347 (*this)[i][j] += C[i][k]*M[k][j];
348 }
349 return *this;
350 }
351
353 template<int l>
355 {
357
358 for (size_type i=0; i<rows; i++) {
359 for (size_type j=0; j<l; j++) {
360 C[i][j] = 0;
361 for (size_type k=0; k<cols; k++)
362 C[i][j] += (*this)[i][k]*M[k][j];
363 }
364 }
365 return C;
366 }
367
368 // make this thing a matrix
369 static constexpr size_type mat_rows() { return ROWS; }
370 static constexpr size_type mat_cols() { return COLS; }
371
372 row_reference mat_access ( size_type i )
373 {
374 DUNE_ASSERT_BOUNDS(i < ROWS);
375 return _data[i];
376 }
377
378 const_row_reference mat_access ( size_type i ) const
379 {
380 DUNE_ASSERT_BOUNDS(i < ROWS);
381 return _data[i];
382 }
383 };
384
385#ifndef DOXYGEN // hide specialization
388 template<class K>
389 class FieldMatrix<K,1,1> : public DenseMatrix< FieldMatrix<K,1,1> >
390 {
391 FieldVector<K,1> _data;
392 typedef DenseMatrix< FieldMatrix<K,1,1> > Base;
393 public:
394 // standard constructor and everything is sufficient ...
395
396 //===== type definitions and constants
397
399 typedef typename Base::size_type size_type;
400
403 constexpr static int blocklevel = 1;
404
405 typedef typename Base::row_type row_type;
406
407 typedef typename Base::row_reference row_reference;
408 typedef typename Base::const_row_reference const_row_reference;
409
412 constexpr static int rows = 1;
415 constexpr static int cols = 1;
416
417 //===== constructors
420 constexpr FieldMatrix() = default;
421
424 FieldMatrix(std::initializer_list<Dune::FieldVector<K, 1>> const &l)
425 {
426 std::copy_n(l.begin(), std::min<std::size_t>(1, l.size()), &_data);
427 }
428
429 template <class T,
430 typename = std::enable_if_t<HasDenseMatrixAssigner<FieldMatrix, T>::value>>
431 FieldMatrix(T const& rhs)
432 {
433 *this = rhs;
434 }
435
436 using Base::operator=;
437
439 FieldMatrix<K, 1, 1> transposed() const
440 {
441 return *this;
442 }
443
445 template <class OtherScalar>
446 friend auto operator+ ( const FieldMatrix& matrixA,
447 const FieldMatrix<OtherScalar,1,1>& matrixB)
448 {
449 return FieldMatrix<typename PromotionTraits<K,OtherScalar>::PromotedType,1,1>{matrixA[0][0] + matrixB[0][0]};
450 }
451
453 template <class Scalar,
454 std::enable_if_t<IsNumber<Scalar>::value, int> = 0>
455 friend auto operator+ ( const FieldMatrix& matrix,
456 const Scalar& scalar)
457 {
458 return FieldMatrix<typename PromotionTraits<K,Scalar>::PromotedType,1,1>{matrix[0][0] + scalar};
459 }
460
462 template <class Scalar,
463 std::enable_if_t<IsNumber<Scalar>::value, int> = 0>
464 friend auto operator+ ( const Scalar& scalar,
465 const FieldMatrix& matrix)
466 {
467 return FieldMatrix<typename PromotionTraits<Scalar,K>::PromotedType,1,1>{scalar + matrix[0][0]};
468 }
469
471 template <class OtherScalar>
472 friend auto operator- ( const FieldMatrix& matrixA,
473 const FieldMatrix<OtherScalar,1,1>& matrixB)
474 {
475 return FieldMatrix<typename PromotionTraits<K,OtherScalar>::PromotedType,1,1>{matrixA[0][0] - matrixB[0][0]};
476 }
477
479 template <class Scalar,
480 std::enable_if_t<IsNumber<Scalar>::value, int> = 0>
481 friend auto operator- ( const FieldMatrix& matrix,
482 const Scalar& scalar)
483 {
484 return FieldMatrix<typename PromotionTraits<K,Scalar>::PromotedType,1,1>{matrix[0][0] - scalar};
485 }
486
488 template <class Scalar,
489 std::enable_if_t<IsNumber<Scalar>::value, int> = 0>
490 friend auto operator- ( const Scalar& scalar,
491 const FieldMatrix& matrix)
492 {
493 return FieldMatrix<typename PromotionTraits<Scalar,K>::PromotedType,1,1>{scalar - matrix[0][0]};
494 }
495
497 template <class Scalar,
498 std::enable_if_t<IsNumber<Scalar>::value, int> = 0>
499 friend auto operator* ( const FieldMatrix& matrix, Scalar scalar)
500 {
501 return FieldMatrix<typename PromotionTraits<K,Scalar>::PromotedType,1,1> {matrix[0][0] * scalar};
502 }
503
505 template <class Scalar,
506 std::enable_if_t<IsNumber<Scalar>::value, int> = 0>
507 friend auto operator* ( Scalar scalar, const FieldMatrix& matrix)
508 {
509 return FieldMatrix<typename PromotionTraits<K,Scalar>::PromotedType,1,1> {scalar * matrix[0][0]};
510 }
511
513 template <class Scalar,
514 std::enable_if_t<IsNumber<Scalar>::value, int> = 0>
515 friend auto operator/ ( const FieldMatrix& matrix, Scalar scalar)
516 {
517 return FieldMatrix<typename PromotionTraits<K,Scalar>::PromotedType,1,1> {matrix[0][0] / scalar};
518 }
519
520 //===== solve
521
524 template <class OtherScalar, int otherCols>
525 friend auto operator* ( const FieldMatrix& matrixA,
526 const FieldMatrix<OtherScalar, 1, otherCols>& matrixB)
527 {
528 FieldMatrix<typename PromotionTraits<K,OtherScalar>::PromotedType,1,otherCols> result;
529
530 for (size_type j = 0; j < matrixB.mat_cols(); ++j)
531 result[0][j] = matrixA[0][0] * matrixB[0][j];
532
533 return result;
534 }
535
542 template <class OtherMatrix, std::enable_if_t<
543 Impl::IsStaticSizeMatrix_v<OtherMatrix>
544 and not Impl::IsFieldMatrix_v<OtherMatrix>
545 and (OtherMatrix::rows==1)
546 , int> = 0>
547 friend auto operator* ( const FieldMatrix& matrixA,
548 const OtherMatrix& matrixB)
549 {
550 using Field = typename PromotionTraits<K, typename OtherMatrix::field_type>::PromotedType;
552 for (std::size_t j=0; j<rows; ++j)
553 matrixB.mtv(matrixA[j], result[j]);
554 return result;
555 }
556
563 template <class OtherMatrix, std::enable_if_t<
564 Impl::IsStaticSizeMatrix_v<OtherMatrix>
565 and not Impl::IsFieldMatrix_v<OtherMatrix>
566 and (OtherMatrix::cols==1)
567 , int> = 0>
568 friend auto operator* ( const OtherMatrix& matrixA,
569 const FieldMatrix& matrixB)
570 {
571 using Field = typename PromotionTraits<K, typename OtherMatrix::field_type>::PromotedType;
573 for (std::size_t j=0; j<cols; ++j)
574 {
575 auto B_j = Impl::ColumnVectorView(matrixB, j);
576 auto result_j = Impl::ColumnVectorView(result, j);
577 matrixA.mv(B_j, result_j);
578 }
579 return result;
580 }
581
583 template<int l>
584 FieldMatrix<K,l,1> leftmultiplyany (const FieldMatrix<K,l,1>& M) const
585 {
586 FieldMatrix<K,l,1> C;
587 for (size_type j=0; j<l; j++)
588 C[j][0] = M[j][0]*(*this)[0][0];
589 return C;
590 }
591
594 {
595 _data[0] *= M[0][0];
596 return *this;
597 }
598
600 template<int l>
601 FieldMatrix<K,1,l> rightmultiplyany (const FieldMatrix<K,1,l>& M) const
602 {
603 FieldMatrix<K,1,l> C;
604
605 for (size_type j=0; j<l; j++)
606 C[0][j] = M[0][j]*_data[0];
607 return C;
608 }
609
610 // make this thing a matrix
611 static constexpr size_type mat_rows() { return 1; }
612 static constexpr size_type mat_cols() { return 1; }
613
614 row_reference mat_access ([[maybe_unused]] size_type i)
615 {
616 DUNE_ASSERT_BOUNDS(i == 0);
617 return _data;
618 }
619
620 const_row_reference mat_access ([[maybe_unused]] size_type i) const
621 {
622 DUNE_ASSERT_BOUNDS(i == 0);
623 return _data;
624 }
625
627 FieldMatrix& operator+= (const K& k)
628 {
629 _data[0] += k;
630 return (*this);
631 }
632
634 FieldMatrix& operator-= (const K& k)
635 {
636 _data[0] -= k;
637 return (*this);
638 }
639
641 FieldMatrix& operator*= (const K& k)
642 {
643 _data[0] *= k;
644 return (*this);
645 }
646
648 FieldMatrix& operator/= (const K& k)
649 {
650 _data[0] /= k;
651 return (*this);
652 }
653
654 //===== conversion operator
655
656 operator const K& () const { return _data[0]; }
657
658 };
659
661 template<typename K>
662 std::ostream& operator<< (std::ostream& s, const FieldMatrix<K,1,1>& a)
663 {
664 s << a[0][0];
665 return s;
666 }
667
668#endif // DOXYGEN
669
670 namespace FMatrixHelp {
671
673 template <typename K>
674 static inline K invertMatrix (const FieldMatrix<K,1,1> &matrix, FieldMatrix<K,1,1> &inverse)
675 {
676 using real_type = typename FieldTraits<K>::real_type;
677 inverse[0][0] = real_type(1.0)/matrix[0][0];
678 return matrix[0][0];
679 }
680
682 template <typename K>
683 static inline K invertMatrix_retTransposed (const FieldMatrix<K,1,1> &matrix, FieldMatrix<K,1,1> &inverse)
684 {
685 return invertMatrix(matrix,inverse);
686 }
687
688
690 template <typename K>
691 static inline K invertMatrix (const FieldMatrix<K,2,2> &matrix, FieldMatrix<K,2,2> &inverse)
692 {
693 using real_type = typename FieldTraits<K>::real_type;
694 // code generated by maple
695 K det = (matrix[0][0]*matrix[1][1] - matrix[0][1]*matrix[1][0]);
696 K det_1 = real_type(1.0)/det;
697 inverse[0][0] = matrix[1][1] * det_1;
698 inverse[0][1] = - matrix[0][1] * det_1;
699 inverse[1][0] = - matrix[1][0] * det_1;
700 inverse[1][1] = matrix[0][0] * det_1;
701 return det;
702 }
703
706 template <typename K>
707 static inline K invertMatrix_retTransposed (const FieldMatrix<K,2,2> &matrix, FieldMatrix<K,2,2> &inverse)
708 {
709 using real_type = typename FieldTraits<K>::real_type;
710 // code generated by maple
711 K det = (matrix[0][0]*matrix[1][1] - matrix[0][1]*matrix[1][0]);
712 K det_1 = real_type(1.0)/det;
713 inverse[0][0] = matrix[1][1] * det_1;
714 inverse[1][0] = - matrix[0][1] * det_1;
715 inverse[0][1] = - matrix[1][0] * det_1;
716 inverse[1][1] = matrix[0][0] * det_1;
717 return det;
718 }
719
721 template <typename K>
722 static inline K invertMatrix (const FieldMatrix<K,3,3> &matrix, FieldMatrix<K,3,3> &inverse)
723 {
724 using real_type = typename FieldTraits<K>::real_type;
725 // code generated by maple
726 K t4 = matrix[0][0] * matrix[1][1];
727 K t6 = matrix[0][0] * matrix[1][2];
728 K t8 = matrix[0][1] * matrix[1][0];
729 K t10 = matrix[0][2] * matrix[1][0];
730 K t12 = matrix[0][1] * matrix[2][0];
731 K t14 = matrix[0][2] * matrix[2][0];
732
733 K det = (t4*matrix[2][2]-t6*matrix[2][1]-t8*matrix[2][2]+
734 t10*matrix[2][1]+t12*matrix[1][2]-t14*matrix[1][1]);
735 K t17 = real_type(1.0)/det;
736
737 inverse[0][0] = (matrix[1][1] * matrix[2][2] - matrix[1][2] * matrix[2][1])*t17;
738 inverse[0][1] = -(matrix[0][1] * matrix[2][2] - matrix[0][2] * matrix[2][1])*t17;
739 inverse[0][2] = (matrix[0][1] * matrix[1][2] - matrix[0][2] * matrix[1][1])*t17;
740 inverse[1][0] = -(matrix[1][0] * matrix[2][2] - matrix[1][2] * matrix[2][0])*t17;
741 inverse[1][1] = (matrix[0][0] * matrix[2][2] - t14) * t17;
742 inverse[1][2] = -(t6-t10) * t17;
743 inverse[2][0] = (matrix[1][0] * matrix[2][1] - matrix[1][1] * matrix[2][0]) * t17;
744 inverse[2][1] = -(matrix[0][0] * matrix[2][1] - t12) * t17;
745 inverse[2][2] = (t4-t8) * t17;
746
747 return det;
748 }
749
751 template <typename K>
752 static inline K invertMatrix_retTransposed (const FieldMatrix<K,3,3> &matrix, FieldMatrix<K,3,3> &inverse)
753 {
754 using real_type = typename FieldTraits<K>::real_type;
755 // code generated by maple
756 K t4 = matrix[0][0] * matrix[1][1];
757 K t6 = matrix[0][0] * matrix[1][2];
758 K t8 = matrix[0][1] * matrix[1][0];
759 K t10 = matrix[0][2] * matrix[1][0];
760 K t12 = matrix[0][1] * matrix[2][0];
761 K t14 = matrix[0][2] * matrix[2][0];
762
763 K det = (t4*matrix[2][2]-t6*matrix[2][1]-t8*matrix[2][2]+
764 t10*matrix[2][1]+t12*matrix[1][2]-t14*matrix[1][1]);
765 K t17 = real_type(1.0)/det;
766
767 inverse[0][0] = (matrix[1][1] * matrix[2][2] - matrix[1][2] * matrix[2][1])*t17;
768 inverse[1][0] = -(matrix[0][1] * matrix[2][2] - matrix[0][2] * matrix[2][1])*t17;
769 inverse[2][0] = (matrix[0][1] * matrix[1][2] - matrix[0][2] * matrix[1][1])*t17;
770 inverse[0][1] = -(matrix[1][0] * matrix[2][2] - matrix[1][2] * matrix[2][0])*t17;
771 inverse[1][1] = (matrix[0][0] * matrix[2][2] - t14) * t17;
772 inverse[2][1] = -(t6-t10) * t17;
773 inverse[0][2] = (matrix[1][0] * matrix[2][1] - matrix[1][1] * matrix[2][0]) * t17;
774 inverse[1][2] = -(matrix[0][0] * matrix[2][1] - t12) * t17;
775 inverse[2][2] = (t4-t8) * t17;
776
777 return det;
778 }
779
781 template< class K, int m, int n, int p >
782 static inline void multMatrix ( const FieldMatrix< K, m, n > &A,
783 const FieldMatrix< K, n, p > &B,
785 {
786 typedef typename FieldMatrix< K, m, p > :: size_type size_type;
787
788 for( size_type i = 0; i < m; ++i )
789 {
790 for( size_type j = 0; j < p; ++j )
791 {
792 ret[ i ][ j ] = K( 0 );
793 for( size_type k = 0; k < n; ++k )
794 ret[ i ][ j ] += A[ i ][ k ] * B[ k ][ j ];
795 }
796 }
797 }
798
800 template <typename K, int rows, int cols>
802 {
803 typedef typename FieldMatrix<K,rows,cols>::size_type size_type;
804
805 for(size_type i=0; i<cols; i++)
806 for(size_type j=0; j<cols; j++)
807 {
808 ret[i][j]=0.0;
809 for(size_type k=0; k<rows; k++)
810 ret[i][j]+=matrix[k][i]*matrix[k][j];
811 }
812 }
813
814 using Dune::DenseMatrixHelp::multAssign;
815
817 template <typename K, int rows, int cols>
819 {
820 typedef typename FieldMatrix<K,rows,cols>::size_type size_type;
821
822 for(size_type i=0; i<cols; ++i)
823 {
824 ret[i] = 0.0;
825 for(size_type j=0; j<rows; ++j)
826 ret[i] += matrix[j][i]*x[j];
827 }
828 }
829
831 template <typename K, int rows, int cols>
833 {
835 multAssign(matrix,x,ret);
836 return ret;
837 }
838
840 template <typename K, int rows, int cols>
842 {
844 multAssignTransposed( matrix, x, ret );
845 return ret;
846 }
847
848 } // end namespace FMatrixHelp
849
852} // end namespace
853
854#include "fmatrixev.hh"
855#endif
Macro for wrapping boundary checks.
A dense n x m matrix.
Definition: densematrix.hh:140
derived_type operator-() const
Matrix negation.
Definition: densematrix.hh:298
void mtv(const X &x, Y &y) const
y = A^T x
Definition: densematrix.hh:387
constexpr size_type M() const
number of columns
Definition: densematrix.hh:703
FieldMatrix< K, ROWS, COLS > & rightmultiply(const DenseMatrix< M2 > &M)
Multiplies M from the right to this matrix.
Definition: densematrix.hh:645
derived_type & operator/=(const field_type &k)
vector space division by scalar
Definition: densematrix.hh:329
derived_type & operator*=(const field_type &k)
vector space multiplication with scalar
Definition: densematrix.hh:321
derived_type & operator-=(const DenseMatrix< Other > &x)
vector space subtraction
Definition: densematrix.hh:312
static constexpr int blocklevel
The number of block levels we contain. This is the leaf, that is, 1.
Definition: densematrix.hh:178
Traits::row_type row_type
The type used to represent a row (must fulfill the Dune::DenseVector interface)
Definition: densematrix.hh:169
Traits::size_type size_type
The type used for the index access and size operation.
Definition: densematrix.hh:166
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:175
Traits::row_reference row_reference
The type used to represent a reference to a row (usually row_type &)
Definition: densematrix.hh:172
derived_type & operator+=(const DenseMatrix< Other > &x)
vector space addition
Definition: densematrix.hh:289
A dense n x m matrix.
Definition: fmatrix.hh:117
constexpr FieldMatrix()=default
Default constructor.
FieldMatrix & operator=(const FieldMatrix< T, ROWS, COLS > &x)
copy assignment from FieldMatrix over a different field
Definition: fmatrix.hh:164
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:354
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:319
FieldMatrix & rightmultiply(const FieldMatrix< K, r, c > &M)
Multiplies M from the right to this matrix.
Definition: fmatrix.hh:337
FieldMatrix(T const &rhs)
copy constructor from assignable type T
Definition: fmatrix.hh:152
friend auto operator*(const FieldMatrix &matrix, Scalar scalar)
vector space multiplication with scalar
Definition: fmatrix.hh:215
FieldMatrix & operator=(FieldMatrix< T, rows, cols > const &)=delete
no copy assignment from FieldMatrix of different size
constexpr FieldMatrix(std::initializer_list< Dune::FieldVector< K, cols > > const &l)
Constructor initializing the matrix from a list of vector.
Definition: fmatrix.hh:140
static constexpr int rows
The number of rows.
Definition: fmatrix.hh:123
FieldMatrix< K, COLS, ROWS > transposed() const
Return transposed of the matrix as FieldMatrix.
Definition: fmatrix.hh:175
static constexpr int cols
The number of columns.
Definition: fmatrix.hh:125
friend auto operator/(const FieldMatrix &matrix, Scalar scalar)
vector space division by scalar
Definition: fmatrix.hh:243
friend auto operator+(const FieldMatrix &matrixA, const FieldMatrix< OtherScalar, ROWS, COLS > &matrixB)
vector space addition – two-argument version
Definition: fmatrix.hh:186
FieldMatrix & operator=(const FieldMatrix &)=default
copy assignment operator
FieldMatrix(const FieldMatrix &)=default
copy constructor
Implements a matrix constructed from a given type representing a field and a compile-time given numbe...
A few common exception classes.
static FieldVector< K, cols > multTransposed(const FieldMatrix< K, rows, cols > &matrix, const FieldVector< K, rows > &x)
calculates ret = matrix^T * x
Definition: fmatrix.hh:841
static K invertMatrix_retTransposed(const FieldMatrix< K, 1, 1 > &matrix, FieldMatrix< K, 1, 1 > &inverse)
invert scalar without changing the original matrix
Definition: fmatrix.hh:683
static 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:782
static K invertMatrix(const FieldMatrix< K, 1, 1 > &matrix, FieldMatrix< K, 1, 1 > &inverse)
invert scalar without changing the original matrix
Definition: fmatrix.hh:674
static FieldVector< K, rows > mult(const FieldMatrix< K, rows, cols > &matrix, const FieldVector< K, cols > &x)
calculates ret = matrix * x
Definition: fmatrix.hh:832
static void multTransposedMatrix(const FieldMatrix< K, rows, cols > &matrix, FieldMatrix< K, cols, cols > &ret)
calculates ret= A_t*A
Definition: fmatrix.hh:801
static 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:818
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
typename Overloads::ScalarType< std::decay_t< V > >::type Scalar
Element type of some SIMD type.
Definition: interface.hh:235
Dune namespace.
Definition: alignedallocator.hh:13
Various precision settings for calculations with FieldMatrix and FieldVector.
Compute type of the result of an arithmetic operation involving two different number types.
Traits for type conversions and type information.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 21, 23:30, 2024)