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

[python][cleanup] Use fstring to improve readability

parent fc4b930f
No related branches found
No related tags found
1 merge request!2834[python][cleanup] Use fstring in properties for better readability
Pipeline #8975 failed
+1
...@@ -23,15 +23,13 @@ def _createFVProblemDecorator(gridGeometry, enableInternalDirichletConstraints=F ...@@ -23,15 +23,13 @@ def _createFVProblemDecorator(gridGeometry, enableInternalDirichletConstraints=F
""" """
def createModule(numEq): def createModule(numEq):
priVarType = "Dune::FieldVector<double, {}>".format(numEq) priVarType = f"Dune::FieldVector<double, {numEq}>"
ggType = gridGeometry._typeName ggType = gridGeometry._typeName
enableIntDirConstraint = "true" if enableInternalDirichletConstraints else "false" enableIntDirConstraint = "true" if enableInternalDirichletConstraints else "false"
problemType = "Dumux::Python::FVProblem<{}, {}, {}>".format( problemType = f"Dumux::Python::FVProblem<{ggType}, {priVarType}, {enableIntDirConstraint}>"
ggType, priVarType, enableIntDirConstraint
)
includes = gridGeometry._includes + ["dumux/python/common/fvproblem.hh"] includes = gridGeometry._includes + ["dumux/python/common/fvproblem.hh"]
moduleName = "fvproblem_" + hashIt(problemType) moduleName = "fvproblem_" + hashIt(problemType)
holderType = "std::shared_ptr<{}>".format(problemType) holderType = f"std::shared_ptr<{problemType}>"
generator = SimpleGenerator("FVProblem", "Dumux::Python") generator = SimpleGenerator("FVProblem", "Dumux::Python")
module = generator.load(includes, problemType, moduleName, options=[holderType]) module = generator.load(includes, problemType, moduleName, options=[holderType])
return module return module
...@@ -57,12 +55,12 @@ def _createBoundaryTypes(numEq=1): ...@@ -57,12 +55,12 @@ def _createBoundaryTypes(numEq=1):
"""Create BoundaryTypes instances""" """Create BoundaryTypes instances"""
# only compile this once per numEq # only compile this once per numEq
cacheKey = "BoundaryTypes_{}".format(numEq) cacheKey = f"BoundaryTypes_{numEq}"
try: try:
return globals()[cacheKey]() return globals()[cacheKey]()
except KeyError: except KeyError:
includes = ["dumux/python/common/boundarytypes.hh"] includes = ["dumux/python/common/boundarytypes.hh"]
typeName = "Dumux::BoundaryTypes<{}>".format(numEq) typeName = f"Dumux::BoundaryTypes<{numEq}>"
moduleName = "boundarytypes_" + hashIt(typeName) moduleName = "boundarytypes_" + hashIt(typeName)
generator = SimpleGenerator("BoundaryTypes", "Dumux::Python") generator = SimpleGenerator("BoundaryTypes", "Dumux::Python")
module = generator.load(includes, typeName, moduleName) module = generator.load(includes, typeName, moduleName)
......
...@@ -18,10 +18,10 @@ def _createGridGeometry(gridView, discMethod="cctpfa"): ...@@ -18,10 +18,10 @@ def _createGridGeometry(gridView, discMethod="cctpfa"):
includes += ["dumux/discretization/box/fvgridgeometry.hh"] includes += ["dumux/discretization/box/fvgridgeometry.hh"]
typeName = "Dumux::BoxFVGridGeometry<double, " + gridView._typeName + ">" typeName = "Dumux::BoxFVGridGeometry<double, " + gridView._typeName + ">"
else: else:
raise ValueError("Unknown discMethod {}".format(discMethod)) raise ValueError(f"Unknown discMethod {discMethod}")
moduleName = "gridgeometry_" + hashIt(typeName) moduleName = "gridgeometry_" + hashIt(typeName)
holderType = "std::shared_ptr<{}>".format(typeName) holderType = f"std::shared_ptr<{typeName}>"
generator = SimpleGenerator("GridGeometry", "Dumux::Python") generator = SimpleGenerator("GridGeometry", "Dumux::Python")
module = generator.load(includes, typeName, moduleName, options=[holderType]) module = generator.load(includes, typeName, moduleName, options=[holderType])
return module.GridGeometry(gridView) return module.GridGeometry(gridView)
...@@ -43,10 +43,10 @@ def _createGridVariables(*, problem, model): ...@@ -43,10 +43,10 @@ def _createGridVariables(*, problem, model):
ggeo = f"Dumux::GetPropType<{model.cppType}, Dumux::Properties::GridGeometry>" ggeo = f"Dumux::GetPropType<{model.cppType}, Dumux::Properties::GridGeometry>"
gvv = f"Dumux::GetPropType<{model.cppType}, Dumux::Properties::GridVolumeVariables>" gvv = f"Dumux::GetPropType<{model.cppType}, Dumux::Properties::GridVolumeVariables>"
gfc = f"Dumux::GetPropType<{model.cppType}, Dumux::Properties::GridFluxVariablesCache>" gfc = f"Dumux::GetPropType<{model.cppType}, Dumux::Properties::GridFluxVariablesCache>"
typeName = "Dumux::FVGridVariables<{}, {}, {}>".format(ggeo, gvv, gfc) typeName = f"Dumux::FVGridVariables<{ggeo}, {gvv}, {gfc}>"
moduleName = "gridvariables_" + hashIt(typeName) moduleName = "gridvariables_" + hashIt(typeName)
holderType = "std::shared_ptr<{}>".format(typeName) holderType = f"std::shared_ptr<{typeName}>"
generator = SimpleGenerator("GridVariables", "Dumux::Python") generator = SimpleGenerator("GridVariables", "Dumux::Python")
module = generator.load( module = generator.load(
includes, typeName, moduleName, options=[holderType], preamble=model.cppHeader includes, typeName, moduleName, options=[holderType], preamble=model.cppHeader
......
...@@ -11,9 +11,7 @@ def _createVtkOutputModule(*, gridVariables, solutionVector, name): ...@@ -11,9 +11,7 @@ def _createVtkOutputModule(*, gridVariables, solutionVector, name):
includes = gridVariables._includes + solutionVector._includes includes = gridVariables._includes + solutionVector._includes
includes += ["dumux/python/io/vtkoutputmodule.hh", "dumux/io/vtkoutputmodule.hh"] includes += ["dumux/python/io/vtkoutputmodule.hh", "dumux/io/vtkoutputmodule.hh"]
typeName = "Dumux::VtkOutputModule<{}, {}>".format( typeName = f"Dumux::VtkOutputModule<{gridVariables._typeName}, {solutionVector._typeName}>"
gridVariables._typeName, solutionVector._typeName
)
moduleName = "vtkoutputmodule_" + hashIt(typeName) moduleName = "vtkoutputmodule_" + hashIt(typeName)
generator = SimpleGenerator("VtkOutputModule", "Dumux::Python") generator = SimpleGenerator("VtkOutputModule", "Dumux::Python")
module = generator.load(includes, typeName, moduleName, preamble=gridVariables.model.cppHeader) module = generator.load(includes, typeName, moduleName, preamble=gridVariables.model.cppHeader)
......
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