diff --git a/dumux/python/material/CMakeLists.txt b/dumux/python/material/CMakeLists.txt index f1c168afc35b03db804df7829820e885bd607308..8400d5f3eb5c466207b0191dc02dc25361439bef 100644 --- a/dumux/python/material/CMakeLists.txt +++ b/dumux/python/material/CMakeLists.txt @@ -1,3 +1,2 @@ add_subdirectory(components) add_subdirectory(fluidsystems) -add_subdirectory(spatialparams) diff --git a/dumux/python/material/spatialparams/CMakeLists.txt b/dumux/python/material/spatialparams/CMakeLists.txt deleted file mode 100644 index 08816c5b1a287597d371c037e0e4703c0496b7cf..0000000000000000000000000000000000000000 --- a/dumux/python/material/spatialparams/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -file(GLOB DUMUX_PYTHON_MATERIAL_SPATIALPARAMS_HEADERS *.hh *.inc) -install(FILES ${DUMUX_PYTHON_MATERIAL_SPATIALPARAMS_HEADERS} - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dumux/python/material/spatialparams) diff --git a/dumux/python/material/spatialparams/spatialparams.hh b/dumux/python/material/spatialparams/spatialparams.hh deleted file mode 100644 index 448a981491bcfca1747799614d79ee7be53d6b3b..0000000000000000000000000000000000000000 --- a/dumux/python/material/spatialparams/spatialparams.hh +++ /dev/null @@ -1,98 +0,0 @@ -// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- -// vi: set et ts=4 sw=4 sts=4: -/**************************************************************************** - * See the file COPYING for full copying permissions. * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see <http://www.gnu.org/licenses/>. * - *****************************************************************************/ -/*! - * \file - * \brief TODO: docme! - */ - -#ifndef DUMUX_PYTHON_MATERIAL_SPATIAL_PARAMS_HH -#define DUMUX_PYTHON_MATERIAL_SPATIAL_PARAMS_HH - -#include <dune/python/pybind11/pybind11.h> -#include <dune/python/pybind11/stl.h> - -#include <dumux/material/spatialparams/fv1p.hh> - -namespace Dumux::Python { - -template<class GridGeometry, class Scalar, class PT> -class FVSpatialParamsOneP -: public Dumux::FVSpatialParamsOneP<GridGeometry, Scalar, FVSpatialParamsOneP<GridGeometry, Scalar, PT>> -{ - using ThisType = FVSpatialParamsOneP<GridGeometry, Scalar, PT>; - using ParentType = Dumux::FVSpatialParamsOneP<GridGeometry, Scalar, ThisType>; - using Element = typename GridGeometry::GridView::template Codim<0>::Entity; - using SubControlVolume = typename GridGeometry::SubControlVolume; - using GlobalPosition = typename GridGeometry::GridView::template Codim<0>::Geometry::GlobalCoordinate; - -public: - - using PermeabilityType = PT; - - FVSpatialParamsOneP(std::shared_ptr<const GridGeometry> gridGeometry, - pybind11::object pySpatialParams) - : ParentType(gridGeometry) - , pySpatialParams_(pySpatialParams) - {} - - template<class ElementSolution> - PermeabilityType permeability(const Element& element, - const SubControlVolume& scv, - const ElementSolution& elemSol) const - { - if (pybind11::hasattr(pySpatialParams_, "permeability")) - return pySpatialParams_.attr("permeability")(element, scv, elemSol).template cast<PermeabilityType>(); - else - return pySpatialParams_.attr("permeabilityAtPos")(scv.center()).template cast<PermeabilityType>(); - } - - template<class ElementSolution> - Scalar porosity(const Element& element, - const SubControlVolume& scv, - const ElementSolution& elemSol) const - { - if (pybind11::hasattr(pySpatialParams_, "porosity")) - return pySpatialParams_.attr("porosity")(element, scv, elemSol).template cast<Scalar>(); - else - return pySpatialParams_.attr("porosityAtPos")(scv.center()).template cast<Scalar>(); - } - -private: - pybind11::object pySpatialParams_; -}; - - - -template <class SP, class... options> -void registerOnePSpatialParams(pybind11::handle scope, - pybind11::class_<SP, options...> cls) -{ - using pybind11::operator""_a; - using GridGeometry = std::decay_t<decltype(std::declval<SP>().gridGeometry())>; - - cls.def(pybind11::init([](std::shared_ptr<GridGeometry> gridGeometry, pybind11::object sp){ - return std::make_shared<SP>(gridGeometry, sp); - })); - - cls.def("gravity", &SP::gravity); -} - -} // namespace Dumux::Python - -#endif diff --git a/python/dumux/material/CMakeLists.txt b/python/dumux/material/CMakeLists.txt index c6683fdb0b9fc87f479c79f405fa95c1e2703360..71b18100e7f4a4122f07c3cd7667d943f4e009de 100644 --- a/python/dumux/material/CMakeLists.txt +++ b/python/dumux/material/CMakeLists.txt @@ -1,6 +1,5 @@ add_subdirectory(components) add_subdirectory(fluidsystems) -add_subdirectory(spatialparams) add_python_targets(material __init__ diff --git a/python/dumux/material/__init__.py b/python/dumux/material/__init__.py index 01534f242281cf3b905f3a0a44349f4076050a0d..f3a972ef3f7bf558bfff2cbce8e5f92efcef2459 100644 --- a/python/dumux/material/__init__.py +++ b/python/dumux/material/__init__.py @@ -2,4 +2,3 @@ from dumux.material.fluidsystems import FluidSystem from dumux.material.components import Component -from dumux.material.spatialparams import OnePSpatialParams diff --git a/python/dumux/material/spatialparams/CMakeLists.txt b/python/dumux/material/spatialparams/CMakeLists.txt deleted file mode 100644 index db81731a161e443a1c2c0f686cbf84d16af1d2cb..0000000000000000000000000000000000000000 --- a/python/dumux/material/spatialparams/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -add_python_targets(spatialparams - __init__ -) diff --git a/python/dumux/material/spatialparams/__init__.py b/python/dumux/material/spatialparams/__init__.py deleted file mode 100644 index 49c950458149fd68bc6730bf7792fe9826351cfc..0000000000000000000000000000000000000000 --- a/python/dumux/material/spatialparams/__init__.py +++ /dev/null @@ -1,77 +0,0 @@ -"""Spatial parameter classes""" - -import numpy as np -from dune.generator.generator import SimpleGenerator -from dune.common.hashit import hashIt -from dumux.common import Property -from dumux.wrapping import cppWrapperCreator, cppWrapperClassAlias - - -@cppWrapperCreator -def _createOnePSpatialParamsDecorator(*, gridGeometry, scalar: Property = None): - """Turn a Python spatial parameter class into an C++/Python hybrid class""" - - dim = gridGeometry.gridView.dimensionworld - includes = gridGeometry._includes + [ - "dumux/python/material/spatialparams/spatialparams.hh", - "dune/common/fmatrix.hh", - ] - - if scalar is None: - scalar = Property.fromCppType("double") - scalarType = scalar.cppType - - permType = f"Dune::FieldMatrix<{scalarType}, {dim}, {dim}>" - typeName = ( - f"Dumux::Python::FVSpatialParamsOneP<{gridGeometry._typeName}, {scalarType}, {permType}>" - ) - moduleName = f"spatialparams_{hashIt(typeName)}" - - def decorateOnePSpatialParams(cls): - generator = SimpleGenerator("OnePSpatialParams", "Dumux::Python") - module = generator.load(includes, typeName, moduleName, holder="std::shared_ptr") - - def maybeConvertScalarToMatrix(permeabilityValue): - if isinstance(permeabilityValue, float): - matrix = np.zeros(shape=(dim, dim)) - np.fill_diagonal(matrix, permeabilityValue) - return matrix.tolist() - - return permeabilityValue - - class Permeability: - """Permeability decorator to make sure permeability has correct type""" - - def __init__(self, permeabilityFunction): - self.permeabilityFunction = permeabilityFunction - - def __call__(self, element, scv, elemSol): - result = self.permeabilityFunction(element, scv, elemSol) - return maybeConvertScalarToMatrix(result) - - class PermeabilityAtPos: - """PermeabilityAtPos decorator to make sure permeability has correct type""" - - def __init__(self, permeabilityFunction): - self.permeabilityFunction = permeabilityFunction - - def __call__(self, globalPos): - result = self.permeabilityFunction(globalPos) - return maybeConvertScalarToMatrix(result) - - def createSpatialParams(): - spatialParams = cls() - if hasattr(cls, "permeability"): - cls.permeability = Permeability(spatialParams.permeability) - if hasattr(cls, "permeabilityAtPos"): - cls.permeabilityAtPos = PermeabilityAtPos(spatialParams.permeabilityAtPos) - return module.OnePSpatialParams(gridGeometry, spatialParams) - - return createSpatialParams - - return decorateOnePSpatialParams - - -@cppWrapperClassAlias(creator=_createOnePSpatialParamsDecorator) -class OnePSpatialParams: - """Class alias used to decorate Python spatial parameter implementations"""