DP Langevin
Loading...
Searching...
No Matches
wrapper_pybind.cpp
Go to the documentation of this file.
1
6
7#include <pybind11/numpy.h>
8// Essential for STL container conversions
9#include <pybind11/stl.h>
10#include "sim_dplangevin.hpp"
11
26PYBIND11_MODULE(dplvn, module)
27{
28 module.attr("__version__") = "2025.10.13a1";
29 module.doc() =
30 "Operator-splitting method of integrating DP-type Langevin equations";
31
32 py::enum_<GridDimension>(module, "GridDimension")
33 .value("D1", GridDimension::D1)
34 .value("D2", GridDimension::D2)
35 .value("D3", GridDimension::D3)
36 // .value("D4", GridDimension::D4) // never gonna happen
37 .export_values();
38
39 py::enum_<GridTopology>(module, "GridTopology")
40 .value("BOUNDED", GridTopology::BOUNDED)
41 .value("PERIODIC", GridTopology::PERIODIC)
42 .export_values();
43
44 py::enum_<BoundaryCondition>(module, "BoundaryCondition")
45 .value("FLOATING", BoundaryCondition::FLOATING)
46 .value("FIXED_VALUE", BoundaryCondition::FIXED_VALUE)
47 .value("FIXED_FLUX", BoundaryCondition::FIXED_FLUX)
48 .export_values();
49
50 py::enum_<InitialCondition>(module, "InitialCondition")
51 .value("RANDOM_UNIFORM", InitialCondition::RANDOM_UNIFORM)
52 .value("RANDOM_GAUSSIAN", InitialCondition::RANDOM_GAUSSIAN)
53 .value("CONSTANT_VALUE", InitialCondition::CONSTANT_VALUE)
54 .value("SINGLE_SEED", InitialCondition::SINGLE_SEED)
55 .export_values();
56
57 py::enum_<IntegrationMethod>(module, "IntegrationMethod")
58 .value("EULER", IntegrationMethod::EULER)
59 .value("RUNGE_KUTTA", IntegrationMethod::RUNGE_KUTTA)
60 .export_values();
61
62 py::class_<SimDP>(module, "SimDP")
63 .def(
64 py::init<
65 double, double,
66 double, double,
67 double, double, double,
68 int,
72 bc_vec_t,
77 >(),
78 "Simulation of DP Langevin equation",
79 py::arg("linear") = 1.0,
80 py::arg("quadratic") = 2.0,
81 py::arg("diffusion") = 0.1,
82 py::arg("noise") = 1.0,
83 py::arg("t_final") = 100.0,
84 py::arg("dx") = 0.5,
85 py::arg("dt") = 0.01,
86 py::arg("random_seed") = 1,
87 py::arg("grid_dimension") = GridDimension::D2,
88 py::arg("grid_size") = int_vec_t(2),
89 py::arg("grid_topologies") = gt_vec_t(2),
90 py::arg("boundary_conditions") = bc_vec_t(4),
91 py::arg("bc_values") = dbl_vec_t(4),
92 py::arg("initial_condition") = InitialCondition::RANDOM_UNIFORM,
93 py::arg("ic_values") = dbl_vec_t(3),
94 py::arg("integration_method") = IntegrationMethod::RUNGE_KUTTA
95 )
96 .def("initialize", &SimDP::initialize)
97 .def("run", &SimDP::run)
98 .def("postprocess", &SimDP::postprocess)
99 .def("get_n_epochs", &SimDP::get_n_epochs)
100 .def("get_i_next_epoch", &SimDP::get_i_next_epoch)
101 .def("get_i_current_epoch", &SimDP::get_i_current_epoch)
102 .def("get_t_next_epoch", &SimDP::get_t_next_epoch)
103 .def("get_t_current_epoch", &SimDP::get_t_current_epoch)
104 .def("get_t_epochs", &SimDP::get_t_epochs)
105 .def("get_mean_densities", &SimDP::get_mean_densities)
106 .def("get_density", &SimDP::get_density);
107}
int get_i_current_epoch() const
Fetch the index of the current epoch of the simulation.
bool run(const int n_next_epochs)
Execute the model simulation for n_next_epochs
bool postprocess()
Process the model results data if available.
py_array_t get_density() const
Fetch the current Langevin density field grid as a Python array.
py_array_t get_t_epochs() const
Fetch a times-series vector of the simulation epochs as a Python array.
double get_t_next_epoch() const
Fetch the next epoch (time) of the simulation.
bool initialize()
Initialize the model simulation.
double get_t_current_epoch() const
Fetch the current epoch (time) of the simulation.
py_array_t get_mean_densities() const
Fetch a times-series vector of the grid-averaged density field over time as a Python array.
int get_n_epochs() const
Fetch the total number of simulation epochs.
int get_i_next_epoch() const
Fetch the index of the next epoch of the simulation.
GridDimension
Density field grid dimension: only 1D or 2D grids implemented so far.
IntegrationMethod
Deterministic integration method: default is 4th-order Runge-Kutta; can be explicit Euler.
InitialCondition
Grid density field initial condition: random uniform or Gaussian variates; constant everywhere; or ce...
std::vector< GridTopology > gt_vec_t
Type for specifying grid topology in each direction x, y, z...
std::vector< int > int_vec_t
Type for vectors of integers.
std::vector< double > dbl_vec_t
Type for vectors of doubles.
Class that manages simulation of DPLangevin equation.
PYBIND11_MODULE(dplvn, module)