Langevin C++ source
Loading...
Searching...
No Matches
sim_dplangevin.cpp
Go to the documentation of this file.
1
5
6#include "sim_dplangevin.hpp"
7
12 const double linear, const double quadratic,
13 const double diffusion, const double noise,
14 const double t_final,
15 const double dx, const double dt,
16 const int random_seed,
17 const GridDimension grid_dimension,
18 const int_vec_t grid_size,
19 const gt_vec_t grid_topologies,
20 const bc_vec_t boundary_conditions,
21 const dbl_vec_t bc_values,
22 const InitialCondition initial_condition,
23 const dbl_vec_t ic_values,
24 const IntegrationMethod integration_method,
25 const bool do_snapshot_grid,
26 const bool do_verbose
27) : coefficients(linear, quadratic, diffusion, noise),
28 p(
29 t_final,
30 dx,
31 dt,
32 random_seed,
33 grid_dimension,
34 grid_size,
35 grid_topologies,
36 boundary_conditions,
37 bc_values,
38 initial_condition,
39 ic_values,
40 integration_method
41 ),
44{
45 rng = new rng_t(p.random_seed);
46 dpLangevin = new DPLangevin(p);
47 if (do_verbose)
48 {
49 coefficients.print();
50 p.print();
51 }
52}
53
59{
60 if (not dpLangevin->construct_grid(p)) {
61 std::cout
62 << "SimDP::initialize failure: couldn't construct grid"
63 << std::endl;
64 return false;
65 }
66 if (not dpLangevin->initialize_grid(p, *rng)) {
67 std::cout
68 << "SimDP::initialize failure: couldn't initialize grid"
69 << std::endl;
70 return false;
71 }
72 dpLangevin->prepare(coefficients);
73 this->n_decimals = n_decimals;
77 // Treat epoch#0 as the initial grid state
78 // So after initialization, we are nominally at epoch#1
79 i_next_epoch = 1;
80 t_next_epoch = p.dt;
81 if (not choose_integrator())
82 {
83 std::cout << "SimDP::initialize failure: unable to choose integrator" << std::endl;
84 return false;
85 }
86 if (not dpLangevin->check_boundary_conditions(p))
87 {
88 std::cout << "SimDP::initialize failure: wrong number of boundary conditions" << std::endl;
89 return false;
90 }
91 is_initialized = true;
92 return is_initialized;
93}
94
99bool SimDP::run(const int n_next_epochs)
100{
101 if (not is_initialized)
102 {
103 std::cout << "SimDP::run failure: must initialize first" << std::endl;
104 return false;
105 }
106 did_integrate = integrate(n_next_epochs);
107 return did_integrate;
108}
109
115{
116 if (not is_initialized)
117 {
118 std::cout
119 << "SimDP::postprocess failure: no data to process yet"
120 << std::endl;
121 return false;
122 }
123 bool did_process_grid;
124 if (do_snapshot_grid) { did_process_grid = pyprep_density_grid(); }
125 else { did_process_grid = true; }
126 bool did_process_time_series = (
128 );
129 return (did_process_grid and did_process_time_series);
130}
DPLangevin model application of BaseLangevin class integrator.
bool initialize(int n_decimals)
Initialize the model 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.
bool do_verbose
Flag whether to report sim parameters etc.
int i_next_epoch
Index of next epoch aka time step.
bool do_snapshot_grid
Flag whether to take density grid snapshots.
Parameters p
Model simulation parameters.
dbl_vec_t mean_densities
Vector time-series of grid-averaged field density values.
SimDP(const double linear, const double quadratic, const double diffusion, const double noise, const double t_final, const double dx, const double dt, const int random_seed, const GridDimension grid_dimension, const int_vec_t grid_size, const gt_vec_t grid_topologies, const bc_vec_t boundary_conditions, const dbl_vec_t bc_values, const InitialCondition initial_condition, const dbl_vec_t ic_values, const IntegrationMethod integration_method, const bool do_snapshot_grid, const bool do_verbose)
Constructor.
int count_epochs() const
Count upcoming number of epochs by running a dummy time-stepping loop.
Coefficients coefficients
Langevin equation coefficients.
bool choose_integrator()
Chooses function implementing either Runge-Kutta or Euler integration methods.
double t_next_epoch
Time of next epoch.
bool is_initialized
Flag whether simulation has been initialized or not.
bool pyprep_mean_densities()
Generate a Python-compatible version of the mean densities time-series vector.
int n_epochs
Total number of simulation time steps aka "epochs".
dbl_vec_t t_epochs
Vector time-series of epochs.
bool pyprep_t_epochs()
Generate a Python-compatible version of the epochs time-series vector.
int n_decimals
Truncation number of decimal places when summing Δt.
DPLangevin * dpLangevin
Instance of DP Langevin integrator class (pointer to instance)
bool did_integrate
Flag whether integration step was successful or not.
bool pyprep_density_grid()
Generate a Python-compatible version of the current density grid.
rng_t * rng
Random number generation function (Mersenne prime) (pointer to RNG)
bool integrate(const int n_next_epochs)
Perform Dornic-type integration of the DP Langevin equation for n_next_epochs
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.
std::mt19937 rng_t
Use Mersenne Twister random number generator.
Class that manages simulation of DPLangevin equation.