53 #define max(a,b) ((a)>=(b)?(a):(b)) 
   78 static inline double pow(
const double* 
a, 
const double* 
b) {
 
   82 static double c_b2 = .333333333333333333333333333333333;
 
   83 static double c_b7 = .333333333333333333333333333333;
 
   84 static double c_b8 = .5;
 
   85 static double c_b14 = 1.333333333333333333333333333333;
 
   88 inline  int x_rks_s__(
const double *r__, 
double *
f, 
double *
 
  121     ra13 = pow(r__, &
c_b2) * .793700525984099737375852819636154;
 
  122     *f = *r__ * -.930525736349100025002010218071667 * ra13;
 
  123     *dfdra = ra13 * -1.24070098179880003333601362409556;
 
  130   double *dfdra, 
double *dfdrb)
 
  161     ra13 = pow(ra, &
c_b2);
 
  162     rb13 = pow(rb, &
c_b2);
 
  163     *f = (*ra * ra13 + *rb * rb13) * -.930525736349100025002010218071667;
 
  164     *dfdra = ra13 * -1.24070098179880003333601362409556;
 
  165     *dfdrb = rb13 * -1.24070098179880003333601362409556;
 
  174     double a2, b2, c2, d2, i1, i2, i3, p1, p2, p3, p4, t4, t5, t6,
 
  175       t7, iv, alpha_rho13__, iv2, pp1, pp2, inv, srho, srho13;
 
  209     t4 = .620350490899399531;
 
  212     t5 = 1.92366105093153617;
 
  215     t6 = 2.56488140124204822;
 
  218     t7 = .584822362263464735;
 
  222     p1 = 6.1519908197590798;
 
  224     p3 = 9.6902277115443745e-4;
 
  225     p4 = .038783294878113009;
 
  229     srho13 = pow(&srho, &
c_b7);
 
  230     alpha_rho13__ = pow(&c_b8, &
c_b7) * srho;
 
  235     inv = 1. / (iv2 + b2 * iv + c2);
 
  237     i2 = 
log((iv - d2) * (iv - d2) * inv);
 
  239     i3 = 
atan(p1 / (iv * 2. + b2));
 
  240     pp1 = p2 * i1 + p3 * i2 + p4 * i3;
 
  241     pp2 = a2 * (1. / iv - iv * inv * (b2 / (iv - d2) + 1.));
 
  244     *dfdra = pp1 - iv * .166666666666666666666666666666 * pp2;
 
  251   f, 
double *dfdra, 
double *dfdrb)
 
  257     double v, beta_rho13__, 
a1, b1, c1, d1, 
a2, b2, c2, d2, a3, b3,
 
  258        c3, d3, 
f1, 
f2, 
f3, p1, p2, p3, s1, t1, t2, s2, t4, t5, t6, t7,
 
  259       s3, s4, p4, 
f4, i1, i2, i3, iv, alpha_rho13__, ff1, ff2, iv2, pp1,
 
  260        pp2, 
ss1, ss2, tau, inv, vwn1, vwn2, dtau, 
zeta, srho, zeta3,
 
  261       zeta4, srho13, inter1, inter2;
 
  292     a1 = -.0337737278807791058;
 
  309     t4 = .620350490899399531;
 
  312     t5 = 1.92366105093153617;
 
  315     t6 = 2.56488140124204822;
 
  318     t7 = .584822362263464735;
 
  322     s1 = 7.12310891781811772;
 
  324     s3 = -6.9917323507644313e-6;
 
  325     s4 = -.0053650918488835769;
 
  329     p1 = 6.1519908197590798;
 
  331     p3 = 9.6902277115443745e-4;
 
  332     p4 = .038783294878113009;
 
  336     f1 = 4.73092690956011364;
 
  344     f3 = .00224786709554261133;
 
  345     f4 = .0524913931697809227;
 
  349     inter1 = .99999999989999999;
 
  350     inter2 = -.99999999989999999;
 
  353     alpha_rho13__ = pow(ra, &
c_b7);
 
  354     beta_rho13__ = pow(rb, &
c_b7);
 
  356     srho13 = pow(&srho, &
c_b7);
 
  361     inv = 1. / (iv2 + b1 * iv + c1);
 
  363     i2 = 
