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 MultiDomain | ||
10 | * \brief Multidomain wrapper for multiple problems | ||
11 | */ | ||
12 | #ifndef DUMUX_MULTIDOMAIN_FV_PROBLEM_HH | ||
13 | #define DUMUX_MULTIDOMAIN_FV_PROBLEM_HH | ||
14 | |||
15 | #include <tuple> | ||
16 | #include <memory> | ||
17 | #include <utility> | ||
18 | |||
19 | #include <dune/common/hybridutilities.hh> | ||
20 | #include <dune/common/indices.hh> | ||
21 | |||
22 | #include <dumux/multidomain/fvgridgeometry.hh> | ||
23 | |||
24 | namespace Dumux { | ||
25 | |||
26 | /*! | ||
27 | * \ingroup MultiDomain | ||
28 | * \brief A multidomain wrapper for multiple problems | ||
29 | * \tparam MDTraits The multidomain traits | ||
30 | */ | ||
31 | template<class MDTraits> | ||
32 |
1/2✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
4 | class MultiDomainFVProblem |
33 | { | ||
34 | using SolutionVector = typename MDTraits::SolutionVector; | ||
35 | static constexpr std::size_t numSubDomains = MDTraits::numSubDomains; | ||
36 | |||
37 | template<std::size_t i> | ||
38 | using GridGeometry = typename MDTraits::template SubDomain<i>::GridGeometry; | ||
39 | using GridGeometries = typename MDTraits::template Tuple<GridGeometry>; | ||
40 | |||
41 | public: | ||
42 | //! export base types of the stored type | ||
43 | template<std::size_t i> | ||
44 | using Type = typename MDTraits::template SubDomain<i>::Problem; | ||
45 | |||
46 | //! export pointer types the stored type | ||
47 | template<std::size_t i> | ||
48 | using PtrType = std::shared_ptr<Type<i>>; | ||
49 | |||
50 | //! export type of tuple of pointers | ||
51 | using TupleType = typename MDTraits::template Tuple<PtrType>; | ||
52 | |||
53 | /*! | ||
54 | * \brief Construct the problem | ||
55 | * \param gridGeometries a tuple of grid geometry shared pointers | ||
56 | */ | ||
57 | MultiDomainFVProblem(MultiDomainFVGridGeometry<MDTraits> gridGeometries) | ||
58 | { | ||
59 | using namespace Dune::Hybrid; | ||
60 | forEach(std::make_index_sequence<numSubDomains>{}, [&](auto&& id) | ||
61 | { | ||
62 | constexpr auto i = std::decay_t<decltype(id)>::value; | ||
63 | std::get<i>(problems_) = std::make_shared<Type<i>>(gridGeometries.template get<i>()); | ||
64 | }); | ||
65 | } | ||
66 | |||
67 | /*! | ||
68 | * \brief Construct wrapper from a tuple of problems | ||
69 | * \param problemTuple a tuple of shared_ptrs to the problems | ||
70 | */ | ||
71 | MultiDomainFVProblem(TupleType problemTuple) | ||
72 | 8 | : problems_(std::move(problemTuple)) | |
73 | {} | ||
74 | |||
75 | /*! | ||
76 | * \brief Applies the initial solution for all degrees of freedom of the grid. | ||
77 | * \param sol the initial solution vector | ||
78 | */ | ||
79 | void applyInitialSolution(SolutionVector& sol) const | ||
80 | { | ||
81 | using namespace Dune::Hybrid; | ||
82 |
2/4✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | forEach(std::make_index_sequence<numSubDomains>{}, [&](auto&& id) |
83 | { | ||
84 | ✗ | elementAt(problems_, id)->applyInitialSolution(sol[id]); | |
85 | }); | ||
86 | } | ||
87 | |||
88 | //! return the problem for domain with index i | ||
89 | template<std::size_t i> | ||
90 | const Type<i>& operator[] (Dune::index_constant<i> id) const | ||
91 | { return *std::get<i>(problems_); } | ||
92 | |||
93 | //! return the problem for domain with index i | ||
94 | template<std::size_t i> | ||
95 | ✗ | Type<i>& operator[] (Dune::index_constant<i> id) | |
96 |
9/18✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 2 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 2 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 2 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 2 times.
✗ Branch 26 not taken.
|
6 | { return *std::get<i>(problems_); } |
97 | |||
98 | //! access the problem ptr for domain with index i | ||
99 | template<std::size_t i> | ||
100 | const PtrType<i>& get(Dune::index_constant<i> id = Dune::index_constant<i>{}) const | ||
101 | { return std::get<i>(problems_); } | ||
102 | |||
103 | //! access the problem ptr for domain with index i | ||
104 | template<std::size_t i> | ||
105 | ✗ | PtrType<i>& get(Dune::index_constant<i> id = Dune::index_constant<i>{}) | |
106 | 16 | { return std::get<i>(problems_); } | |
107 | |||
108 | /*! | ||
109 | * \brief Access the underlying tuple representation | ||
110 | */ | ||
111 | TupleType& asTuple() | ||
112 | { return problems_; } | ||
113 | |||
114 | /*! | ||
115 | * \brief Access the underlying tuple representation | ||
116 | */ | ||
117 | const TupleType& asTuple() const | ||
118 | { return problems_; } | ||
119 | |||
120 | private: | ||
121 | |||
122 | //! a tuple of points to all grid variables | ||
123 | TupleType problems_; | ||
124 | }; | ||
125 | |||
126 | } // end namespace Dumux | ||
127 | |||
128 | #endif | ||
129 |