From 5b6354538ff2ed067146219a370332c8196fcd9c Mon Sep 17 00:00:00 2001 From: Timo Koch <timo.koch@iws.uni-stuttgart.de> Date: Wed, 15 Apr 2020 22:31:07 +0200 Subject: [PATCH] [test][python] Add a test for the grid geometry Python bindings --- test/CMakeLists.txt | 5 +++++ test/python/CMakeLists.txt | 4 ++++ test/python/test_py_gridgeometry.py | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 test/python/CMakeLists.txt create mode 100755 test/python/test_py_gridgeometry.py diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b6d855fcc0..d11f39959f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -10,3 +10,8 @@ add_subdirectory(multidomain) add_subdirectory(nonlinear) add_subdirectory(porousmediumflow) add_subdirectory(discretization) + +# if Python bindings are enabled, include Python binding tests +if(DUNE_ENABLE_PYTHONBINDINGS) + add_subdirectory(python) +endif() diff --git a/test/python/CMakeLists.txt b/test/python/CMakeLists.txt new file mode 100644 index 0000000000..c63ae7c4a0 --- /dev/null +++ b/test/python/CMakeLists.txt @@ -0,0 +1,4 @@ +dune_python_add_test(NAME test_py_gridgeometry + COMMAND ${PYTHON_EXECUTABLE} test_py_gridgeometry.py + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + LABELS python unit) diff --git a/test/python/test_py_gridgeometry.py b/test/python/test_py_gridgeometry.py new file mode 100755 index 0000000000..ca25ba36a1 --- /dev/null +++ b/test/python/test_py_gridgeometry.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 + +from dune.grid import structuredGrid +from dumux.discretization import GridGeometry + +gridView = structuredGrid([0,0],[1,1],[5,5]) + +gridGeometry = GridGeometry(gridView, discMethod="cctpfa") +gridGeometry.update() + +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) + + for scv in fvGeometry.scvs(): + print("scv dofIndex: {}".format(scv.dofIndex())) + print("scv center: {}".format(scv.center())) + print("scv volume: {}".format(scv.volume())) -- GitLab