diff --git a/src/amdis/ProblemStat.hpp b/src/amdis/ProblemStat.hpp index faf6a34219f968efe7d481dfd0001d3695f97a1e..1029dcf85a211867a0c20a2238bc2c6311a94af0 100644 --- a/src/amdis/ProblemStat.hpp +++ b/src/amdis/ProblemStat.hpp @@ -49,7 +49,7 @@ namespace AMDiS template <class Traits> class ProblemStat : public ProblemStatBase - , public StandardProblemIteration + , public StandardProblemIterationAdaptor<ProblemStat<Traits>> { using Self = ProblemStat; @@ -81,8 +81,7 @@ namespace AMDiS * access values corresponding to this problem in the parameter file. **/ explicit ProblemStat(std::string const& name) - : StandardProblemIteration(dynamic_cast<ProblemStatBase&>(*this)) - , name_(name) + : name_(name) {} /// Constructor taking additionally a reference to a grid that is used diff --git a/src/amdis/StandardProblemIteration.hpp b/src/amdis/StandardProblemIteration.hpp index 9d719759c8ba40ad54232d6eeca8ae39a2d7d509..4ec7983cd79e61fcc91e69e168e9b81148d6bfdd 100644 --- a/src/amdis/StandardProblemIteration.hpp +++ b/src/amdis/StandardProblemIteration.hpp @@ -53,4 +53,44 @@ namespace AMDiS ProblemStatBase& problem_; }; + + /// \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)) + {} + }; + + } // end namespace AMDiS diff --git a/test/ProblemStatTest.cpp b/test/ProblemStatTest.cpp index d4fa6a495f27e0ba0c98fc15f43b515969d9e000..8c6b36dbbadcb315ce8186ae9307eb7a06df5b05 100644 --- a/test/ProblemStatTest.cpp +++ b/test/ProblemStatTest.cpp @@ -1,4 +1,5 @@ #include <amdis/AMDiS.hpp> +#include <amdis/AdaptStationary.hpp> #include <amdis/LocalOperators.hpp> #include <amdis/ProblemStat.hpp> @@ -21,6 +22,19 @@ void test() prob.addMatrixOperator(sot(T(1)), 0, 0); prob.addVectorOperator(zot(T(1)), 0); prob.addDirichletBC(BoundaryType{1}, 0,0, T(0)); + + + AdaptInfo adaptInfo("adapt"); + + // test copy constructor of problem + auto prob2(prob); + AdaptStationary adaptStat2("adapt", prob2, adaptInfo); + adaptStat2.adapt(); + + // test move constructor of problem + auto prob3(std::move(prob2)); + AdaptStationary adaptStat3("adapt", prob3, adaptInfo); + adaptStat3.adapt(); } int main(int argc, char** argv)