version 3.10-dev
python/porousmediumflow/spatialparams.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_PYTHON_POROUSMEDIUMFLOW_FVSPATIALPARAMS_1P_HH
13#define DUMUX_PYTHON_POROUSMEDIUMFLOW_FVSPATIALPARAMS_1P_HH
14
15#include <dune/python/pybind11/pybind11.h>
16#include <dune/python/pybind11/stl.h>
17
19
20namespace Dumux::Python {
21
22template<class GridGeometry_, class PT>
24: public Dumux::Python::FVSpatialParams<GridGeometry_>
25{
28public:
29 using GridGeometry = GridGeometry_;
30 using Scalar = typename GridGeometry::GridView::ctype;
31 using Element = typename GridGeometry::GridView::template Codim<0>::Entity;
32 using SubControlVolume = typename GridGeometry::SubControlVolume;
33 using PermeabilityType = PT;
34
35 FVSpatialParamsOneP(std::shared_ptr<const GridGeometry> gridGeometry,
36 pybind11::object pySpatialParams)
37 : ParentType(gridGeometry, pySpatialParams)
38 , pySpatialParams_(pySpatialParams)
39 {}
40
41 template<class ElementSolution>
43 const SubControlVolume& scv,
44 const ElementSolution& elemSol) const
45 {
46 if (pybind11::hasattr(pySpatialParams_, "permeability"))
47 return pySpatialParams_.attr("permeability")(element, scv, elemSol).template cast<PermeabilityType>();
48 else
49 return pySpatialParams_.attr("permeabilityAtPos")(scv.center()).template cast<PermeabilityType>();
50 }
51
52 template<class ElementSolution>
53 Scalar porosity(const Element& element,
54 const SubControlVolume& scv,
55 const ElementSolution& elemSol) const
56 {
57 if (pybind11::hasattr(pySpatialParams_, "porosity"))
58 return pySpatialParams_.attr("porosity")(element, scv, elemSol).template cast<Scalar>();
59 else
60 return pySpatialParams_.attr("porosityAtPos")(scv.center()).template cast<Scalar>();
61 }
62
63 template<class SolidSystem, class ElementSolution>
65 const SubControlVolume& scv,
66 const ElementSolution& elemSol,
67 int compIdx) const
68
69 {
70 if (pybind11::hasattr(pySpatialParams_, "inertVolumeFraction"))
71 return pySpatialParams_.attr("inertVolumeFraction")(element, scv, elemSol, compIdx).template cast<Scalar>();
72 else if (pybind11::hasattr(pySpatialParams_, "inertVolumeFractionAtPos"))
73 return pySpatialParams_.attr("inertVolumeFractionAtPos")(scv.center(), compIdx).template cast<Scalar>();
74 else
75 return 1.0 - this->porosity(element, scv, elemSol);
76 }
77
78 static constexpr bool evaluatePermeabilityAtScvfIP()
79 { return false; }
80
81private:
82 pybind11::object pySpatialParams_;
83};
84
85template <class SpatialParams, class... options>
86void registerFVSpatialParamsOneP(pybind11::handle scope, pybind11::class_<SpatialParams, options...> cls)
87{
88 using pybind11::operator""_a;
89 using GridGeometry = typename SpatialParams::GridGeometry;
90
91 cls.def(pybind11::init([](std::shared_ptr<const GridGeometry> gridGeometry, pybind11::object p){
92 return std::make_shared<SpatialParams>(gridGeometry, p);
93 }));
94
95 cls.def("permeability", &SpatialParams::template permeability<decltype(std::ignore)>);
96 cls.def("porosity", &SpatialParams::template porosity<decltype(std::ignore)>);
97 cls.def("inertVolumeFraction", &SpatialParams::template inertVolumeFraction<decltype(std::ignore), decltype(std::ignore)>);
98}
99
100} // namespace Dumux::Python
101
102#endif
The base class for spatial parameters used with finite-volume schemes.
Definition: python/common/fvspatialparams.hh:34
typename GridGeometry::SubControlVolume SubControlVolume
Definition: python/common/fvspatialparams.hh:40
const GridGeometry & gridGeometry() const
The finite volume grid geometry.
Definition: python/common/fvspatialparams.hh:127
typename GridView::template Codim< 0 >::Entity Element
Definition: python/common/fvspatialparams.hh:39
GridGeometry_ GridGeometry
Definition: python/common/fvspatialparams.hh:36
typename GridView::ctype Scalar
Definition: python/common/fvspatialparams.hh:38
Definition: python/porousmediumflow/spatialparams.hh:25
static constexpr bool evaluatePermeabilityAtScvfIP()
Definition: python/porousmediumflow/spatialparams.hh:78
PermeabilityType permeability(const Element &element, const SubControlVolume &scv, const ElementSolution &elemSol) const
Definition: python/porousmediumflow/spatialparams.hh:42
Scalar inertVolumeFraction(const Element &element, const SubControlVolume &scv, const ElementSolution &elemSol, int compIdx) const
Definition: python/porousmediumflow/spatialparams.hh:64
FVSpatialParamsOneP(std::shared_ptr< const GridGeometry > gridGeometry, pybind11::object pySpatialParams)
Definition: python/porousmediumflow/spatialparams.hh:35
Scalar porosity(const Element &element, const SubControlVolume &scv, const ElementSolution &elemSol) const
Definition: python/porousmediumflow/spatialparams.hh:53
PT PermeabilityType
Definition: python/porousmediumflow/spatialparams.hh:33
std::string permeability() noexcept
I/O name of permeability.
Definition: name.hh:131
std::string porosity() noexcept
I/O name of porosity.
Definition: name.hh:127
Definition: python/assembly/fvassembler.hh:18
void registerFVSpatialParamsOneP(pybind11::handle scope, pybind11::class_< SpatialParams, options... > cls)
Definition: python/porousmediumflow/spatialparams.hh:86
Basic spatial parameters to be used with finite-volume schemes.