version 3.8
symmetrize_constraints.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_LINEAR_SYMMETRIZE_CONSTRAINTS_HH
13#define DUMUX_LINEAR_SYMMETRIZE_CONSTRAINTS_HH
14
15#include <iostream>
16
17#include <dune/common/hybridutilities.hh>
18#include <dune/common/fmatrix.hh>
19#include <dune/istl/bcrsmatrix.hh>
20#include <dune/istl/multitypeblockmatrix.hh>
21
22namespace Dumux::Detail {
23
24// loop over dense matrix block: end of recursion (actually do some work)
25template<class K, int rows, int cols, class VectorRow, class VectorCol>
26void symmetrizeConstraintsImpl(Dune::FieldMatrix<K, rows, cols>& A,
27 VectorRow& bRow, const VectorCol& bCol,
28 const VectorCol& constrainedRows,
29 bool isDiagonal)
30{
31 for (int j = 0; j < A.M(); ++j)
32 {
33 // all rows in this column can be eliminated by a Dirichlet row
34 const auto& constrainedRowsJ = constrainedRows[j];
35 if (constrainedRowsJ > 0.5)
36 {
37 for (int i = 0; i < A.N(); ++i)
38 {
39 auto& Aij = A[i][j];
40 auto& bi = bRow[i];
41 const auto& bj = bCol[j];
42 if (!((i == j) && isDiagonal))
43 {
44 bi -= Aij*bj;
45 Aij = 0.0;
46 }
47 }
48 }
49 }
50}
51
52// recursively loop over sub-blocks
53template<class MBlock, class VectorRow, class VectorCol>
55 VectorRow& bRow, const VectorCol& bCol,
56 const VectorCol& constrainedRows,
57 bool isDiagonal)
58{
59 const auto rowEnd = A.end();
60 for (auto row = A.begin(); row != rowEnd; ++row)
61 {
62 const auto colEnd = row->end();
63 for (auto col = row->begin(); col != colEnd; ++col)
64 {
65 const auto i = row.index();
66 const auto j = col.index();
67
68 auto& Aij = A[i][j];
69 auto& bi = bRow[i];
70 const auto& bj = bCol[j];
71 const auto& dj = constrainedRows[j];
72
73 symmetrizeConstraintsImpl(Aij, bi, bj, dj, ((i == j) && isDiagonal));
74 }
75 }
76}
77
78// recursively loop over sub-blocks
79template<class... MBlock, class VectorRow, class VectorCol>
81 VectorRow& bRow, const VectorCol& bCol,
82 const VectorCol& constrainedRows,
83 bool isDiagonal)
84{
85 using namespace Dune::Hybrid;
86 forEach(std::make_index_sequence<Dune::MultiTypeBlockMatrix<MBlock...>::N()>{}, [&](const auto i)
87 {
88 forEach(std::make_index_sequence<Dune::MultiTypeBlockMatrix<MBlock...>::M()>{}, [&](const auto j)
89 {
90 auto& Aij = A[i][j];
91 auto& bi = bRow[i];
92 const auto& bj = bCol[j];
93 const auto& dj = constrainedRows[j];
94
95 symmetrizeConstraintsImpl(Aij, bi, bj, dj, ((i == j) && isDiagonal));
96 });
97 });
98}
99
100} // end namespace Dumux::Detail
101
102namespace Dumux {
103
116template<class MBlock, class Vector>
117void symmetrizeConstraints(Dune::BCRSMatrix<MBlock>& A, Vector& b, const Vector& constrainedRows)
118{
119 Detail::symmetrizeConstraintsImpl(A, b, b, constrainedRows, true);
120}
121
134template<class... MBlock, class Vector>
135void symmetrizeConstraints(Dune::MultiTypeBlockMatrix<MBlock...>& A, Vector& b, const Vector& constrainedRows)
136{
137 Detail::symmetrizeConstraintsImpl(A, b, b, constrainedRows, true);
138}
139
140} // end namespace Dumux
141
142#endif
Definition: matrix.hh:20
Definition: common/pdesolver.hh:26
void symmetrizeConstraints(Dune::BCRSMatrix< MBlock > &A, Vector &b, const Vector &constrainedRows)
Symmetrize the constrained system Ax=b.
Definition: symmetrize_constraints.hh:117
Distance implementation details.
Definition: cvfelocalresidual.hh:25
void symmetrizeConstraintsImpl(Dune::FieldMatrix< K, rows, cols > &A, VectorRow &bRow, const VectorCol &bCol, const VectorCol &constrainedRows, bool isDiagonal)
Definition: symmetrize_constraints.hh:26
Definition: adapt.hh:17