diff --git a/python/dumux/discretization/__init__.py b/python/dumux/discretization/__init__.py index 5c0e8b4298e0752bee4a80dc126da5389d78cd1a..f9ab3d47ec0839603a8e5f41ed462a7e55f64aea 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"""