1 /*-*-mode: C; c-indentation-style: "bsd"; c-basic-offset: 4; -*-*/ 2 /* general.h: general definitions needed by C code: 3 function prototypes, often used constants, etc. 4 5 (c) Pawel Salek, pawsa@theochem.kth.se, feb 2002 6 */ 7 #ifndef _GENERAL_H_ 8 #define _GENERAL_H_ 9 10 #include <stdlib.h> 11 12 #if defined(VAR_INT64) 13 #include <stdint.h> 14 typedef int64_t integer; 15 #else 16 typedef int integer; 17 #endif 18 19 #if !defined(M_PI) 20 #define M_PI 3.14159265358979323846 21 #endif 22 23 #if !defined(RESTRICT) 24 #define RESTRICT 25 #endif 26 27 /* define the basic floating-point variable type used by the Fortran code */ 28 29 #if !defined(__CVERSION) 30 #define __CVERSION__ 31 #endif 32 33 #include "functionals.h" 34 35 #include "FSYMdef.h" 36 37 #define ELEMENTS(arr) (sizeof(arr)/sizeof(arr[0])) 38 39 40 41 /* Density evaluators */ 42 typedef struct DftDensity_ DftDensity; 43 typedef struct DftGrid_ DftGrid; 44 45 typedef void (*DftDensEvaluator)(DftDensity* dens, FunDensProp* dp, 46 DftGrid* grid, real* tmp_vec); 47 struct DftDensity_ { 48 DftDensEvaluator evaluate; 49 real *dmata, *dmatb; 50 }; 51 52 /* FirstDrv: matrix of first order derivatives with respect to two 53 * parameters: density rho and SQUARE of the gradient of density grho. 54 * zeta_i = |\nabla\rho_i| 55 * mu = |\nabla\rho_\alpha||\nabla\rho_\beta| 56 */ 57 58 typedef struct { 59 real fR; /* d/drho F */ 60 real fZ; /* d/zeta F */ 61 } FirstDrv; 62 63 /* SecondDrv: matrix of second order functional derivatives with 64 * respect to two parameters: density rho and SQUARE of the 65 * density gradient zeta. The derivatives are computed for alpha-alpha 66 * or beta-beta spin-orbital block (i.e. include triplet flag). 67 */ 68 typedef struct { 69 real fR; /* d/drho F */ 70 real fZ; /* d/dzeta F */ 71 real fRR; /* d/drho^2 F */ 72 real fRZ; /* d/(drho dzeta) F */ 73 real fZZ; /* d/dzeta^2 F */ 74 /* additional derivatives required by */ 75 /* general linear response scheme */ 76 real fRG; /* d/(drho dgamma) F */ 77 real fZG; /* d/(dzeta dgamma) F */ 78 real fGG; /* d/dzgamma^2 F */ 79 real fG; /* d/dgamma F */ 80 } SecondDrv; 81 82 /* ThirdDrv: matrix of third derivatives with respect to two parameters: 83 density rho and SQUARE of the density gradient zeta. 84 */ 85 typedef struct { 86 real fR; /* d/drho F */ 87 real fZ; /* d/dzeta F */ 88 real fG; /* d/dgamma F */ 89 real fRR[2]; /* d/drho^2 F */ 90 real fRZ[2]; /* d/(drho dzeta) F */ 91 real fZZ[2]; /* d/dzeta^2 F */ 92 real fRG[2]; /* d/(drho dgamma) F */ 93 real fRRR[2]; /* d/drho^2 F */ 94 real fRRZ[2][2]; /* d/(drho^2 dzeta) F */ 95 /* two forms of fRRG needed as the formulae is non symmetric */ 96 real fRRG[2]; /* d/(drho^2 dgamma) F */ 97 real fRRGX[2][2]; /* d/(drho^2 dgamma) F */ 98 real fRZZ[2][2]; /* d/(drho dzeta^2 F */ 99 real fZZZ[2]; /* d/dzeta^3 F */ 100 } ThirdDrv; 101 102 103 typedef struct { 104 real fR; /* d/drho F */ 105 real fZ; /* d/dzeta F */ 106 107 real fRR; /* d/drho^2 F */ 108 real fRZ; /* d/(drho dzeta) F */ 109 real fZZ; /* d/dzeta^2 F */ 110 111 real fRRR; /* d/drho^3 F */ 112 real fRRZ; /* d/(drho^2 dzeta) F */ 113 real fRZZ; /* d/(drho dzeta^2 F */ 114 real fZZZ; 115 116 real fRRRR; 117 real fRRRZ; 118 real fRRZZ; 119 real fRZZZ; 120 real fZZZZ; 121 } FourthDrv; 122 123 void dftpot0_(FirstDrv *ds, const real* weight, const FunDensProp* dp); 124 void dftpot1_(SecondDrv *ds, const real* w, const FunDensProp* dp, 125 const integer* triplet); 126 void dftpot2_(ThirdDrv *ds, real factor, const FunDensProp* dp, integer isgga, 127 integer triplet); 128 void dftpot3ab_(FourthDrv *ds, const real *factor, const FunDensProp* dp, 129 const integer *isgga); 130 131 132 void dft_dens_restricted (DftDensity* dens, FunDensProp* dp, DftGrid* grid, 133 real* tmp_vec); 134 void dft_dens_unrestricted(DftDensity* dens, FunDensProp* dp, DftGrid* grid, 135 real* tmp_vec); 136 extern void 137 FSYM2(getexp_blocked_lda)(const integer *idsym, real*dmat, const real* atv, 138 const integer *nblocks, integer (*orbblocks)[2], 139 const integer *lda, 140 real *tmp, const integer * bllen, real *rho); 141 142 extern void 143 FSYM2(getexp_blocked_gga)(const integer *idsym, real*dmat, const real* atv, 144 const integer *nblocks, integer (*orbblocks)[2], 145 const integer *lda, 146 real *tmp, const integer * bllen, real (*grad)[4]); 147 148 149 150 /* Property evaluators */ 151 void dft_lin_resp_(real* fmat, real *cmo, real *zymat, integer *trplet, 152 integer *ksymop, real* work, integer* lwork, integer* iprint); 153 void FSYM2(dft_lin_respf)(integer *nosim, real* fmat, real *cmo, real *zymat, 154 integer *trplet, integer *ksymop, real* work, 155 integer* lwork, integer* iprint); 156 void dft_mol_grad_(real* dmat, real* work, integer* lwork, integer* iprint); 157 void dftqrcf_(real* fi, real* cmo, real* kappaY, integer* symY, integer* spinY, 158 real* kappaZ, integer* symZ, integer* spinZ, integer* addfock, 159 real* work, integer* lwork, integer* iprint); 160 void FSYM2(dft_qr_respons)(real* fi, real* cmo, 161 real* kappaY, integer* symY, integer* spinY, 162 real* kappaZ, integer* symZ, integer* spinZ, 163 integer* addfock, real* work, integer* lwork, integer* iprint); 164 void FSYM(dftcrcf)(real* fi, real* cmo, 165 real* kappaB, integer* symB, 166 real* kappaC, integer* symC, 167 real* kappaD, integer* symD, 168 real* work, integer* lwork, integer* iprint); 169 void FSYM(numdso) (real* spndso, integer *nucind, 170 real* work, integer* lwork, integer* iprint); 171 172 173 void FSYM2(dft_kohn_shamab) (real* dmat, real* ksm, real *edfty, 174 real* work, integer *lwork, integer* iprint); 175 void FSYM2(dft_lin_respab) (real* fmatc, real* fmato, real *cmo, real *zymat, 176 integer *trplet, integer *ksymop, 177 real* work, integer* lwork, integer* iprint); 178 void FSYM(dftmolgradab) (real* work, integer* lwork, integer* iprint); 179 void FSYM2(dft_kohn_shamab_b)(real* dmat, real* ksm, real *edfty, 180 real* work, integer *lwork, integer* iprint); 181 void FSYM2(dft_lin_respab_b) (integer *nosim, real* fmatc, real* fmato, real *cmo, 182 real *zymat, integer *trplet, integer *ksymop, 183 real* work, integer* lwork, integer* iprint); 184 185 typedef void (*DFTPropEvalMaster)(void); 186 typedef void (*DFTPropEvalSlave)(real* work, integer* lwork, integer* iprint); 187 #if defined(VAR_MPI) 188 #include <mpi.h> 189 void dft_kohn_sham_slave (real* work, integer* lwork, integer* iprint); 190 void dft_lin_resp_slave (real* work, integer* lwork, integer* iprint); 191 void dft_lin_respf_slave (real* work, integer* lwork, integer* iprint); 192 void dft_kohn_shamab_slave (real* work, integer* lwork, integer* iprint); 193 void dft_lin_respab_slave (real* work, integer* lwork, integer* iprint); 194 195 void dft_mol_grad_slave (real* work, integer* lwork, integer* iprint); 196 void dft_qr_resp_slave (real* work, integer* lwork, integer* iprint); 197 void dft_cr_resp_slave (real* work, integer* lwork, integer* iprint); 198 void dft_qrbl_slave (real* work, integer* lwork, integer* iprint); 199 void numdso_slave (real* work, integer* lwork, integer* iprint); 200 void dft_kohn_shamab_b_slave(real* work, integer* lwork, integer* iprint); 201 void dft_lin_respab_b_slave (real* work, integer* lwork, integer* iprint); 202 void dft_wake_slaves(DFTPropEvalMaster); 203 typedef struct { 204 void* data; 205 integer count; 206 MPI_Datatype type; 207 } SyncData; 208 void mpi_sync_data(const SyncData* data, integer count); 209 #else 210 #define dft_wake_slaves(a) 211 #endif 212 213 void* dal_malloc_(size_t sz, const char *func, unsigned line); 214 #define dal_malloc(sz) dal_malloc_((sz),__FUNCTION__, __LINE__) 215 #define dal_new(sz,tp) (tp*)dal_malloc_((sz)*sizeof(tp),__FUNCTION__, __LINE__) 216 217 integer fort_print(const char* format, ...); 218 /* FORTRAN FUNCTION PROTOTYPES */ 219 void FSYM(dzero) (real* arr, const integer* len); 220 void FSYM(dunit) (real* arr, const integer* len); 221 void FSYM(outmat)(const real* mat, const integer* rowlow, const integer* rowhi, 222 const integer* collow, const integer* colhi, 223 const integer* rowdim, const integer* coldim); 224 void FSYM(getrho)(const real*dmat, const real* atv, real* rho, real* dmagao, 225 const real* densthr); 226 void FSYM(make_dftgrid)(real* work, integer* lwork, const integer* d1, const integer* log1); 227 void FSYM(dftdns)(real* dmat, real* work, integer *lwork, const integer* iprint); 228 void FSYM(gtdmso)(real* udv, real* cmo, real* di, real* dv, real* work); 229 void FSYM(dftdnsab)(real* dmata,real* dmatb, real* work, 230 integer* lwork, integer* iprint); 231 void udftmolgrdab_(real* gao, real* damta, real* dmatb, real* rha, real* rhb, 232 real* vra, real* vrb, real* vza, real* vzb, real* vzg); 233 integer FSYM2(ishell_cnt)(void); 234 void dalton_quit(const char* format, ...); 235 236 /* BLAS and other linear algebra routines */ 237 real dsum_(const integer* cnt, const real* v, const integer* stride); 238 void dscal_(const integer* cnt, const real* fac, real* v, const integer* stride); 239 real dnorm2_(const integer* cnt, const real* v, const integer* stride); 240 real ddot_(const integer* cnt, const real* v1, const integer* stride1, 241 const real* v2, const integer* stride2); 242 real dcopy_(const integer* cnt, const real* v1, const integer* stride1, 243 const real* v2, const integer* stride2); 244 void daxpy_(const integer* cnt, const real* alpha, const real* v1, 245 const integer* stride1, const real* v2, const integer* stride2); 246 247 void dger_(const integer* m, const integer* n, const real* alpha, 248 const real* x, const integer* incx, const real* y, const integer* incy, 249 real* a, const integer* lda); 250 251 void dgemv_(const char* tr, const integer* nrows, const integer* ncols, 252 const real* alpha, const real* a, const integer* lda, 253 const real* vb, const integer* strideb, const real* beta, 254 real* c, const integer* stridec); 255 256 void dgemm_(const char* transa, const char* transb, const integer* nrowc, 257 const integer* ncolc, const integer* ncolopa, const real* alpha, 258 const real* a, const integer* lda, const real* b, const integer* ldb, 259 const real* beta, real* c, const integer* ldc); 260 261 real* alloc_mat_MO(integer cnt); 262 263 void FSYM2(dft_get_ao_dens_mat)(const real* cmo, real* dmat, 264 real* work, integer* lwork); 265 void FSYM2(dft_get_ao_dens_matab)(real* cmo, real* dmata, real* dmatb, 266 real* work, integer* lwork); 267 void FSYM(lrao2mo)(const real* cmo, const integer *ksymop, 268 const real*res, real* fmat, real* work, integer*lw); 269 270 /* useful constants for fortran interfacing */ 271 extern const integer ZEROI, ONEI, THREEI, FOURI; 272 extern const real ZEROR, ONER, TWOR, FOURR; 273 274 #if !defined __inline__ 275 /* inline some stuff whenever possible */ 276 #define __inline__ 277 #endif 278 #define CHECK_WRKMEM(req,lwork)\ 279 if((req)>(lwork)){dalton_quit("%s requires %u words but only %u available\n",\ 280 __FUNCTION__, (unsigned)(req), (unsigned)(lwork));} 281 282 #endif 283 284 /*strdup() replacement*/ 285 char *StringDuplicate(const char *s1); 286