DataTransfer.hpp 1.94 KB
Newer Older
1
2
3
4
5
6
7
8
#pragma once

#include <memory>

#include <amdis/Output.hpp>

namespace AMDiS
{
9
10
11
12
13
  /**
   * \addtogroup Adaption
   * @{
   **/

14
15
16
17
18
19
  typedef enum {
    NO_OPERATION = 0,
    INTERPOLATE  = 1
  } DataTransferOperation;


20
  /// \brief Interface for Containers allowing data transfer between grid changes.
21
22
23
24
25
26
27
28
29
30
31
  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
32
    virtual void postAdapt(Container& container, bool refined) = 0;
33
34
35
  };


36
37
38
39
  /**
   * \brief Implementation of \ref DataTransferInterface that does not interpolate, but
   * just resizes the containers to the dimension of the basis
   **/
40
41
42
43
44
  template <class Container>
  class NoDataTransfer
      : public DataTransferInterface<Container>
  {
  public:
45
    void preAdapt(Container const& container, bool) override {}
46

47
    void postAdapt(Container& container, bool) override
48
49
50
51
52
53
54
    {
      container.compress();
    }
  };


  template <class Container, class Basis>
55
  class DataTransfer;
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

  /// 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:
72
          return std::make_unique< DataTransfer<Container, Basis> >(basis);
73
74
75
76
77
78
79
        default:
          error_exit("Invalid data transfer\n");
          return nullptr; // avoid warnings
      }
    }
  };

80
81
  /// @}

82
} // end namespace AMDiS
83
84

#include "DataTransfer.inc.hpp"