| 1 |
|
| 2 |
// Copyright (C) 2017 Chris Richardson and Garth N. Wells |
| 3 |
// |
| 4 |
// This file is part of DOLFIN. |
| 5 |
// |
| 6 |
// DOLFIN is free software: you can redistribute it and/or modify |
| 7 |
// it under the terms of the GNU Lesser 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 |
// DOLFIN 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 Lesser General Public License for more details. |
| 15 |
// |
| 16 |
// You should have received a copy of the GNU Lesser General Public License |
| 17 |
// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
#include <memory> |
| 20 |
#include <pybind11/pybind11.h> |
| 21 |
#include <pybind11/stl.h> |
| 22 |
|
| 23 |
#include <dolfin/fem/DirichletBC.h> |
| 24 |
#include <dolfin/fem/Form.h> |
| 25 |
#include <dolfin/fem/GenericDofMap.h> |
| 26 |
#include <dolfin/function/Constant.h> |
| 27 |
#include <dolfin/function/Function.h> |
| 28 |
#include <dolfin/la/GenericVector.h> |
| 29 |
#include <dolfin/ts/CVode.h> |
| 30 |
|
| 31 |
namespace py = pybind11; |
| 32 |
|
| 33 |
namespace dolfin_wrappers |
| 34 |
{ |
| 35 |
|
| 36 |
void ts(py::module& m) |
| 37 |
{ |
| 38 |
|
| 39 |
#ifdef HAS_SUNDIALS |
| 40 |
// CVode trampoline class for allowing overloading of virtual functions |
| 41 |
class PyCVode : public dolfin::CVode |
| 42 |
{ |
| 43 |
public: |
| 44 |
using dolfin::CVode::CVode; |
| 45 |
|
| 46 |
void derivs(double t, std::shared_ptr<dolfin::GenericVector> u, |
| 47 |
std::shared_ptr<dolfin::GenericVector> udot) |
| 48 |
{ PYBIND11_OVERLOAD_NAME(void, dolfin::CVode, "derivs", derivs, |
| 49 |
t, u, udot); } |
| 50 |
|
| 51 |
int jacobian(std::shared_ptr<const dolfin::GenericVector> v, |
| 52 |
std::shared_ptr<dolfin::GenericVector> Jv, |
| 53 |
double t, |
| 54 |
std::shared_ptr<const dolfin::GenericVector> y, |
| 55 |
std::shared_ptr<const dolfin::GenericVector> fy) |
| 56 |
{ PYBIND11_OVERLOAD_NAME(int, dolfin::CVode, "jacobian", jacobian, |
| 57 |
v, Jv, t, y, fy); } |
| 58 |
|
| 59 |
int psolve(double t, |
| 60 |
std::shared_ptr<const dolfin::GenericVector> y, |
| 61 |
std::shared_ptr<const dolfin::GenericVector> fy, |
| 62 |
std::shared_ptr<const dolfin::GenericVector> r, |
| 63 |
std::shared_ptr<dolfin::GenericVector> z, |
| 64 |
double gamma, double delta, int lr) |
| 65 |
{ PYBIND11_OVERLOAD_NAME(int, dolfin::CVode, "psolve", psolve, |
| 66 |
t, y, fy, r, z, gamma, delta, lr); } |
| 67 |
}; |
| 68 |
|
| 69 |
py::class_<dolfin::CVode, PyCVode, std::shared_ptr<dolfin::CVode>>cvode(m,"CVode"); |
| 70 |
//dolfin::CVode |
| 71 |
cvode |
| 72 |
.def(py::init<dolfin::CVode::LMM, dolfin::CVode::ITER>()) |
| 73 |
.def("init", &dolfin::CVode::init, py::arg("u0"), py::arg("atol"), |
| 74 |
py::arg("rtol"), py::arg("mxsteps")=0) |
| 75 |
.def("set_time", &dolfin::CVode::set_time, py::arg("t0")) |
| 76 |
.def("get_time", &dolfin::CVode::get_time) |
| 77 |
.def("step", &dolfin::CVode::step, py::arg("dt")) |
| 78 |
.def("statistics", &dolfin::CVode::statistics) |
| 79 |
.def("derivs", &dolfin::CVode::derivs) |
| 80 |
.def("jacobian", &dolfin::CVode::jacobian) |
| 81 |
.def("psolve", &dolfin::CVode::psolve); |
| 82 |
|
| 83 |
py::enum_<dolfin::CVode::LMM>(cvode,"LMM") |
| 84 |
.value("CV_BDF", dolfin::CVode::LMM::cv_bdf) |
| 85 |
.value("CV_ADAMS", dolfin::CVode::LMM::cv_adams); |
| 86 |
|
| 87 |
py::enum_<dolfin::CVode::ITER>(cvode,"ITER") |
| 88 |
.value("CV_FUNCTIONAL", dolfin::CVode::ITER::cv_functional) |
| 89 |
.value("CV_NEWTON", dolfin::CVode::ITER::cv_newton); |
| 90 |
|
| 91 |
#endif |
| 92 |
|
| 93 |
} |
| 94 |
} |