00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00037 #ifndef _DFT_COMMON_H_
00038 #define _DFT_COMMON_H_
00039
00040 #include <stdlib.h>
00041 #include <vector>
00042
00043 #ifdef __cplusplus
00044 #define EXTERN_C extern "C"
00045 #else
00046 #define EXTERN_C
00047 #endif
00048
00049 #include "realtype.h"
00050 #include "basisinfo.h"
00051 #include "matrix_typedefs.h"
00052 #include "functionals.h"
00053 #include "grid_atomic.h"
00054
00060 typedef struct {
00061 real fR;
00062 real fZ;
00063 } FirstDrv;
00064
00065
00066
00067
00068
00069
00070 typedef struct {
00071 real fR;
00072 real fZ;
00073 real fRR;
00074 real fRZ;
00075 real fZZ;
00076
00077
00078 real fRG;
00079 real fZG;
00080 real fGG;
00081 real fG;
00082 } SecondDrv;
00083
00084
00085 EXTERN_C void dftpot0_(FirstDrv *ds, const real* weight, const FunDensProp* dp);
00086 EXTERN_C void dftpot1_(SecondDrv *ds, const real* w, const FunDensProp* dp,
00087 const int* triplet);
00088
00089 EXTERN_C void dft_init(void);
00090 EXTERN_C int dft_setfunc(const char *line);
00091
00092 class ShellTree;
00093
00095 class ErgoMolInfo : public GridGenMolInfo {
00096 const BasisInfoStruct& bis;
00097 const Molecule& molecule;
00098 public:
00099 ErgoMolInfo(const BasisInfoStruct& bis_, const Molecule& mol);
00100 virtual ~ErgoMolInfo();
00101
00102 virtual void getAtom(int icent, int *cnt, real (*coor)[3],
00103 int *charge, int *mult) const;
00104 virtual void setShellRadii(real *shellRadii) const;
00105 virtual void getBlocks(const real *center, real cellsz,
00106 const real *rshell,
00107 int *nblcnt, int (*iblcks)[2]) const;
00108 void getBlocks1(const real *center, real cellsz,
00109 const real *rshell,
00110 int *nblcnt, int (*iblcks)[2]) const;
00111 virtual void getExps(int *maxl, int **nucbas, real (**aa)[2]) const;
00112 ShellTree *shellTree;
00113 };
00114
00115 EXTERN_C void ergoShellsToOrbs(const int *nshlbl, const int (*shlblock)[2],
00116 int *norbbl, int (*orbblock)[2],
00117 const BasisInfoStruct& bis);
00118
00119 EXTERN_C int dft_get_num_threads();
00120 EXTERN_C void dft_set_num_threads(int nThreads);
00121
00122
00123 EXTERN_C void dft_init(void);
00124
00125 #define dal_new(sz,tp) (tp*)dal_malloc_((sz)*sizeof(tp),__FUNCTION__, __LINE__)
00126 void* dal_malloc_(size_t sz, const char *func, unsigned line);
00127
00128 #define dal_malloc(sz) dal_malloc_((sz),__FUNCTION__, __LINE__)
00129
00130
00131 extern int ZEROI, ONEI, THREEI, FOURI;
00132 extern real ZEROR, ONER, TWOR, FOURR;
00133
00137 class Box {
00138 public:
00139 real getDistanceTo(const real* v) const;
00140 int getMaxDim() const;
00141 real size(int dim) const { return hi[dim]-lo[dim]; }
00142
00143 bool overlapsWith(const real *center, real radius) const {
00144 real d = getDistanceTo(center);
00145 return d < radius;
00146 }
00147
00152 bool contains(const real *p) const {
00153 #if 0
00154 printf("B:(%8.2f %8.2f %8.2f)-(%8.2f %8.2f %8.2f): %8.2f %8.2f %8.2f ",
00155 lo[0], lo[1], lo[2], hi[0], hi[1], hi[2],
00156 p[0], p[1], p[2]);
00157 #endif
00158 for(int i=0; i<3; i++)
00159 if(p[i]<lo[i] || p[i] >= hi[i]) {
00160
00161 return false;
00162 }
00163
00164 return true;
00165 }
00166
00167 real lo[3];
00168 real hi[3];
00169 };
00170
00171 template<typename Iterator>
00172 void getBoundingBox(Box& box, Iterator start, Iterator end)
00173 {
00174 static const ergo_real OFF = 0.1;
00175 if(start == end)
00176 throw "BoundingBox called for empty set";
00177
00178 real r = start->radius() + OFF;
00179 for(int i=0; i<3; i++) {
00180 box.lo[i] = start->center[i]-r;
00181 box.hi[i] = start->center[i]+r;
00182 }
00183
00184 for(++start; start != end; ++start) {
00185 real r = start->radius() + OFF;
00186 for(int i=0; i<3; i++) {
00187 real l = start->center[i]-r; if (l<box.lo[i]) box.lo[i] = l;
00188 real h = start->center[i]+r; if (h>box.hi[i]) box.hi[i] = h;
00189 }
00190 }
00191 }
00192
00193
00194 int sync_threads(bool release, int nThreads);
00195
00196 #endif