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 vtk output modules | ||
11 | */ | ||
12 | #ifndef DUMUX_MULTIDOMAIN_VTK_OUTPUT_MODULE_HH | ||
13 | #define DUMUX_MULTIDOMAIN_VTK_OUTPUT_MODULE_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/common/typetraits/utility.hh> | ||
23 | #include <dumux/io/vtkoutputmodule.hh> | ||
24 | |||
25 | namespace Dumux { | ||
26 | |||
27 | /*! | ||
28 | * \ingroup MultiDomain | ||
29 | * \brief A multidomain wrapper for multiple vtk output modules | ||
30 | * \tparam MDTraits The multidomain traits | ||
31 | * \tparam Module An output module class template that takes GridVariables and SolutionVector as arguments | ||
32 | */ | ||
33 | template<class MDTraits, template<class GV, class S> class Module = Dumux::VtkOutputModule> | ||
34 | 2 | class MultiDomainVtkOutputModule | |
35 | { | ||
36 | using MDSolutionVector = typename MDTraits::SolutionVector; | ||
37 | static constexpr std::size_t numSubDomains = MDTraits::numSubDomains; | ||
38 | |||
39 | template<std::size_t i> | ||
40 | using GridVariables = typename MDTraits::template SubDomain<i>::GridVariables; | ||
41 | |||
42 | using MDGridVars = typename MDTraits::template TupleOfSharedPtrConst<GridVariables>; | ||
43 | |||
44 | template<std::size_t i> | ||
45 | using SolutionVector = typename MDTraits::template SubDomain<i>::SolutionVector; | ||
46 | |||
47 | template<std::size_t i> | ||
48 | using VtkOutputModule = Module<GridVariables<i>, SolutionVector<i>>; | ||
49 | |||
50 | using VtkOutputModuleTuple = typename MDTraits::template TupleOfSharedPtr<VtkOutputModule>; | ||
51 | |||
52 | public: | ||
53 | //! export base types of the stored type | ||
54 | template<std::size_t i> | ||
55 | using Type = VtkOutputModule<i>; | ||
56 | |||
57 | //! export pointer types the stored type | ||
58 | template<std::size_t i> | ||
59 | using PtrType = std::shared_ptr<Type<i>>; | ||
60 | |||
61 | /*! | ||
62 | * \brief The default constructor | ||
63 | */ | ||
64 | MultiDomainVtkOutputModule() = default; | ||
65 | |||
66 | /*! | ||
67 | * \brief Construct the vtk output modules | ||
68 | * \param gridVars a tuple of grid variables | ||
69 | * \param sol the multidomain solution vector | ||
70 | * \param name the base name for the vtk output | ||
71 | */ | ||
72 | 2 | MultiDomainVtkOutputModule(MDGridVars&& gridVars, const MDSolutionVector& sol, | |
73 | const std::array<std::string, numSubDomains>& name) | ||
74 | 2 | { | |
75 | using namespace Dune::Hybrid; | ||
76 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
14 | forEach(std::make_index_sequence<numSubDomains>{}, [&](auto&& id) |
77 | { | ||
78 | 6 | constexpr auto i = std::decay_t<decltype(id)>::value; | |
79 |
9/36✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 2 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 2 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 2 times.
✗ Branch 27 not taken.
✓ Branch 28 taken 2 times.
✗ Branch 29 not taken.
✓ Branch 30 taken 2 times.
✗ Branch 31 not taken.
✓ Branch 32 taken 2 times.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
✗ Branch 63 not taken.
✗ Branch 64 not taken.
✗ Branch 65 not taken.
|
30 | elementAt(vtkOutputModule_, id) = std::make_shared<Type<i>>(*std::get<i>(gridVars), sol[id], name[id]); |
80 | }); | ||
81 | 2 | } | |
82 | |||
83 | //! initialized all vtkoutput modules with the models default output fields | ||
84 | void initDefaultOutputFields() | ||
85 | { | ||
86 | using namespace Dune::Hybrid; | ||
87 |
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) |
88 | { | ||
89 | ✗ | constexpr auto i = std::decay_t<decltype(id)>::value; | |
90 | ✗ | MDTraits::template SubDomain<i>::IOFields::initOutputModule(*elementAt(vtkOutputModule_, id)); | |
91 | }); | ||
92 | } | ||
93 | |||
94 | //! Write the data for this timestep to file for all output modules | ||
95 | void write(double t, Dune::VTK::OutputType type = Dune::VTK::ascii) | ||
96 | { | ||
97 | using namespace Dune::Hybrid; | ||
98 |
4/8✓ 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 9 taken 2 times.
✗ Branch 10 not taken.
|
4 | forEach(std::make_index_sequence<numSubDomains>{}, [&](auto&& id) |
99 | { | ||
100 | 12 | elementAt(vtkOutputModule_, id)->write(t, type); | |
101 | }); | ||
102 | } | ||
103 | |||
104 | //! return the output module for domain with index i | ||
105 | template<std::size_t i> | ||
106 | const Type<i>& operator[] (Dune::index_constant<i> id) const | ||
107 | { return *Dune::Hybrid::elementAt(vtkOutputModule_, id); } | ||
108 | |||
109 | //! return the output module for domain with index i | ||
110 | template<std::size_t i> | ||
111 | Type<i>& operator[] (Dune::index_constant<i> id) | ||
112 | { return *Dune::Hybrid::elementAt(vtkOutputModule_, id); } | ||
113 | |||
114 | //! return the vtkoutput module for domain with index i | ||
115 | template<std::size_t i> | ||
116 | PtrType<i> get(Dune::index_constant<i> id = Dune::index_constant<i>{}) | ||
117 | { return Dune::Hybrid::elementAt(vtkOutputModule_, id); } | ||
118 | |||
119 | //! set the pointer for sub domain i | ||
120 | template<std::size_t i> | ||
121 | void set(PtrType<i> p, Dune::index_constant<i> id = Dune::index_constant<i>{}) | ||
122 | { Dune::Hybrid::elementAt(vtkOutputModule_, id) = p; } | ||
123 | |||
124 | private: | ||
125 | |||
126 | //! a tuple of points to all vtk output modules | ||
127 | typename MDTraits::template Tuple<PtrType> vtkOutputModule_; | ||
128 | }; | ||
129 | |||
130 | } // end namespace Dumux | ||
131 | |||
132 | #endif | ||
133 |