MADNESS  version 0.9
lda.h
Go to the documentation of this file.
1 /*
2  This file is part of MADNESS.
3 
4  Copyright (C) 2007,2010 Oak Ridge National Laboratory
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 
20  For more information please contact:
21 
22  Robert J. Harrison
23  Oak Ridge National Laboratory
24  One Bethel Valley Road
25  P.O. Box 2008, MS-6367
26 
27  email: harrisonrj@ornl.gov
28  tel: 865-241-3937
29  fax: 865-572-0680
30 
31  $Id$
32 */
33 /*
34  * lda.h
35  *
36  * Created on: Nov 10, 2008
37  * Author: wsttiger
38  */
39 
40 #ifndef LDA_H_
41 #define LDA_H_
42 
43 //#define WORLD_INSTANTIATE_STATIC_TEMPLATES
44 #include <madness/mra/mra.h>
45 #include <madness/world/world.h>
46 #include <math.h>
47 #include <madness/madness_config.h>
48 
49 typedef double doublereal;
50 typedef MADNESS_FORINT integer;
51 typedef int logical;
52 
53 #define max(a,b) ((a)>=(b)?(a):(b))
54 
55 /* static double pow_dd(doublereal* a, doublereal* b) { */
56 /* return pow(*a,*b); */
57 /* } */
58 
59 using namespace madness;
60 
61 /* lda.f -- translated by f2c (version 20050501).
62  You must link the resulting object file with libf2c:
63  on Microsoft Windows system, link with libf2c.lib;
64  on Linux or Unix systems, link with .../path/to/libf2c.a -lm
65  or, if you install libf2c.a in a standard place, with -lf2c -lm
66  -- in that order, at the end of the command line, as in
67  cc *.o -lf2c -lm
68  Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
69 
70  http://www.netlib.org/f2c/libf2c.zip
71 */
72 
73 
74 /* Table of constant values */
75 
76 #include <cmath>
77 
78 static inline double pow(const double* a, const double* b) {
79  return pow(*a, *b);
80 }
81 
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;
86 
87 
88 inline /* Subroutine */ int x_rks_s__(const double *r__, double *f, double *
89  dfdra)
90 {
91 
92  /* Local variables */
93  double ra13;
94 
95 
96 /* This subroutine evaluates the spin polarised exchange functional */
97 /* in the Local Density Approximation [1], and the corresponding */
98 /* potential. Often this functional is referred to as the Dirac */
99 /* functional [2] or Slater functional. */
100 
101 /* [1] F. Bloch, Zeitschrift fuer Physik, Vol. 57 (1929) 545. */
102 
103 /* [2] P.A.M. Dirac, Proceedings of the Cambridge Philosophical */
104 /* Society, Vol. 26 (1930) 376. */
105 
106 /* Parameters: */
107 
108 /* r the total electron density */
109 /* f On return the functional value */
110 /* dfdra On return the derivative of f with respect to alpha electron */
111 /* density */
112 
113 
114 /* Ax = -3/4*(6/pi)**(1/3) */
115 /* Bx = -(6/pi)**(1/3) */
116 /* C = (1/2)**(1/3) */
117 
118 
119 
120 
121  ra13 = pow(r__, &c_b2) * .793700525984099737375852819636154;
122  *f = *r__ * -.930525736349100025002010218071667 * ra13;
123  *dfdra = ra13 * -1.24070098179880003333601362409556;
124 
125  return 0;
126 } /* x_rks_s__ */
127 
128 /* ----------------------------------------------------------------------- */
129 inline /* Subroutine */ int x_uks_s__(double *ra, double *rb, double *f,
130  double *dfdra, double *dfdrb)
131 {
132  /* Local variables */
133  double ra13, rb13;
134 
135 
136 /* This subroutine evaluates the spin polarised exchange functional */
137 /* in the Local Density Approximation [1], and the corresponding */
138 /* potential. Often this functional is referred to as the Dirac */
139 /* functional [2] or Slater functional. */
140 
141 /* [1] F. Bloch, Zeitschrift fuer Physik, Vol. 57 (1929) 545. */
142 
143 /* [2] P.A.M. Dirac, Proceedings of the Cambridge Philosophical */
144 /* Society, Vol. 26 (1930) 376. */
145 
146 /* Parameters: */
147 
148 /* ra the alpha electron density */
149 /* rb the beta electron density */
150 /* f On return the functional value */
151 /* dfdra On return the derivative of f with respect to ra */
152 /* dfdrb On return the derivative of f with respect to rb */
153 
154 
155 /* Ax = -3/4*(6/pi)**(1/3) */
156 /* Bx = -(6/pi)**(1/3) */
157 
158 
159 
160 
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;
166 
167  return 0;
168 } /* x_uks_s__ */
169 
170 inline /* Subroutine */ int c_rks_vwn5__(const double *r__, double *f, double *
171  dfdra)
172 {
173  /* Local variables */
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;
176 
177 
178 /* This subroutine evaluates the Vosko, Wilk and Nusair correlation */
179 /* functional number 5 [1] for the closed shell case, with the */
180 /* parametrisation as given in table 5. */
181 
182 /* The original code was obtained from Dr. Phillip Young, */
183 /* with corrections from Dr. Paul Sherwood. */
184 
185 /* [1] S.H. Vosko, L. Wilk, and M. Nusair */
186 /* "Accurate spin-dependent electron liquid correlation energies */
187 /* for local spin density calculations: a critical analysis", */
188 /* Can.J.Phys, Vol. 58 (1980) 1200-1211. */
189 
190 /* Parameters: */
191 
192 /* r the total electron density */
193 /* f On return the functional value */
194 /* dfdra On return the derivative of f with respect to the alpha */
195 /* electron density */
196 
197 
198 
199 
200 /* VWN interpolation parameters */
201 
202 /* paramagnetic */
203  a2 = .0621814;
204  b2 = 3.72744;
205  c2 = 12.9352;
206  d2 = -.10498;
207 
208 /* t4 = (1/(4/3)*pi)**(1/3) */
209  t4 = .620350490899399531;
210 
211 /* t5 = 0.5/(2**(1/3)-1) */
212  t5 = 1.92366105093153617;
213 
214 /* t6 = 2/(3*(2**(1/3)-1)) */
215  t6 = 2.56488140124204822;
216 
217 /* t7 = 2.25*(2**(1/3)-1) */
218  t7 = .584822362263464735;
219 
220 /* Paramagnetic interpolation constants */
221 
222  p1 = 6.1519908197590798;
223  p2 = a2 * .5;
224  p3 = 9.6902277115443745e-4;
225  p4 = .038783294878113009;
226 
227 /* closed shell case */
228  srho = *r__;
229  srho13 = pow(&srho, &c_b7);
230  alpha_rho13__ = pow(&c_b8, &c_b7) * srho;
231  iv2 = t4 / srho13;
232  iv = sqrt(iv2);
233 
234 /* paramagnetic */
235  inv = 1. / (iv2 + b2 * iv + c2);
236  i1 = log(iv2 * inv);
237  i2 = log((iv - d2) * (iv - d2) * inv);
238 /* corrected b1->b2 ps Apr98 */
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.));
242 
243  *f = pp1 * srho;
244  *dfdra = pp1 - iv * .166666666666666666666666666666 * pp2;
245 
246  return 0;
247 } /* c_rks_vwn5__ */
248 
249 /* ----------------------------------------------------------------------- */
250 inline /* Subroutine */ int c_uks_vwn5__(double *ra, double *rb, double *
251  f, double *dfdra, double *dfdrb)
252 {
253  /* System generated locals */
254  double d__1, d__2;
255 
256  /* Local variables */
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;
262 
263 
264 /* This subroutine evaluates the Vosko, Wilk and Nusair correlation */
265 /* functional number 5 [1], with the parametrisation as given in */
266 /* table 5. */
267 
268 /* The original code was obtained from Dr. Phillip Young, */
269 /* with corrections from Dr. Paul Sherwood. */
270 
271 /* [1] S.H. Vosko, L. Wilk, and M. Nusair */
272 /* "Accurate spin-dependent electron liquid correlation energies */
273 /* for local spin density calculations: a critical analysis", */
274 /* Can.J.Phys, Vol. 58 (1980) 1200-1211. */
275 
276 /* Parameters: */
277 
278 /* ra the alpha-electron density */
279 /* rb the beta-electron density */
280 /* f On return the functional value */
281 /* dfdra On return the derivative of f with respect to ra */
282 /* dfdrb On return the derivative of f with respect to rb */
283 
284 
285 
286 /* tn13 = 2**(1/3) */
287 /* tn43 = 2**(4/3) */
288 
289 /* VWN interpolation parameters */
290 
291 /* spin stiffness */
292  a1 = -.0337737278807791058;
293  b1 = 1.13107;
294  c1 = 13.0045;
295  d1 = -.0047584;
296 /* paramagnetic */
297  a2 = .0621814;
298  b2 = 3.72744;
299  c2 = 12.9352;
300  d2 = -.10498;
301 /* ferromagnetic */
302 /* try cadpac/nwchem value (.5*a2) */
303  a3 = .0310907;
304  b3 = 7.06042;
305  c3 = 18.0578;
306  d3 = -.325;
307 
308 /* t4 = (1/(4/3)*pi)**(1/3) */
309  t4 = .620350490899399531;
310 
311 /* t5 = 0.5/(2**(1/3)-1) */
312  t5 = 1.92366105093153617;
313 
314 /* t6 = 2/(3*(2**(1/3)-1)) */
315  t6 = 2.56488140124204822;
316 
317 /* t7 = 2.25*(2**(1/3)-1) */
318  t7 = .584822362263464735;
319 
320 /* Spin stiffness interpolation constants */
321 
322  s1 = 7.12310891781811772;
323  s2 = a1 * .5;
324  s3 = -6.9917323507644313e-6;
325  s4 = -.0053650918488835769;
326 
327 /* Paramagnetic interpolation constants */
328 
329  p1 = 6.1519908197590798;
330  p2 = a2 * .5;
331  p3 = 9.6902277115443745e-4;
332  p4 = .038783294878113009;
333 
334 /* Ferromagnetic interpolation constants */
335 
336  f1 = 4.73092690956011364;
337  f2 = a3 * .5;
338 
339 /* F3 = -0.244185082989490298d-02 *0.5d0 */
340 /* F4 = -0.570212323620622186d-01 *0.5d0 */
341 
342 /* try nwchem values */
343 
344  f3 = .00224786709554261133;
345  f4 = .0524913931697809227;
346 
347 /* Interpolation intervals */
348 
349  inter1 = .99999999989999999;
350  inter2 = -.99999999989999999;
351 
352 /* open shell case */
353  alpha_rho13__ = pow(ra, &c_b7);
354  beta_rho13__ = pow(rb, &c_b7);
355  srho = *ra + *rb;
356  srho13 = pow(&srho, &c_b7);
357  iv2 = t4 / srho13;
358  iv = sqrt(iv2);
359 
360 /* spin-stiffness */
361  inv = 1. / (iv2 + b1 * iv + c1);
362  i1 = log(iv2 * inv);
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.));
367 
368 /* paramagnetic */
369  inv = 1. / (iv2 + b2 * iv + c2);
370  i1 = log(iv2 * inv);
371  i2 = log((iv - d2) * (iv - d2) * inv);
372 /* corrected b1->b2 ps Apr98 */
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.));
376 
377 /* ferromagnetic */
378  inv = 1. / (iv2 + b3 * iv + c3);
379  i1 = log(iv2 * inv);
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.));
384 
385 /* polarisation function */
386 
387  zeta = (*ra - *rb) / srho;
388  zeta3 = zeta * zeta * zeta;
389  zeta4 = zeta3 * zeta;
390  if (zeta > inter1) {
391  vwn1 = t5 * .51984209978974638;
392  vwn2 = t6 * 1.25992104989487316476721060727823;
393  } else if (zeta < inter2) {
394  vwn1 = t5 * .51984209978974638;
395  vwn2 = t6 * -1.25992104989487316476721060727823;
396  } else {
397  d__1 = zeta + 1.;
398  d__2 = 1. - zeta;
399  vwn1 = (pow(&d__1, &c_b14) + pow(&d__2, &c_b14) - 2.) * t5;
400  d__1 = zeta + 1.;
401  d__2 = 1. - zeta;
402  vwn2 = (pow(&d__1, &c_b7) - pow(&d__2, &c_b7)) * t6;
403  }
404  ss1 *= t7;
405  ss2 *= t7;
406  tau = ff1 - pp1 - ss1;
407  dtau = ff2 - pp2 - ss2;
408 
409  v = pp1 + vwn1 * (ss1 + tau * zeta4);
410  *f = v * srho;
411 
412  t1 = v - iv * .166666666666666666666666666667 * (pp2 + vwn1 * (ss2 + dtau
413  * zeta4));
414  t2 = vwn2 * (ss1 + tau * zeta4) + vwn1 * 4. * tau * zeta3;
415  *dfdra = t1 + t2 * (1. - zeta);
416  *dfdrb = t1 - t2 * (zeta + 1.);
417 
418  return 0;
419 } /* c_uks_vwn5__ */
420 
422 //int rks_x_lda__ (integer *ideriv, integer *npt, doublereal *rhoa1,
423 // doublereal *sigmaaa1, doublereal *zk, doublereal *vrhoa,
424 // doublereal *vsigmaaa, doublereal *v2rhoa2, doublereal *v2rhoasigmaaa,
425 // doublereal *v2sigmaaa2);
427 //
429 //int rks_c_vwn5__ (integer *ideriv, integer *npt, doublereal *rhoa1,
430 // doublereal *sigmaaa1, doublereal *zk, doublereal *vrhoa,
431 // doublereal *vsigmaaa, doublereal *v2rhoa2, doublereal *v2rhoasigmaaa,
432 // doublereal *v2sigmaaa2);
434 
435 inline /* Subroutine */ int rks_c_vwn5__(integer *ideriv, integer *npt, doublereal *
436  rhoa1, doublereal *sigmaaa1, doublereal *zk, doublereal *vrhoa,
437  doublereal *vsigmaaa, doublereal *v2rhoa2, doublereal *v2rhoasigmaaa,
438  doublereal *v2sigmaaa2)
439 {
440  // WSTHORNTON
441  static doublereal c_b2 = .16666666666666666;
442  static doublereal c_b3 = .33333333333333331;
443  /* System generated locals */
444  integer i__1;
445  doublereal d__1, d__2;
446 
447  /* Builtin functions */
448  double pow_dd(doublereal *, doublereal *), log(doublereal), atan(
449  doublereal);
450 
451  /* Local variables */
452  static integer i__;
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;
458 
459 
460 /* S.H. Vosko, L. Wilk, and M. Nusair */
461 /* Accurate spin-dependent electron liquid correlation energies for */
462 /* local spin density calculations: a critical analysis */
463 /* Can. J. Phys. 58 (1980) 1200-1211 */
464 
465 
466 /* CITATION: */
467 
468 /* Functionals were obtained from the Density Functional Repository */
469 /* as developed and distributed by the Quantum Chemistry Group, */
470 /* CCLRC Daresbury Laboratory, Daresbury, Cheshire, WA4 4AD */
471 /* United Kingdom. Contact Huub van Dam (h.j.j.vandam@dl.ac.uk) or */
472 /* Paul Sherwood for further information. */
473 
474 /* COPYRIGHT: */
475 
476 /* Users may incorporate the source code into software packages and */
477 /* redistribute the source code provided the source code is not */
478 /* changed in anyway and is properly cited in any documentation or */
479 /* publication related to its use. */
480 
481 /* ACKNOWLEDGEMENT: */
482 
483 /* The source code was generated using Maple 8 through a modified */
484 /* version of the dfauto script published in: */
485 
486 /* R. Strange, F.R. Manby, P.J. Knowles */
487 /* Automatic code generation in density functional theory */
488 /* Comp. Phys. Comm. 136 (2001) 310-318. */
489 
490  /* Parameter adjustments */
491  --v2sigmaaa2;
492  --v2rhoasigmaaa;
493  --v2rhoa2;
494  --vsigmaaa;
495  --vrhoa;
496  --zk;
497  --sigmaaa1;
498  --rhoa1;
499 
500  /* Function Body */
501  if (*ideriv == 0) {
502  i__1 = *npt;
503  for (i__ = 1; i__ <= i__1; ++i__) {
504 /* Computing MAX */
505  d__1 = 0., d__2 = rhoa1[i__];
506  rho = max(d__1,d__2);
507  if (rho > 1e-20) {
508  t1 = 1 / rho;
509  t2 = pow_dd(&t1, &c_b3);
510  t4 = pow_dd(&t1, &c_b2);
511  t7 = 1 / (t2 * .6203504908994 + t4 * 2.935818660072219 +
512  12.9352);
513  t10 = log(t2 * .6203504908994 * t7);
514  t16 = atan(6.15199081975908 / (t4 * 1.575246635799487 +
515  3.72744));
516 /* Computing 2nd power */
517  d__1 = t4 * .7876233178997433 + .10498;
518  t20 = d__1 * d__1;
519  t22 = log(t20 * t7);
520  zk[i__] = rho * (t10 * .0310907 + t16 * .03878329487811301 +
521  t22 * 9.690227711544374e-4);
522  } else {
523 /* rho */
524  zk[i__] = 0.;
525  }
526 /* rho */
527  }
528  } else if (*ideriv == 1) {
529  i__1 = *npt;
530  for (i__ = 1; i__ <= i__1; ++i__) {
531 /* Computing MAX */
532  d__1 = 0., d__2 = rhoa1[i__];
533  rho = max(d__1,d__2);
534  if (rho > 1e-20) {
535  t1 = 1 / rho;
536  t2 = pow_dd(&t1, &c_b3);
537  t4 = pow_dd(&t1, &c_b2);
538  t6 = t2 * .6203504908994 + t4 * 2.935818660072219 + 12.9352;
539  t7 = 1 / t6;
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;
546 /* Computing 2nd power */
547  d__1 = t19;
548  t20 = d__1 * d__1;
549  t22 = log(t20 * t7);
550  t23 = t22 * 9.690227711544374e-4;
551  zk[i__] = rho * (t11 + t17 + t23);
552 /* Computing 2nd power */
553  d__1 = t2;
554  t25 = d__1 * d__1;
555  t26 = 1 / t25;
556 /* Computing 2nd power */
557  d__1 = rho;
558  t28 = d__1 * d__1;
559  t29 = 1 / t28;
560 /* Computing 2nd power */
561  d__1 = t6;
562  t32 = d__1 * d__1;
563  t33 = 1 / t32;
564 /* Computing 2nd power */
565  d__1 = t4;
566  t37 = d__1 * d__1;
567 /* Computing 2nd power */
568  d__1 = t37;
569  t38 = d__1 * d__1;
570  t40 = 1 / t38 / t4;
571  t41 = t40 * t29;
572  t43 = t26 * -.2067834969664667 * t29 - t41 *
573  .4893031100120365;
574 /* Computing 2nd power */
575  d__1 = t13;
576  t51 = d__1 * d__1;
577  t52 = 1 / t51;
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);
584  } else {
585 /* rho */
586  zk[i__] = 0.;
587  vrhoa[i__] = 0.;
588  }
589 /* rho */
590  }
591  } else if (*ideriv == 2) {
592  i__1 = *npt;
593  for (i__ = 1; i__ <= i__1; ++i__) {
594 /* Computing MAX */
595  d__1 = 0., d__2 = rhoa1[i__];
596  rho = max(d__1,d__2);
597  if (rho > 1e-20) {
598  t1 = 1 / rho;
599  t2 = pow_dd(&t1, &c_b3);
600  t4 = pow_dd(&t1, &c_b2);
601  t6 = t2 * .6203504908994 + t4 * 2.935818660072219 + 12.9352;
602  t7 = 1 / t6;
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;
609 /* Computing 2nd power */
610  d__1 = t19;
611  t20 = d__1 * d__1;
612  t22 = log(t20 * t7);
613  t23 = t22 * 9.690227711544374e-4;
614  zk[i__] = rho * (t11 + t17 + t23);
615 /* Computing 2nd power */
616  d__1 = t2;
617  t25 = d__1 * d__1;
618  t26 = 1 / t25;
619  t27 = t26 * t7;
620 /* Computing 2nd power */
621  d__1 = rho;
622  t28 = d__1 * d__1;
623  t29 = 1 / t28;
624 /* Computing 2nd power */
625  d__1 = t6;
626  t32 = d__1 * d__1;
627  t33 = 1 / t32;
628  t34 = t2 * t33;
629 /* Computing 2nd power */
630  d__1 = t4;
631  t37 = d__1 * d__1;
632 /* Computing 2nd power */
633  d__1 = t37;
634  t38 = d__1 * d__1;
635  t39 = t38 * t4;
636  t40 = 1 / t39;
637  t41 = t40 * t29;
638  t43 = t26 * -.2067834969664667 * t29 - t41 *
639  .4893031100120365;
640  t46 = t27 * -.2067834969664667 * t29 - t34 * .6203504908994 *
641  t43;
642  t47 = 1 / t2;
643  t48 = t46 * t47;
644  t49 = t48 * t6;
645 /* Computing 2nd power */
646  d__1 = t13;
647  t51 = d__1 * d__1;
648  t52 = 1 / t51;
649  t53 = t52 * t40;
650  t55 = t52 * 37.8469910464 + 1.;
651  t56 = 1 / t55;
652  t58 = t53 * t29 * t56;
653  t60 = t19 * t7;
654  t63 = t20 * t33;
655  t66 = t60 * -.2625411059665811 * t41 - t63 * 1. * t43;
656  t67 = 1 / t20;
657  t68 = t66 * t67;
658  t69 = t68 * t6;
659  vrhoa[i__] = t11 + t17 + t23 + rho * (t49 *
660  .05011795824473985 + t58 * .0626408570946439 + t69 *
661  9.690227711544374e-4);
662  t77 = 1 / t25 / t1;
663 /* Computing 2nd power */
664  d__1 = t28;
665  t79 = d__1 * d__1;
666  t80 = 1 / t79;
667  t81 = t77 * t7 * t80;
668  t88 = 1 / t28 / rho;
669  t92 = 1 / t32 / t6;
670 /* Computing 2nd power */
671  d__1 = t43;
672  t94 = d__1 * d__1;
673  t102 = 1 / t39 / t1;
674  t103 = t102 * t80;
675  t105 = t40 * t88;
676  t107 = t77 * -.1378556646443111 * t80 + t26 *
677  .4135669939329333 * t88 - t103 * .4077525916766971 +
678  t105 * .978606220024073;
679  t125 = t80 * t56;
680 /* Computing 2nd power */
681  d__1 = t51;
682  t134 = d__1 * d__1;
683 /* Computing 2nd power */
684  d__1 = t55;
685  t138 = d__1 * d__1;
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);
703  } else {
704 /* rho */
705  zk[i__] = 0.;
706  vrhoa[i__] = 0.;
707  v2rhoa2[i__] = 0.;
708  }
709 /* rho */
710  }
711  }
712 /* ideriv */
713  return 0;
714 } /* rks_c_vwn5__ */
715 
716 inline /* Subroutine */ int rks_x_lda__(integer *ideriv, integer *npt, doublereal *
717  rhoa1, doublereal *sigmaaa1, doublereal *zk, doublereal *vrhoa,
718  doublereal *vsigmaaa, doublereal *v2rhoa2, doublereal *v2rhoasigmaaa,
719  doublereal *v2sigmaaa2)
720 {
721  // WSTHORNTON
722  static doublereal c_b2 = .33333333333333331;
723 
724  /* System generated locals */
725  integer i__1;
726  doublereal d__1, d__2;
727 
728  /* Builtin functions */
729  double pow_dd(doublereal *, doublereal *);
730 
731  /* Local variables */
732  static integer i__;
733  static doublereal t1, t5, rho;
734 
735 
736 /* P.A.M. Dirac */
737 /* Proceedings of the Cambridge Philosophical Society, 26 (1930) 376 */
738 
739 
740 /* CITATION: */
741 
742 /* Functionals were obtained from the Density Functional Repository */
743 /* as developed and distributed by the Quantum Chemistry Group, */
744 /* CCLRC Daresbury Laboratory, Daresbury, Cheshire, WA4 4AD */
745 /* United Kingdom. Contact Huub van Dam (h.j.j.vandam@dl.ac.uk) or */
746 /* Paul Sherwood for further information. */
747 
748 /* COPYRIGHT: */
749 
750 /* Users may incorporate the source code into software packages and */
751 /* redistribute the source code provided the source code is not */
752 /* changed in anyway and is properly cited in any documentation or */
753 /* publication related to its use. */
754 
755 /* ACKNOWLEDGEMENT: */
756 
757 /* The source code was generated using Maple 8 through a modified */
758 /* version of the dfauto script published in: */
759 
760 /* R. Strange, F.R. Manby, P.J. Knowles */
761 /* Automatic code generation in density functional theory */
762 /* Comp. Phys. Comm. 136 (2001) 310-318. */
763 
764  /* Parameter adjustments */
765  --v2sigmaaa2;
766  --v2rhoasigmaaa;
767  --v2rhoa2;
768  --vsigmaaa;
769  --vrhoa;
770  --zk;
771  --sigmaaa1;
772  --rhoa1;
773 
774  /* Function Body */
775  if (*ideriv == 0) {
776  i__1 = *npt;
777  for (i__ = 1; i__ <= i__1; ++i__) {
778 /* Computing MAX */
779  d__1 = 0., d__2 = rhoa1[i__];
780  rho = max(d__1,d__2);
781  if (rho > 1e-20) {
782  t1 = pow_dd(&rho, &c_b2);
783  zk[i__] = t1 * -.7385587663820224 * rho;
784  } else {
785 /* rho */
786  zk[i__] = 0.;
787  }
788 /* rho */
789  }
790  } else if (*ideriv == 1) {
791  i__1 = *npt;
792  for (i__ = 1; i__ <= i__1; ++i__) {
793 /* Computing MAX */
794  d__1 = 0., d__2 = rhoa1[i__];
795  rho = max(d__1,d__2);
796  if (rho > 1e-20) {
797  t1 = pow_dd(&rho, &c_b2);
798  zk[i__] = t1 * -.7385587663820224 * rho;
799  vrhoa[i__] = t1 * -.9847450218426965;
800  } else {
801 /* rho */
802  zk[i__] = 0.;
803  vrhoa[i__] = 0.;
804  }
805 /* rho */
806  }
807  } else if (*ideriv == 2) {
808  i__1 = *npt;
809  for (i__ = 1; i__ <= i__1; ++i__) {
810 /* Computing MAX */
811  d__1 = 0., d__2 = rhoa1[i__];
812  rho = max(d__1,d__2);
813  if (rho > 1e-20) {
814  t1 = pow_dd(&rho, &c_b2);
815  zk[i__] = t1 * -.7385587663820224 * rho;
816  vrhoa[i__] = t1 * -.9847450218426965;
817 /* Computing 2nd power */
818  d__1 = t1;
819  t5 = d__1 * d__1;
820  v2rhoa2[i__] = -.6564966812284644 / t5;
821  } else {
822 /* rho */
823  zk[i__] = 0.;
824  vrhoa[i__] = 0.;
825  v2rhoa2[i__] = 0.;
826  }
827 /* rho */
828  }
829  }
830 /* ideriv */
831  return 0;
832 } /* rks_x_lda__ */
833 
834 const double THRESH_RHO = 1e-8;
835 const double THRESH_GRHO = 1e-20;
836 
837 inline void wst_munge_grho(int npoint, double *rho, double *grho) {
838  for (int i=0; i<npoint; i++) {
839  if (rho[i]<THRESH_RHO) rho[i] = THRESH_RHO;
840  if ((rho[i] <=THRESH_RHO) ||
841  (grho[i] < THRESH_GRHO)) grho[i] = THRESH_GRHO;
842  }
843 }
844 
845 inline void wst_munge_rho(int npoint, double *rho) {
846  for (int i=0; i<npoint; i++) {
847  if (rho[i]<THRESH_RHO) rho[i] = THRESH_RHO;
848  }
849 }
850 
851 //***************************************************************************
852 inline void xc_rks_generic_lda(Tensor<double> rho_alpha,
853  Tensor<double> f,
854  Tensor<double> df_drho)
855  {
856  MADNESS_ASSERT(rho_alpha.iscontiguous());
857  MADNESS_ASSERT(f.iscontiguous());
858  MADNESS_ASSERT(df_drho.iscontiguous());
859 
860  rho_alpha = rho_alpha.flat();
861  f = f.flat();
862  df_drho = df_drho.flat();
863 
864  integer ideriv = 2;
865  integer npt = rho_alpha.dim(0);
866 
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);
874 
875  wst_munge_rho(npt, rho_alpha.ptr());
876 
877  f.fill(0.0);
878  df_drho.fill(0.0);
879 
880  int returnvalue = ::rks_x_lda__(&ideriv, &npt, rho_alpha.ptr(), gamma_alpha.ptr(),
881  tf.ptr(),
882  tdf_drho.ptr(), tdf_dgamma.ptr(),
883  td2f_drho2.ptr(), td2f_drhodgamma.ptr(), td2f_dgamma2.ptr());
884 
885  f.gaxpy(1.0, tf, 1.0);
886  df_drho.gaxpy(1.0, tdf_drho, 1.0);
887 
888  tf.fill(0.0);
889  tdf_drho.fill(0.0);
890 
891  returnvalue = ::rks_c_vwn5__(&ideriv, &npt, rho_alpha.ptr(), gamma_alpha.ptr(),
892  tf.ptr(),
893  tdf_drho.ptr(), tdf_dgamma.ptr(),
894  td2f_drho2.ptr(), td2f_drhodgamma.ptr(), td2f_dgamma2.ptr());
895 
896  f.gaxpy(1.0, tf, 1.0);
897  df_drho.gaxpy(1.0, tdf_drho, 1.0);
898 
899  }
900  //***************************************************************************
901 
902  //***************************************************************************
903  template <int NDIM>
904  inline void dft_xc_lda_V(const Key<NDIM>& key, Tensor<double>& t)
905  {
906  Tensor<double> enefunc = copy(t);
907  Tensor<double> V = copy(t);
908  ::xc_rks_generic_lda(t, enefunc, V);
909  t(___) = V(___);
910  }
911  //***************************************************************************
912 
913  //***************************************************************************
914  template <int NDIM>
915  inline void dft_xc_lda_ene(const Key<NDIM>& key, Tensor<double>& t)
916  {
917  Tensor<double> V = copy(t);
918  Tensor<double> enefunc = copy(t);
919  ::xc_rks_generic_lda(t, enefunc, V);
920  t(___) = enefunc(___);
921  }
922  //***************************************************************************
923 
924 // //***************************************************************************
925 // static double munge(double r) {
926 // if (r < 1e-12) r = 1e-12;
927 // return r;
928 // }
929 // //***************************************************************************
930 //
931 // //***************************************************************************
932 // static void ldaop(const Key<3>& key, Tensor<double>& t) {
933 // UNARY_OPTIMIZED_ITERATOR(double, t, double r=munge(2.0* *_p0); double q; double dq1; double dq2;x_rks_s__(&r, &q, &dq1);c_rks_vwn5__(&r, &q, &dq2); *_p0 = dq1+dq2);
934 // }
935 // //***************************************************************************
936 //
937 // //***************************************************************************
938 // static void ldaeop(const Key<3>& key, Tensor<double>& t) {
939 // UNARY_OPTIMIZED_ITERATOR(double, t, double r=munge(2.0* *_p0); double q1; double q2; double dq;x_rks_s__(&r, &q1, &dq);c_rks_vwn5__(&r, &q2, &dq); *_p0 = q1+q2);
940 // }
941 // //***************************************************************************
942 
943 
944 
945 #endif /* LDA_H_ */
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