From 499669cf80e1917bd301b730b9ffa47bb4a6dc34 Mon Sep 17 00:00:00 2001 From: Timo Koch <timo.koch@iws.uni-stuttgart.de> Date: Sat, 24 Jul 2021 12:10:08 +0200 Subject: [PATCH] [python][assembly] Improve style, add some, use wrapper helpers --- python/dumux/assembly/__init__.py | 37 ++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/python/dumux/assembly/__init__.py b/python/dumux/assembly/__init__.py index b09a7f4776..b9e9ddcd3a 100644 --- a/python/dumux/assembly/__init__.py +++ b/python/dumux/assembly/__init__.py @@ -1,19 +1,39 @@ +"""Classes and function related to the assembly of linear systems""" + from dune.generator.generator import SimpleGenerator from dune.common.hashit import hashIt +from dumux.wrapping import cppWrapperCreator, cppWrapperClassAlias + + +@cppWrapperCreator +def _createFVAssembler(*, problem, gridVariables, model, diffMethod="numeric", isImplicit=True): + """ + Create an FVAssembler object + Args: + problem: A problem instance (boundary & initial conditions) + gridVariables: A grid variable instance (primary & secondary variables defined on a grid) + model: A DuMux model configuration instance + diffMethod (str): The method to compute derivatives of the residual (numeric or analytic) + isImplicit (bool): If the time discretization method is implicit or explicit -def FVAssembler(*, problem, gridVariables, model, diffMethod="numeric", isImplicit=True): + Returns: + An assembler object (Python-bindings of the corresponding C++ type) - TypeTag = model.getTypeTag() + Usage: + assembler = FVAssembler( + problem=problem, gridVariables=gridVars, model=model, diffMethod=diffMethod + ) + """ if diffMethod == "numeric": - dm = "Dumux::DiffMethod::numeric" + cppDiffMethod = "Dumux::DiffMethod::numeric" elif diffMethod == "analytic": - dm = "Dumux::DiffMethod::analytic" + cppDiffMethod = "Dumux::DiffMethod::analytic" else: raise ValueError(f"Unknown diffMethod {diffMethod}") - assemblerType = f"Dumux::FVAssembler<{TypeTag}, {dm}, {int(isImplicit)}>" + assemblerType = f"Dumux::FVAssembler<{model.cppType}, {cppDiffMethod}, {int(isImplicit)}>" includes = ( problem._includes + problem.gridGeometry()._includes + ["dumux/assembly/fvassembler.hh"] ) @@ -26,6 +46,11 @@ def FVAssembler(*, problem, gridVariables, model, diffMethod="numeric", isImplic assemblerType, moduleName, holder="std::shared_ptr", - preamble=model.getProperties(), + preamble=model.cppHeader, ) return module.FVAssembler(problem, problem.gridGeometry(), gridVariables) + + +@cppWrapperClassAlias(creator=_createFVAssembler) +class FVAssembler: + """Class alias used to instantiate an FVAssembler""" -- GitLab