DP Langevin
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) : coefficients(linear, quadratic, diffusion, noise),
26 p(
27 t_final,
28 dx,
29 dt,
30 random_seed,
31 grid_dimension,
32 grid_size,
33 grid_topologies,
34 boundary_conditions,
35 bc_values,
36 initial_condition,
37 ic_values,
38 integration_method
39 )
40{
41 rng = new rng_t(p.random_seed);
42 dpLangevin = new DPLangevin(p);
43 coefficients.print();
44 p.print();
45}
46
52{
53 if (not dpLangevin->construct_grid(p)) {
54 std::cout
55 << "SimDP::initialize failure: couldn't construct grid"
56 << std::endl;
57 return false;
58 }
59 if (not dpLangevin->initialize_grid(p, *rng)) {
60 std::cout
61 << "SimDP::initialize failure: couldn't initialize grid"
62 << std::endl;
63 return false;
64 }
65 dpLangevin->prepare(coefficients);
69 // Treat epoch#0 as the initial grid state
70 // So after initialization, we are nominally at epoch#1
71 i_next_epoch = 1;
72 t_next_epoch = p.dt;
73 if (not choose_integrator())
74 {
75 std::cout << "SimDP::initialize failure: unable to choose integrator" << std::endl;
76 return false;
77 }
78 if (not dpLangevin->check_boundary_conditions(p))
79 {
80 std::cout << "SimDP::initialize failure: wrong number of boundary conditions" << std::endl;
81 return false;
82 }
83 is_initialized = true;
84 return is_initialized;
85}
86
91bool SimDP::run(const int n_next_epochs)
92{
93 if (not is_initialized)
94 {
95 std::cout << "SimDP::run failure: must initialize first" << std::endl;
96 return false;
97 }
98 did_integrate = integrate(n_next_epochs);
99 return did_integrate;
100}
101
107{
108 if (not is_initialized)
109 {
110 std::cout << "SimDP::postprocess failure: no data to process yet" << std::endl;
111 return false;
112 }
113 bool did_process = (
115 );
116 return did_process;
117}
DPLangevin model application of BaseLangevin class integrator.
bool run(const int n_next_epochs)
Execute the model simulation for n_next_epochs
bool postprocess()
Process the model results data if available.
int i_next_epoch
Index of next epoch aka time step.
Parameters p
Model simulation parameters.
dbl_vec_t mean_densities
Vector time-series of grid-averaged field density values.
int count_epochs() const
Count upcoming number of epochs by running a dummy time-stepping loop.
Coefficients coefficients
Langevin equation coefficients.
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)
Constructor.
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.
bool initialize()
Initialize the model simulation.
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.