Loading [MathJax]/jax/input/TeX/config.js

DUNE PDELab (unstable)

fastamgsmoother.hh
1// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4// vi: set et ts=4 sw=2 sts=2:
5#ifndef DUNE_ISTL_FASTAMGSMOOTHER_HH
6#define DUNE_ISTL_FASTAMGSMOOTHER_HH
7
8#include <cstddef>
10
11namespace Dune
12{
13 namespace Amg
14 {
15
16 template<std::size_t level>
17 struct GaussSeidelPresmoothDefect {
18
19 template<typename M, typename X, typename Y>
20 static void apply(const M& A, X& x, Y& d,
21 const Y& b)
22 {
23 typedef typename M::ConstRowIterator RowIterator;
24 typedef typename M::ConstColIterator ColIterator;
25
26 typename Y::iterator dIter=d.begin();
27 typename Y::const_iterator bIter=b.begin();
28 typename X::iterator xIter=x.begin();
29
30 for(RowIterator row=A.begin(), end=A.end(); row != end;
31 ++row, ++dIter, ++xIter, ++bIter)
32 {
33 ColIterator col=(*row).begin();
34 *dIter = *bIter;
35
36 for (; col.index()<row.index(); ++col)
37 {
38 if constexpr (Dune::IsNumber<std::decay_t<decltype(*col)>>::value)
39 *dIter -= (*col)*x[col.index()];
40 else
41 (*col).mmv(x[col.index()],*dIter); // rhs -= sum_{j<i} a_ij * xnew_j
42 }
43 assert(row.index()==col.index());
44 ColIterator diag=col; // upper diagonal matrix not needed as x was 0 before.
45
46 // Not recursive yet. Just solve with the diagonal
47 if constexpr (Dune::IsNumber<std::decay_t<decltype(*diag)>>::value)
48 *xIter = (*dIter)/(*diag);
49 else
50 diag->solve(*xIter,*dIter);
51
52 *dIter=0; //as r=v
53
54 // Update residual for the symmetric case
55 for(col=(*row).begin(); col.index()<row.index(); ++col)
56 {
57 if constexpr (Dune::IsNumber<std::decay_t<decltype(*col)>>::value)
58 d[col.index()] -= (*col)*(*xIter);
59 else
60 col->mmv(*xIter, d[col.index()]); //d_j-=A_ij x_i
61 }
62 }
63 }
64 };
65
66 template<std::size_t level>
67 struct GaussSeidelPostsmoothDefect {
68
69 template<typename M, typename X, typename Y>
70 static void apply(const M& A, X& x, Y& d,
71 const Y& b)
72 {
73 typedef typename M::ConstRowIterator RowIterator;
74 typedef typename M::ConstColIterator ColIterator;
75 typedef typename Y::block_type YBlock;
76
77 typename Y::iterator dIter=d.beforeEnd();
78 typename X::iterator xIter=x.beforeEnd();
79 typename Y::const_iterator bIter=b.beforeEnd();
80
81 for(RowIterator row=A.beforeEnd(), end=A.beforeBegin(); row != end;
82 --row, --dIter, --xIter, --bIter)
83 {
84 ColIterator endCol=(*row).beforeBegin();
85 ColIterator col=(*row).beforeEnd();
86 *dIter = *bIter;
87
88 for (; col.index()>row.index(); --col)
89 {
90 if constexpr (Dune::IsNumber<std::decay_t<decltype(*col)>>::value)
91 *dIter -= (*col)*x[col.index()];
92 else
93 (*col).mmv(x[col.index()],*dIter); // rhs -= sum_{j<i} a_ij * xnew_j
94 }
95 assert(row.index()==col.index());
96 ColIterator diag=col;
97 YBlock v=*dIter;
98 // upper diagonal matrix
99 for (--col; col!=endCol; --col)
100 {
101 if constexpr (Dune::IsNumber<std::decay_t<decltype(*col)>>::value)
102 v -= (*col)*x[col.index()];
103 else
104 (*col).mmv(x[col.index()],v); // v -= sum_{j<i} a_ij * xold_j
105 }
106
107 // Not recursive yet. Just solve with the diagonal
108 if constexpr (Dune::IsNumber<std::decay_t<decltype(*diag)>>::value)
109 *xIter = v/(*diag);
110 else
111 diag->solve(*xIter,v);
112
113 *dIter-=v;
114
115 // Update residual for the symmetric case
116 // Skip residual computation as it is not needed.
117 //for(col=(*row).begin();col.index()<row.index(); ++col)
118 //col.mmv(*xIter, d[col.index()]); //d_j-=A_ij x_i
119 }
120 }
121 };
122 } // end namespace Amg
123} // end namespace Dune
124#endif
Traits for type conversions and type information.
Dune namespace.
Definition: alignedallocator.hh:13
Whether this type acts as a scalar in the context of (hierarchically blocked) containers.
Definition: typetraits.hh:194
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Apr 5, 23:02, 2025)