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

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

parent 8437f927
No related branches found
No related tags found
1 merge request!2681Feature/python main file
"""Classes and functions related to discretization methods"""
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 _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"] includes = gridView._includes + ["dumux/python/discretization/gridgeometry.hh"]
if discMethod == "cctpfa": if discMethod == "cctpfa":
...@@ -22,27 +27,34 @@ def GridGeometry(*, gridView, discMethod="cctpfa"): ...@@ -22,27 +27,34 @@ def GridGeometry(*, gridView, discMethod="cctpfa"):
return module.GridGeometry(gridView) return module.GridGeometry(gridView)
# construct GridVariables @cppWrapperClassAlias(creator=_createGridGeometry)
# the grid variables is JIT compiled class GridGeometry:
def GridVariables(*, problem, model): """Class alias used to instantiate a GridGeometry"""
@cppWrapperCreator
def _createGridVariables(*, problem, model):
"""Construct a GridGeometry from problem and the model"""
includes = [ includes = [
"dumux/discretization/fvgridvariables.hh", "dumux/discretization/fvgridvariables.hh",
"dumux/python/discretization/gridvariables.hh", "dumux/python/discretization/gridvariables.hh",
] ]
GG = "Dumux::GetPropType<{}, Dumux::Properties::GridGeometry>".format(model.getTypeTag()) ggeo = f"Dumux::GetPropType<{model.cppType}, Dumux::Properties::GridGeometry>"
GVV = "Dumux::GetPropType<{}, Dumux::Properties::GridVolumeVariables>".format( gvv = f"Dumux::GetPropType<{model.cppType}, Dumux::Properties::GridVolumeVariables>"
model.getTypeTag() gfc = f"Dumux::GetPropType<{model.cppType}, Dumux::Properties::GridFluxVariablesCache>"
) typeName = "Dumux::FVGridVariables<{}, {}, {}>".format(ggeo, gvv, gfc)
GFC = "Dumux::GetPropType<{}, Dumux::Properties::GridFluxVariablesCache>".format(
model.getTypeTag()
)
typeName = "Dumux::FVGridVariables<{}, {}, {}>".format(GG, GVV, GFC)
moduleName = "gridvariables_" + hashIt(typeName) moduleName = "gridvariables_" + hashIt(typeName)
holderType = "std::shared_ptr<{}>".format(typeName) holderType = "std::shared_ptr<{}>".format(typeName)
generator = SimpleGenerator("GridVariables", "Dumux::Python") generator = SimpleGenerator("GridVariables", "Dumux::Python")
module = generator.load( 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()) return module.GridVariables(problem, problem.gridGeometry())
@cppWrapperClassAlias(creator=_createGridVariables)
class GridVariables:
"""Class alias used to instantiate GridVariables"""
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