StandardProblemIteration.hpp 2.5 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
#pragma once

#include <string>

#include "ProblemIterationInterface.hpp"

namespace AMDiS
{
  // forward declarations
  class AdaptInfo;
11
  class Flag;
12
  class ProblemStatBase;
13

14
  /// A master problem for a single non coupled problem.
15
16
  class StandardProblemIteration
      : public virtual ProblemIterationInterface
17
18
19
  {
  public:
    /// constructor
20
    explicit StandardProblemIteration(ProblemStatBase& prob)
21
      : problem_(prob)
22
23
24
    {}

    /// Implementation of \ref ProblemIterationIterface::beginIteration()
25
    void beginIteration(AdaptInfo& adaptInfo) override;
26
27

    /// Implementation of \ref ProblemIterationInterface::oneIteration()
28
    Flag oneIteration(AdaptInfo& adaptInfo, Flag toDo) override;
29
30

    /// Implementation of \ref ProblemIterationInterface::endIteration()
31
    void endIteration(AdaptInfo& adaptInfo) override;
32
33

    /// Returns the name of the problem.
34
    std::string const& name() const override;
35

36
    int numProblems() const override
37
38
39
40
41
    {
      return 1;
    }

    /// Return the managed ProblemStat \ref problem, by number
42
    ProblemStatBase& problem(int number = 0) override;
43
44

    /// Return the managed ProblemStat \ref problem, by name
45
    ProblemStatBase& problem(std::string const& name) override;
46

47
48
49
50
51
52
  protected:
    /// Nested assemblage and mesh adaption.
    Flag buildAndAdapt(AdaptInfo& adaptInfo, Flag toDo);

  protected:
    /// The problem to solve.
53
    ProblemStatBase& problem_;
54
55
  };

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

  /// \brief StandardProblemIteration when derived from ProblemStat
  /**
   * Use this adaptor when multiple inheritance is used:
   * ```
   * class Problem
   *     : public ProblemStatBase
   *     : StandardProblemIterationAdaptor<Problem>
   * {};
   * ```
   *
   * **Requirements:**
   * - Model must be derived from ProblemStatBase and from StandardProblemIterationAdaptor
   **/
  template <class Model>
  class StandardProblemIterationAdaptor
      : public StandardProblemIteration
  {
    template <class Self>
    static ProblemStatBase& asProblemStatBase(Self& self)
    {
      Model& model = static_cast<Model&>(self);
      return dynamic_cast<ProblemStatBase&>(model);
    }

  public:
    StandardProblemIterationAdaptor()
      : StandardProblemIteration(asProblemStatBase(*this))
    {}

    StandardProblemIterationAdaptor(StandardProblemIterationAdaptor const&)
      : StandardProblemIteration(asProblemStatBase(*this))
    {}

    StandardProblemIterationAdaptor(StandardProblemIterationAdaptor&&)
      : StandardProblemIteration(asProblemStatBase(*this))
    {}
  };


96
} // end namespace AMDiS