From db91bb1361bbf4447dee99ca82872d58d87756f4 Mon Sep 17 00:00:00 2001 From: Timo Koch <timo.koch@iws.uni-stuttgart.de> Date: Mon, 26 Jul 2021 17:12:47 +0200 Subject: [PATCH] [python][gridgeometry] Add convenience interface boundLocalView(element) --- dumux/python/discretization/gridgeometry.hh | 10 +++++++++- test/python/test_fvproblem.py | 3 +-- test/python/test_gridgeometry.py | 4 +--- 3 files changed, 11 insertions(+), 6 deletions(-) mode change 100644 => 100755 test/python/test_fvproblem.py diff --git a/dumux/python/discretization/gridgeometry.hh b/dumux/python/discretization/gridgeometry.hh index f153f9caa3..34a4c6a806 100644 --- a/dumux/python/discretization/gridgeometry.hh +++ b/dumux/python/discretization/gridgeometry.hh @@ -103,6 +103,7 @@ void registerFVElementGeometry(pybind11::handle scope) cls.def_property_readonly("numScv", &FVEG::numScv); cls.def_property_readonly("hasBoundaryScvf", &FVEG::hasBoundaryScvf); cls.def("bind", &FVEG::bind, "element"_a); + cls.def("bindElement", &FVEG::bindElement, "element"_a); cls.def_property_readonly("scvs", [](FVEG& self){ const auto range = scvs(self); return pybind11::make_iterator(range.begin(), range.end()); @@ -151,6 +152,14 @@ void registerGridGeometry(pybind11::handle scope, pybind11::class_<GG, Options.. return localView(self); }); + using LocalView = typename GG::LocalView; + using Element = typename LocalView::Element; + cls.def("boundLocalView", [](GG& self, const Element& element){ + auto view = localView(self); + view.bind(element); + return view; + }, "element"_a); + using SubControlVolume = typename GG::SubControlVolume; Impl::registerSubControlVolume<SubControlVolume>(scope); @@ -158,7 +167,6 @@ void registerGridGeometry(pybind11::handle scope, pybind11::class_<GG, Options.. Impl::registerSubControlVolumeFace<SubControlVolumeFace>(scope); // also compile the corresponding local view - using LocalView = typename GG::LocalView; Impl::registerFVElementGeometry<LocalView>(scope); } diff --git a/test/python/test_fvproblem.py b/test/python/test_fvproblem.py old mode 100644 new mode 100755 index ebfbd91a5b..12adceaad7 --- a/test/python/test_fvproblem.py +++ b/test/python/test_fvproblem.py @@ -65,8 +65,7 @@ numNeumann = 0 numDirichlet = 0 totalSource = 0 for e in gridView.elements: - fvGeometry = problem.gridGeometry.localView # test problem interface - fvGeometry.bind(e) + fvGeometry = problem.gridGeometry.boundLocalView(e) # test problem interface for scv in fvGeometry.scvs: bTypes = problem.boundaryTypes(element=e, scv=scv) if bTypes.isDirichlet: diff --git a/test/python/test_gridgeometry.py b/test/python/test_gridgeometry.py index 7d7fa8e2d1..03e0a42496 100755 --- a/test/python/test_gridgeometry.py +++ b/test/python/test_gridgeometry.py @@ -11,9 +11,7 @@ print("The total number of scvs is {}".format(gridGeometry.numScv)) print("The total number of scvfs is {}".format(gridGeometry.numScvf)) for e in gridView.elements: - fvGeometry = gridGeometry.localView - fvGeometry.bind(e) - + fvGeometry = gridGeometry.boundLocalView(e) for scv in fvGeometry.scvs: print(f"scv dofIndex: {scv.dofIndex}") print(f"scv center: {scv.center}") -- GitLab