ProblemInstat.hpp 3.36 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
#include <dune/grid/yaspgrid.hh>

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

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

Praetorius, Simon's avatar
Praetorius, Simon committed
30
    using SolutionVector = typename ProblemType::SolutionVector;
Praetorius, Simon's avatar
Praetorius, Simon committed
31

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

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

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

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

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

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

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

    /// Return a const view to a oldSolution component
67
68
69
70
71
    /**
     * \tparam Range  The range type return by evaluating the view in coordinates. If not specified,
     *                it is automatically selected using \ref RangeType_t template.
     **/
    template <class Range = void, class... Indices>
72
    auto oldSolution(Indices... ii) const
73
    {
74
75
      test_exit_dbg(bool(oldSolution_),
        "OldSolution need to be created. Call initialize with INIT_UH_OLD.");
76
      return valueOf<Range>(*oldSolution_, ii...);
77
    }
78
79

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

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

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

    /// Solution of the last timestep.
Praetorius, Simon's avatar
Praetorius, Simon committed
91
    std::shared_ptr<SolutionVector> oldSolution_;
92
93
  };

94

95
  // Deduction guides
96
  template <class Traits>
97
  ProblemInstat(std::string const& name, ProblemStat<Traits>& prob)
98
    -> ProblemInstat<Traits>;
99
100
101
102

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

104

105
  // mark template as explicitly instantiated in cpp file
106
107
  extern template class ProblemInstat<LagrangeBasis<Dune::YaspGrid<2>,1>>;
  extern template class ProblemInstat<LagrangeBasis<Dune::YaspGrid<2>,1,1>>;
108

109
110
111
} // end namespace AMDiS

#include "ProblemInstat.inc.hpp"