3.5-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
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 * 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_PROBLEM_HH
25#define DUMUX_PYTHON_POROUSMEDIUMFLOW_PROBLEM_HH
26
27
28#include <dune/python/pybind11/pybind11.h>
29
31
32namespace Dumux::Python {
33
38template<class GridGeometry_, class SpatialParams_, class PrimaryVariables, bool enableInternalDirichletConstraints>
40: public Dumux::Python::FVProblem<GridGeometry_, SpatialParams_, PrimaryVariables, enableInternalDirichletConstraints>
41{
43public:
44 using GridGeometry = GridGeometry_;
45 using SpatialParams = SpatialParams_;
46 using Scalar = typename PrimaryVariables::value_type;
47 using NumEqVector = Dune::FieldVector<Scalar, PrimaryVariables::dimension>;
48 using Element = typename GridGeometry::GridView::template Codim<0>::Entity;
49 using FVElementGeometry = typename GridGeometry::LocalView;
50 using SubControlVolume = typename GridGeometry::SubControlVolume;
51 using SubControlVolumeFace = typename GridGeometry::SubControlVolumeFace;
52 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
53
54 static constexpr bool isBox = GridGeometry::discMethod == DiscretizationMethods::box;
55 static constexpr std::size_t numEq = static_cast<std::size_t>(PrimaryVariables::dimension);
57
58 PorousMediumFlowProblem(std::shared_ptr<const GridGeometry> gridGeometry,
59 std::shared_ptr<const SpatialParams> spatialParams,
60 pybind11::object pyProblem)
62 , spatialParams_(spatialParams)
63 {}
64
66 { return *spatialParams_; }
67
68private:
69 std::shared_ptr<const SpatialParams> spatialParams_;
70};
71
72// Python wrapper for the above FVProblem C++ class
73template<class Problem, class... options>
74void registerPorousMediumFlowProblem(pybind11::handle scope, pybind11::class_<Problem, options...> cls)
75{
76 using pybind11::operator""_a;
77 using namespace Dune::Python;
78
79 using GridGeometry = typename Problem::GridGeometry;
80 using SpatialParams = typename Problem::SpatialParams;
81 cls.def(pybind11::init([](std::shared_ptr<const GridGeometry> gridGeometry,
82 std::shared_ptr<SpatialParams> spatialParams,
83 pybind11::object p){
84 return std::make_shared<Problem>(gridGeometry, spatialParams, p);
85 }));
86
87 cls.def_property_readonly("name", &Problem::name);
88 cls.def_property_readonly("numEq", [](Problem&){ return Problem::numEq; });
89
90 using GridView = typename GridGeometry::GridView;
91 using Element = typename GridView::template Codim<0>::Entity;
92 using Vertex = typename GridView::template Codim<GridView::dimension>::Entity;
93
94 if constexpr (Problem::isBox)
95 {
96 using SCV = typename Problem::SubControlVolume;
97 cls.def("boundaryTypes", pybind11::overload_cast<const Element&, const SCV&>(&Problem::boundaryTypes, pybind11::const_), "element"_a, "scv"_a);
98 cls.def("dirichlet", pybind11::overload_cast<const Element&, const SCV&>(&Problem::dirichlet, pybind11::const_), "element"_a, "scv"_a);
99 }
100 else
101 {
102 using SCVF = typename Problem::SubControlVolumeFace;
103 cls.def("boundaryTypes", pybind11::overload_cast<const Element&, const SCVF&>(&Problem::boundaryTypes, pybind11::const_), "element"_a, "scvf"_a);
104 cls.def("dirichlet", pybind11::overload_cast<const Element&, const SCVF&>(&Problem::dirichlet, pybind11::const_), "element"_a, "scvf"_a);
105 }
106
107 cls.def("neumann", &Problem::template neumann<decltype(std::ignore), decltype(std::ignore)>);
108 cls.def("source", &Problem::template source<decltype(std::ignore)>);
109 cls.def("sourceAtPos", &Problem::sourceAtPos);
110 cls.def("initial", &Problem::template initial<Element>);
111 cls.def("initial", &Problem::template initial<Vertex>);
112 cls.def("gridGeometry", &Problem::gridGeometry);
113 cls.def("spatialParams", &Problem::spatialParams);
114}
115
116} // end namespace Dumux::Python
117
118#endif
constexpr Box box
Definition: method.hh:139
Definition: python/assembly/fvassembler.hh:30
void registerPorousMediumFlowProblem(pybind11::handle scope, pybind11::class_< Problem, options... > cls)
Definition: python/porousmediumflow/problem.hh:74
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:48
A C++ wrapper for a Python PorousMediumFlow problem.
Definition: python/porousmediumflow/problem.hh:41
typename GridGeometry::SubControlVolume SubControlVolume
Definition: python/porousmediumflow/problem.hh:50
typename PrimaryVariables::value_type Scalar
Definition: python/porousmediumflow/problem.hh:46
typename GridGeometry::LocalView FVElementGeometry
Definition: python/porousmediumflow/problem.hh:49
Dune::FieldVector< Scalar, PrimaryVariables::dimension > NumEqVector
Definition: python/porousmediumflow/problem.hh:47
typename Element::Geometry::GlobalCoordinate GlobalPosition
Definition: python/porousmediumflow/problem.hh:52
static constexpr std::size_t numEq
Definition: python/porousmediumflow/problem.hh:55
SpatialParams_ SpatialParams
Definition: python/porousmediumflow/problem.hh:45
PorousMediumFlowProblem(std::shared_ptr< const GridGeometry > gridGeometry, std::shared_ptr< const SpatialParams > spatialParams, pybind11::object pyProblem)
Definition: python/porousmediumflow/problem.hh:58
typename GridGeometry::GridView::template Codim< 0 >::Entity Element
Definition: python/porousmediumflow/problem.hh:48
GridGeometry_ GridGeometry
Definition: python/porousmediumflow/problem.hh:44
static constexpr bool isBox
Definition: python/porousmediumflow/problem.hh:54
typename GridGeometry::SubControlVolumeFace SubControlVolumeFace
Definition: python/porousmediumflow/problem.hh:51
const SpatialParams & spatialParams() const
Definition: python/porousmediumflow/problem.hh:65
TODO: docme!