ProblemInstat.hpp 3.59 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

28
    using SystemVector = typename ProblemType::SystemVector;
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 \ref oldSolution.
Praetorius, Simon's avatar
Praetorius, Simon committed
57
    SystemVector const& oldSolutionVector() const
58
    {
59
      test_exit_dbg(oldSolution_,
60
        "OldSolution need to be created. Call initialize with INIT_UH_OLD.");
61
      return *oldSolution_;
62
63
64
65
    }

    /// Return a mutable view to a oldSolution component
    template <class TreePath = RootTreePath>
Praetorius, Simon's avatar
Praetorius, Simon committed
66
    auto oldSolution(TreePath path = {})
67
68
    {
      auto&& tp = makeTreePath(path);
Praetorius, Simon's avatar
Praetorius, Simon committed
69
      return makeDOFVectorView(oldSolutionVector(), tp);
70
    }
Praetorius, Simon's avatar
Praetorius, Simon committed
71

72
73
    /// Return a const view to a oldSolution component
    template <class TreePath = RootTreePath>
Praetorius, Simon's avatar
Praetorius, Simon committed
74
    auto oldSolution(TreePath path = {}) const
75
76
    {
      auto&& tp = makeTreePath(path);
Praetorius, Simon's avatar
Praetorius, Simon committed
77
      return makeDOFVectorView(oldSolutionVector(), tp);
78
    }
79
80

    /// Implementation of \ref ProblemTimeInterface::transferInitialSolution().
81
    void transferInitialSolution(AdaptInfo& adaptInfo) override;
82
83

  protected:
84
85
86
87
88
89
    /// Used in \ref initialize() to create the \ref oldSolution_.
    void createUhOld();

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

    /// Solution of the last timestep.
92
    std::unique_ptr<SystemVector> oldSolution_;
93
94
  };

95
96
97
98

#if DUNE_HAVE_CXX_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
  // Deduction rule
  template <class Traits>
99
  ProblemInstat(std::string const& name, ProblemStat<Traits>& prob)
100
    -> ProblemInstat<Traits>;
101
102
103
104

  template <class Traits>
  ProblemInstat(std::string const& name, ProblemStat<Traits>& prob, ProblemStatBase& initialProb)
    -> ProblemInstat<Traits>;
105
106
107
108
#endif

  // Generator for ProblemInstat with given ProblemStat
  template <class Traits>
109
  ProblemInstat<Traits> makeProblemInstat(std::string const& name, ProblemStat<Traits>& prob)
110
  {
111
    return {name, prob};
112
113
  }

114
115
116
117
118
119
120
  // 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};
  }

121
122
123
} // end namespace AMDiS

#include "ProblemInstat.inc.hpp"