ProblemInstat.hpp 3.56 KB
Newer Older
1
2
#pragma once

3
4
#include <string>

5
6
#include <amdis/ProblemInstatBase.hpp>
#include <amdis/ProblemStat.hpp>
7
#include <amdis/common/TypeTraits.hpp>
8
9
10
11
12

namespace AMDiS
{
  // forward declarations
  class AdaptInfo;
Praetorius, Simon's avatar
Praetorius, Simon committed
13

14
15
16
17
18
19
20
  /**
   * \ingroup Problem
   *
   * \brief
   * Standard implementation of ProblemTimeInterface for a time
   * dependent problems.
   */
21
  template <class Traits>
22
23
  class ProblemInstat
      : public ProblemInstatBase
24
25
  {
    using Self        = ProblemInstat;
26
    using ProblemType = ProblemStat<Traits>;
Praetorius, Simon's avatar
Praetorius, Simon committed
27

Praetorius, Simon's avatar
Praetorius, Simon committed
28
    using SolutionVector = typename ProblemType::SolutionVector;
Praetorius, Simon's avatar
Praetorius, Simon committed
29

30
  public:
31
    /// Constructs a ProblemInstat with prob as its stationary problem, stored as reference.
32
    ProblemInstat(std::string const& name, ProblemType& prob)
33
34
      : ProblemInstatBase(name)
      , problemStat_(&prob)
35
36
    {}

37
    /// Constructor. Stores a reference to prob and initialProb.
38
    ProblemInstat(std::string const& name, ProblemType& prob, ProblemStatBase& initialProb)
39
40
      : ProblemInstatBase(name, initialProb)
      , problemStat_(&prob)
41
42
43
    {}

    /// Initialisation of the problem.
44
    void initialize(Flag initFlag = INIT_NOTHING);
45
46

    /// Implementation of \ref ProblemTimeInterface::initTimestep().
47
    void initTimestep(AdaptInfo& adaptInfo) override;
48
49

    /// Implementation of \ref ProblemTimeInterface::closeTimestep().
50
    void closeTimestep(AdaptInfo& adaptInfo) override;
51
52

    /// Returns \ref problemStat.
53
54
    ProblemType&       problemStat()       { return *problemStat_; }
    ProblemType const& problemStat() const { return *problemStat_; }
55

56
    /// Returns const-ref of \ref oldSolution.
Praetorius, Simon's avatar
Praetorius, Simon committed
57
    std::shared_ptr<SolutionVector const> oldSolutionVector() const
58
    {
59
      test_exit_dbg(bool(oldSolution_),
60
        "OldSolution need to be created. Call initialize with INIT_UH_OLD.");
61
      return oldSolution_;
62
63
64
65
    }

    /// Return a const view to a oldSolution component
    template <class TreePath = RootTreePath>
Praetorius, Simon's avatar
Praetorius, Simon committed
66
    auto oldSolution(TreePath path = {}) const
67
    {
68
69
70
      test_exit_dbg(bool(oldSolution_),
        "OldSolution need to be created. Call initialize with INIT_UH_OLD.");
      return oldSolution_->child(path);
71
    }
72
73

    /// Implementation of \ref ProblemTimeInterface::transferInitialSolution().
74
    void transferInitialSolution(AdaptInfo& adaptInfo) override;
75
76

  protected:
77
78
79
80
81
82
    /// Used in \ref initialize() to create the \ref oldSolution_.
    void createUhOld();

  protected:
    /// Space problem solved in each timestep. (non-owning pointer)
    ProblemType* problemStat_;
83
84

    /// Solution of the last timestep.
Praetorius, Simon's avatar
Praetorius, Simon committed
85
    std::shared_ptr<SolutionVector> oldSolution_;
86
87
  };

88

89
  // Deduction guides
90
  template <class Traits>
91
  ProblemInstat(std::string const& name, ProblemStat<Traits>& prob)
92
    -> ProblemInstat<Traits>;
93
94
95
96

  template <class Traits>
  ProblemInstat(std::string const& name, ProblemStat<Traits>& prob, ProblemStatBase& initialProb)
    -> ProblemInstat<Traits>;
97

98
99
100

  // Generator for ProblemInstat with given ProblemStat
  template <class Traits>
101
  ProblemInstat<Traits> makeProblemInstat(std::string const& name, ProblemStat<Traits>& prob)
102
  {
103
    return {name, prob};
104
105
  }

106
107
108
109
110
111
112
  // Generator for ProblemInstat with given ProblemStat and initialization problem
  template <class Traits>
  ProblemInstat<Traits> makeProblemInstat(std::string const& name, ProblemStat<Traits>& prob, ProblemStatBase& initialProb)
  {
    return {name, prob, initialProb};
  }

113
114
115
116
  // mark template as explicitly instantiated in cpp file
  extern template class ProblemInstat<YaspGridBasis<2,1>>;
  extern template class ProblemInstat<YaspGridBasis<2,2>>;

117
118
119
} // end namespace AMDiS

#include "ProblemInstat.inc.hpp"