From 72fef88fdcd305eb5438c75aaa8214db1d9a9226 Mon Sep 17 00:00:00 2001
From: Ansgar Burchardt <Ansgar.Burchardt@tu-dresden.de>
Date: Fri, 27 Apr 2018 18:35:01 +0200
Subject: [PATCH] DDD: move DDD_CTRL to context object

---
 dune/uggrid/parallel/ddd/dddcontext.cc | 5 ++++-
 dune/uggrid/parallel/ddd/dddcontext.hh | 8 ++++----
 gm/ugm.cc                              | 5 ++++-
 parallel/dddif/initddd.cc              | 4 ----
 parallel/dddif/parallel.h              | 8 ++------
 5 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/dune/uggrid/parallel/ddd/dddcontext.cc b/dune/uggrid/parallel/ddd/dddcontext.cc
index d3065d92c..a0f34add3 100644
--- a/dune/uggrid/parallel/ddd/dddcontext.cc
+++ b/dune/uggrid/parallel/ddd/dddcontext.cc
@@ -6,8 +6,11 @@
 
 namespace DDD {
 
-DDDContext::DDDContext(const std::shared_ptr<PPIF::PPIFContext>& ppifContext)
+DDDContext::DDDContext(
+  const std::shared_ptr<PPIF::PPIFContext>& ppifContext,
+  const std::shared_ptr<void>& data)
   : ppifContext_(ppifContext)
+  , data_(data)
 {
   /* Nothing. */
 }
diff --git a/dune/uggrid/parallel/ddd/dddcontext.hh b/dune/uggrid/parallel/ddd/dddcontext.hh
index ddff02e9c..d5a4e317d 100644
--- a/dune/uggrid/parallel/ddd/dddcontext.hh
+++ b/dune/uggrid/parallel/ddd/dddcontext.hh
@@ -208,7 +208,7 @@ struct CouplingContext
 
 class DDDContext {
 public:
-  DDDContext(const std::shared_ptr<PPIF::PPIFContext>& ppifContext);
+  DDDContext(const std::shared_ptr<PPIF::PPIFContext>& ppifContext, const std::shared_ptr<void>& data);
 
   const PPIF::PPIFContext& ppifContext() const
     { return *ppifContext_; }
@@ -235,13 +235,13 @@ public:
    * return pointer to user data
    */
   void* data()
-    { return data_; }
+    { return data_.get(); }
 
   /**
    * return const pointer to user data
    */
   const void* data() const
-    { return data_; }
+    { return data_.get(); }
 
   Basic::LowCommContext& lowCommContext()
     { return lowCommContext_; }
@@ -353,7 +353,7 @@ public:
 
 protected:
   std::shared_ptr<PPIF::PPIFContext> ppifContext_;
-  void* data_ = nullptr;
+  std::shared_ptr<void> data_;
   Basic::LowCommContext lowCommContext_;
   Basic::NotifyContext notifyContext_;
   Basic::TopoContext topoContext_;
diff --git a/gm/ugm.cc b/gm/ugm.cc
index df90ca0b3..e3039857b 100644
--- a/gm/ugm.cc
+++ b/gm/ugm.cc
@@ -2836,7 +2836,10 @@ MULTIGRID * NS_DIM_PREFIX MakeMGItem (const char *name, std::shared_ptr<PPIF::PP
 
 #if ModelP
   theMG->ppifContext_ = ppifContext;
-  theMG->dddContext_ = std::make_shared<DDD::DDDContext>(theMG->ppifContext_);
+  theMG->dddContext_ = std::make_shared<DDD::DDDContext>(
+    theMG->ppifContext_,
+    std::make_shared<DDD_CTRL>()
+    );
 
   InitDDD(theMG->dddContext());
 
diff --git a/parallel/dddif/initddd.cc b/parallel/dddif/initddd.cc
index dbed9d8af..501660c1f 100644
--- a/parallel/dddif/initddd.cc
+++ b/parallel/dddif/initddd.cc
@@ -121,10 +121,6 @@ DDD_IF NS_DIM_PREFIX EdgeIF, NS_DIM_PREFIX BorderEdgeSymmIF, NS_DIM_PREFIX EdgeH
 NS_DIM_PREFIX EdgeSymmVHIF;
 
 
-
-/* DDD global controls */
-DDD_CTRL NS_DIM_PREFIX dddctrl;
-
 /****************************************************************************/
 /*																			*/
 /* definition of variables global to this source file only (static!)		*/
diff --git a/parallel/dddif/parallel.h b/parallel/dddif/parallel.h
index ebec186f4..4a4665519 100644
--- a/parallel/dddif/parallel.h
+++ b/parallel/dddif/parallel.h
@@ -249,8 +249,6 @@ struct DDD_CTRL
   bool allTypesDefined;
 };
 
-extern DDD_CTRL dddctrl;
-
 #endif
 
 /****************************************************************************/
@@ -267,8 +265,7 @@ extern DDD_CTRL dddctrl;
 inline
 const DDD_CTRL& ddd_ctrl(const DDD::DDDContext& context)
 {
-  return dddctrl;
-  // return *static_cast<const DDD_CTRL*>(context.data());
+  return *static_cast<const DDD_CTRL*>(context.data());
 }
 
 /**
@@ -277,8 +274,7 @@ const DDD_CTRL& ddd_ctrl(const DDD::DDDContext& context)
 inline
 DDD_CTRL& ddd_ctrl(DDD::DDDContext& context)
 {
-  return dddctrl;
-  // return *static_cast<DDD_CTRL*>(context.data());
+  return *static_cast<DDD_CTRL*>(context.data());
 }
 
 /* from initddd.c */
-- 
GitLab