3.6-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_PYTHON_POROUSMEDIUMFLOW_FVSPATIALPARAMS_1P_HH
25#define DUMUX_PYTHON_POROUSMEDIUMFLOW_FVSPATIALPARAMS_1P_HH
26
27#include <dune/python/pybind11/pybind11.h>
28#include <dune/python/pybind11/stl.h>
29
31
32namespace Dumux::Python {
33
34template<class GridGeometry_, class PT>
36: public Dumux::Python::FVSpatialParams<GridGeometry_>
37{
40public:
41 using GridGeometry = GridGeometry_;
42 using Scalar = typename GridGeometry::GridView::ctype;
43 using Element = typename GridGeometry::GridView::template Codim<0>::Entity;
44 using SubControlVolume = typename GridGeometry::SubControlVolume;
45 using PermeabilityType = PT;
46
47 FVSpatialParamsOneP(std::shared_ptr<const GridGeometry> gridGeometry,
48 pybind11::object pySpatialParams)
49 : ParentType(gridGeometry, pySpatialParams)
50 , pySpatialParams_(pySpatialParams)
51 {}
52
53 template<class ElementSolution>
55 const SubControlVolume& scv,
56 const ElementSolution& elemSol) const
57 {
58 if (pybind11::hasattr(pySpatialParams_, "permeability"))
59 return pySpatialParams_.attr("permeability")(element, scv, elemSol).template cast<PermeabilityType>();
60 else
61 return pySpatialParams_.attr("permeabilityAtPos")(scv.center()).template cast<PermeabilityType>();
62 }
63
64 template<class ElementSolution>
65 Scalar porosity(const Element& element,
66 const SubControlVolume& scv,
67 const ElementSolution& elemSol) const
68 {
69 if (pybind11::hasattr(pySpatialParams_, "porosity"))
70 return pySpatialParams_.attr("porosity")(element, scv, elemSol).template cast<Scalar>();
71 else
72 return pySpatialParams_.attr("porosityAtPos")(scv.center()).template cast<Scalar>();
73 }
74
75 template<class SolidSystem, class ElementSolution>
77 const SubControlVolume& scv,
78 const ElementSolution& elemSol,
79 int compIdx) const
80
81 {
82 if (pybind11::hasattr(pySpatialParams_, "inertVolumeFraction"))
83 return pySpatialParams_.attr("inertVolumeFraction")(element, scv, elemSol, compIdx).template cast<Scalar>();
84 else if (pybind11::hasattr(pySpatialParams_, "inertVolumeFractionAtPos"))
85 return pySpatialParams_.attr("inertVolumeFractionAtPos")(scv.center(), compIdx).template cast<Scalar>();
86 else
87 return 1.0 - this->porosity(element, scv, elemSol);
88 }
89
90 static constexpr bool evaluatePermeabilityAtScvfIP()
91 { return false; }
92
93private:
94 pybind11::object pySpatialParams_;
95};
96
97template <class SpatialParams, class... options>
98void registerFVSpatialParamsOneP(pybind11::handle scope, pybind11::class_<SpatialParams, options...> cls)
99{
100 using pybind11::operator""_a;
101 using GridGeometry = typename SpatialParams::GridGeometry;
102
103 cls.def(pybind11::init([](std::shared_ptr<const GridGeometry> gridGeometry, pybind11::object p){
104 return std::make_shared<SpatialParams>(gridGeometry, p);
105 }));
106
107 cls.def("permeability", &SpatialParams::template permeability<decltype(std::ignore)>);
108 cls.def("porosity", &SpatialParams::template porosity<decltype(std::ignore)>);
109 cls.def("inertVolumeFraction", &SpatialParams::template inertVolumeFraction<decltype(std::ignore), decltype(std::ignore)>);
110}
111
112} // namespace Dumux::Python
113
114#endif
std::string permeability() noexcept
I/O name of permeability.
Definition: name.hh:143
std::string porosity() noexcept
I/O name of porosity.
Definition: name.hh:139
Definition: python/assembly/fvassembler.hh:30
void registerFVSpatialParamsOneP(pybind11::handle scope, pybind11::class_< SpatialParams, options... > cls)
Definition: python/porousmediumflow/spatialparams.hh:98
The base class for spatial parameters used with finite-volume schemes.
Definition: python/common/fvspatialparams.hh:46
typename GridGeometry::SubControlVolume SubControlVolume
Definition: python/common/fvspatialparams.hh:52
const GridGeometry & gridGeometry() const
The finite volume grid geometry.
Definition: python/common/fvspatialparams.hh:139
typename GridView::template Codim< 0 >::Entity Element
Definition: python/common/fvspatialparams.hh:51
GridGeometry_ GridGeometry
Definition: python/common/fvspatialparams.hh:48
typename GridView::ctype Scalar
Definition: python/common/fvspatialparams.hh:50
Definition: python/porousmediumflow/spatialparams.hh:37
static constexpr bool evaluatePermeabilityAtScvfIP()
Definition: python/porousmediumflow/spatialparams.hh:90
PermeabilityType permeability(const Element &element, const SubControlVolume &scv, const ElementSolution &elemSol) const
Definition: python/porousmediumflow/spatialparams.hh:54
Scalar inertVolumeFraction(const Element &element, const SubControlVolume &scv, const ElementSolution &elemSol, int compIdx) const
Definition: python/porousmediumflow/spatialparams.hh:76
FVSpatialParamsOneP(std::shared_ptr< const GridGeometry > gridGeometry, pybind11::object pySpatialParams)
Definition: python/porousmediumflow/spatialparams.hh:47
Scalar porosity(const Element &element, const SubControlVolume &scv, const ElementSolution &elemSol) const
Definition: python/porousmediumflow/spatialparams.hh:65
PT PermeabilityType
Definition: python/porousmediumflow/spatialparams.hh:45
Basic spatial parameters to be used with finite-volume schemes.