ProblemInstat.hpp 3.37 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 const-ref of \ref oldSolution.
Praetorius, Simon's avatar
Praetorius, Simon committed
57
    SystemVector 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
    {
      auto&& tp = makeTreePath(path);
69
      return makeDiscreteFunction(oldSolutionVector(), tp);
70
    }
71 72

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

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

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

    /// Solution of the last timestep.
84
    std::unique_ptr<SystemVector> oldSolution_;
85 86
  };

87 88 89 90

#if DUNE_HAVE_CXX_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
  // Deduction rule
  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
#endif

  // 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
} // end namespace AMDiS

#include "ProblemInstat.inc.hpp"