24#ifndef DUMUX_PYTHON_COMMON_FVPROBLEM_HH
25#define DUMUX_PYTHON_COMMON_FVPROBLEM_HH
31#include <dune/common/fvector.hh>
32#include <dune/common/exceptions.hh>
33#include <dune/python/pybind11/pybind11.h>
45template<
class Gr
idGeometry_,
class PrimaryVariables>
50 using Scalar =
typename PrimaryVariables::value_type;
51 using NumEqVector = Dune::FieldVector<Scalar, PrimaryVariables::dimension>;
52 using Element =
typename GridGeometry::GridView::template Codim<0>::Entity;
59 static constexpr std::size_t
numEq =
static_cast<std::size_t
>(PrimaryVariables::dimension);
68 return pyProblem_.attr(
"name").template cast<std::string>();
75 DUNE_THROW(Dune::InvalidStateException,
"boundaryTypes(..., scv) called for cell-centered method.");
77 return pyProblem_.attr(
"boundaryTypes")(element, scv).
template cast<BoundaryTypes>();
84 DUNE_THROW(Dune::InvalidStateException,
"boundaryTypes(..., scvf) called for box method.");
86 return pyProblem_.attr(
"boundaryTypes")(element, scvf).
template cast<BoundaryTypes>();
93 DUNE_THROW(Dune::InvalidStateException,
"dirichlet(scv) called for cell-centered method.");
95 return pyProblem_.attr(
"dirichlet")(element, scv).
template cast<PrimaryVariables>();
102 DUNE_THROW(Dune::InvalidStateException,
"dirichlet(scvf) called for box method.");
104 return pyProblem_.attr(
"dirichlet")(element, scvf).
template cast<PrimaryVariables>();
107 template<
class ElementVolumeVariables,
class ElementFluxVariablesCache>
110 const ElementVolumeVariables& elemVolVars,
111 const ElementFluxVariablesCache& elemFluxVarsCache,
114 return pyProblem_.attr(
"neumann")(element, fvGeometry, scvf).
template cast<NumEqVector>();
117 template<
class ElementVolumeVariables>
120 const ElementVolumeVariables& elemVolVars,
123 return pyProblem_.attr(
"source")(element, fvGeometry, scv).
template cast<NumEqVector>();
128 return pyProblem_.attr(
"sourceAtPos")(globalPos).
template cast<NumEqVector>();
131 template<
class Entity>
132 PrimaryVariables
initial(
const Entity& entity)
const
134 return pyProblem_.attr(
"initial")(entity).
template cast<PrimaryVariables>();
137 template<
class ElementSolution>
140 const ElementSolution& elemSol)
const
142 return pyProblem_.attr(
"extrusionFactor")(element, scv).
template cast<Scalar>();
146 {
return *gridGeometry_; }
149 std::shared_ptr<const GridGeometry> gridGeometry_;
150 pybind11::object pyProblem_;
154template<
class Problem,
class... options>
157 using pybind11::operator
""_a;
158 using namespace Dune::Python;
160 using GridGeometry =
typename Problem::GridGeometry;
161 cls.def(pybind11::init([](std::shared_ptr<const GridGeometry> gridGeometry, pybind11::object p){
162 return std::make_shared<Problem>(gridGeometry, p);
165 cls.def_property_readonly(
"name", &Problem::name);
166 cls.def_property_readonly(
"numEq", [](Problem&){
return Problem::numEq; });
168 using GridView =
typename GridGeometry::GridView;
169 using Element =
typename GridView::template Codim<0>::Entity;
170 using Vertex =
typename GridView::template Codim<GridView::dimension>::Entity;
172 if constexpr (Problem::isBox)
174 using SCV =
typename Problem::SubControlVolume;
175 cls.def(
"boundaryTypes", pybind11::overload_cast<const Element&, const SCV&>(&Problem::boundaryTypes, pybind11::const_),
"element"_a,
"scv"_a);
176 cls.def(
"dirichlet", pybind11::overload_cast<const Element&, const SCV&>(&Problem::dirichlet, pybind11::const_),
"element"_a,
"scv"_a);
180 using SCVF =
typename Problem::SubControlVolumeFace;
181 cls.def(
"boundaryTypes", pybind11::overload_cast<const Element&, const SCVF&>(&Problem::boundaryTypes, pybind11::const_),
"element"_a,
"scvf"_a);
182 cls.def(
"dirichlet", pybind11::overload_cast<const Element&, const SCVF&>(&Problem::dirichlet, pybind11::const_),
"element"_a,
"scvf"_a);
185 cls.def(
"neumann", &Problem::template neumann<
decltype(std::ignore),
decltype(std::ignore)>);
186 cls.def(
"source", &Problem::template source<
decltype(std::ignore)>);
187 cls.def(
"sourceAtPos", &Problem::sourceAtPos);
188 cls.def(
"initial", &Problem::template initial<Element>);
189 cls.def(
"initial", &Problem::template initial<Vertex>);
190 cls.def(
"extrusionFactor", &Problem::template extrusionFactor<
decltype(std::ignore)>);
191 cls.def(
"gridGeometry", &Problem::gridGeometry);
The available discretization methods in Dumux.
Definition: python/common/boundarytypes.hh:33
void registerFVProblem(pybind11::handle scope, pybind11::class_< Problem, options... > cls)
Definition: python/common/fvproblem.hh:155
Class to specify the type of a boundary.
Definition: common/boundarytypes.hh:38
A C++ wrapper for a Python problem.
Definition: python/common/fvproblem.hh:47
typename GridGeometry::GridView::template Codim< 0 >::Entity Element
Definition: python/common/fvproblem.hh:52
static constexpr bool isBox
Definition: python/common/fvproblem.hh:58
PrimaryVariables initial(const Entity &entity) const
Definition: python/common/fvproblem.hh:132
static constexpr std::size_t numEq
Definition: python/common/fvproblem.hh:59
FVProblem(std::shared_ptr< const GridGeometry > gridGeometry, pybind11::object pyProblem)
Definition: python/common/fvproblem.hh:62
Scalar extrusionFactor(const Element &element, const SubControlVolume &scv, const ElementSolution &elemSol) const
Definition: python/common/fvproblem.hh:138
PrimaryVariables dirichlet(const Element &element, const SubControlVolume &scv) const
Definition: python/common/fvproblem.hh:89
NumEqVector sourceAtPos(const GlobalPosition &globalPos) const
Definition: python/common/fvproblem.hh:126
PrimaryVariables dirichlet(const Element &element, const SubControlVolumeFace &scvf) const
Definition: python/common/fvproblem.hh:98
typename GridGeometry::SubControlVolumeFace SubControlVolumeFace
Definition: python/common/fvproblem.hh:55
typename Element::Geometry::GlobalCoordinate GlobalPosition
Definition: python/common/fvproblem.hh:56
typename GridGeometry::LocalView FVElementGeometry
Definition: python/common/fvproblem.hh:53
const GridGeometry & gridGeometry() const
Definition: python/common/fvproblem.hh:145
NumEqVector source(const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolume &scv) const
Definition: python/common/fvproblem.hh:118
Dune::FieldVector< Scalar, PrimaryVariables::dimension > NumEqVector
Definition: python/common/fvproblem.hh:51
GridGeometry_ GridGeometry
Definition: python/common/fvproblem.hh:49
typename PrimaryVariables::value_type Scalar
Definition: python/common/fvproblem.hh:50
BoundaryTypes boundaryTypes(const Element &element, const SubControlVolume &scv) const
Definition: python/common/fvproblem.hh:71
typename GridGeometry::SubControlVolume SubControlVolume
Definition: python/common/fvproblem.hh:54
NumEqVector neumann(const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const ElementFluxVariablesCache &elemFluxVarsCache, const SubControlVolumeFace &scvf) const
Definition: python/common/fvproblem.hh:108
std::string name() const
Definition: python/common/fvproblem.hh:66
BoundaryTypes boundaryTypes(const Element &element, const SubControlVolumeFace &scvf) const
Definition: python/common/fvproblem.hh:80
Class to specify the type of a boundary.