version 3.10-dev
multidomain/io/vtkoutputmodule.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_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
24
25namespace Dumux {
26
33template<class MDTraits, template<class GV, class S> class Module = Dumux::VtkOutputModule>
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
52public:
54 template<std::size_t i>
55 using Type = VtkOutputModule<i>;
56
58 template<std::size_t i>
59 using PtrType = std::shared_ptr<Type<i>>;
60
65
72 MultiDomainVtkOutputModule(MDGridVars&& gridVars, const MDSolutionVector& sol,
73 const std::array<std::string, numSubDomains>& name)
74 {
75 using namespace Dune::Hybrid;
76 forEach(std::make_index_sequence<numSubDomains>{}, [&](auto&& id)
77 {
78 constexpr auto i = std::decay_t<decltype(id)>::value;
79 elementAt(vtkOutputModule_, id) = std::make_shared<Type<i>>(*std::get<i>(gridVars), sol[id], name[id]);
80 });
81 }
82
85 {
86 using namespace Dune::Hybrid;
87 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
95 void write(double t, Dune::VTK::OutputType type = Dune::VTK::ascii)
96 {
97 using namespace Dune::Hybrid;
98 forEach(std::make_index_sequence<numSubDomains>{}, [&](auto&& id)
99 {
100 elementAt(vtkOutputModule_, id)->write(t, type);
101 });
102 }
103
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
110 template<std::size_t i>
111 Type<i>& operator[] (Dune::index_constant<i> id)
112 { return *Dune::Hybrid::elementAt(vtkOutputModule_, id); }
113
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
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
124private:
125
127 typename MDTraits::template Tuple<PtrType> vtkOutputModule_;
128};
129
130} // end namespace Dumux
131
132#endif
A multidomain wrapper for multiple vtk output modules.
Definition: multidomain/io/vtkoutputmodule.hh:35
PtrType< i > get(Dune::index_constant< i > id=Dune::index_constant< i >{})
return the vtkoutput module for domain with index i
Definition: multidomain/io/vtkoutputmodule.hh:116
void set(PtrType< i > p, Dune::index_constant< i > id=Dune::index_constant< i >{})
set the pointer for sub domain i
Definition: multidomain/io/vtkoutputmodule.hh:121
void initDefaultOutputFields()
initialized all vtkoutput modules with the models default output fields
Definition: multidomain/io/vtkoutputmodule.hh:84
std::shared_ptr< Type< i > > PtrType
export pointer types the stored type
Definition: multidomain/io/vtkoutputmodule.hh:59
MultiDomainVtkOutputModule()=default
The default constructor.
MultiDomainVtkOutputModule(MDGridVars &&gridVars, const MDSolutionVector &sol, const std::array< std::string, numSubDomains > &name)
Construct the vtk output modules.
Definition: multidomain/io/vtkoutputmodule.hh:72
void write(double t, Dune::VTK::OutputType type=Dune::VTK::ascii)
Write the data for this timestep to file for all output modules.
Definition: multidomain/io/vtkoutputmodule.hh:95
const Type< i > & operator[](Dune::index_constant< i > id) const
return the output module for domain with index i
Definition: multidomain/io/vtkoutputmodule.hh:106
VtkOutputModule< i > Type
export base types of the stored type
Definition: multidomain/io/vtkoutputmodule.hh:55
A VTK output module to simplify writing dumux simulation data to VTK format.
Definition: io/vtkoutputmodule.hh:300
A VTK output module to simplify writing dumux simulation data to VTK format.
Definition: adapt.hh:17
Utilities for template meta programming.