DataTransfer.hpp 1.78 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#pragma once

#include <memory>

#include <amdis/Output.hpp>

namespace AMDiS
{
  typedef enum {
    NO_OPERATION = 0,
    INTERPOLATE  = 1
  } DataTransferOperation;


  template <class Container>
  class DataTransferInterface
  {
  public:
    /// Virtual destructor
    virtual ~DataTransferInterface() = default;

    /// Collect data that is needed before grid adaption
    virtual void preAdapt(Container const& container, bool mightCoarsen) = 0;

    /// Interpolate data to new grid after grid adaption
26
    virtual void postAdapt(Container& container, bool refined) = 0;
27
28
29
30
31
32
33
34
35
36
  };


  /// Implementation of \ref DataTransferInterface that does not interpolation, but
  /// just resizes the containers to the dimension of the basis
  template <class Container>
  class NoDataTransfer
      : public DataTransferInterface<Container>
  {
  public:
37
    void preAdapt(Container const& container, bool) override {}
38

39
    void postAdapt(Container& container, bool) override
40
41
42
43
44
45
46
    {
      container.compress();
    }
  };


  template <class Container, class Basis>
47
  class DataTransfer;
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

  /// Factory to create DataTransfer objects based on the \ref DataTransferOperation
  template <class Container>
  class DataTransferFactory
  {
    using Interface = DataTransferInterface<Container>;

  public:
    template <class Basis>
    static std::unique_ptr<Interface> create(DataTransferOperation op, Basis const& basis)
    {
      switch (op)
      {
        case NO_OPERATION:
          return std::make_unique<NoDataTransfer<Container>>();
        case INTERPOLATE:
64
          return std::make_unique< DataTransfer<Container, Basis> >(basis);
65
66
67
68
69
70
71
72
        default:
          error_exit("Invalid data transfer\n");
          return nullptr; // avoid warnings
      }
    }
  };

} // end namespace AMDiS
73
74

#include "DataTransfer.inc.hpp"