Langevin C++ source

Loading...
Searching...
No Matches
dplangevin.cpp
Go to the documentation of this file.
1
5
6#include <pybind11/numpy.h>
7#include <string>
8#include "dplangevin.hpp"
9
13 DPLangevin::DPLangevin(Parameters p)
14{
15 // "Local" copies
16 n_cells = p.n_cells;
17 dt = p.dt;
18 dx = p.dx;
19 // The Langevin density field grid as a 1d vector
20 density_grid = grid_t(n_cells, 0.0);
21 // Supplementary grids (as 1d vectors of same length)
22 aux_grid1 = grid_t(n_cells, 0.0);
23 aux_grid2 = grid_t(n_cells, 0.0);
24 k1_grid = grid_t(n_cells, 0.0);
25 k2_grid = grid_t(n_cells, 0.0);
26 k3_grid = grid_t(n_cells, 0.0);
27}
28
31 void DPLangevin::set_nonlinear_coefficients(const Coefficients& coefficients)
32{
33 quadratic_coefficient = coefficients.quadratic;
34 diffusion_coefficient = coefficients.diffusion / (dx*dx);
35}
36
39 double DPLangevin::nonlinear_rhs(const int i_cell, const grid_t& grid) const
40{
41 // Non-linear term, which is quadratic in the DP Langevin equation
42 const double quadratic_term
43 = -quadratic_coefficient*grid[i_cell]*grid[i_cell];
44
45 // For integration of diffusion
46 double diffusion_sum = 0.0;
47 const neighborhood_t& cell_wiring = grid_wiring[i_cell];
48 for (auto j_wire=0; j_wire<cell_wiring.size(); j_wire++)
49 {
50 const auto j_neighbor_cell = cell_wiring[j_wire];
51 diffusion_sum += grid[j_neighbor_cell];
52 }
53 const auto diffusion_term = (
54 diffusion_coefficient*(diffusion_sum
55 - cell_wiring.size()*grid[i_cell])
56 );
57 // Combine terms
58 return diffusion_term + quadratic_term;
59}
BaseLangevin::density_grid
grid_t density_grid
Density field grid.
Definition langevin_base.hpp:21
BaseLangevin::dt
double dt
Time step, i.e, epoch-to-epoch Δt.
Definition langevin_base.hpp:26
BaseLangevin::n_cells
int n_cells
Total number of cells in n-D grid.
Definition langevin_base.hpp:19
BaseLangevin::aux_grid1
grid_t aux_grid1
Temporary density grid used to perform an integration step.
Definition langevin_base.hpp:55
BaseLangevin::grid_wiring
grid_wiring_t grid_wiring
Neighorhood topology for all grid cells.
Definition langevin_base.hpp:23
BaseLangevin::aux_grid2
grid_t aux_grid2
Temporary density grid used to perform an integration step.
Definition langevin_base.hpp:57
BaseLangevin::k1_grid
grid_t k1_grid
Runge-Kutta variable grid #1.
Definition langevin_base.hpp:49
BaseLangevin::k2_grid
grid_t k2_grid
Runge-Kutta variable grid #2.
Definition langevin_base.hpp:51
BaseLangevin::k3_grid
grid_t k3_grid
Runge-Kutta variable grid #3.
Definition langevin_base.hpp:53
BaseLangevin::dx
double dx
Grid spacing, i.e., spacing Δx between cell centers in all directions.
Definition langevin_base.hpp:28
DPLangevin::set_nonlinear_coefficients
void set_nonlinear_coefficients(const Coefficients &coefficients)
Method to set nonlinear coefficients for deterministic integration step.
Definition dplangevin.cpp:31
DPLangevin::nonlinear_rhs
double nonlinear_rhs(const int i_cell, const grid_t &density) const
Method to set nonlinear RHS of Langevin equation for deterministic integration step.
Definition dplangevin.cpp:39
DPLangevin::diffusion_coefficient
double diffusion_coefficient
Diffusion coefficient D in DP-Langevin equation.
Definition dplangevin.hpp:26
DPLangevin::quadratic_coefficient
double quadratic_coefficient
Coefficient in nonlinear term -bρ² in DP-Langevin equation.
Definition dplangevin.hpp:24
DPLangevin::DPLangevin
DPLangevin()=default
Constructor assuming default model parameters.
dplangevin.hpp
DPLangevin model application of BaseLangevin class integrator.
grid_t
std::vector< double > grid_t
Type for density grid.
Definition langevin_types.hpp:24
neighborhood_t
std::vector< int > neighborhood_t
Type for density grid wiring.
Definition langevin_types.hpp:28
Coefficients
Container for nonlinear Langevin equation coefficients.
Definition langevin_coefficients.hpp:24
Parameters
Container for BaseLangevin integrator parameters.
Definition langevin_parameters.hpp:21