KIDS  ver-0.0.1
KIDS : Kernel Integrated Dynamics Simulator
Loading...
Searching...
No Matches
Kernel_NADForce.cpp
Go to the documentation of this file.
2
3#include "kids/Kernel_Elec.h"
6#include "kids/debug_utils.h"
7#include "kids/hash_fnv1a.h"
8#include "kids/linalg.h"
9#include "kids/macro_utils.h"
10#include "kids/vars_list.h"
11
12namespace PROJECT_NS {
13
14const std::string Kernel_NADForce::getName() { return "Kernel_NADForce"; }
15
17
18void Kernel_NADForce::setInputParam_impl(std::shared_ptr<Param>& PM) {
19 FORCE_OPT::BATH_FORCE_BILINEAR = _param->get_bool("BATH_FORCE_BILINEAR", LOC(), false);
20 offd_projected = _param->get_bool("offd_projected", LOC(), true);
21};
22
23void Kernel_NADForce::setInputDataSet_impl(std::shared_ptr<DataSet>& DS) {
24 f = DS->def(DATA::integrator::f);
25 p = DS->def(DATA::integrator::p);
26 m = DS->def(DATA::integrator::m);
29 grad = DS->def(DATA::model::grad);
30 dV = DS->def(DATA::model::dV);
31 dE = DS->def(DATA::model::rep::dE);
32 T = DS->def(DATA::model::rep::T);
33 succ_ptr = DS->def(DATA::iter::succ);
34
36 case RepresentationPolicy::Diabatic:
37 Force = dV;
38 break;
39 case RepresentationPolicy::Adiabatic:
40 Force = dE;
41 break;
42 }
43}
44
46
48 if (!succ_ptr[0]) return stat;
49
50 for (int iP = 0; iP < Dimension::P; ++iP) {
51 int* occ_nuc = Kernel_Elec::occ_nuc + iP;
53
54 kids_real* f = this->f + iP * Dimension::N;
55 kids_real* p = this->p + iP * Dimension::N;
56 kids_real* m = this->m + iP * Dimension::N;
57 kids_real* fadd = this->fadd + iP * Dimension::N;
58 kids_real* grad = this->grad + iP * Dimension::N;
59 kids_real* Force = this->Force + iP * Dimension::NFF;
60 kids_real* T = this->T + iP * Dimension::FF;
61
63 switch (NADForce_type) {
64 case NADForcePolicy::BO: {
65 for (int j = 0, idxdV0 = 0; j < Dimension::N; ++j, idxdV0 += Dimension::FF)
66 f[j] = Force[j * Dimension::FF + (*occ_nuc) * Dimension::Fadd1];
67 break;
68 }
69 case NADForcePolicy::EHR: {
72 if (FORCE_OPT::BATH_FORCE_BILINEAR) { // for both dV & dE (only for FMO-like model)
73 int& B = FORCE_OPT::nbath;
74 int& J = FORCE_OPT::Nb;
75 int JFF = J * Dimension::FF;
76 for (int b = 0, bj = 0, b0FF = 0, b0bb = 0; b < B;
77 ++b, b0FF += JFF, b0bb += (JFF + Dimension::Fadd1)) {
78 double* Forceb0 = Force + b0FF;
79 double fb0 = std::real(ARRAY_TRACE2(rho_nuc, Forceb0, Dimension::F, Dimension::F));
80 for (int j = 0, bjbb = b0bb; j < J; ++j, ++bj, bjbb += Dimension::FF) {
81 f[bj] = fb0 * Force[bjbb] / Force[b0bb];
82 }
83 }
84 } else {
85 for (int j = 0, jFF = 0; j < Dimension::N; ++j, jFF += Dimension::FF) {
86 double* dVj = Force + jFF;
87 f[j] = std::real(ARRAY_TRACE2(rho_nuc, dVj, Dimension::F, Dimension::F));
88 }
89 }
92 SpacePolicy::L); // not need
93 break;
94 }
95 case NADForcePolicy::CV: {
98 if (FORCE_OPT::BATH_FORCE_BILINEAR) { // for both dV & dE (only for FMO-like model)
99 int& B = FORCE_OPT::nbath;
100 int& J = FORCE_OPT::Nb;
101 int JFF = J * Dimension::FF;
102 for (int b = 0, bj = 0, b0FF = 0, b0bb = 0; b < B;
103 ++b, b0FF += JFF, b0bb += (JFF + Dimension::Fadd1)) {
104 double* Forceb0 = Force + b0FF;
105 double fb0 = Forceb0[(*occ_nuc) * Dimension::Fadd1];
106 double fprojb0 = std::real(ARRAY_TRACE2_OFFD(rho_nuc, Forceb0, Dimension::F, Dimension::F));
107 for (int j = 0, bjbb = b0bb; j < J; ++j, ++bj, bjbb += Dimension::FF) {
108 f[bj] = fb0 * Force[bjbb] / Force[b0bb];
109 fproj[bj] = fprojb0 * Force[bjbb] / Force[b0bb];
110 }
111 }
112 } else {
113 for (int j = 0, jFF = 0; j < Dimension::N; ++j, jFF += Dimension::FF) {
114 double* dVj = Force + jFF;
115 f[j] = dVj[(*occ_nuc) * Dimension::Fadd1];
116 fproj[j] = std::real(ARRAY_TRACE2_OFFD(rho_nuc, dVj, Dimension::F, Dimension::F));
117 }
118 }
119 if (offd_projected) { // then the offdiagonal force is projected
120 double fdotR = 0.0e0, PdotR = 0.0e0;
121 for (int j = 0; j < Dimension::N; ++j) fdotR += fproj[j] * p[j] / m[j], PdotR += p[j] * p[j] / m[j];
122 for (int j = 0; j < Dimension::N; ++j) fproj[j] -= fdotR / PdotR * p[j];
123 }
124 for (int j = 0; j < Dimension::N; ++j) f[j] += fproj[j];
125
128 SpacePolicy::L); // not need
129 break;
130 }
131 case NADForcePolicy::BOSD:
132 case NADForcePolicy::CVSD: { // smooth dynamics
135 if (FORCE_OPT::BATH_FORCE_BILINEAR) { // for both dV & dE (only for FMO-like model)
136 int& B = FORCE_OPT::nbath;
137 int& J = FORCE_OPT::Nb;
138 int JFF = J * Dimension::FF;
139 for (int b = 0, bj = 0, b0FF = 0, b0bb = 0; b < B;
140 ++b, b0FF += JFF, b0bb += (JFF + Dimension::Fadd1)) {
141 double* Forceb0 = Force + b0FF;
142 double fb0 = std::real(ARRAY_TRACE2_DIAG(rho_nuc, Forceb0, Dimension::F, Dimension::F));
143 double fprojb0 = std::real(ARRAY_TRACE2_OFFD(rho_nuc, Forceb0, Dimension::F, Dimension::F));
144 for (int j = 0, bjbb = b0bb; j < J; ++j, ++bj, bjbb += Dimension::FF) {
145 f[bj] = fb0 * Force[bjbb] / Force[b0bb];
146 fproj[bj] = fprojb0 * Force[bjbb] / Force[b0bb];
147 }
148 }
149 } else {
150 for (int j = 0, jFF = 0; j < Dimension::N; ++j, jFF += Dimension::FF) {
151 double* dVj = Force + jFF;
152 f[j] = std::real(ARRAY_TRACE2_DIAG(rho_nuc, dVj, Dimension::F, Dimension::F));
153 fproj[j] = std::real(ARRAY_TRACE2_OFFD(rho_nuc, dVj, Dimension::F, Dimension::F));
154 }
155 }
156
157 if (NADForce_type == NADForcePolicy::CVSD) {
158 if (offd_projected) {
159 double fdotR = 0.0e0, vnorm2 = 0.0e0;
160 for (int j = 0; j < Dimension::N; ++j) fdotR += fproj[j] * p[j], vnorm2 += p[j] * p[j];
161 if (vnorm2 > 1.0e-8) {
162 for (int j = 0; j < Dimension::N; ++j) fproj[j] += (fproj[j] - fdotR / vnorm2 * p[j]);
163 }
164 } else {
165 for (int j = 0; j < Dimension::N; ++j) fproj[j] += fproj[j];
166 }
167 }
168
169 for (int j = 0; j < Dimension::N; ++j) f[j] += fproj[j];
170
173 SpacePolicy::L); // not need
174 break;
175 }
176 }
177 for (int j = 0; j < Dimension::N; ++j) f[j] += grad[j];
178 for (int j = 0; j < Dimension::N; ++j) f[j] += fadd[j]; // additional force
179 }
180 return stat;
181}
182
183NADForcePolicy::_type Kernel_NADForce::NADForce_type = NADForcePolicy::EHR;
184
185namespace FORCE_OPT {
186int nbath = 1;
187int Nb = 1;
189}; // namespace FORCE_OPT
190
191}; // namespace PROJECT_NS
initialization kernels for electonic DOFs
this file provides Kernel_NADForce class enabling force weighting from electronic properties.
#define ARRAY_TRACE2(_B, _C, _n1, _n2)
static int * occ_nuc
weighting density for nuclear force
Definition Kernel_Elec.h:48
static kids_complex * rho_nuc
Definition Kernel_Elec.h:49
virtual Status & executeKernel_impl(Status &stat)
Virtual function to execute the kernel implementation.
virtual void setInputParam_impl(std::shared_ptr< Param > &PM)
Virtual function to set input parameters for the kernel implementation.
static NADForcePolicy::_type NADForce_type
virtual Status & initializeKernel_impl(Status &stat)
Virtual function to initialize the kernel implementation.
virtual void setInputDataSet_impl(std::shared_ptr< DataSet > &DS)
Virtual function to set input data set for the kernel implementation.
virtual int getType() const
Get the type of the kernel.
virtual const std::string getName()
Get the name of the kernel.
static RepresentationPolicy::_type nuc_repr_type
representation for nuclear 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
provide utils for debugging the code
#define LOC()
show the location information for debug
Definition fmt.h:49
Provide linalg APIs.
#define FUNCTION_NAME
Definition macro_utils.h:9
VARIABLE< kids_real > fproj
VARIABLE< kids_real > f
VARIABLE< kids_real > p
VARIABLE< kids_real > fadd
VARIABLE< kids_real > m
VARIABLE< kids_bint > succ
VARIABLE< kids_real > dE
VARIABLE< kids_real > T
VARIABLE< kids_real > dV
VARIABLE< kids_real > grad
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 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 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
kids_real ARRAY_TRACE2_DIAG(kids_real *B, kids_real *C, size_t N1, size_t N2)
Compute the trace of the diagonal elements of the matrix product B * C for real matrices.
Definition linalg.cpp:340
kids_real ARRAY_TRACE2_OFFD(kids_real *B, kids_real *C, size_t N1, size_t N2)
Compute the trace of the off-diagonal elements of the matrix product B * C for real matrices.
Definition linalg.cpp:368
constexpr uint32_t hash(const char *str)
Definition hash_fnv1a.h:12
declaration of variables used in the program.