ergo
functionals.h
Go to the documentation of this file.
1 /* Ergo, version 3.2, a program for linear scaling electronic structure
2  * calculations.
3  * Copyright (C) 2012 Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * Primary academic reference:
19  * Kohn−Sham Density Functional Theory Electronic Structure Calculations
20  * with Linearly Scaling Computational Time and Memory Usage,
21  * Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek,
22  * J. Chem. Theory Comput. 7, 340 (2011),
23  * <http://dx.doi.org/10.1021/ct100611z>
24  *
25  * For further information about Ergo, see <http://www.ergoscf.org>.
26  */
27 
28 /*-*-mode: C; c-indentation-style: "bsd"; c-basic-offset: 4; -*-*/
42 #ifndef _FUNCTIONALS_H_
43 #define _FUNCTIONALS_H_
44 
45 #include "realtype.h"
46 
47 #ifdef __cplusplus
48 #define EXTERN_C extern "C"
49 #else
50 #define EXTERN_C
51 #endif
52 
53 typedef ergo_real real;
54 
55 #if defined(FUNC_PRECISION) && FUNC_PRECISION == 1
56 #define ASINH asinhf
57 #define ATAN atanf
58 #define ERF erff
59 #define EXP expf
60 #define FABS fabsf
61 #define LOG logf
62 #define POW powf
63 #define SQRT sqrtf
64 #elif defined(FUNC_PRECISION) && FUNC_PRECISION == 2
65 #define ASINH asinh
66 #define ATAN atan
67 #define ERF erf
68 #define EXP exp
69 #define FABS fabs
70 #define LOG log
71 #define POW pow
72 #define SQRT sqrt
73 #else
74 #define ASINH asinhl
75 #define ATAN atanl
76 #define ERF erfl
77 #define EXP expl
78 #define FABS fabsl
79 #define LOG logl
80 #define POW powl
81 #define SQRT sqrtl
82 /* FIXME! */
83 /* #define _XOPEN_SOURCE 600 */
84 #endif
85 
86 /* FirstDrv: matrix of first order derivatives with respect to two
87  * parameters: density rho and SQUARE of the gradient of density grho.
88  * zeta_i = |\nabla\rho_i|˛
89  * mu = |\nabla\rho_\alpha||\nabla\rho_\beta|
90  */
91 typedef struct {
92  real df1000; /* d/drho F */
94  real df0010; /* d/zeta F */
98 
99 /* SecondFuncDrv: this structure is used by functional derivative
100  * evaluation procedures. Do not include "triplet" transformation.
101  */
102 typedef struct {
103  real df1000; /* d/drho_alpha F */
104  real df0100; /* d/drho_beta F */
105  real df0010; /* d/|zeta_alpha| F */
106  real df0001; /* d/|zeta_beta| F */
108  real df2000; /* d/drho_alpha^2 F */
109  real df1100; /* d/(drho_alpha drho_beta) F */
110  real df1010; /* d/drho_alpha d/dzeta_alpha F */
111  real df1001; /* d/drho_alpha d/dzeta_beta F */
113  real df0200; /* d/drho_beta^2 F */
114  real df0110; /* d/drho_beta d/dzeta_alpha F */
115  real df0101; /* d/drho_beta d/dzeta_beta F */
117  real df0020; /* d/dzeta_alpha^2 F */
118  real df0011; /* d2/dzeta_a zeta_b F */
120  real df0002; /* d/dzeta_beta^2 F */
124 
125 
126 /* ThirdFuncDrv: matrix of third derivatives with respect to five
127  parameters: density rho_alpha and SQUARE of the density gradient
128  zeta. and mu.
129 */
130 
131 typedef struct {
132  real df1000; /* d/drho F */
134  real df0010; /* d/|zeta| F */
137 
138  real df2000; /* d/drho_alpha^2 F */
139  real df1100; /* d/(drho_alpha drho_beta) F */
140  real df1010; /* d/drho_alpha d/dzeta_alpha F */
141  real df1001; /* d/drho_alpha d/dzeta_beta F */
143  real df0200; /* d/drho_beta^2 F */
144  real df0110; /* d/drho_beta d/dzeta_alpha F */
145  real df0101; /* d/drho_beta d/dzeta_beta F */
147  real df0020; /* d/dzeta_alpha^2 F */
148  real df0011; /* d2/dzeta_a zeta_b F */
150  real df0002; /* d/dzeta_beta^2 F */
153 
190 
191 
192 typedef struct {
193 
194  /* First order derivatives with respect to all 5 variables */
195 
201 
202  /* Second order mixed derivatives with respect to all 5 variables */
203 
219 
220  /* Third order mixed derivatives with respect to all 5 variables */
221 
257 
258  /* Fourth order mixed derivatives with respect to all 5 variables */
259 
331 
332 
333 typedef struct Functional_ Functional;
334 
336 EXTERN_C enum FunError fun_select_by_name(const char *conf_string);
337 extern Functional *selected_func;
338 extern int (*fun_printf)(const char *fmt, ...);
339 extern void (*fun_set_hf_weight)(real w);
340 extern real (*fun_get_hf_weight)(void);
341 extern void (*fun_set_cam_param)(real w, real b);
342 int dft_get_cam_param(real *alpha, real *beta, real *mu);
343 
344 /* FunDensProp structure contains properties of the density that are
345  needed for functional evaluation and possibly other purposes.
346 */
347 typedef struct FunDensProp_ {
349  real grada, gradb; /* norms of the density gradient, not squares */
350  real gradab; /* scalar product of grada and gradb */
351  /* real current[3] or something may come in the future :-) */
352 } FunDensProp;
353 
354 /* EnergyFunc: the function returning the energy for given densities
355  and gradients. Note that some functionals(like LYP) depend explicitely
356  on separately alpha and beta densities
357 */
358 typedef int (*IsGGAFunc)(void);
359 typedef int (*ReadInputFunc)(const char* conf_string);
360 typedef void (*ReportFunc)(void);
361 typedef real (*EnergyFunc)(const FunDensProp* dens_prop);
362 typedef void (*FirstOrderFun)(FunFirstFuncDrv *ds, real factor,
363  const FunDensProp* dns_prp);
364 
365 typedef void (*SecondOrderFun)(FunSecondFuncDrv *ds, real factor,
366  const FunDensProp* dens_prop);
367 
368 typedef void (*ThirdOrderFun)(FunThirdFuncDrv *ds, real factor,
369  const FunDensProp* dens_prop);
370 typedef void (*FourthOrderFun)(FunFourthFuncDrv *ds, real factor,
371  const FunDensProp *dens_prop);
372 
373 struct Functional_ {
374  const char* name; /* descriptive functional name (usually 5 characters) */
378  /* Only unrestricted implementations are needed. A benchmark for
379  * a CO molecule with 28 basis function reveals a 4% time difference.
380  * This difference will only decrease for larger systems. */
386 };
387 
388 EXTERN_C void drv1_clear(FunFirstFuncDrv* gga); /* set all components to 0 */
389 EXTERN_C void drv2_clear(FunSecondFuncDrv* gga); /* set all components to 0 */
390 EXTERN_C void drv3_clear(FunThirdFuncDrv* gga); /* set all components to 0 */
391 EXTERN_C void drv4_clear(FunFourthFuncDrv* gga); /* set all components to 0 */
392 
393 /* The list of functionals */
394 /* sorted list of generic functionals */
396 extern Functional KTFunctional;
415 
416 /* sorted list of mixed functionals */
441 
442 /* the list of the functionals */
444 
445 extern int fun_true(void);
446 extern int fun_false(void);
447 /* fortran (and not only) functional stub routines */
448 EXTERN_C void dftlistfuncs_(void);
449 int dft_isgga_(void);
450 int dft_isgga__(void);
451 
452 EXTERN_C void dftreport_(void);
453 EXTERN_C int fun_get_cam_param(real *alpha, real *beta, real *mu);
454 
455 #endif /* _FUNCTIONALS_H_ */