log((iv - d1) * (iv - d1) * inv);
 
  364     i3 = 
atan(s1 / (iv * 2. + b1));
 
  365     ss1 = s2 * i1 + s3 * i2 + s4 * i3;
 
  366     ss2 = a1 * (1. / iv - iv * inv * (b1 / (iv - d1) + 1.));
 
  369     inv = 1. / (iv2 + b2 * iv + c2);
 
  371     i2 = 
log((iv - d2) * (iv - d2) * inv);
 
  373     i3 = 
atan(p1 / (iv * 2. + b2));
 
  374     pp1 = p2 * i1 + p3 * i2 + p4 * i3;
 
  375     pp2 = a2 * (1. / iv - iv * inv * (b2 / (iv - d2) + 1.));
 
  378     inv = 1. / (iv2 + b3 * iv + c3);
 
  380     i2 = 
log((iv - d3) * (iv - d3) * inv);
 
  381     i3 = 
atan(f1 / (iv * 2. + b3));
 
  382     ff1 = f2 * i1 + f3 * i2 + f4 * i3;
 
  383     ff2 = a3 * (1. / iv - iv * inv * (b3 / (iv - d3) + 1.));
 
  387     zeta = (*ra - *rb) / srho;
 
  388     zeta3 = zeta * zeta * 
zeta;
 
  389     zeta4 = zeta3 * 
zeta;
 
  391   vwn1 = t5 * .51984209978974638;
 
  392   vwn2 = t6 * 1.25992104989487316476721060727823;
 
  393     } 
