Skip to content
Snippets Groups Projects
Commit 499669cf authored by Timo Koch's avatar Timo Koch
Browse files

[python][assembly] Improve style, add some, use wrapper helpers

parent 36c49595
No related branches found
No related tags found
1 merge request!2681Feature/python main file
"""Classes and function related to the assembly of linear systems"""
from dune.generator.generator import SimpleGenerator from dune.generator.generator import SimpleGenerator
from dune.common.hashit import hashIt 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": if diffMethod == "numeric":
dm = "Dumux::DiffMethod::numeric" cppDiffMethod = "Dumux::DiffMethod::numeric"
elif diffMethod == "analytic": elif diffMethod == "analytic":
dm = "Dumux::DiffMethod::analytic" cppDiffMethod = "Dumux::DiffMethod::analytic"
else: else:
raise ValueError(f"Unknown diffMethod {diffMethod}") raise ValueError(f"Unknown diffMethod {diffMethod}")
assemblerType = f"Dumux::FVAssembler<{TypeTag}, {dm}, {int(isImplicit)}>" assemblerType = f"Dumux::FVAssembler<{model.cppType}, {cppDiffMethod}, {int(isImplicit)}>"
includes = ( includes = (
problem._includes + problem.gridGeometry()._includes + ["dumux/assembly/fvassembler.hh"] problem._includes + problem.gridGeometry()._includes + ["dumux/assembly/fvassembler.hh"]
) )
...@@ -26,6 +46,11 @@ def FVAssembler(*, problem, gridVariables, model, diffMethod="numeric", isImplic ...@@ -26,6 +46,11 @@ def FVAssembler(*, problem, gridVariables, model, diffMethod="numeric", isImplic
assemblerType, assemblerType,
moduleName, moduleName,
holder="std::shared_ptr", holder="std::shared_ptr",
preamble=model.getProperties(), preamble=model.cppHeader,
) )
return module.FVAssembler(problem, problem.gridGeometry(), gridVariables) return module.FVAssembler(problem, problem.gridGeometry(), gridVariables)
@cppWrapperClassAlias(creator=_createFVAssembler)
class FVAssembler:
"""Class alias used to instantiate an FVAssembler"""
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment