From fd599ff30cad260b7ad9cfa00ab48eceb9608116 Mon Sep 17 00:00:00 2001
From: Kilian Weishaupt <kilian.weishaupt@iws.uni-stuttgart.de>
Date: Tue, 14 Aug 2018 11:27:41 +0200
Subject: [PATCH] [staggered][md] Fix cyclic dependency in coupling manager

---
 dumux/assembly/staggeredfvassembler.hh        |  4 +--
 .../boundary/stokesdarcy/couplingmanager.hh   |  2 +-
 dumux/multidomain/staggeredcouplingmanager.hh | 34 ++-----------------
 dumux/multidomain/staggeredtraits.hh          |  5 ++-
 4 files changed, 10 insertions(+), 35 deletions(-)

diff --git a/dumux/assembly/staggeredfvassembler.hh b/dumux/assembly/staggeredfvassembler.hh
index cb424d8f81..6730bd0452 100644
--- a/dumux/assembly/staggeredfvassembler.hh
+++ b/dumux/assembly/staggeredfvassembler.hh
@@ -78,7 +78,7 @@ public:
                  std::make_shared<CouplingManager>())
     {
         static_assert(isImplicit, "Explicit assembler for stationary problem doesn't make sense!");
-        this->couplingManager_->init(problem);
+        this->couplingManager_->setSubProblems(std::make_tuple(problem, problem));
     }
 
     //! The constructor for instationary problems
@@ -93,7 +93,7 @@ public:
                  timeLoop)
     {
         static_assert(isImplicit, "Explicit assembler for stationary problem doesn't make sense!");
-        this->couplingManager_->init(problem);
+        this->couplingManager_->setSubProblems(std::make_tuple(problem, problem));
     }
 
 
diff --git a/dumux/multidomain/boundary/stokesdarcy/couplingmanager.hh b/dumux/multidomain/boundary/stokesdarcy/couplingmanager.hh
index 04b704f33e..b5f47e9f7b 100644
--- a/dumux/multidomain/boundary/stokesdarcy/couplingmanager.hh
+++ b/dumux/multidomain/boundary/stokesdarcy/couplingmanager.hh
@@ -141,7 +141,7 @@ public:
         if(Dune::FloatCmp::ne(stokesProblem->gravity(), darcyProblem->gravity()))
             DUNE_THROW(Dune::InvalidStateException, "Both models must use the same gravity vector");
 
-        ParentType::init(std::make_tuple(stokesProblem, stokesProblem, darcyProblem));
+        this->setSubProblems(std::make_tuple(stokesProblem, stokesProblem, darcyProblem));
         this->curSol() = curSol;
         couplingData_ = std::make_shared<CouplingData>(*this);
         computeStencils();
diff --git a/dumux/multidomain/staggeredcouplingmanager.hh b/dumux/multidomain/staggeredcouplingmanager.hh
index bc75a3c53f..687d641c79 100644
--- a/dumux/multidomain/staggeredcouplingmanager.hh
+++ b/dumux/multidomain/staggeredcouplingmanager.hh
@@ -69,23 +69,6 @@ public:
     static constexpr auto cellCenterIdx = Dune::index_constant<0>();
     static constexpr auto faceIdx = Dune::index_constant<1>();
 
-    void init(std::shared_ptr<const Problem<0>> problem)
-    {
-        problemTuple_ = std::make_tuple(problem, problem);
-    }
-
-    template<class... Args>
-    void init(Args&&... args)
-    {
-        problemTuple_ = std::make_tuple(args...);
-    }
-
-    void init(typename Traits::ProblemTuple&& problemTuple)
-    {
-        problemTuple_ = std::move(problemTuple);
-    }
-
-
     /*!
      * \copydoc ParentType::updateCouplingContext
      *
@@ -134,8 +117,8 @@ public:
                                            const Element& elementI,
                                            Dune::index_constant<faceIdx> domainJ) const
     {
-        const auto& connectivityMap = problem(domainI).fvGridGeometry().connectivityMap();
-        const auto eIdx = problem(domainI).fvGridGeometry().elementMapper().index(elementI);
+        const auto& connectivityMap = this->problem(domainI).fvGridGeometry().connectivityMap();
+        const auto eIdx = this->problem(domainI).fvGridGeometry().elementMapper().index(elementI);
         return connectivityMap(domainI, domainJ, eIdx);
     }
 
@@ -175,7 +158,7 @@ public:
                                            const SubControlVolumeFace& scvfI,
                                            Dune::index_constant<cellCenterIdx> domainJ) const
     {
-        const auto& connectivityMap = problem(domainI).fvGridGeometry().connectivityMap();
+        const auto& connectivityMap = this->problem(domainI).fvGridGeometry().connectivityMap();
         return connectivityMap(domainI, domainJ, scvfI.index());
     }
 
@@ -264,17 +247,6 @@ public:
 
     }
 
-    //! Return a reference to the problem
-    template<std::size_t id>
-    const Problem<id>& problem(Dune::index_constant<id> domainIdx) const
-    {
-        assert(std::get<id>(problemTuple_) && "No problem set. Call init() first!");
-        return *std::get<id>(problemTuple_);
-    }
-
-private:
-    typename Traits::ProblemTuple problemTuple_;
-
 };
 
 template<class MDTraits>
diff --git a/dumux/multidomain/staggeredtraits.hh b/dumux/multidomain/staggeredtraits.hh
index 39fadb2691..eb34f23d32 100644
--- a/dumux/multidomain/staggeredtraits.hh
+++ b/dumux/multidomain/staggeredtraits.hh
@@ -99,7 +99,6 @@ private:
     template<std::size_t id>
     using SubDomainProblem = std::shared_ptr<const typename GET_PROP_TYPE(SubDomainTypeTag<id>, Problem)>;
 
-
     template<std::size_t id>
     using SubDomainFVGridGeometry = std::shared_ptr<std::conditional_t<(id < 2),
                                                                        std::conditional_t<(id == 0),
@@ -159,6 +158,10 @@ public:
 
     //! the tuple of grid variables
     using GridVariablesTuple = typename makeFromIndexedType<std::tuple, SubDomainGridVariables, Indices>::type;
+
+    //! convenience alias to create tuple from type
+    template<template<std::size_t> class T>
+    using MakeTuple = typename makeFromIndexedType<std::tuple, T, Indices>::type;
 };
 
 } //end namespace Dumux
-- 
GitLab