dft_common.h

Go to the documentation of this file.
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 #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;  /* d/drho F     */
00053     real fZ;  /* d/zeta F     */
00054 } FirstDrv;
00055 
00056 /* SecondDrv:  matrix  of  second  order functional  derivatives  with
00057  * respect  to two  parameters: density  rho and  SQUARE  of the
00058  * density gradient zeta.  The derivatives are computed for alpha-alpha
00059  * or beta-beta spin-orbital block (i.e. include triplet flag).
00060  */
00061 typedef struct {
00062     real fR; /* d/drho  F */
00063     real fZ; /* d/dzeta F */
00064     real fRR; /* d/drho^2 F */
00065     real fRZ; /* d/(drho dzeta) F */
00066     real fZZ; /* d/dzeta^2 F */
00067     /* additional derivatives required by  */
00068     /* general linear response scheme     */
00069     real fRG; /* d/(drho dgamma) F */
00070     real fZG; /* d/(dzeta dgamma) F */
00071     real fGG; /* d/dgamma^2 F */
00072     real fG;  /* d/dgamma F */
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 /* dal_malloc: usage discouraged */
00119 #define dal_malloc(sz) dal_malloc_((sz),__FUNCTION__, __LINE__)
00120 
00121 /* useful  constants for BLAS interfacing */
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         //puts("F");
00152         return false;
00153       }
00154     //puts("T");
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 /* _DFT_COMMON_H_ */

Generated on Mon Sep 17 14:32:55 2012 for ergo by  doxygen 1.4.7