version 3.10-dev
python/common/boundarytypes.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_COMMON_BOUNDARYTYPES_HH
13#define DUMUX_PYTHON_COMMON_BOUNDARYTYPES_HH
14
15#include <dune/common/classname.hh>
16#include <dune/python/pybind11/pybind11.h>
17#include <dune/python/common/typeregistry.hh>
18
20
21namespace Dumux::Python {
22
23template <class BoundaryTypes, class... Options>
24void registerBoundaryTypes(pybind11::handle scope, pybind11::class_<BoundaryTypes, Options...> cls)
25{
26 using pybind11::operator""_a;
27
28 cls.def(pybind11::init());
29 cls.def("__copy__", [](const BoundaryTypes& self) {
30 return BoundaryTypes(self);
31 });
32 cls.def("__deepcopy__", [](const BoundaryTypes& self, pybind11::dict) {
33 return BoundaryTypes(self);
34 }, "memo"_a);
35 cls.def("reset", &BoundaryTypes::reset);
36 cls.def("setNeumann", &BoundaryTypes::setAllNeumann);
37 cls.def("setDirichlet", &BoundaryTypes::setAllDirichlet);
38 cls.def_property_readonly("isDirichlet", &BoundaryTypes::hasDirichlet);
39 cls.def_property_readonly("isNeumann", &BoundaryTypes::hasNeumann);
40}
41
42template <class BoundaryTypes>
43void registerBoundaryTypes(pybind11::handle scope)
44{
45 using namespace Dune::Python;
46
47 auto [cls, addedToRegistry] = insertClass<BoundaryTypes>(
48 scope, "BoundaryTypes",
49 GenerateTypeName(Dune::className<BoundaryTypes>()),
50 IncludeFiles{"dumux/python/common/boundarytypes.hh"}
51 );
52
53 if (addedToRegistry)
54 registerBoundaryTypes(scope, cls);
55}
56
57} // namespace Dumux::Python
58
59#endif
Class to specify the type of a boundary.
Definition: common/boundarytypes.hh:26
void setAllNeumann()
Set all boundary conditions to Neumann.
Definition: common/boundarytypes.hh:90
void setAllDirichlet()
Set all boundary conditions to Dirichlet.
Definition: common/boundarytypes.hh:99
void reset()
Reset the boundary types for all equations.
Definition: common/boundarytypes.hh:42
bool hasNeumann() const
Returns true if some equation is used to specify a Neumann condition.
Definition: common/boundarytypes.hh:260
bool hasDirichlet() const
Returns true if some equation is used to specify a Dirichlet condition.
Definition: common/boundarytypes.hh:222
Class to specify the type of a boundary.
Definition: python/assembly/fvassembler.hh:18
void registerBoundaryTypes(pybind11::handle scope, pybind11::class_< BoundaryTypes, Options... > cls)
Definition: python/common/boundarytypes.hh:24