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