else if (zeta < inter2) {
 
  394   vwn1 = t5 * .51984209978974638;
 
  395   vwn2 = t6 * -1.25992104989487316476721060727823;
 
  399   vwn1 = (pow(&d__1, &
c_b14) + pow(&d__2, &
c_b14) - 2.) * t5;
 
  402   vwn2 = (pow(&d__1, &
c_b7) - pow(&d__2, &
c_b7)) * t6;
 
  406     tau = ff1 - pp1 - 
ss1;
 
  407     dtau = ff2 - pp2 - ss2;
 
  409     v = pp1 + vwn1 * (ss1 + tau * zeta4);
 
  412     t1 = v - iv * .166666666666666666666666666667 * (pp2 + vwn1 * (ss2 + dtau
 
  414     t2 = vwn2 * (ss1 + tau * zeta4) + vwn1 * 4. * tau * zeta3;
 
  415     *dfdra = t1 + t2 * (1. - 
zeta);
 
  416     *dfdrb = t1 - t2 * (zeta + 1.);
 
  453     static doublereal s1, t1, t2, t4, t6, t7, t10, t20, t11, t22, t13, t23,
 
  454       t16, t17, t25, t19, t26, t28, t29, t32, t33, t37, t38, t40, t41,
 
  455       t43, t51, t52, t27, t34, t39, t46, t47, t48, t49, t53, t55, t56,
 
  456       t58, t60, t63, t66, t67, t68, t69, t77, t79, t80, t81, t88, t92,
 
  457       t94, t102, t103, t105, t107, t125, t134, t138, rho;
 
  503   for (i__ = 1; i__ <= i__1; ++i__) {
 
  505       d__1 = 0., d__2 = rhoa1[i__];
 
  506       rho = 
max(d__1,d__2);
 
  509     t2 = pow_dd(&t1, &c_b3);
 
  510     t4 = pow_dd(&t1, &c_b2);
 
  511     t7 = 1 / (t2 * .6203504908994 + t4 * 2.935818660072219 +
 
  513     t10 = 
log(t2 * .6203504908994 * t7);
 
  514     t16 = 
atan(6.15199081975908 / (t4 * 1.575246635799487 +
 
  517     d__1 = t4 * .7876233178997433 + .10498;
 
  520     zk[i__] = rho * (t10 * .0310907 + t16 * .03878329487811301 +
 
  521       t22 * 9.690227711544374e-4);
 
  528     } 
else if (*ideriv == 1) {
 
  530   for (i__ = 1; i__ <= i__1; ++i__) {
 
  532       d__1 = 0., d__2 = rhoa1[i__];
 
  533       rho = 
max(d__1,d__2);
 
  536     t2 = pow_dd(&t1, &c_b3);
 
  537     t4 = pow_dd(&t1, &c_b2);
 
  538     t6 = t2 * .6203504908994 + t4 * 2.935818660072219 + 12.9352;
 
  540     t10 = 
log(t2 * .6203504908994 * t7);
 
  541     t11 = t10 * .0310907;
 
  542     t13 = t4 * 1.575246635799487 + 3.72744;
 
  543     t16 = 
atan(6.15199081975908 / t13);
 
  544     t17 = t16 * .03878329487811301;
 
  545     t19 = t4 * .7876233178997433 + .10498;
 
  550     t23 = t22 * 9.690227711544374e-4;
 
  551     zk[i__] = rho * (t11 + t17 + t23);
 
  572     t43 = t26 * -.2067834969664667 * t29 - t41 *
 
  578     vrhoa[i__] = t11 + t17 + t23 + rho * ((t26 *
 
  579       -.2067834969664667 * t7 * t29 - t2 * .6203504908994 *
 
  580       t33 * t43) * .05011795824473985 / t2 * t6 + t52 *
 
  581       .0626408570946439 * t40 * t29 / (t52 * 37.8469910464
 
  582       + 1.) + (t19 * -.2625411059665811 * t7 * t41 - t20 *
 
  583       1. * t33 * t43) * 9.690227711544374e-4 / t20 * t6);
 
  591     } 
else if (*ideriv == 2) {
 
  593   for (i__ = 1; i__ <= i__1; ++i__) {
 
  595       d__1 = 0., d__2 = rhoa1[i__];
 
  596       rho = 
max(d__1,d__2);
 
  599     t2 = pow_dd(&t1, &c_b3);
 
  600     t4 = pow_dd(&t1, &c_b2);
 
  601     t6 = t2 * .6203504908994 + t4 * 2.935818660072219 + 12.9352;
 
  603     t10 = 
log(t2 * .6203504908994 * t7);
 
  604     t11 = t10 * .0310907;
 
  605     t13 = t4 * 1.575246635799487 + 3.72744;
 
  606     t16 = 
atan(6.15199081975908 / t13);
 
  607     t17 = t16 * .03878329487811301;
 
  608     t19 = t4 * .7876233178997433 + .10498;
 
  613     t23 = t22 * 9.690227711544374e-4;
 
  614     zk[i__] = rho * (t11 + t17 + t23);
 
  638     t43 = t26 * -.2067834969664667 * t29 - t41 *
 
  640     t46 = t27 * -.2067834969664667 * t29 - t34 * .6203504908994 *
 
  650     t55 = t52 * 37.8469910464 + 1.;
 
  652     t58 = t53 * t29 * t56;
 
  655     t66 = t60 * -.2625411059665811 * t41 - t63 * 1. * t43;
 
  659     vrhoa[i__] = t11 + t17 + t23 + rho * (t49 *
 
  660       .05011795824473985 + t58 * .0626408570946439 + t69 *
 
  661       9.690227711544374e-4);
 
  667     t81 = t77 * t7 * t80;
 
  676     t107 = t77 * -.1378556646443111 * t80 + t26 *
 
  677       .4135669939329333 * t88 - t103 * .4077525916766971 +
 
  678       t105 * .978606220024073;
 
  686     s1 = t49 * .2004718329789594 + t58 * .2505634283785756;
 
  687     v2rhoa2[i__] = s1 + t69 * .00387609108461775 + rho * 2. * ((
 
  688       t81 * -.1378556646443111 + t26 * .4135669939329333 *
 
  689       t33 * t29 * t43 + t27 * .4135669939329333 * t88 + t2 *
 
  690        1.2407009817988 * t92 * t94 - t34 * .6203504908994 *
 
  691       t107) * .05011795824473985 * t47 * t6 + t46 *
 
  692       .01670598608157995 / t2 / t1 * t6 * t29 + t48 *
 
  693       .05011795824473985 * t43 + .03289159980064473 / t51 /
 
  694       t13 * t77 * t125 + t52 * .05220071424553658 * t102 *
 
  695       t125 - t53 * .1252817141892878 * t88 * t56 -
 
  696       1.244848083156773 / t134 / t13 * t77 * t80 / t138 + (
 
  697       t81 * .03446391616107778 + t19 * .5250822119331622 *
 
  698       t33 * t41 * t43 - t60 * .2187842549721509 * t103 +
 
  699       t60 * .5250822119331622 * t105 + t20 * 2. * t92 * t94
 
  700       - t63 * 1. * t107) * 9.690227711544374e-4 * t67 * t6
 
  701       + t66 * 2.544083100456872e-4 / t20 / t19 * t6 * t40 *
 
  702       t29 + t68 * 9.690227711544374e-4 * t43);
 
  777   for (i__ = 1; i__ <= i__1; ++i__) {
 
  779       d__1 = 0., d__2 = rhoa1[i__];
 
  780       rho = 
max(d__1,d__2);
 
  782     t1 = pow_dd(&rho, &c_b2);
 
  783     zk[i__] = t1 * -.7385587663820224 * rho;
 
  790     } 
else if (*ideriv == 1) {
 
  792   for (i__ = 1; i__ <= i__1; ++i__) {
 
  794       d__1 = 0., d__2 = rhoa1[i__];
 
  795       rho = 
max(d__1,d__2);
 
  797     t1 = pow_dd(&rho, &c_b2);
 
  798     zk[i__] = t1 * -.7385587663820224 * rho;
 
  799     vrhoa[i__] = t1 * -.9847450218426965;
 
  807     } 
else if (*ideriv == 2) {
 
  809   for (i__ = 1; i__ <= i__1; ++i__) {
 
  811       d__1 = 0., d__2 = rhoa1[i__];
 
  812       rho = 
max(d__1,d__2);
 
  814     t1 = pow_dd(&rho, &c_b2);
 
  815     zk[i__] = t1 * -.7385587663820224 * rho;
 
  816     vrhoa[i__] = t1 * -.9847450218426965;
 
  820     v2rhoa2[i__] = -.6564966812284644 / t5;
 
  838     for (
int i=0; i<npoint; i++) {
 
  846     for (
int i=0; i<npoint; i++) {
 
  854                           Tensor<double> df_drho)                   
 
  856     MADNESS_ASSERT(rho_alpha.iscontiguous());
 
  857     MADNESS_ASSERT(f.iscontiguous());
 
  858     MADNESS_ASSERT(df_drho.iscontiguous());
 
  860     rho_alpha = rho_alpha.flat();
 
  862     df_drho = df_drho.flat();
 
  865       integer npt = rho_alpha.dim(0);
 
  867       Tensor<double> gamma_alpha(npt);
 
  868       Tensor<double> tf(npt);
 
  869       Tensor<double> tdf_drho(npt);
 
  870       Tensor<double> tdf_dgamma(npt);
 
  871       Tensor<double> td2f_drho2(npt);
 
  872       Tensor<double> td2f_drhodgamma(npt);
 
  873       Tensor<double> td2f_dgamma2(npt);
 
  880       int returnvalue = 
::rks_x_lda__(&ideriv, &npt, rho_alpha.ptr(), gamma_alpha.ptr(),
 
  882                tdf_drho.ptr(), tdf_dgamma.ptr(),
 
  883                td2f_drho2.ptr(), td2f_drhodgamma.ptr(), td2f_dgamma2.ptr());
 
  885       f.gaxpy(1.0, tf, 1.0);
 
  886       df_drho.gaxpy(1.0, tdf_drho, 1.0);
 
  891       returnvalue = 
::rks_c_vwn5__(&ideriv, &npt, rho_alpha.ptr(), gamma_alpha.ptr(),
 
  893                 tdf_drho.ptr(), tdf_dgamma.ptr(),
 
  894                 td2f_drho2.ptr(), td2f_drhodgamma.ptr(), td2f_dgamma2.ptr());
 
  896       f.gaxpy(1.0, tf, 1.0);
 
  897       df_drho.gaxpy(1.0, tdf_drho, 1.0);
 
  906     Tensor<double> enefunc = 
copy(t);
 
  907     Tensor<double> 
V = 
copy(t);
 
  917     Tensor<double> 
V = 
copy(t);
 
  918     Tensor<double> enefunc = 
copy(t);
 
  920     t(___) = enefunc(___);
 
int rks_x_lda__(integer *ideriv, integer *npt, doublereal *rhoa1, doublereal *sigmaaa1, doublereal *zk, doublereal *vrhoa, doublereal *vsigmaaa, doublereal *v2rhoa2, doublereal *v2rhoasigmaaa, doublereal *v2sigmaaa2)
Definition: lda.h:716
void xc_rks_generic_lda(Tensor< double > rho_alpha, Tensor< double > f, Tensor< double > df_drho)
Definition: lda.h:852
int x_rks_s__(const double *r__, double *f, double *dfdra)
Definition: chem/lda.cc:58
Main include file for MADNESS and defines Function interface. 
const T1 const T2 const T3 & f3
Definition: gtest-tuple.h:686
const mpreal log(const mpreal &v, mp_rnd_t rnd_mode)
Definition: mpreal.h:2213
int x_uks_s__(double *ra, double *rb, double *f, double *dfdra, double *dfdrb)
Definition: chem/lda.cc:86
double V(const Vector< double, 3 > &r)
Definition: apps/ii/hatom_energy.cc:46
NDIM & f
Definition: mra.h:2179
double ss1
Definition: lapack.cc:66
This header should include pretty much everything needed for the parallel runtime. 
void wst_munge_grho(int npoint, double *rho, double *grho)
Definition: lda.h:837
const T1 const T2 const T3 const T4 & f4
Definition: gtest-tuple.h:692
int logical
Definition: lda.h:51
const double a2
Definition: vnucso.cc:91
#define max(a, b)
Definition: lda.h:53
const double zeta
Definition: vnucso.cc:87
Function< T, NDIM > copy(const Function< T, NDIM > &f, const std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > &pmap, bool fence=true)
Create a new copy of the function with different distribution and optional fence. ...
Definition: mra.h:1835
FLOAT a(int j, FLOAT z)
Definition: y1.cc:86
int rks_c_vwn5__(integer *ideriv, integer *npt, doublereal *rhoa1, doublereal *sigmaaa1, doublereal *zk, doublereal *vrhoa, doublereal *vsigmaaa, doublereal *v2rhoa2, doublereal *v2rhoasigmaaa, doublereal *v2sigmaaa2)
Definition: lda.h:435
const double c_b7
Definition: chem/lda.cc:54
const mpreal atan(const mpreal &v, mp_rnd_t rnd_mode)
Definition: mpreal.h:2316
tensorT sqrt(const tensorT &s, double tol=1e-8)
Computes matrix square root (not used any more?) 
Definition: DFcode/moldft.cc:446
void dft_xc_lda_ene(const Key< NDIM > &key, Tensor< double > &t)
Definition: lda.h:915
const double c_b14
Definition: chem/lda.cc:55
int c_uks_vwn5__(double *ra, double *rb, double *f, double *dfdra, double *dfdrb)
Definition: chem/lda.cc:181
int integer
Definition: DFcode/fci/crayio.c:25
double doublereal
Definition: lda.h:49
const double a1
Definition: vnucso.cc:90
int c_rks_vwn5__(const double *r__, double *f, double *dfdra)
Definition: chem/lda.cc:116
const T1 & f1
Definition: gtest-tuple.h:680
MADNESS_FORINT integer
Definition: lda.h:50
const double c_b2
Definition: chem/lda.cc:53
const T1 const T2 & f2
Definition: gtest-tuple.h:680
const double THRESH_GRHO
Definition: lda.h:835
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces. 
Definition: chem/atomutil.cc:45
FLOAT b(int j, FLOAT z)
Definition: y1.cc:79
void dft_xc_lda_V(const Key< NDIM > &key, Tensor< double > &t)
Definition: lda.h:904
Key is the index for a node of the 2^NDIM-tree. 
Definition: key.h:69
const double THRESH_RHO
Definition: lda.h:834
void wst_munge_rho(int npoint, double *rho)
Definition: lda.h:845