Line | Branch | Exec | Source |
---|---|---|---|
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 | // | ||
7 | /*! | ||
8 | * \file | ||
9 | * \ingroup Linear | ||
10 | * \brief Define traits for linear solvers. | ||
11 | */ | ||
12 | #ifndef DUMUX_LINEAR_SOLVER_TRAITS_HH | ||
13 | #define DUMUX_LINEAR_SOLVER_TRAITS_HH | ||
14 | |||
15 | #include <bitset> | ||
16 | |||
17 | #include <dune/istl/schwarz.hh> | ||
18 | #include <dune/istl/novlpschwarz.hh> | ||
19 | #include <dune/istl/owneroverlapcopy.hh> | ||
20 | #include <dune/istl/paamg/pinfo.hh> | ||
21 | #include <dune/istl/preconditioners.hh> | ||
22 | #include <dune/grid/common/capabilities.hh> | ||
23 | |||
24 | #include <dumux/common/gridcapabilities.hh> | ||
25 | #include <dumux/discretization/method.hh> | ||
26 | |||
27 | namespace Dumux { | ||
28 | |||
29 | //! The implementation is specialized for the different discretizations | ||
30 | template<class GridGeometry, class DiscretizationMethod> | ||
31 | struct LinearSolverTraitsImpl; | ||
32 | |||
33 | /*! | ||
34 | * \brief The type traits required for using the IstlFactoryBackend | ||
35 | */ | ||
36 | template<class GridGeometry> | ||
37 | using LinearSolverTraits = LinearSolverTraitsImpl<GridGeometry, typename GridGeometry::DiscretizationMethod>; | ||
38 | |||
39 | //! sequential solver traits | ||
40 | template<class MType, class VType> | ||
41 | struct SequentialSolverTraits | ||
42 | { | ||
43 | using Matrix = MType; | ||
44 | using Vector = VType; | ||
45 | using LinearOperator = Dune::MatrixAdapter<MType, VType, VType>; | ||
46 | using ScalarProduct = Dune::SeqScalarProduct<VType>; | ||
47 | |||
48 | template<class SeqPreconditioner> | ||
49 | using Preconditioner = SeqPreconditioner; | ||
50 | }; | ||
51 | |||
52 | struct SeqLinearSolverTraits | ||
53 | { | ||
54 | template<class Matrix, class Vector> | ||
55 | using Sequential = SequentialSolverTraits<Matrix, Vector>; | ||
56 | |||
57 | static constexpr bool canCommunicate = false; | ||
58 | }; | ||
59 | |||
60 | #if HAVE_MPI | ||
61 | template <class MType, class VType> | ||
62 | struct NonoverlappingSolverTraits | ||
63 | { | ||
64 | public: | ||
65 | using Matrix = MType; | ||
66 | using Vector = VType; | ||
67 | using Comm = Dune::OwnerOverlapCopyCommunication<Dune::bigunsignedint<96>, int>; | ||
68 | using LinearOperator = Dune::NonoverlappingSchwarzOperator<MType, VType, VType, Comm>; | ||
69 | using ScalarProduct = Dune::NonoverlappingSchwarzScalarProduct<VType, Comm>; | ||
70 | static constexpr bool isNonOverlapping = true; | ||
71 | |||
72 | template<class SeqPreconditioner> | ||
73 | using Preconditioner = Dune::NonoverlappingBlockPreconditioner<Comm, SeqPreconditioner>; | ||
74 | }; | ||
75 | |||
76 | template <class MType, class VType> | ||
77 | struct OverlappingSolverTraits | ||
78 | { | ||
79 | public: | ||
80 | using Matrix = MType; | ||
81 | using Vector = VType; | ||
82 | using Comm = Dune::OwnerOverlapCopyCommunication<Dune::bigunsignedint<96>, int>; | ||
83 | using LinearOperator = Dune::OverlappingSchwarzOperator<MType, VType, VType, Comm>; | ||
84 | using ScalarProduct = Dune::OverlappingSchwarzScalarProduct<VType, Comm>; | ||
85 | static constexpr bool isNonOverlapping = false; | ||
86 | |||
87 | template<class SeqPreconditioner> | ||
88 | using Preconditioner = Dune::BlockPreconditioner<VType, VType, Comm, SeqPreconditioner>; | ||
89 | }; | ||
90 | #endif | ||
91 | |||
92 | template<class GridGeometry> | ||
93 | struct LinearSolverTraitsBase | ||
94 | { | ||
95 | using GridView = typename GridGeometry::GridView; | ||
96 | using Grid = typename GridGeometry::GridView::Traits::Grid; | ||
97 | |||
98 | template<class Matrix, class Vector> | ||
99 | using Sequential = SequentialSolverTraits<Matrix, Vector>; | ||
100 | |||
101 | #if HAVE_MPI | ||
102 | template<class Matrix, class Vector> | ||
103 | using ParallelOverlapping = OverlappingSolverTraits<Matrix, Vector>; | ||
104 | |||
105 | template<class Matrix, class Vector> | ||
106 | using ParallelNonoverlapping = NonoverlappingSolverTraits<Matrix, Vector>; | ||
107 | #endif | ||
108 | }; | ||
109 | |||
110 | //! Box: use overlapping or non-overlapping model depending on the grid | ||
111 | template<class GridGeometry> | ||
112 | struct LinearSolverTraitsImpl<GridGeometry, DiscretizationMethods::Box> | ||
113 | : public LinearSolverTraitsBase<GridGeometry> | ||
114 | { | ||
115 | using DofMapper = typename GridGeometry::VertexMapper; | ||
116 | using Grid = typename GridGeometry::GridView::Traits::Grid; | ||
117 | static constexpr int dofCodim = Grid::dimension; | ||
118 | static constexpr bool canCommunicate = Dumux::Detail::canCommunicate<Grid, dofCodim>; | ||
119 | |||
120 | template<class GridView> | ||
121 | ✗ | static bool isNonOverlapping(const GridView& gridView) | |
122 |
5/6✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 90 times.
✓ Branch 4 taken 90 times.
✓ Branch 5 taken 90 times.
|
376 | { return gridView.overlapSize(0) == 0; } |
123 | }; | ||
124 | |||
125 | template<class GridGeometry> | ||
126 | struct LinearSolverTraitsImpl<GridGeometry, DiscretizationMethods::PQ1Bubble> | ||
127 | : public LinearSolverTraitsImpl<GridGeometry, DiscretizationMethods::Box> | ||
128 | { | ||
129 | using Grid = typename GridGeometry::GridView::Traits::Grid; | ||
130 | using DofMapper = typename GridGeometry::DofMapper; | ||
131 | |||
132 | static constexpr int dofCodim = Grid::dimension; | ||
133 | static constexpr std::bitset<Grid::dimension+1> dofCodims{ (1UL << Grid::dimension) + 1UL }; | ||
134 | |||
135 | static const DofMapper& dofMapper(const GridGeometry& gg) | ||
136 |
2/4✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
4 | { return { gg.dofMapper() }; } |
137 | }; | ||
138 | |||
139 | //! Cell-centered tpfa: use overlapping model | ||
140 | template<class GridGeometry> | ||
141 | struct LinearSolverTraitsImpl<GridGeometry, DiscretizationMethods::CCTpfa> | ||
142 | : public LinearSolverTraitsBase<GridGeometry> | ||
143 | { | ||
144 | using DofMapper = typename GridGeometry::ElementMapper; | ||
145 | using Grid = typename GridGeometry::GridView::Traits::Grid; | ||
146 | static constexpr int dofCodim = 0; | ||
147 | static constexpr bool canCommunicate = Dumux::Detail::canCommunicate<Grid, dofCodim>; | ||
148 | |||
149 | template<class GridView> | ||
150 | ✗ | static bool isNonOverlapping(const GridView& gridView) | |
151 | ✗ | { return false; } | |
152 | }; | ||
153 | |||
154 | //! Face-centered staggered: use overlapping model | ||
155 | template<class GridGeometry> | ||
156 | struct LinearSolverTraitsImpl<GridGeometry, DiscretizationMethods::FCStaggered> | ||
157 | : public LinearSolverTraitsBase<GridGeometry> | ||
158 | { | ||
159 | class DofMapper | ||
160 | { | ||
161 | public: | ||
162 | DofMapper(const typename GridGeometry::GridView& gridView) | ||
163 | 10 | : gridView_(gridView) {} | |
164 | |||
165 | template<class Entity> | ||
166 | 8080 | auto index(const Entity& e) const | |
167 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4040 times.
|
8080 | { return gridView_.indexSet().index(e); } |
168 | |||
169 | auto size() const | ||
170 |
4/8✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 4 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 4 times.
✗ Branch 13 not taken.
|
12 | { return gridView_.size(1); } |
171 | |||
172 | private: | ||
173 | typename GridGeometry::GridView gridView_; | ||
174 | }; | ||
175 | |||
176 | static DofMapper dofMapper(const GridGeometry& gg) | ||
177 |
3/6✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 5 times.
✗ Branch 8 not taken.
|
15 | { return { gg.gridView() }; } |
178 | |||
179 | using Grid = typename GridGeometry::GridView::Traits::Grid; | ||
180 | static constexpr int dofCodim = 1; | ||
181 | |||
182 | // TODO: see above for description of this workaround, remove second line if fixed upstream | ||
183 | static constexpr bool canCommunicate = | ||
184 | Dune::Capabilities::canCommunicate<Grid, dofCodim>::v | ||
185 | || Dumux::Temp::Capabilities::canCommunicate<Grid, dofCodim>::v; | ||
186 | |||
187 | template<class GridView> | ||
188 | 12 | static bool isNonOverlapping(const GridView& gridView) | |
189 | { | ||
190 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
|
12 | assert(gridView.overlapSize(0) > 0); |
191 | 12 | return false; | |
192 | } | ||
193 | }; | ||
194 | |||
195 | //! Face-centered diamond scheme: use overlapping or non-overlapping model depending on the grid | ||
196 | template<class GridGeometry> | ||
197 | struct LinearSolverTraitsImpl<GridGeometry, DiscretizationMethods::FCDiamond> | ||
198 | : public LinearSolverTraitsBase<GridGeometry> | ||
199 | { | ||
200 | using DofMapper = typename GridGeometry::DofMapper; | ||
201 | using Grid = typename GridGeometry::GridView::Traits::Grid; | ||
202 | static constexpr int dofCodim = 1; | ||
203 | static constexpr bool canCommunicate = Dumux::Detail::canCommunicate<Grid, dofCodim>; | ||
204 | |||
205 | static const DofMapper& dofMapper(const GridGeometry& gg) | ||
206 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
20 | { return { gg.dofMapper() }; } |
207 | |||
208 | template<class GridView> | ||
209 | static bool isNonOverlapping(const GridView& gridView) | ||
210 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 16 times.
|
24 | { return gridView.overlapSize(0) == 0; } |
211 | }; | ||
212 | |||
213 | //! Cell-centered mpfa: use overlapping model | ||
214 | template<class GridGeometry> | ||
215 | struct LinearSolverTraitsImpl<GridGeometry, DiscretizationMethods::CCMpfa> | ||
216 | : public LinearSolverTraitsImpl<GridGeometry, DiscretizationMethods::CCTpfa> {}; | ||
217 | |||
218 | //! staggered: use overlapping model | ||
219 | template<class GridGeometry> | ||
220 | struct LinearSolverTraitsImpl<GridGeometry, DiscretizationMethods::Staggered> | ||
221 | : public LinearSolverTraitsImpl<GridGeometry, DiscretizationMethods::CCTpfa> {}; | ||
222 | |||
223 | } // end namespace Dumux | ||
224 | |||
225 | #endif | ||
226 |