version 3.8
python/porousmediumflow/problem.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_PROBLEM_HH
13#define DUMUX_PYTHON_POROUSMEDIUMFLOW_PROBLEM_HH
14
15
16#include <dune/python/pybind11/pybind11.h>
17
19
20namespace Dumux::Python {
21
26template<class GridGeometry_, class SpatialParams_, class PrimaryVariables, bool enableInternalDirichletConstraints>
28: public Dumux::Python::FVProblem<GridGeometry_, SpatialParams_, PrimaryVariables, enableInternalDirichletConstraints>
29{
31public:
32 using GridGeometry = GridGeometry_;
33 using SpatialParams = SpatialParams_;
34 using Scalar = typename PrimaryVariables::value_type;
35 using NumEqVector = Dune::FieldVector<Scalar, PrimaryVariables::dimension>;
36 using Element = typename GridGeometry::GridView::template Codim<0>::Entity;
37 using FVElementGeometry = typename GridGeometry::LocalView;
38 using SubControlVolume = typename GridGeometry::SubControlVolume;
39 using SubControlVolumeFace = typename GridGeometry::SubControlVolumeFace;
40 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
41
42 static constexpr bool isBox = GridGeometry::discMethod == DiscretizationMethods::box;
43 static constexpr std::size_t numEq = static_cast<std::size_t>(PrimaryVariables::dimension);
45
46 PorousMediumFlowProblem(std::shared_ptr<const GridGeometry> gridGeometry,
47 std::shared_ptr<const SpatialParams> spatialParams,
48 pybind11::object pyProblem)
50 , spatialParams_(spatialParams)
51 {}
52
54 { return *spatialParams_; }
55
56private:
57 std::shared_ptr<const SpatialParams> spatialParams_;
58};
59
60// Python wrapper for the above FVProblem C++ class
61template<class Problem, class... options>
62void registerPorousMediumFlowProblem(pybind11::handle scope, pybind11::class_<Problem, options...> cls)
63{
64 using pybind11::operator""_a;
65 using namespace Dune::Python;
66
67 using GridGeometry = typename Problem::GridGeometry;
68 using SpatialParams = typename Problem::SpatialParams;
69 cls.def(pybind11::init([](std::shared_ptr<const GridGeometry> gridGeometry,
70 std::shared_ptr<SpatialParams> spatialParams,
71 pybind11::object p){
72 return std::make_shared<Problem>(gridGeometry, spatialParams, p);
73 }));
74
75 cls.def_property_readonly("name", &Problem::name);
76 cls.def_property_readonly("numEq", [](Problem&){ return Problem::numEq; });
77
78 using GridView = typename GridGeometry::GridView;
79 using Element = typename GridView::template Codim<0>::Entity;
80 using Vertex = typename GridView::template Codim<GridView::dimension>::Entity;
81
82 if constexpr (Problem::isBox)
83 {
84 using SCV = typename Problem::SubControlVolume;
85 cls.def("boundaryTypes", pybind11::overload_cast<const Element&, const SCV&>(&Problem::boundaryTypes, pybind11::const_), "element"_a, "scv"_a);
86 cls.def("dirichlet", pybind11::overload_cast<const Element&, const SCV&>(&Problem::dirichlet, pybind11::const_), "element"_a, "scv"_a);
87 }
88 else
89 {
90 using SCVF = typename Problem::SubControlVolumeFace;
91 cls.def("boundaryTypes", pybind11::overload_cast<const Element&, const SCVF&>(&Problem::boundaryTypes, pybind11::const_), "element"_a, "scvf"_a);
92 cls.def("dirichlet", pybind11::overload_cast<const Element&, const SCVF&>(&Problem::dirichlet, pybind11::const_), "element"_a, "scvf"_a);
93 }
94
95 cls.def("neumann", &Problem::template neumann<decltype(std::ignore), decltype(std::ignore)>);
96 cls.def("source", &Problem::template source<decltype(std::ignore)>);
97 cls.def("sourceAtPos", &Problem::sourceAtPos);
98 cls.def("initial", &Problem::template initial<Element>);
99 cls.def("initial", &Problem::template initial<Vertex>);
100 cls.def("gridGeometry", &Problem::gridGeometry);
101 cls.def("spatialParams", &Problem::spatialParams);
102}
103
104} // end namespace Dumux::Python
105
106#endif
Class to specify the type of a boundary.
Definition: common/boundarytypes.hh:26
A C++ wrapper for a Python problem.
Definition: python/common/fvproblem.hh:36
A C++ wrapper for a Python PorousMediumFlow problem.
Definition: python/porousmediumflow/problem.hh:29
typename GridGeometry::SubControlVolume SubControlVolume
Definition: python/porousmediumflow/problem.hh:38
typename PrimaryVariables::value_type Scalar
Definition: python/porousmediumflow/problem.hh:34
typename GridGeometry::LocalView FVElementGeometry
Definition: python/porousmediumflow/problem.hh:37
Dune::FieldVector< Scalar, PrimaryVariables::dimension > NumEqVector
Definition: python/porousmediumflow/problem.hh:35
typename Element::Geometry::GlobalCoordinate GlobalPosition
Definition: python/porousmediumflow/problem.hh:40
static constexpr std::size_t numEq
Definition: python/porousmediumflow/problem.hh:43
SpatialParams_ SpatialParams
Definition: python/porousmediumflow/problem.hh:33
PorousMediumFlowProblem(std::shared_ptr< const GridGeometry > gridGeometry, std::shared_ptr< const SpatialParams > spatialParams, pybind11::object pyProblem)
Definition: python/porousmediumflow/problem.hh:46
typename GridGeometry::GridView::template Codim< 0 >::Entity Element
Definition: python/porousmediumflow/problem.hh:36
GridGeometry_ GridGeometry
Definition: python/porousmediumflow/problem.hh:32
static constexpr bool isBox
Definition: python/porousmediumflow/problem.hh:42
typename GridGeometry::SubControlVolumeFace SubControlVolumeFace
Definition: python/porousmediumflow/problem.hh:39
const SpatialParams & spatialParams() const
Definition: python/porousmediumflow/problem.hh:53
constexpr Box box
Definition: method.hh:147
Definition: python/assembly/fvassembler.hh:18
void registerPorousMediumFlowProblem(pybind11::handle scope, pybind11::class_< Problem, options... > cls)
Definition: python/porousmediumflow/problem.hh:62
TODO: docme!