AMDiS 2.10
The Adaptive Multi-Dimensional Simulation Toolbox
DataTransfer.hpp
1#pragma once
2
3#include <map>
4#include <memory>
5
6#include <dune/common/concept.hh>
7#include <dune/functions/common/typeerasure.hh>
8#include <amdis/Output.hpp>
9
10namespace AMDiS {
11namespace Impl {
12
13template <class B, class C>
14struct DataTransferDefinition
15{
16 // Definition of the interface a DataTransfer class must fulfill
17 struct Interface
18 {
19 virtual ~Interface() = default;
20 virtual void preAdapt(B const& basis, C const& container, bool mightCoarsen) = 0;
21 virtual void adapt(B const& basis, C& container) = 0;
22 virtual void postAdapt(C& container) = 0;
23 };
24
25 // Templatized implementation of the interface
26 template <class Impl>
27 struct Model : public Impl
28 {
29 using Impl::Impl;
30 void preAdapt(B const& b, C const& c, bool mc) final { this->get().preAdapt(b,c,mc); }
31 void adapt(B const& b, C& c) final { this->get().adapt(b,c); }
32 void postAdapt(C& c) final { this->get().postAdapt(c); }
33 };
34
35 // The Concept definition of a DataTransfer
36 struct Concept
37 {
38 template <class DT>
39 auto require(DT&& dt) -> decltype
40 (
41 dt.preAdapt(std::declval<B const&>(), std::declval<C const&>(), true),
42 dt.adapt(std::declval<B const&>(), std::declval<C&>()),
43 dt.postAdapt(std::declval<C&>())
44 );
45 };
46
47 using Base = Dune::Functions::TypeErasureBase<Interface,Model>;
48};
49
50} // end namespace Impl
51
52
59
65template <class Basis, class Container>
67 : public Impl::DataTransferDefinition<Basis,Container>::Base
68{
69 using Definition = Impl::DataTransferDefinition<Basis,Container>;
70 using Super = typename Definition::Base;
71
72public:
74 template <class Impl, Dune::disableCopyMove<DataTransfer,Impl> = 0>
76 : Super{FWD(impl)}
77 {
78 static_assert(Concepts::models<typename Definition::Concept(Impl)>,
79 "Implementation does not model the DataTransfer concept.");
80 }
81
83 DataTransfer() = default;
84
86
92 void preAdapt(Basis const& basis, Container const& container, bool mightCoarsen)
93 {
94 this->asInterface().preAdapt(basis, container, mightCoarsen);
95 }
96
98
102 void adapt(Basis const& basis, Container& container)
103 {
104 this->asInterface().adapt(basis, container);
105 }
106
108
111 void postAdapt(Container& container)
112 {
113 this->asInterface().postAdapt(container);
114 }
115};
116
117
118namespace tag {
119
121 struct datatransfer {};
122
123} // end namespace tag
124
125
127
131template <class Tag>
133{
134 template <class Basis, class Container>
135 static DataTransfer<Basis,Container> create(Basis const&, Container const&)
136 {
137 error_exit("Unknown <tag> passed to the DataTransferFactory.");
139 }
140};
141
143
144} // end namespace AMDiS
The base class for data transfer classes.
Definition: DataTransfer.hpp:68
DataTransfer()=default
Default Constructor.
DataTransfer(Impl &&impl)
Constructor from a type supporting the DataTransferInterface.
Definition: DataTransfer.hpp:75
void postAdapt(Container &container)
Perform cleanup after grid adaption.
Definition: DataTransfer.hpp:111
void adapt(Basis const &basis, Container &container)
Interpolate data to new grid after grid adaption.
Definition: DataTransfer.hpp:102
void preAdapt(Basis const &basis, Container const &container, bool mightCoarsen)
Collect data that is needed before grid adaption.
Definition: DataTransfer.hpp:92
Definition: DataTransfer.hpp:133
Base tag type for all data transfer tags.
Definition: DataTransfer.hpp:121