From e13ba56cb0b57032f7166bbdc44a047347f1cc50 Mon Sep 17 00:00:00 2001
From: Timo Koch <timo.koch@iws.uni-stuttgart.de>
Date: Sat, 24 Jul 2021 12:13:18 +0200
Subject: [PATCH] [python][disc] Improve style, add some, use wrapper helpers

---
 python/dumux/discretization/__init__.py | 44 ++++++++++++++++---------
 1 file changed, 28 insertions(+), 16 deletions(-)

diff --git a/python/dumux/discretization/__init__.py b/python/dumux/discretization/__init__.py
index 5c0e8b4298..f9ab3d47ec 100644
--- a/python/dumux/discretization/__init__.py
+++ b/python/dumux/discretization/__init__.py
@@ -1,9 +1,14 @@
+"""Classes and functions related to discretization methods"""
+
 from dune.generator.generator import SimpleGenerator
 from dune.common.hashit import hashIt
+from dumux.wrapping import cppWrapperCreator, cppWrapperClassAlias
+
+
+@cppWrapperCreator
+def _createGridGeometry(gridView, discMethod="cctpfa"):
+    """Construct a GridGeometry from a gridView"""
 
-# construct a GridGeometry from a gridView
-# the grid geometry is JIT compiled
-def GridGeometry(*, gridView, discMethod="cctpfa"):
     includes = gridView._includes + ["dumux/python/discretization/gridgeometry.hh"]
 
     if discMethod == "cctpfa":
@@ -22,27 +27,34 @@ def GridGeometry(*, gridView, discMethod="cctpfa"):
     return module.GridGeometry(gridView)
 
 
-# construct GridVariables
-# the grid variables is JIT compiled
-def GridVariables(*, problem, model):
+@cppWrapperClassAlias(creator=_createGridGeometry)
+class GridGeometry:
+    """Class alias used to instantiate a GridGeometry"""
+
+
+@cppWrapperCreator
+def _createGridVariables(*, problem, model):
+    """Construct a GridGeometry from problem and the model"""
+
     includes = [
         "dumux/discretization/fvgridvariables.hh",
         "dumux/python/discretization/gridvariables.hh",
     ]
-    GG = "Dumux::GetPropType<{}, Dumux::Properties::GridGeometry>".format(model.getTypeTag())
-    GVV = "Dumux::GetPropType<{}, Dumux::Properties::GridVolumeVariables>".format(
-        model.getTypeTag()
-    )
-    GFC = "Dumux::GetPropType<{}, Dumux::Properties::GridFluxVariablesCache>".format(
-        model.getTypeTag()
-    )
-    typeName = "Dumux::FVGridVariables<{}, {}, {}>".format(GG, GVV, GFC)
+    ggeo = f"Dumux::GetPropType<{model.cppType}, Dumux::Properties::GridGeometry>"
+    gvv = f"Dumux::GetPropType<{model.cppType}, Dumux::Properties::GridVolumeVariables>"
+    gfc = f"Dumux::GetPropType<{model.cppType}, Dumux::Properties::GridFluxVariablesCache>"
+    typeName = "Dumux::FVGridVariables<{}, {}, {}>".format(ggeo, gvv, gfc)
 
     moduleName = "gridvariables_" + hashIt(typeName)
     holderType = "std::shared_ptr<{}>".format(typeName)
     generator = SimpleGenerator("GridVariables", "Dumux::Python")
     module = generator.load(
-        includes, typeName, moduleName, options=[holderType], preamble=model.getProperties()
+        includes, typeName, moduleName, options=[holderType], preamble=model.cppHeader
     )
-    module.GridVariables._model = property(lambda self: model)
+    module.GridVariables.model = property(lambda self: model)
     return module.GridVariables(problem, problem.gridGeometry())
+
+
+@cppWrapperClassAlias(creator=_createGridVariables)
+class GridVariables:
+    """Class alias used to instantiate GridVariables"""
-- 
GitLab