KIDS  ver-0.0.1
KIDS : Kernel Integrated Dynamics Simulator
Loading...
Searching...
No Matches
Model_ElectronTransfer.cpp
Go to the documentation of this file.
2
5#include "kids/hash_fnv1a.h"
6#include "kids/linalg.h"
7#include "kids/macro_utils.h"
8#include "kids/vars_list.h"
9
10namespace PROJECT_NS {
11
12const std::string Model_ElectronTransfer::getName() { return "Model_ElectronTransfer"; }
13
15
16void Model_ElectronTransfer::setInputParam_impl(std::shared_ptr<Param>& PM) {
17 // size information
18 Nb = _param->get_int("Nb", LOC());
19 nbath = _param->get_int("nbath", LOC());
20 scan_flag = _param->get_int("scan_flag", LOC(), 0);
21
22 // CHECK_EQ(nbath, 1);
23 // CHECK_EQ(Nb + 1, Dimension::N);
24
26 FORCE_OPT::Nb = Nb; //@ bugs
27 // omega0 = 3.5e-4;
28 // lambda0 = 2.39e-2;
29 // c0 = std::sqrt(0.5 * lambda0) * omega0;
30 // eta = 1.49e-5;
31 // alpha = 2.0 * eta / phys::math::pi;
32 // omegac = omega0;
33 // lambda = 0.5*alpha*omegac
34}
35
36void Model_ElectronTransfer::setInputDataSet_impl(std::shared_ptr<DataSet>& DS) {
38 Hsys = DS->def_real("model.Hsys", Dimension::FF);
39 memset(Hsys, 0, Dimension::FF * sizeof(kids_real));
40
41 omega0 = _param->get_double("omega0", LOC(), 3.5e-4);
42 lambda0 = _param->get_double("lambda0", LOC(), 2.39e-2);
43 coeff0 = _param->get_double("coeff0", LOC(), std::sqrt(0.5 * lambda0) * omega0);
44 double temperature = _param->get_double("temperature", LOC(), phys::temperature_d, 1.0f);
45 beta = 1.0f / (phys::au::k * temperature); // don't ignore k_Boltzman
46 double fullbias = _param->get_double("fullbias", LOC(), phys::energy_d, 0.0f);
47 double delta = _param->get_double("delta", LOC(), phys::energy_d, 5.0e-5);
48 // double eta = 1.49e-5; // eta has different relation with alpha!!!
49
50 switch (scan_flag) {
51 case 1:
52 fullbias = 0.0e0;
53 beta = 1.0 / 9.5e-4;
54 delta = delta / beta;
55 break;
56 case 2:
57 fullbias = fullbias * lambda0;
58 // beta = 1.0 / 9.5e-4;
59 delta = 5.0e-5;
60 break;
61 default: {
62 break;
63 }
64 }
65 double bias = fullbias / 2;
66 double HSB[4] = {bias, delta, delta, -bias};
67 for (int i = 0; i < Dimension::FF; ++i) Hsys[i] = HSB[i];
68
70 for (auto pkernel : _child_kernels) pkernel->setInputDataSet(DS);
75
76 double w2 = omega0 * omega0;
77 for (int j = 0; j < Nb; ++j) { w2 += (coeffs[j] * coeffs[j]) / (omegas[j] * omegas[j]); }
78 omega0 = std::sqrt(w2);
79
81 Q = DS->def(DATA::model::coupling::Q);
82 Q[0] = 1.0f, Q[1] = 0.0f, Q[2] = 0.0f, Q[3] = -1.0f;
83
84 // model field
85 mass = DS->def(DATA::model::mass);
86 for (int j = 0; j < Dimension::N; ++j) mass[j] = 1.0f;
87
88 vpes = DS->def(DATA::model::vpes);
89 grad = DS->def(DATA::model::grad);
90 hess = DS->def(DATA::model::hess);
91 V = DS->def(DATA::model::V);
92 dV = DS->def(DATA::model::dV);
93 // ddV = DS->def(DATA::model::ddV);
94
95 // init & integrator
96 x = DS->def(DATA::integrator::x);
97 p = DS->def(DATA::integrator::p);
98}
99
101 for (int iP = 0; iP < Dimension::P; ++iP) {
102 kids_real* x = this->x + iP * Dimension::N;
103 kids_real* p = this->p + iP * Dimension::N;
104
107
108 x[0] = x[0] * std::sqrt(0.5e0 / (omega0 * tanh(0.5e0 * beta * omega0))) //
109 - coeff0 / (omega0 * omega0);
110 p[0] = p[0] * std::sqrt(0.5e0 * omega0 / (tanh(0.5e0 * beta * omega0)));
111 for (int j = 0, jadd1 = 1; j < Nb; ++j, ++jadd1) {
112 x[jadd1] = x[jadd1] * std::sqrt(0.5e0 / (omegas[j] * tanh(0.5e0 * beta * omegas[j])));
113 p[jadd1] = p[jadd1] * std::sqrt(0.5e0 * omegas[j] / (tanh(0.5e0 * beta * omegas[j])));
114 }
115 }
116
117 _dataset->def_real("init.x", x, Dimension::PN);
118 _dataset->def_real("init.p", p, Dimension::PN);
119 executeKernel(stat);
120 return stat;
121}
122
124 for (int iP = 0; iP < Dimension::P; ++iP) {
125 kids_real* x = this->x + iP * Dimension::N;
126 kids_real* vpes = this->vpes + iP;
127 kids_real* grad = this->grad + iP * Dimension::N;
128 kids_real* hess = this->hess + iP * Dimension::NN;
129 kids_real* V = this->V + iP * Dimension::FF;
130 kids_real* dV = this->dV + iP * Dimension::NFF;
131
132 // note we implement mass = 1
133
134 // calculate nuclear vpes and grad
135 vpes[0] = omega0 * omega0 * x[0] * x[0];
136 grad[0] = omega0 * omega0 * x[0];
137 for (int j = 0, jadd1 = 1; j < Nb; ++j, ++jadd1) {
138 vpes[0] += omegas[j] * omegas[j] * x[jadd1] * x[jadd1];
139 grad[jadd1] = omegas[j] * omegas[j] * x[jadd1];
140 }
141 vpes[0] *= 0.5e0;
142 for (int j = 0, jadd1 = 1; j < Nb; ++j, ++jadd1) {
143 vpes[0] += coeffs[j] * x[0] * x[jadd1];
144 grad[0] += coeffs[j] * x[jadd1];
145 grad[jadd1] += coeffs[j] * x[0];
146 }
147
148 // calculate electronic V and dV
149 for (int i = 0; i < Dimension::FF; ++i) V[i] = Hsys[i];
150 V[0] += coeff0 * x[0];
151 V[3] -= coeff0 * x[0];
152
153 if (count_exec == 0) { // only calculate once time
155 dV[0] = coeff0;
156 dV[3] = -coeff0;
157 }
158 }
159 return stat;
160}
161
162}; // namespace PROJECT_NS
this file provides Kernel_NADForce class enabling force weighting from electronic properties.
#define ARRAY_CLEAR(_A, _n)
Definition array_macro.h:36
static int rand_gaussian(kids_real *res_arr, int N=1, kids_real sigma=1.0, kids_real mu=0.0)
std::vector< std::shared_ptr< Kernel > > _child_kernels
Vector containing shared pointers to the child kernels of this kernel.
Definition Kernel.h:298
std::shared_ptr< Param > _param
Shared pointer to the Param object associated with this kernel.
Definition Kernel.h:273
Status & executeKernel(Status &stat)
Execute the kernel's algorithm and those of its children.
Definition Kernel.cpp:48
std::shared_ptr< DataSet > _dataset
Shared pointer to the DataSet object associated with this kernel.
Definition Kernel.h:278
kids_real * omegas
save discrete frequencies (only for simple model, L=1)
virtual int getType() const
Get the type of the kernel.
virtual void setInputParam_impl(std::shared_ptr< Param > &PM)
Virtual function to set input parameters for the kernel implementation.
kids_real * coeffs
save coupling coefficients (only for simple model, L=1)
virtual const std::string getName()
Get the name of the kernel.
virtual void setInputDataSet_impl(std::shared_ptr< DataSet > &DS)
Virtual function to set input data set for the kernel implementation.
virtual Status & executeKernel_impl(Status &stat)
Virtual function to execute the kernel implementation.
virtual Status & initializeKernel_impl(Status &stat)
Virtual function to initialize the kernel implementation.
#define LOC()
show the location information for debug
Definition fmt.h:49
int count_exec
Counter for the number of executions performed by this kernel.
Definition Kernel.h:258
Provide linalg APIs.
#define FUNCTION_NAME
Definition macro_utils.h:9
VARIABLE< kids_real > p
VARIABLE< kids_real > x
VARIABLE< kids_real > p_sigma
VARIABLE< kids_real > x_sigma
VARIABLE< kids_real > omegas
VARIABLE< kids_real > coeffs
VARIABLE< kids_real > hess
VARIABLE< kids_real > vpes
VARIABLE< kids_real > V
VARIABLE< kids_real > dV
VARIABLE< kids_real > grad
VARIABLE< kids_real > mass
std::size_t PN
Product of P and N (P * N).
Definition vars_list.cpp:14
std::size_t NFF
Product of N, F, and F (N * F * F).
Definition vars_list.cpp:22
std::size_t N
Number of nuclear degrees of freedom.
Definition vars_list.cpp:10
std::size_t P
Number of parallel trajectories (swarms of trajectories) in each Monte Carlo run.
Definition vars_list.cpp:9
std::size_t NN
Product of N and N (N * N).
Definition vars_list.cpp:20
std::size_t FF
Product of F and F (F * F).
Definition vars_list.cpp:21
< http://warp.povusers.org/FunctionParser/fparser.html
Definition Context.h:39
double kids_real
Alias for real number type.
Definition Types.h:59
constexpr dimension7 temperature_d
Definition phys.h:195
constexpr dimension7 energy_d
[M*L^2/T^2] force integrate length
Definition phys.h:251
constexpr uint32_t hash(const char *str)
Definition hash_fnv1a.h:12
declaration of variables used in the program.