ergo
|
00001 /* Ergo, version 3.2, a program for linear scaling electronic structure 00002 * calculations. 00003 * Copyright (C) 2012 Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek. 00004 * 00005 * This program is free software: you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation, either version 3 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 * 00018 * Primary academic reference: 00019 * KohnâSham Density Functional Theory Electronic Structure Calculations 00020 * with Linearly Scaling Computational Time and Memory Usage, 00021 * Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek, 00022 * J. Chem. Theory Comput. 7, 340 (2011), 00023 * <http://dx.doi.org/10.1021/ct100611z> 00024 * 00025 * For further information about Ergo, see <http://www.ergoscf.org>. 00026 */ 00027 00028 /*-*-mode: C; c-indentation-style: "bsd"; c-basic-offset: 4; -*-*/ 00042 #ifndef _FUNCTIONALS_H_ 00043 #define _FUNCTIONALS_H_ 00044 00045 #include "realtype.h" 00046 00047 #ifdef __cplusplus 00048 #define EXTERN_C extern "C" 00049 #else 00050 #define EXTERN_C 00051 #endif 00052 00053 typedef ergo_real real; 00054 00055 #if defined(FUNC_PRECISION) && FUNC_PRECISION == 1 00056 #define ASINH asinhf 00057 #define ATAN atanf 00058 #define ERF erff 00059 #define EXP expf 00060 #define FABS fabsf 00061 #define LOG logf 00062 #define POW powf 00063 #define SQRT sqrtf 00064 #elif defined(FUNC_PRECISION) && FUNC_PRECISION == 2 00065 #define ASINH asinh 00066 #define ATAN atan 00067 #define ERF erf 00068 #define EXP exp 00069 #define FABS fabs 00070 #define LOG log 00071 #define POW pow 00072 #define SQRT sqrt 00073 #else 00074 #define ASINH asinhl 00075 #define ATAN atanl 00076 #define ERF erfl 00077 #define EXP expl 00078 #define FABS fabsl 00079 #define LOG logl 00080 #define POW powl 00081 #define SQRT sqrtl 00082 /* FIXME! */ 00083 /* #define _XOPEN_SOURCE 600 */ 00084 #endif 00085 00086 /* FirstDrv: matrix of first order derivatives with respect to two 00087 * parameters: density rho and SQUARE of the gradient of density grho. 00088 * zeta_i = |\nabla\rho_i|˛ 00089 * mu = |\nabla\rho_\alpha||\nabla\rho_\beta| 00090 */ 00091 typedef struct { 00092 real df1000; /* d/drho F */ 00093 real df0100; 00094 real df0010; /* d/zeta F */ 00095 real df0001; 00096 real df00001; 00097 } FunFirstFuncDrv; 00098 00099 /* SecondFuncDrv: this structure is used by functional derivative 00100 * evaluation procedures. Do not include "triplet" transformation. 00101 */ 00102 typedef struct { 00103 real df1000; /* d/drho_alpha F */ 00104 real df0100; /* d/drho_beta F */ 00105 real df0010; /* d/|zeta_alpha| F */ 00106 real df0001; /* d/|zeta_beta| F */ 00107 real df00001; 00108 real df2000; /* d/drho_alpha^2 F */ 00109 real df1100; /* d/(drho_alpha drho_beta) F */ 00110 real df1010; /* d/drho_alpha d/dzeta_alpha F */ 00111 real df1001; /* d/drho_alpha d/dzeta_beta F */ 00112 real df10001; 00113 real df0200; /* d/drho_beta^2 F */ 00114 real df0110; /* d/drho_beta d/dzeta_alpha F */ 00115 real df0101; /* d/drho_beta d/dzeta_beta F */ 00116 real df01001; 00117 real df0020; /* d/dzeta_alpha^2 F */ 00118 real df0011; /* d2/dzeta_a zeta_b F */ 00119 real df00101; 00120 real df0002; /* d/dzeta_beta^2 F */ 00121 real df00011; 00122 real df00002; 00123 } FunSecondFuncDrv; 00124 00125 00126 /* ThirdFuncDrv: matrix of third derivatives with respect to five 00127 parameters: density rho_alpha and SQUARE of the density gradient 00128 zeta. and mu. 00129 */ 00130 00131 typedef struct { 00132 real df1000; /* d/drho F */ 00133 real df0100; 00134 real df0010; /* d/|zeta| F */ 00135 real df0001; 00136 real df00001; 00137 00138 real df2000; /* d/drho_alpha^2 F */ 00139 real df1100; /* d/(drho_alpha drho_beta) F */ 00140 real df1010; /* d/drho_alpha d/dzeta_alpha F */ 00141 real df1001; /* d/drho_alpha d/dzeta_beta F */ 00142 real df10001; 00143 real df0200; /* d/drho_beta^2 F */ 00144 real df0110; /* d/drho_beta d/dzeta_alpha F */ 00145 real df0101; /* d/drho_beta d/dzeta_beta F */ 00146 real df01001; 00147 real df0020; /* d/dzeta_alpha^2 F */ 00148 real df0011; /* d2/dzeta_a zeta_b F */ 00149 real df00101; 00150 real df0002; /* d/dzeta_beta^2 F */ 00151 real df00011; 00152 real df00002; 00153 00154 real df3000; 00155 real df2100; 00156 real df2010; 00157 real df2001; 00158 real df20001; 00159 real df1200; 00160 real df1110; 00161 real df1101; 00162 real df11001; 00163 real df1020; 00164 real df1011; 00165 real df10101; 00166 real df1002; 00167 real df10011; 00168 real df10002; 00169 real df0300; 00170 real df0210; 00171 real df0201; 00172 real df02001; 00173 real df0120; 00174 real df0111; 00175 real df01101; 00176 real df0102; 00177 real df01011; 00178 real df01002; 00179 real df0030; 00180 real df0021; 00181 real df00201; 00182 real df0012; 00183 real df00111; 00184 real df00102; 00185 real df0003; 00186 real df00021; 00187 real df00012; 00188 real df00003; 00189 } FunThirdFuncDrv; 00190 00191 00192 typedef struct { 00193 00194 /* First order derivatives with respect to all 5 variables */ 00195 00196 real df1000; 00197 real df0100; 00198 real df0010; 00199 real df0001; 00200 real df00001; 00201 00202 /* Second order mixed derivatives with respect to all 5 variables */ 00203 00204 real df2000; 00205 real df1100; 00206 real df1010; 00207 real df1001; 00208 real df10001; 00209 real df0200; 00210 real df0110; 00211 real df0101; 00212 real df01001; 00213 real df0020; 00214 real df0011; 00215 real df00101; 00216 real df0002; 00217 real df00011; 00218 real df00002; 00219 00220 /* Third order mixed derivatives with respect to all 5 variables */ 00221 00222 real df3000; 00223 real df2100; 00224 real df2010; 00225 real df2001; 00226 real df20001; 00227 real df1200; 00228 real df1110; 00229 real df1101; 00230 real df11001; 00231 real df1020; 00232 real df1011; 00233 real df10101; 00234 real df1002; 00235 real df10011; 00236 real df10002; 00237 real df0300; 00238 real df0210; 00239 real df0201; 00240 real df02001; 00241 real df0120; 00242 real df0111; 00243 real df01101; 00244 real df0102; 00245 real df01011; 00246 real df01002; 00247 real df0030; 00248 real df0021; 00249 real df00201; 00250 real df0012; 00251 real df00111; 00252 real df00102; 00253 real df0003; 00254 real df00021; 00255 real df00012; 00256 real df00003; 00257 00258 /* Fourth order mixed derivatives with respect to all 5 variables */ 00259 00260 real df4000; 00261 real df3100; 00262 real df3010; 00263 real df3001; 00264 real df30001; 00265 real df2200; 00266 real df2110; 00267 real df2101; 00268 real df21001; 00269 real df2020; 00270 real df2011; 00271 real df20101; 00272 real df2002; 00273 real df20011; 00274 real df20002; 00275 real df1300; 00276 real df1210; 00277 real df1201; 00278 real df12001; 00279 real df1120; 00280 real df1111; 00281 real df11101; 00282 real df1102; 00283 real df11011; 00284 real df11002; 00285 real df1030; 00286 real df1021; 00287 real df10201; 00288 real df1012; 00289 real df10111; 00290 real df10102; 00291 real df1003; 00292 real df10021; 00293 real df10012; 00294 real df10003; 00295 real df0400; 00296 real df0310; 00297 real df0301; 00298 real df03001; 00299 real df0220; 00300 real df0211; 00301 real df02101; 00302 real df0202; 00303 real df02011; 00304 real df02002; 00305 real df0130; 00306 real df0121; 00307 real df01201; 00308 real df0112; 00309 real df01111; 00310 real df01102; 00311 real df0103; 00312 real df01021; 00313 real df01012; 00314 real df01003; 00315 real df0040; 00316 real df0031; 00317 real df00301; 00318 real df0022; 00319 real df00211; 00320 real df00202; 00321 real df0013; 00322 real df00121; 00323 real df00112; 00324 real df00103; 00325 real df0004; 00326 real df00031; 00327 real df00022; 00328 real df00013; 00329 real df00004; 00330 } FunFourthFuncDrv; 00331 00332 00333 typedef struct Functional_ Functional; 00334 00335 enum FunError { FUN_OK, FUN_UNKNOWN, FUN_CONF_ERROR }; 00336 EXTERN_C enum FunError fun_select_by_name(const char *conf_string); 00337 extern Functional *selected_func; 00338 extern int (*fun_printf)(const char *fmt, ...); 00339 extern void (*fun_set_hf_weight)(real w); 00340 extern real (*fun_get_hf_weight)(void); 00341 extern void (*fun_set_cam_param)(real w, real b); 00342 int dft_get_cam_param(real *alpha, real *beta, real *mu); 00343 00344 /* FunDensProp structure contains properties of the density that are 00345 needed for functional evaluation and possibly other purposes. 00346 */ 00347 typedef struct FunDensProp_ { 00348 real rhoa, rhob; 00349 real grada, gradb; /* norms of the density gradient, not squares */ 00350 real gradab; /* scalar product of grada and gradb */ 00351 /* real current[3] or something may come in the future :-) */ 00352 } FunDensProp; 00353 00354 /* EnergyFunc: the function returning the energy for given densities 00355 and gradients. Note that some functionals(like LYP) depend explicitely 00356 on separately alpha and beta densities 00357 */ 00358 typedef int (*IsGGAFunc)(void); 00359 typedef int (*ReadInputFunc)(const char* conf_string); 00360 typedef void (*ReportFunc)(void); 00361 typedef real (*EnergyFunc)(const FunDensProp* dens_prop); 00362 typedef void (*FirstOrderFun)(FunFirstFuncDrv *ds, real factor, 00363 const FunDensProp* dns_prp); 00364 00365 typedef void (*SecondOrderFun)(FunSecondFuncDrv *ds, real factor, 00366 const FunDensProp* dens_prop); 00367 00368 typedef void (*ThirdOrderFun)(FunThirdFuncDrv *ds, real factor, 00369 const FunDensProp* dens_prop); 00370 typedef void (*FourthOrderFun)(FunFourthFuncDrv *ds, real factor, 00371 const FunDensProp *dens_prop); 00372 00373 struct Functional_ { 00374 const char* name; /* descriptive functional name (usually 5 characters) */ 00375 IsGGAFunc is_gga; 00376 ReadInputFunc read; 00377 ReportFunc report; 00378 /* Only unrestricted implementations are needed. A benchmark for 00379 * a CO molecule with 28 basis function reveals a 4% time difference. 00380 * This difference will only decrease for larger systems. */ 00381 EnergyFunc func; 00382 FirstOrderFun first; 00383 SecondOrderFun second; 00384 ThirdOrderFun third; 00385 FourthOrderFun fourth; 00386 }; 00387 00388 EXTERN_C void drv1_clear(FunFirstFuncDrv* gga); /* set all components to 0 */ 00389 EXTERN_C void drv2_clear(FunSecondFuncDrv* gga); /* set all components to 0 */ 00390 EXTERN_C void drv3_clear(FunThirdFuncDrv* gga); /* set all components to 0 */ 00391 EXTERN_C void drv4_clear(FunFourthFuncDrv* gga); /* set all components to 0 */ 00392 00393 /* The list of functionals */ 00394 /* sorted list of generic functionals */ 00395 extern Functional BeckeFunctional; 00396 extern Functional KTFunctional; 00397 extern Functional LB94Functional; 00398 extern Functional LYPFunctional; 00399 extern Functional OPTXFunctional; 00400 extern Functional P86cFunctional; 00401 extern Functional PW86xFunctional; 00402 extern Functional Pw91xFunctional; 00403 extern Functional Pw91cFunctional; 00404 extern Functional PW92cFunctional; 00405 extern Functional PZ81Functional; 00406 extern Functional PbecFunctional; 00407 extern Functional PbexFunctional; 00408 extern Functional SlaterFunctional; 00409 extern Functional VWN3Functional; 00410 extern Functional VWN5Functional; 00411 extern Functional VWNIFunctional; 00412 extern Functional VWN3IFunctional; 00413 extern Functional VWNFunctional; 00414 extern Functional XAlphaFunctional; 00415 00416 /* sorted list of mixed functionals */ 00417 extern Functional B3LYPFunctional; 00418 extern Functional B3LYPGaussFunctional; 00419 extern Functional B3P86Functional; 00420 extern Functional B3P86GFunctional; 00421 extern Functional B3PW91Functional; 00422 extern Functional BHandHFunctional; 00423 extern Functional BHandHLYPFunctional; 00424 extern Functional BLYPFunctional; 00425 extern Functional BP86Functional; 00426 extern Functional BPW91Functional; 00427 extern Functional Camb3lypFunctional; 00428 extern Functional CamFunctional; 00429 extern Functional CombineFunctional; 00430 extern Functional GGAKeyFunctional; 00431 extern Functional HseFunctional; 00432 extern Functional KT1Functional; 00433 extern Functional KT2Functional; 00434 extern Functional KT3Functional; 00435 extern Functional LDAFunctional; 00436 extern Functional OLYPFunctional; 00437 extern Functional PBE0Functional; 00438 extern Functional PBEFunctional; 00439 extern Functional SVWN3Functional; 00440 extern Functional SVWN5Functional; 00441 00442 /* the list of the functionals */ 00443 extern Functional* available_functionals[]; 00444 00445 extern int fun_true(void); 00446 extern int fun_false(void); 00447 /* fortran (and not only) functional stub routines */ 00448 EXTERN_C void dftlistfuncs_(void); 00449 int dft_isgga_(void); 00450 int dft_isgga__(void); 00451 00452 EXTERN_C void dftreport_(void); 00453 EXTERN_C int fun_get_cam_param(real *alpha, real *beta, real *mu); 00454 00455 #endif /* _FUNCTIONALS_H_ */