24#ifndef DUMUX_PYTHON_DISCRETIZATION_GRIDVARIABLES_HH
25#define DUMUX_PYTHON_DISCRETIZATION_GRIDVARIABLES_HH
28#include <dune/istl/bvector.hh>
29#include <dune/python/pybind11/pybind11.h>
30#include <dune/python/common/typeregistry.hh>
37template<
class ElementSolution>
38void registerElementSolution(pybind11::handle scope)
40 using namespace Dune::Python;
42 auto [cls, addedToRegistry] = insertClass<ElementSolution>(
43 scope,
"ElementSolution",
44 GenerateTypeName(Dune::className<ElementSolution>()),
45 IncludeFiles{
"dumux/discretization/elementsolution.hh"}
50 using pybind11::operator
""_a;
52 cls.def(
"__getitem__", [](
const ElementSolution& self, std::size_t i){
54 throw pybind11::index_error();
58 cls.def_property_readonly(
"size", &ElementSolution::size);
66template <
class GV,
class... Options>
69 using pybind11::operator
""_a;
71 using Problem =
typename GV::GridVolumeVariables::Problem;
72 using PrimaryVariables =
typename GV::GridVolumeVariables::VolumeVariables::PrimaryVariables;
73 using GridGeometry =
typename GV::GridGeometry;
74 using Element =
typename GridGeometry::GridView::template Codim<0>::Entity;
75 using SolutionVector = Dune::BlockVector<PrimaryVariables>;
77 cls.def(pybind11::init([](std::shared_ptr<const Problem> problem,
78 std::shared_ptr<const GridGeometry> gridGeometry){
79 return std::make_shared<GV>(problem, gridGeometry);
82 cls.def(
"init", [](GV& self,
const SolutionVector& sol) {
return self.init(sol); });
83 cls.def(
"advanceTimeStep", &GV::advanceTimeStep);
84 cls.def_property_readonly(
"curGridVolVars", [](GV& self) {
return self.curGridVolVars(); });
85 cls.def_property_readonly(
"gridFluxVarsCache", [](GV& self) {
return self.gridFluxVarsCache(); });
86 cls.def_property_readonly(
"prevGridVolVars", [](GV& self) {
return self.prevGridVolVars(); });
87 cls.def_property_readonly(
"gridGeometry", &GV::gridGeometry);
89 cls.def(
"updateAfterGridAdaption", [](GV& self,
const SolutionVector& sol){
90 return self.updateAfterGridAdaption(sol);
93 cls.def(
"resetTimeStep", [](GV& self,
const SolutionVector& sol){
94 return self.resetTimeStep(sol);
97 cls.def(
"update", [](GV& self,
const SolutionVector& sol,
const bool forceFluxCacheUpdate =
false){
98 return self.update(sol, forceFluxCacheUpdate);
101 using ElementSolution = std::decay_t<decltype(elementSolution(std::declval<Element>(),
102 std::declval<SolutionVector>(),
103 std::declval<GridGeometry>()))>;
104 Impl::registerElementSolution<ElementSolution>(scope);
Element solution classes and factory functions.
Definition: python/assembly/fvassembler.hh:30
void registerGridVariables(pybind11::handle scope, pybind11::class_< GV, Options... > cls)
Definition: python/discretization/gridvariables.hh:67