Langevin C++ source

Loading...
Searching...
No Matches
wrapper_dplvn.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
26 PYBIND11_MODULE(dplvn, module)
27{
28 module.attr("__version__") = "2025.12.16a4";
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,
69 GridDimension,
70 int_vec_t,
71 gt_vec_t,
72 bc_vec_t,
73 dbl_vec_t,
74 InitialCondition,
75 dbl_vec_t,
76 IntegrationMethod,
77 bool,
78 bool
79 >(),
80 "Simulation of DP Langevin equation",
81 py::arg("linear") = 1.0,
82 py::arg("quadratic") = 2.0,
83 py::arg("diffusion") = 0.1,
84 py::arg("noise") = 1.0,
85 py::arg("t_final") = 100.0,
86 py::arg("dx") = 0.5,
87 py::arg("dt") = 0.01,
88 py::arg("random_seed") = 1,
89 py::arg("grid_dimension") = GridDimension::D2,
90 py::arg("grid_size") = int_vec_t(2),
91 py::arg("grid_topologies") = gt_vec_t(2),
92 py::arg("boundary_conditions") = bc_vec_t(4),
93 py::arg("bc_values") = dbl_vec_t(4),
94 py::arg("initial_condition") = InitialCondition::RANDOM_UNIFORM,
95 py::arg("ic_values") = dbl_vec_t(3),
96 py::arg("integration_method") = IntegrationMethod::RUNGE_KUTTA,
97 py::arg("do_snapshot_grid") = false,
98 py::arg("do_verbose") = false
99 )
100 .def("initialize", &SimDP::initialize)
101 .def("run", &SimDP::run)
102 .def("postprocess", &SimDP::postprocess)
103 .def("get_n_epochs", &SimDP::get_n_epochs)
104 .def("get_i_next_epoch", &SimDP::get_i_next_epoch)
105 .def("get_i_current_epoch", &SimDP::get_i_current_epoch)
106 .def("get_t_next_epoch", &SimDP::get_t_next_epoch)
107 .def("get_t_current_epoch", &SimDP::get_t_current_epoch)
108 .def("get_t_epochs", &SimDP::get_t_epochs)
109 .def("get_mean_densities", &SimDP::get_mean_densities)
110 .def("get_density", &SimDP::get_density);
111}
SimDP::initialize
bool initialize(int n_decimals)
Initialize the model simulation.
Definition sim_dplangevin.cpp:58
SimDP::get_i_current_epoch
int get_i_current_epoch() const
Fetch the index of the current epoch of the simulation.
Definition sim_dplangevin_utilities.cpp:9
SimDP::run
bool run(const int n_next_epochs)
Execute the model simulation for n_next_epochs
Definition sim_dplangevin.cpp:99
SimDP::postprocess
bool postprocess()
Process the model results data if available.
Definition sim_dplangevin.cpp:114
SimDP::get_density
py_array_t get_density() const
Fetch the current Langevin density field grid as a Python array.
Definition sim_dplangevin_utilities.cpp:15
SimDP::get_t_epochs
py_array_t get_t_epochs() const
Fetch a times-series vector of the simulation epochs as a Python array.
Definition sim_dplangevin_utilities.cpp:13
SimDP::get_t_next_epoch
double get_t_next_epoch() const
Fetch the next epoch (time) of the simulation.
Definition sim_dplangevin_utilities.cpp:12
SimDP::get_t_current_epoch
double get_t_current_epoch() const
Fetch the current epoch (time) of the simulation.
Definition sim_dplangevin_utilities.cpp:11
SimDP::get_mean_densities
py_array_t get_mean_densities() const
Fetch a times-series vector of the grid-averaged density field over time as a Python array.
Definition sim_dplangevin_utilities.cpp:14
SimDP::get_n_epochs
int get_n_epochs() const
Fetch the total number of simulation epochs.
Definition sim_dplangevin_utilities.cpp:8
SimDP::get_i_next_epoch
int get_i_next_epoch() const
Fetch the index of the next epoch of the simulation.
Definition sim_dplangevin_utilities.cpp:10
GridDimension
GridDimension
Density field grid dimension: only 1D or 2D grids implemented so far.
Definition langevin_enums.hpp:15
IntegrationMethod
IntegrationMethod
Deterministic integration method: default is 4th-order Runge-Kutta; can be explicit Euler.
Definition langevin_enums.hpp:58
InitialCondition
InitialCondition
Grid density field initial condition: random uniform or Gaussian variates; constant everywhere; or ce...
Definition langevin_enums.hpp:49
gt_vec_t
std::vector< GridTopology > gt_vec_t
Type for specifying grid topology in each direction x, y, z...
Definition langevin_types.hpp:45
int_vec_t
std::vector< int > int_vec_t
Type for vectors of integers.
Definition langevin_types.hpp:21
dbl_vec_t
std::vector< double > dbl_vec_t
Type for vectors of doubles.
Definition langevin_types.hpp:19
sim_dplangevin.hpp
Class that manages simulation of DPLangevin equation.
PYBIND11_MODULE
PYBIND11_MODULE(dplvn, module)
Definition wrapper_dplvn.cpp:26