KIDS  ver-0.0.1
KIDS : Kernel Integrated Dynamics Simulator
Loading...
Searching...
No Matches
Kernel_Elec_NAD.cpp
Go to the documentation of this file.
2
7#include "kids/debug_utils.h"
8#include "kids/hash_fnv1a.h"
9#include "kids/linalg.h"
10#include "kids/macro_utils.h"
11#include "kids/vars_list.h"
12
13inline bool isFileExists(const std::string& name) { return std::ifstream{name.c_str()}.good(); }
14
15double phi(double lambda, double N0_max, int F) {
16 double x = lambda * N0_max / 2;
17 double term1 = 1.0e0;
18 { // hypergeometric(double a, double b, double c, double x)
19 const double TOLERANCE = 1.0e-10;
20 int a = 1, b = 1, c = 1 + F;
21 double t = a * b * x / c;
22 term1 += t;
23 int n = 1;
24 while (abs(t) > TOLERANCE) {
25 a++, b++, c++, n++;
26 t *= a * b * x / c / n;
27 term1 += t;
28 }
29 }
30 int Fact = 1;
31 for (int i = 1; i < F; ++i) Fact *= i;
32 term1 = 2 * (F - 2) * (F - 1) * term1 / Fact / F;
33 double term2 = (6 - 2 * F - 2 * x) / Fact;
34 return pow(lambda, F) * pow(2 - 2 * x, 1 - F) * (term1 + term2);
35}
36
37namespace PROJECT_NS {
38
39double calc_alpha(kids_real* V, int i = 0, int k = 1, int F = 2) { // acoording to mix angle
40 int ii = i * (F + 1), kk = k * (F + 1), ik = i * F + k;
41 if (V[ii] == V[kk]) return 1.0e0;
42 double res = 2.0e0 / phys::math::pi * atan(2 * V[ik] / (V[ii] - V[kk]));
43 if (abs(res) < 1.0e-4) res = copysign(1.0e-4, res);
44 return res;
45}
46
47int calc_wrho(kids_complex* wrho, // distorted rho
48 kids_complex* rho, // rho_ele
49 double xi, // xi must be 1
50 double gamma, // gamma must be 0
51 double alpha) {
52 // initialize distorted-density
53 kids_real L = 1.0e0 - log(std::abs(alpha)); // @NOTE
54 kids_complex norm = 0.0e0;
55 for (int i = 0, ik = 0; i < Dimension::F; ++i) {
56 for (int k = 0; k < Dimension::F; ++k, ++ik) {
57 if (i == k) {
58 wrho[ik] = copysign(1.0, std::real(rho[ik])) * std::pow(std::abs(rho[ik]), L);
59 norm += wrho[ik];
60 } else {
61 wrho[ik] = xi * rho[ik];
62 }
63 }
64 }
65 // normalization of distorted-density
66 for (int i = 0, ii = 0; i < Dimension::F; ++i, ii += Dimension::Fadd1) wrho[ii] /= norm;
67 return 0;
68}
69
70double calc_Ew(kids_real* E, kids_complex* wrho, int occ) {
71 double Ecalc = 0.0e0;
73 case NADForcePolicy::BO:
74 case NADForcePolicy::CV: {
75 Ecalc = E[occ];
76 break;
77 }
78 default: { // EHR, MIX, SD (Eto == Efrom will skip hopping procedure)
79 for (int i = 0, ii = 0; i < Dimension::F; ++i, ii += Dimension::Fadd1) {
80 Ecalc += std::real(wrho[ii] * E[i]);
81 }
82 break;
83 }
84 }
85 return Ecalc;
86}
87
102int calc_distforce(kids_real* f1, // to be calculated
103 kids_real* E, // (input)
104 kids_real* dE, // (input)
105 kids_complex* wrho, // distorted rho
106 kids_complex* rho, // rho_ele
107 double alpha) {
108 // initialize distorted-density
109 kids_real L = 1.0e0 - log(std::abs(alpha)); // @NOTE
110 kids_real rate_default = (L == 1.0e0) ? 1.0e0 : 0.0e0;
111
112 // averaged adiabatic energy by distorted-density
113 double Ew = 0.0e0;
114 for (int i = 0, ii = 0; i < Dimension::F; ++i, ii += Dimension::Fadd1) Ew += std::real(wrho[ii] * E[i]);
115
116 // distortion force (when L= 1 [EHR], the distortion force is zero)
117 for (int j = 0, jFF = 0; j < Dimension::N; ++j, jFF += Dimension::FF) {
118 kids_real* dEj = dE + jFF;
119 f1[j] = 0.0e0;
120 for (int i = 0, ii = 0; i < Dimension::F; ++i, ii += Dimension::Fadd1) {
121 double rate = ((std::real(rho[ii]) == 0.0e0) ? rate_default : std::real(wrho[ii] / rho[ii]));
122 double coeff = (E[i] - (E[i] - Ew) * L * rate);
123 for (int k = 0; k < Dimension::F; ++k) {
124 if (i == k) continue;
125 f1[j] += coeff * std::real(dEj[i * Dimension::F + k] / (E[k] - E[i]) * wrho[k * Dimension::F + i] -
126 dEj[k * Dimension::F + i] / (E[i] - E[k]) * wrho[i * Dimension::F + k]);
127 }
128 }
129 }
130 return 0;
131}
132
133int hopping_impulse(kids_real* direction, kids_real* np, kids_real* nm, //
134 kids_real Efrom, kids_real Eto, int from, int to, bool reflect) {
135 if (to == from) return from;
136
137 // solve x: Ef + P**2 / (2*M) = Et + (P + direction*x)**2 / (2*M)
138 kids_real coeffa = 0.0f, coeffb = 0.0f, coeffc = Eto - Efrom;
139 for (int i = 0; i < Dimension::N; ++i) {
140 coeffa += 0.5f * direction[i] * direction[i] / nm[i];
141 coeffb += np[i] / nm[i] * direction[i];
142 }
143 coeffb /= coeffa, coeffc /= coeffa; // normalization for safety
144
145 kids_real coeffd = coeffb * coeffb - 4 * coeffc;
146 if (coeffd > 0) {
147 kids_real x1 = 0.5f * (-coeffb + sqrt(coeffd)), x2 = 0.5f * (-coeffb - sqrt(coeffd));
148 kids_real xx = (std::abs(x1) < std::abs(x2)) ? x1 : x2;
149 for (int i = 0; i < Dimension::N; ++i) np[i] += xx * direction[i];
150 return to;
151 } else if (reflect) { // 2008Algorithm
152 kids_real xx = -coeffb;
153 for (int i = 0; i < Dimension::N; ++i) np[i] += xx * direction[i];
154 return from;
155 } else { // 1990Algorithm, do nothing
156 return from;
157 }
158 return from;
159}
160
161const std::string Kernel_Elec_NAD::getName() { return "Kernel_Elec_NAD"; }
162
164
165void Kernel_Elec_NAD::setInputParam_impl(std::shared_ptr<Param>& PM) {
166 cmsh_type = NADPolicy::_from(PM->get_string("cmsh_flag", LOC(), "CVSH"));
167
168 alpha0 = PM->get_double("alpha0", LOC(), 0.5);
169 gamma1 = PM->get_double("gamma", LOC(), elec_utils::gamma_wigner(Dimension::F));
170
173
174 gamma2 = (1 - gamma1) / (1.0f + Dimension::F * gamma1);
175 xi1 = (1 + Dimension::F * gamma1);
176 xi2 = (1 + Dimension::F * gamma2);
177 use_wmm = PM->get_bool("use_wmm", LOC(), false);
178 use_sqc = PM->get_bool("use_sqc", LOC(), false);
179 sqc_init = PM->get_int("sqc_init", LOC(), 0);
180 use_fssh = PM->get_bool("use_fssh", LOC(), false);
181 use_strange_win = PM->get_bool("use_strange_win", LOC(), false);
182 use_focus = PM->get_bool("use_focus", LOC(), false);
183 use_fall = PM->get_bool("use_fall", LOC(), false);
184 use_gdtwa = PM->get_bool("use_gdtwa", LOC(), false);
185 only_adjust = PM->get_bool("only_adjust", LOC(), false);
186 use_sum = PM->get_bool("use_sum", LOC(), false);
187 check_cxs = PM->get_bool("check_cxs", LOC(), false);
188 dt = PM->get_double("dt", LOC(), phys::time_d);
189
190 cread_from_ds = PM->get_bool("cread_from_ds", LOC(), false);
191 disable_inner_switch = PM->get_bool("disable_inner_switch", LOC(), false);
192
193 hopping_type1 = 0;
194 hopping_type2 = 0;
195 reflect = true;
196 use_cv = false;
197 dynamic_alpha = false;
198 switch (cmsh_type) {
199 case NADPolicy::EHR:
200 Kernel_NADForce::NADForce_type = NADForcePolicy::EHR;
201 break;
202 case NADPolicy::BOSH:
203 Kernel_NADForce::NADForce_type = NADForcePolicy::BO;
204 hopping_type1 = 0; // max(rho_ele)
205 hopping_type2 = 0; // MASH direction
206 reflect = true;
207 break;
208 case NADPolicy::CVSH:
209 Kernel_NADForce::NADForce_type = NADForcePolicy::CV;
210 hopping_type1 = 1; // max(rho_nuc)
211 hopping_type2 = 2; // P direction
212 reflect = false;
213 use_cv = true;
214 break;
215 case NADPolicy::BOSD:
216 Kernel_NADForce::NADForce_type = NADForcePolicy::BOSD;
217 dynamic_alpha = true;
218 break;
219 case NADPolicy::CVSD:
220 Kernel_NADForce::NADForce_type = NADForcePolicy::CVSD;
221 dynamic_alpha = true;
222 break;
223 }
224 hopping_type1 = PM->get_int("hopping_type1", LOC(), hopping_type1);
225 hopping_type2 = PM->get_int("hopping_type2", LOC(), hopping_type2);
226 use_cv = PM->get_bool("use_cv", LOC(), use_cv);
227 reflect = PM->get_bool("reflect", LOC(), reflect);
228 dynamic_alpha = PM->get_bool("dynamic_alpha", LOC(), dynamic_alpha);
229}
230
231void Kernel_Elec_NAD::setInputDataSet_impl(std::shared_ptr<DataSet>& DS) {
233 Epot = DS->def(DATA::integrator::Epot);
234 p = DS->def(DATA::integrator::p);
235 m = DS->def(DATA::integrator::m);
236 fadd = DS->def(DATA::integrator::fadd);
239 vpes = DS->def(DATA::model::vpes);
240 V = DS->def(DATA::model::V);
241 E = DS->def(DATA::model::rep::E);
242 dE = DS->def(DATA::model::rep::dE);
243 T = DS->def(DATA::model::rep::T);
244 H = DS->def(DATA::model::rep::H);
246 sqcw = DS->def(DATA::integrator::sqcw);
250}
251
253 for (int iP = 0; iP < Dimension::P; ++iP) {
255 kids_complex* wz_A = Kernel_Elec::wz_A + iP;
256 kids_complex* wz_D = Kernel_Elec::wz_D + iP;
257 kids_complex* ww_A = Kernel_Elec::ww_A + iP;
258 kids_complex* ww_D = Kernel_Elec::ww_D + iP;
264 int* occ_nuc = Kernel_Elec::occ_nuc + iP;
265 kids_real* alpha = this->alpha + iP;
266 kids_real* V = this->V + iP * Dimension::FF;
267
270
271 w[0] = kids_complex(Dimension::F);
272 int iocc;
273 Kernel_Random::rand_catalog(&iocc, 1, true, 0, Dimension::F - 1);
274 iocc = ((use_sum) ? iocc : Kernel_Elec::occ0);
275 *occ_nuc = iocc;
276 if (use_focus) {
278 } else if (use_sqc) {
279 switch (sqc_init) {
280 case 0: { // traditional SQC
281 elec_utils::c_window(c, iocc, SQCPolicy::TRI, Dimension::F);
282 break;
283 }
284 case 1: { // simplex SQC
286 for (int i = 0; i < Dimension::F; ++i) c[i] = std::abs(c[i] * c[i]);
287 c[iocc] += 1.0e0;
288 for (int i = 0; i < Dimension::F; ++i) {
289 kids_real randu;
291 randu *= phys::math::twopi;
292 c[i] = sqrt(c[i]);
293 c[i] *= (cos(randu) + phys::math::im * sin(randu));
294 }
295 break;
296 }
297 case 2: { // suggested by YHShang
299 break;
300 }
301 case 3: { // suggested by Liu
302 elec_utils::c_window(c, iocc, SQCPolicy::TRI, Dimension::F);
303 break;
304 }
305 case 4: { // suggested by Liu
306 elec_utils::c_window(c, iocc, SQCPolicy::TRI, Dimension::F);
307 double norm = 0.0e0;
308 for (int i = 0; i < Dimension::F; ++i) norm += std::abs(c[i] * c[i]);
309 xi1 = norm;
310 gamma1 = (xi1 - 1.0e0) / Dimension::F;
311 norm = sqrt(norm);
312 for (int i = 0; i < Dimension::F; ++i) c[i] /= norm;
313 break;
314 }
315 }
316 } else {
318 // for (int i = 0; i < Dimension::F; ++i) c[i] = 1.0e0 * i;
319 }
320 if (cread_from_ds) {
321 std::string init_nuclinp = _param->get_string("init_nuclinp", LOC());
322 std::string open_file = init_nuclinp;
323 if (!isFileExists(init_nuclinp)) open_file = utils::concat(init_nuclinp, stat.icalc, ".ds");
324
325 std::string stmp, eachline;
326 std::ifstream ifs(open_file);
327 while (getline(ifs, eachline)) {
328 if (eachline.find("init.c") != eachline.npos) {
329 getline(ifs, eachline);
330 for (int i = 0; i < Dimension::N; ++i) ifs >> c[i];
331 }
332 }
333 }
334
335 Kernel_Elec::ker_from_c(rho_ele, c, 1, 0, Dimension::F);
336
337 if (use_gdtwa) {
338 xi1 = 1.0e0;
339 gamma1 = 0.0e0;
340 use_cv = false;
341
342 double randu = 1.0e0;
343 double gamma_ou = phys::math::sqrthalf;
344 double gamma_uu = 0.0e0;
345 for (int j = 0; j < Dimension::F; ++j) {
346 if (j == iocc) {
347 rho_ele[j * Dimension::Fadd1] = 1.0e0;
348 continue;
349 }
351 randu = phys::math::halfpi * (int(randu / 0.25f) + 0.5);
352 rho_ele[iocc * Dimension::F + j] = cos(randu) + phys::math::im * sin(randu);
353 rho_ele[j * Dimension::F + iocc] = std::conj(rho_ele[iocc * Dimension::F + j]);
354 }
355 for (int i = 0, ij = 0; i < Dimension::F; ++i) {
356 for (int j = 0; j < Dimension::F; ++j, ++ij) {
357 if (i == iocc || j == iocc) continue;
358 rho_ele[ij] = rho_ele[iocc * Dimension::F + j] / rho_ele[iocc * Dimension::F + i];
359 }
360 }
361 for (int i = 0, ij = 0; i < Dimension::F; ++i) {
362 for (int j = 0; j < Dimension::F; ++j, ++ij) {
363 if (i == j) {
364 rho_ele[ij] = (i == iocc) ? phys::math::iu : phys::math::iz;
365 } else if (i == iocc || j == iocc) {
366 rho_ele[ij] *= gamma_ou;
367 } else {
368 rho_ele[ij] *= gamma_uu;
369 }
370 }
371 }
372 }
373
374 if (use_sqc) {
375 if (sqc_init == 0 || sqc_init == 1) {
376 Kernel_Elec::ker_from_rho(rho_nuc, rho_ele, 1.0, gamma1, Dimension::F, use_cv,
377 iocc);
378 } else if (sqc_init <= 3) { // by youhao shang / Liu scheme
379 double norm = 0.0;
380 for (int i = 0; i < Dimension::F; ++i) norm += std::abs(rho_ele[i * Dimension::Fadd1]);
381 Kernel_Elec::ker_from_rho(rho_nuc, rho_ele, xi1 / norm, gamma1, Dimension::F, use_cv,
382 iocc);
383 } else if (sqc_init <= 4) {
384 double norm = 0.0;
385 for (int i = 0; i < Dimension::F; ++i) norm += std::abs(rho_ele[i * Dimension::Fadd1]);
386 Kernel_Elec::ker_from_rho(rho_nuc, rho_ele, 1.0, (norm - 1.0) / Dimension::F, Dimension::F, use_cv,
387 iocc);
388 }
389 } else {
391 iocc);
392 }
394
395 // BO occupation in adiabatic representation
398 RepresentationPolicy::Adiabatic, //
399 SpacePolicy::L);
400 *occ_nuc = elec_utils::max_choose(rho_nuc);
401 if (use_fssh) *occ_nuc = elec_utils::pop_choose(rho_nuc);
403 RepresentationPolicy::Adiabatic, //
405 SpacePolicy::L);
406
407 // weight factor in tcf_repr
410 RepresentationPolicy::Adiabatic, //
411 SpacePolicy::L);
412 wz_A[0] = std::abs(rho_ele[0] - rho_ele[3]);
413 int max_pop = elec_utils::max_choose(rho_ele);
414 double max_val = std::abs(rho_ele[max_pop * Dimension::Fadd1]);
415 ww_A[0] = 4.0 - 1.0 / (max_val * max_val);
417 RepresentationPolicy::Adiabatic, //
418 RepresentationPolicy::Diabatic, //
419 SpacePolicy::L);
420 wz_D[0] = std::abs(rho_ele[0] - rho_ele[3]);
421 max_pop = elec_utils::max_choose(rho_ele);
422 max_val = std::abs(rho_ele[max_pop * Dimension::Fadd1]);
423 ww_D[0] = 4.0 - 1.0 / (max_val * max_val);
425 RepresentationPolicy::Diabatic, //
427 SpacePolicy::L);
428 }
429
430 _dataset->def_complex("init.wz_A", Kernel_Elec::wz_A, Dimension::P);
431 _dataset->def_complex("init.wz_D", Kernel_Elec::wz_D, Dimension::P);
434 Kernel_Elec::c_init = _dataset->def_complex("init.c", Kernel_Elec::c, Dimension::PF);
438
440 executeKernel(stat);
441 return stat;
442}
443
445 for (int iP = 0; iP < Dimension::P; ++iP) {
446 int* occ_nuc = Kernel_Elec::occ_nuc + iP;
467 kids_complex* ww_A_init = Kernel_Elec::ww_A_init + iP;
468 kids_complex* ww_D_init = Kernel_Elec::ww_D_init + iP;
469 kids_complex* ww_A = Kernel_Elec::ww_A + iP;
470 kids_complex* ww_D = Kernel_Elec::ww_D + iP;
471
472 kids_real* alpha = this->alpha + iP;
473 kids_real* Epot = this->Epot + iP;
474 kids_real* vpes = this->vpes + iP;
475 kids_real* V = this->V + iP * Dimension::FF;
476 kids_real* E = this->E + iP * Dimension::F;
477 kids_real* dE = this->dE + iP * Dimension::NFF;
478 kids_real* p = this->p + iP * Dimension::N;
479 kids_real* m = this->m + iP * Dimension::N;
480 kids_real* fadd = this->fadd + iP * Dimension::N;
481 kids_complex* H = this->H + iP * Dimension::FF;
482
484
485 // * additional evolution can be appended here
486
487 // 1) transform from inp_repr => ele_repr
488 for (int i = 0; i < Dimension::F; ++i) c[i] = c_init[i]; // @debug
489 for (int ik = 0; ik < Dimension::FF; ++ik) rho_ele[ik] = rho_ele_init[ik];
490 for (int ik = 0; ik < Dimension::FF; ++ik) rho_nuc[ik] = rho_nuc_init[ik];
494 SpacePolicy::H);
498 SpacePolicy::L);
502 SpacePolicy::L);
503
504 // 2) propagte along ele_repr
508
509 // 3) hopping in adiabatic representation
512 RepresentationPolicy::Adiabatic, //
513 SpacePolicy::L);
516 RepresentationPolicy::Adiabatic, //
517 SpacePolicy::L);
518
520 // std::cout << "****\n";
521 // step 1: determine where to hop (BOSH & CVSH)
523 kids_real Efrom, Eto;
524 Efrom = calc_Ew(E, rho_nuc, *occ_nuc);
526 int to;
527 switch (hopping_type1) {
528 case 0: {
529 to = elec_utils::max_choose(rho_ele);
530 break;
531 }
532 case 1: {
533 to = elec_utils::max_choose(rho_nuc);
534 break;
535 }
536 case 2: {
537 to = elec_utils::pop_choose(rho_ele);
538 break;
539 }
540 case 3: {
541 to = elec_utils::hopping_choose(rho_ele, H, *occ_nuc, scale * dt);
542 break;
543 }
544 case 4: {
545 to = elec_utils::pop_choose(rho_nuc);
546 break;
547 }
548 case 5: {
549 to = elec_utils::pop_neg_choose(rho_nuc);
550 break;
551 }
552 }
553 Eto = calc_Ew(E, rho_nuc, to);
554 // step 2: determine direction to hop
555 switch (hopping_type2) {
556 case 0: {
557 elec_utils::hopping_direction(direction, E, dE, rho_ele, *occ_nuc, to);
558 break;
559 }
560 case 1: {
562 break;
563 }
564 case 2: {
565 for (int j = 0; j < Dimension::N; ++j) direction[j] = p[j];
566 break;
567 }
568 case 3: {
569 for (int j = 0; j < Dimension::N; ++j)
570 direction[j] = dE[j * Dimension::FF + to * Dimension::Fadd1] -
571 dE[j * Dimension::FF + (*occ_nuc) * Dimension::Fadd1];
572 break;
573 }
574 }
575 // step 3: try hop
576 *occ_nuc = hopping_impulse(direction, p, m, Efrom, Eto, *occ_nuc, to, reflect);
577 Epot[0] = vpes[0] + ((*occ_nuc == to) ? Eto : Efrom);
578 }
579
580 // if (*occ_nuc == to && Eto != Efrom) std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
581
582 // smooth dynamics (BOSD & CVSD)
583 if (cmsh_type == NADPolicy::BOSD || cmsh_type == NADPolicy::CVSD) {
585
586 // Win is for calculate energy
587 calc_wrho(wrho, rho_ele, xi1, gamma1, alpha[0]);
588 double Ew_old = calc_Ew(E, wrho, *occ_nuc);
589 calc_distforce(ftmp, E, dE, wrho, rho_ele, alpha[0]);
590
591 if (dynamic_alpha) alpha[0] = calc_alpha(V);
592 calc_wrho(wrho, rho_ele, xi1, gamma1, alpha[0]);
593 double Ew_new = calc_Ew(E, wrho, *occ_nuc);
594 calc_distforce(ftmp, E, dE, wrho, rho_ele, alpha[0]);
595 // non-linear force
596 for (int j = 0; j < Dimension::N; ++j) fadd[j] += ftmp[j];
597 Epot[0] = vpes[0] + Ew_new;
598
599 // region force
600 if (Ew_new != Ew_old) {
601 double vdotd = 0.0e0;
602 for (int j = 0; j < Dimension::N; ++j) vdotd += p[j] / m[j] * dE[j * Dimension::FF + 1];
603 double xsolve = (Ew_new - Ew_old) / (scale * dt) / vdotd;
604 for (int j = 0; j < Dimension::N; ++j) fadd[j] += xsolve * dE[j * Dimension::FF + 1];
605 }
606 for (int ik = 0; ik < Dimension::FF; ++ik) rho_nuc[ik] = wrho[ik];
607 }
608
610 RepresentationPolicy::Adiabatic, //
612 SpacePolicy::L);
613 if ((use_sqc && reflect) || (use_sqc && only_adjust)) { // only adjusted
615 RepresentationPolicy::Adiabatic, //
617 SpacePolicy::L);
618 double norm = 0.0e0;
619 for (int i = 0; i < Dimension::F; ++i) norm += std::abs(rho_ele[i * Dimension::Fadd1]);
620 // Kernel_Elec::ker_from_rho(rho_nuc, rho_ele, xi1/norm, gamma1, Dimension::F, use_cv,
621 // iocc); ///< initial rho_nuc /// adjust only support for sqc_init=0!!!
622 for (int i = 0; i < Dimension::FF; ++i) rho_nuc[i] = rho_ele[i] + (rho_nuc_init[i] - rho_ele_init[i]);
625 RepresentationPolicy::Adiabatic, //
626 SpacePolicy::L);
627 }
628
629 if (!at_samplingstep_finally_ptr[0]) continue;
630
631 // 4) calculated TCF in adiabatic rep & diabatic rep respectively
632 // 4-1) Adiabatic rep
633 int max_pop = elec_utils::max_choose(rho_ele);
634 double max_val = std::abs(rho_ele[max_pop * Dimension::Fadd1]);
635 ww_A[0] = 4.0 - 1.0 / (max_val * max_val);
636 ww_A[0] = std::min({std::abs(ww_A[0]), std::abs(ww_A_init[0])});
637
638 Kernel_Elec::ker_from_rho(K1QA, rho_ele, 1, 0, Dimension::F, true, ((use_fall) ? *occ_nuc : max_pop));
639 Kernel_Elec::ker_from_rho(K2QA, rho_ele, 1, 0, Dimension::F, true, ((use_fall) ? *occ_nuc : max_pop));
640 for (int i = 0; i < Dimension::F; ++i) {
641 K2QA[i * Dimension::Fadd1] = (std::abs(rho_ele[i * Dimension::Fadd1]) < 1 / xi1) ? 0.0e0 : 1.0e0;
642 }
643 if (use_fssh) { Kernel_Elec::ker_from_rho(K2QA, rho_ele, 1, 0, Dimension::F, true, *occ_nuc); }
644 if (use_sqc) {
645 elec_utils::ker_binning(K2QA, rho_ele, SQCPolicy::TRI);
646 sqcIA[0] = 0;
647 for (int i = 0; i < Dimension::F; ++i) sqcIA[0] += std::real(K2QA[i * Dimension::Fadd1]);
648 }
649
650 ARRAY_MAT_DIAG(K1DA, K1QA, Dimension::F);
651 ARRAY_MAT_DIAG(K2DA, K2QA, Dimension::F);
652
654 RepresentationPolicy::Adiabatic, //
656 SpacePolicy::L);
658 RepresentationPolicy::Adiabatic, //
660 SpacePolicy::L);
662 RepresentationPolicy::Adiabatic, //
664 SpacePolicy::L);
666 RepresentationPolicy::Adiabatic, //
668 SpacePolicy::L);
669 // 4-2) Diabatic rep
671 RepresentationPolicy::Adiabatic, //
672 RepresentationPolicy::Diabatic, //
673 SpacePolicy::L);
674
675 Kernel_Elec::ker_from_rho(K0, rho_ele, 1, 0, Dimension::F);
678
679 max_pop = elec_utils::max_choose(rho_ele); // (in dia rep)
680 max_val = std::abs(rho_ele[max_pop * Dimension::Fadd1]);
681
682 ww_D[0] = 4.0 - 1.0 / (max_val * max_val);
683 if (check_cxs) {
684 double y = max_val - 0.5e0;
685 ww_D[0] = (23.0e0 / 2 * y - 72.0e0 * y * y + 140.0e0 * y * y * y + 480.0e0 * y * y * y * y -
686 840.0e0 * y * y * y * y * y) +
687 (9.0e0 / 4.0 - 9.0e0 * y * y - 420.0e0 * y * y * y * y + 1680.0e0 * y * y * y * y * y * y) *
688 atan(2.0e0 * y);
689 }
690 ww_D[0] = std::min({std::abs(ww_D[0]), std::abs(ww_D_init[0])});
691 { // general squeezed sqc
692 Kernel_Representation::transform(rho_ele_init, T_init, Dimension::F, //
694 RepresentationPolicy::Diabatic, //
695 SpacePolicy::L);
696 double vmax0 = 0.0e0, vsec0 = 0.0e0;
697 double vmaxt = 0.0e0, vsect = 0.0e0;
698 for (int i = 0, ii = 0; i < Dimension::F; ++i, ii += Dimension::Fadd1) {
699 if (std::abs(rho_ele_init[ii]) > vmax0) {
700 vsec0 = vmax0;
701 vmax0 = std::abs(rho_ele_init[ii]);
702 } else if (std::abs(rho_ele_init[ii]) > vsec0) {
703 vsec0 = std::abs(rho_ele_init[ii]);
704 }
705 if (std::abs(rho_ele[ii]) > vmax0) {
706 vsect = vmaxt;
707 vmaxt = std::abs(rho_ele[ii]);
708 } else if (std::abs(rho_ele[ii]) > vsect) {
709 vsect = std::abs(rho_ele[ii]);
710 }
711 }
712
713 double lambda1 = std::min({1 / vsect, 2 / (vmax0 + vsec0)});
714 double lambda2 = std::max({1 / vmaxt, 1 / vmax0});
715 if (lambda1 > lambda2) {
716 ww_D[0] = phi(lambda1, vmax0, Dimension::F) - phi(lambda2, vmax0, Dimension::F);
717 } else {
718 ww_D[0] = 0.0e0;
719 }
720 Kernel_Representation::transform(rho_ele_init, T_init, Dimension::F, //
721 RepresentationPolicy::Diabatic, //
723 SpacePolicy::L);
724 }
725
726 Kernel_Elec::ker_from_rho(K1QD, rho_ele, 1, 0, Dimension::F, true, max_pop);
727 Kernel_Elec::ker_from_rho(K2QD, rho_ele, 1, 0, Dimension::F);
728 for (int i = 0; i < Dimension::F; ++i) {
729 K2QD[i * Dimension::Fadd1] = (std::abs(rho_ele[i * Dimension::Fadd1]) < 1 / xi1) ? 0.0e0 : 1.0e0;
730 }
731 if (use_strange_win) calc_wrho(K2QD, rho_ele, 1, 0, 0.2);
732 if (use_sqc) {
733 elec_utils::ker_binning(K2QD, rho_ele, SQCPolicy::TRI);
734 if (count_exec <= 0) { // only count at the beginning
735 for (int k = 0; k < Dimension::F; ++k) {
736 double radius =
737 std::abs(2.0e0 - rho_ele[Kernel_Elec::occ0 * Dimension::Fadd1] - rho_ele[k * Dimension::Fadd1]);
738 // radius = sqrt(radius * radius + 0.0025e0); // @bad soft radius
739 sqcw[k] = pow(radius, 3 - Dimension::F);
740 }
741 }
742
743 sqcID[0] = 0;
744 for (int i = 0; i < Dimension::F; ++i) sqcID[0] += std::real(K2QD[i * Dimension::Fadd1]);
745
746 if (sqc_init == 2) { // overload for K2QD
747 int imax = elec_utils::max_choose(rho_ele);
748 double vmax = std::abs(rho_ele[imax * Dimension::Fadd1]);
749 for (int ik = 0; ik < Dimension::FF; ++ik) K2QD[ik] = 0.0e0;
750 if (vmax * vmax * 8.0e0 / 7.0e0 * (Dimension::F + 0.5e0) > 1) K2QD[imax * Dimension::Fadd1] = 1.0e0;
751 }
752 }
753
754 ARRAY_MAT_DIAG(K1DD, K1QD, Dimension::F);
755 ARRAY_MAT_DIAG(K2DD, K2QD, Dimension::F);
756
757 // 5) transform back from tcf_repr => inp_repr
759 RepresentationPolicy::Diabatic, //
761 SpacePolicy::L);
763 RepresentationPolicy::Diabatic, //
765 SpacePolicy::L);
767 RepresentationPolicy::Diabatic, //
769 SpacePolicy::L);
771 RepresentationPolicy::Diabatic, //
773 SpacePolicy::L);
775 RepresentationPolicy::Diabatic, //
777 SpacePolicy::L);
779 RepresentationPolicy::Diabatic, //
781 SpacePolicy::L);
783 RepresentationPolicy::Diabatic, //
785 SpacePolicy::L);
787 RepresentationPolicy::Diabatic, //
789 SpacePolicy::L);
790 }
791 return stat;
792}
793}; // namespace PROJECT_NS
bool isFileExists(const std::string &name)
double phi(double lambda, double N0_max, int F)
this file provides Kernel_Elec_NAD class for electronic dynamics and properties in nonadiabatic traje...
this file provides Kernel_NADForce class enabling force weighting from electronic properties.
#define ARRAY_MATMUL3_TRANS2(_A, _B, _C, _D, _n1, _n2, _n0, _n3)
#define ARRAY_MATMUL(_A, _B, _C, _n1, _n2, _n3)
#define ARRAY_EYE(_A, _n)
Definition array_macro.h:75
#define ARRAY_CLEAR(_A, _n)
Definition array_macro.h:36
virtual const std::string getName()
Get the name of the kernel.
virtual Status & executeKernel_impl(Status &stat)
Virtual function to execute the kernel implementation.
virtual int getType() const
Get the type 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 & initializeKernel_impl(Status &stat)
Virtual function to initialize the kernel implementation.
virtual void setInputParam_impl(std::shared_ptr< Param > &PM)
Virtual function to set input parameters for the kernel implementation.
static kids_complex * U
dynamics variables for electronic DOFs
Definition Kernel_Elec.h:39
static int ker_from_rho(kids_complex *ker, kids_complex *rho, kids_real xi, kids_real gamma, int fdim, bool quantize=false, int occ=-1)
convert c (electonic amplititude) to kernel (affine map of the density)
static kids_complex * ww_A_init
Definition Kernel_Elec.h:59
static int * occ_nuc
weighting density for nuclear force
Definition Kernel_Elec.h:48
static kids_complex * K1QA
Simplex Quantization.
Definition Kernel_Elec.h:65
static kids_complex * ww_D_init
Definition Kernel_Elec.h:60
static kids_real * T_init
Definition Kernel_Elec.h:43
static kids_real * T
Definition Kernel_Elec.h:43
static kids_complex * rho_ele
Definition Kernel_Elec.h:41
static kids_complex * rho_nuc_init
Definition Kernel_Elec.h:49
static kids_complex * K1QD
Simplex Quantization.
Definition Kernel_Elec.h:69
static kids_complex * rho_nuc
Definition Kernel_Elec.h:49
static kids_complex * c
Definition Kernel_Elec.h:40
static kids_complex * K2QA
Heaviside Quantization.
Definition Kernel_Elec.h:66
static kids_complex * K2QD
Heaviside Quantization.
Definition Kernel_Elec.h:70
static int ker_from_c(kids_complex *ker, kids_complex *c, kids_real xi, kids_real gamma, int fdim)
convert c (electonic amplititude) to kernel (affine map of the density)
static kids_complex * ww_D
Definition Kernel_Elec.h:58
static kids_complex * c_init
electronic vector
Definition Kernel_Elec.h:40
static kids_complex * K2
partial version of K2
Definition Kernel_Elec.h:64
static kids_complex * ww_A
Definition Kernel_Elec.h:57
static int occ0
read parameters
Definition Kernel_Elec.h:31
static kids_complex * K1DD
Definition Kernel_Elec.h:71
static kids_complex * K2DD
Definition Kernel_Elec.h:72
static kids_complex * K1DA
Definition Kernel_Elec.h:67
static kids_complex * wz_A
Definition Kernel_Elec.h:55
static kids_complex * rho_ele_init
electronic density
Definition Kernel_Elec.h:41
static kids_complex * K1
partial version of K1
Definition Kernel_Elec.h:63
static kids_complex * K0
partial version of K0
Definition Kernel_Elec.h:62
static kids_complex * K2DA
Definition Kernel_Elec.h:68
static kids_complex * w
kernels for time correlation function
Definition Kernel_Elec.h:54
static kids_complex * wz_D
Definition Kernel_Elec.h:56
static NADForcePolicy::_type NADForce_type
static int rand_uniform(kids_real *res_arr, int N=1, kids_real sigma=1.0)
static int rand_catalog(int *res_arr, int N=1, bool reset=false, int begin=0, int end=1)
static RepresentationPolicy::_type ele_repr_type
representation for electronic dynamics
static int transform(kids_complex *A, kids_real *T, int fdim, RepresentationPolicy::_type from, RepresentationPolicy::_type to, SpacePolicy::_type Stype)
static RepresentationPolicy::_type inp_repr_type
representatioin for input (quantities)
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
static int hopping_choose(kids_complex *rho, kids_complex *H, int from, kids_real dt)
static double gamma_wigner(int fdim)
static int pop_neg_choose(kids_complex *rho)
static int pop_choose(kids_complex *rho)
static int c_window(kids_complex *c, int iocc, int type, int fdim)
static double gamma_opt(int fdim)
static int c_focus(kids_complex *c, double xi, double gamma, int occ, int fdim)
static void hopping_direction(kids_real *direction, kids_real *dE, int from, int to)
static int max_choose(kids_complex *rho)
static int c_sphere(kids_complex *c, int fdim)
sampling mapping variables from uniform sphere distribution (i.e.
static int ker_binning(kids_complex *ker, kids_complex *rho, int sqc_type)
provide utils for debugging the code
#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 > direction
VARIABLE< kids_complex > wrho
VARIABLE< kids_real > ftmp
VARIABLE< kids_real > sqcIA
VARIABLE< kids_real > p
VARIABLE< kids_real > Epot
VARIABLE< kids_real > alpha
VARIABLE< kids_real > fadd
VARIABLE< kids_real > m
VARIABLE< kids_real > sqcID
VARIABLE< kids_real > sqcw
VARIABLE< kids_bint > at_samplingstep_finally
VARIABLE< kids_real > dE
VARIABLE< kids_real > E
VARIABLE< kids_real > T
VARIABLE< kids_complex > H
VARIABLE< kids_real > vpes
VARIABLE< kids_real > V
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 PF
Product of P and F (P * F).
Definition vars_list.cpp:16
std::size_t PFF
Product of P, F, and F (P * F * F).
Definition vars_list.cpp:17
std::size_t P
Number of parallel trajectories (swarms of trajectories) in each Monte Carlo run.
Definition vars_list.cpp:9
std::size_t F
Number of electronic degrees of freedom.
Definition vars_list.cpp:11
std::size_t Fadd1
F plus 1 (F + 1).
Definition vars_list.cpp:24
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 calc_alpha(kids_real *V, int i=0, int k=1, int F=2)
void ARRAY_MAT_DIAG(kids_real *A, kids_real *B, size_t N1)
Copy the diagonal elements from matrix B to matrix A for real matrices.
Definition linalg.cpp:458
int calc_distforce(kids_real *f1, kids_real *E, kids_real *dE, kids_complex *wrho, kids_complex *rho, double alpha)
the force driven from the shape of distorted-density W(\rho)
double calc_Ew(kids_real *E, kids_complex *wrho, int occ)
double kids_real
Alias for real number type.
Definition Types.h:59
std::complex< double > kids_complex
Alias for complex number type.
Definition Types.h:60
int hopping_impulse(kids_real *direction, kids_real *np, kids_real *nm, kids_real Efrom, kids_real Eto, int from, int to, bool reflect)
int calc_wrho(kids_complex *wrho, kids_complex *rho, double xi, double gamma, double alpha)
constexpr real_precision halfpi
Definition phys.h:32
constexpr std::complex< real_precision > iu(1.0L, 0.0L)
constexpr real_precision pi
pi
Definition phys.h:30
constexpr real_precision sqrthalf
Definition phys.h:38
constexpr std::complex< real_precision > im(0.0L, 1.0L)
Imaginary Unit.
constexpr real_precision twopi
Definition phys.h:31
constexpr std::complex< real_precision > iz(0.0L, 0.0L)
constexpr dimension7 time_d
[T]
Definition phys.h:187
std::basic_string< CharT > concat(const separator_t< CharT > &sep, Args &&... seq)
Definition concat.h:242
constexpr uint32_t hash(const char *str)
Definition hash_fnv1a.h:12
declaration of variables used in the program.