Skip to content
Snippets Groups Projects
Commit 98fe97a7 authored by Martin Nolte's avatar Martin Nolte
Browse files

add registry for grid part modules

parent aabd17cf
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,7 @@ from mpi4py import MPI
import dune.common as common
from dune.fem import leafGrid
from dune.fem.gridpart import create as gridPart
from dune.fem.gridpart import create as gridpart
#from dune.fem.gridpart.geometry import create as geometryGridPart
#from dune.fem.gridpart.filtered import create as filteredGridPart
......@@ -16,8 +16,7 @@ def testGeometryGridPart(grid, prefix):
gf = grid.function("expr_global", order=1, globalExpr=expr_global)
df = grid.interpolate(gf, space="Lagrange", name="test")
geogp = gridPart("geometry", df)
#geogp = geometryGridPart(df)
geogp = gridpart("Geometry", df)
vtk = geogp.vtkWriter()
gfnew = geogp.function("global", order=1, globalExpr=expr_global)
gfnew.addToVTKWriter(vtk, common.DataType.PointData)
......@@ -34,8 +33,7 @@ def testGridPart(gridtype):
grid = leafGrid("../data/unitcube-2d.dgf", gridtype, dimgrid=2)
testGeometryGridPart(grid, "gridpart_demo")
#subGrid = filteredGridPart(grid, lambda e: (e.geometry.center - [0.5, 0.5]).two_norm < 0.25)
subGrid = gridPart("filtered", grid, lambda e: (e.geometry.center - [0.5, 0.5]).two_norm < 0.25)
subGrid = gridpart("Filtered", grid, lambda e: (e.geometry.center - [0.5, 0.5]).two_norm < 0.25)
testGeometryGridPart(subGrid, "gridpart_demo_sub")
print("YASPGRID B")
......
......@@ -106,12 +106,23 @@ def module(includes, typeName, constructors=None, methods=None):
addAttr(module, module.GridPart)
return module
_modules = dict()
def register(**modules):
_modules.update(modules)
def create(gridpart, *args, **kwargs):
try:
gridpart = importlib.import_module("dune.fem.gridpart." + gridpart)
return gridpart.create(*args, **kwargs)
except ImportError:
raise ValueError("No grid part named " + gridpart)
gridpart = importlib.import_module(_modules[gridpart])
return gridpart.create(*args, **kwargs)
# register our own grid parts
register(Geometry = "dune.fem.gridpart.geometry")
register(Filtered = "dune.fem.gridpart.filtered")
# enable doc test
if __name__ == "__main__":
import doctest
......
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