ergo
dft_common.h
Go to the documentation of this file.
1 /* Ergo, version 3.4, a program for linear scaling electronic structure
2  * calculations.
3  * Copyright (C) 2014 Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * Primary academic reference:
19  * Kohn−Sham Density Functional Theory Electronic Structure Calculations
20  * with Linearly Scaling Computational Time and Memory Usage,
21  * Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek,
22  * J. Chem. Theory Comput. 7, 340 (2011),
23  * <http://dx.doi.org/10.1021/ct100611z>
24  *
25  * For further information about Ergo, see <http://www.ergoscf.org>.
26  */
27 
28 #ifndef _DFT_COMMON_H_
29 #define _DFT_COMMON_H_
30 
31 #include <stdlib.h>
32 #include <vector>
33 
34 #ifdef __cplusplus
35 #define EXTERN_C extern "C"
36 #else
37 #define EXTERN_C
38 #endif
39 
40 #include "realtype.h"
41 #include "basisinfo.h"
42 #include "matrix_typedefs.h"
43 #include "functionals.h"
44 #include "grid_atomic.h"
45 
51 typedef struct {
52  real fR; /* d/drho F */
53  real fZ; /* d/zeta F */
54 } FirstDrv;
55 
56 /* SecondDrv: matrix of second order functional derivatives with
57  * respect to two parameters: density rho and SQUARE of the
58  * density gradient zeta. The derivatives are computed for alpha-alpha
59  * or beta-beta spin-orbital block (i.e. include triplet flag).
60  */
61 typedef struct {
62  real fR; /* d/drho F */
63  real fZ; /* d/dzeta F */
64  real fRR; /* d/drho^2 F */
65  real fRZ; /* d/(drho dzeta) F */
66  real fZZ; /* d/dzeta^2 F */
67  /* additional derivatives required by */
68  /* general linear response scheme */
69  real fRG; /* d/(drho dgamma) F */
70  real fZG; /* d/(dzeta dgamma) F */
71  real fGG; /* d/dgamma^2 F */
72  real fG; /* d/dgamma F */
73 } SecondDrv;
74 
75 
76 EXTERN_C void dftpot0_(FirstDrv *ds, const real* weight, const FunDensProp* dp);
77 EXTERN_C void dftpot1_(SecondDrv *ds, const real* w, const FunDensProp* dp,
78  const int* triplet);
79 
80 EXTERN_C void dft_init(void);
81 EXTERN_C int dft_setfunc(const char *line);
82 
83 class ShellTree;
84 
86 class ErgoMolInfo : public GridGenMolInfo {
89  public:
90  ErgoMolInfo(const BasisInfoStruct& bis_, const Molecule& mol);
91  virtual ~ErgoMolInfo();
92 
93  virtual void getAtom(int icent, int *cnt, real (*coor)[3],
94  int *charge, int *mult) const;
95  virtual void setShellRadii(real *shellRadii) const;
96  virtual void getBlocks(const real *center, real cellsz,
97  const real *rshell,
98  int *nblcnt, int (*iblcks)[2]) const;
99  void getBlocks1(const real *center, real cellsz,
100  const real *rshell,
101  int *nblcnt, int (*iblcks)[2]) const;
102  virtual void getExps(int *maxl, int **nucbas, real (**aa)[2]) const;
104 };
105 
106 EXTERN_C void ergoShellsToOrbs(const int *nshlbl, const int (*shlblock)[2],
107  int *norbbl, int (*orbblock)[2],
108  const BasisInfoStruct& bis);
109 
111 EXTERN_C void dft_set_num_threads(int nThreads);
112 
113 
114 EXTERN_C void dft_init(void);
115 
116 #define dal_new(sz,tp) (tp*)dal_malloc_((sz)*sizeof(tp),__FUNCTION__, __LINE__)
117 void* dal_malloc_(size_t sz, const char *func, unsigned line);
118 /* dal_malloc: usage discouraged */
119 #define dal_malloc(sz) dal_malloc_((sz),__FUNCTION__, __LINE__)
120 
121 /* useful constants for BLAS interfacing */
122 extern int ZEROI, ONEI, THREEI, FOURI;
123 extern real ZEROR, ONER, TWOR, FOURR;
124 
128 class Box {
129 public:
130  real getDistanceTo(const real* v) const;
131  int getMaxDim() const;
132  real size(int dim) const { return hi[dim]-lo[dim]; }
133 
134  bool overlapsWith(const real *center, real radius) const {
135  real d = getDistanceTo(center);
136  return d < radius;
137  }
138 
143  bool contains(const real *p) const {
144 #if 0
145  printf("B:(%8.2f %8.2f %8.2f)-(%8.2f %8.2f %8.2f): %8.2f %8.2f %8.2f ",
146  lo[0], lo[1], lo[2], hi[0], hi[1], hi[2],
147  p[0], p[1], p[2]);
148 #endif
149  for(int i=0; i<3; i++)
150  if(p[i]<lo[i] || p[i] >= hi[i]) {
151  //puts("F");
152  return false;
153  }
154  //puts("T");
155  return true;
156  }
157 
158  real lo[3];
159  real hi[3];
160 };
161 
162 template<typename Iterator>
163  void getBoundingBox(Box& box, Iterator start, Iterator end)
164 {
165  static const ergo_real OFF = 0.1;
166  if(start == end)
167  throw "BoundingBox called for empty set";
168 
169  real r = start->radius() + OFF;
170  for(int i=0; i<3; i++) {
171  box.lo[i] = start->center[i]-r;
172  box.hi[i] = start->center[i]+r;
173  }
174 
175  for(++start; start != end; ++start) {
176  real r = start->radius() + OFF;
177  for(int i=0; i<3; i++) {
178  real l = start->center[i]-r; if (l<box.lo[i]) box.lo[i] = l;
179  real h = start->center[i]+r; if (h>box.hi[i]) box.hi[i] = h;
180  }
181  }
182 }
183 
184 
185 int sync_threads(bool release, int nThreads);
186 
187 #endif /* _DFT_COMMON_H_ */
EXTERN_C void dft_set_num_threads(int nThreads)
Definition: dft_common.cc:230
int ZEROI
Definition: dft_common.cc:68
int ONEI
Definition: dft_common.cc:68
double ergo_real
Definition: realtype.h:53
const Molecule & molecule
Definition: dft_common.h:88
real fRG
Definition: dft_common.h:69
virtual ~ErgoMolInfo()
Definition: dft_common.cc:587
Definition: functionals.h:347
bool overlapsWith(const real *center, real radius) const
Definition: dft_common.h:134
A vector of first order derivatives with respect to two parameters: density rho and SQUARE of the gra...
Definition: dft_common.h:51
virtual void getBlocks(const real *center, real cellsz, const real *rshell, int *nblcnt, int(*iblcks)[2]) const
same as ergo_get_shlblocks, except it should scale NlogN.
Definition: dft_common.cc:597
real fZ
Definition: dft_common.h:53
Representation of a molecule as a set of nuclei and total charge.
Definition: molecule.h:76
real fZG
Definition: dft_common.h:70
int THREEI
Definition: dft_common.cc:68
Implements shared parts of the grid generation code.
bool contains(const real *p) const
Determines whether given point is inside the box.
Definition: dft_common.h:143
real fRR
Definition: dft_common.h:64
real fR
Definition: dft_common.h:62
real fGG
Definition: dft_common.h:71
virtual void setShellRadii(real *shellRadii) const
Definition: dft_common.cc:321
real ZEROR
Definition: dft_common.cc:69
ShellTree * shellTree
Definition: dft_common.h:103
real fZ
Definition: dft_common.h:63
Class that allows to find in NLogN time all shells that overlap with a given box. ...
Definition: dft_common.cc:390
int FOURI
Definition: dft_common.cc:68
real TWOR
Definition: dft_common.cc:69
Definition: basisinfo.h:111
ergo_real real
Definition: cubature_rules.h:33
void getBlocks1(const real *center, real cellsz, const real *rshell, int *nblcnt, int(*iblcks)[2]) const
get blocks of active SHELLS in cube of CELLSZ size centered at CENTER.
Definition: dft_common.cc:356
Class Box provides an ability to determine box containing all Objects.
Definition: dft_common.h:128
Header file with typedefs for matrix and vector types.
void getBoundingBox(Box &box, Iterator start, Iterator end)
Definition: dft_common.h:163
EXTERN_C int dft_setfunc(const char *line)
Definition: dft_common.cc:281
GridGenMolInfo is an abstract class providing information about the molecule so that the grid generat...
Definition: grid_interface.h:43
real fR
Definition: dft_common.h:52
ErgoMolInfo(const BasisInfoStruct &bis_, const Molecule &mol)
Ther standard constructor.
Definition: dft_common.cc:577
EXTERN_C void dftpot1_(SecondDrv *ds, const real *w, const FunDensProp *dp, const int *triplet)
Definition: dft_common.cc:780
int charge
Definition: grid_test.cc:49
const BasisInfoStruct & bis
Definition: dft_common.h:87
real size(int dim) const
Definition: dft_common.h:132
EXTERN_C void ergoShellsToOrbs(const int *nshlbl, const int(*shlblock)[2], int *norbbl, int(*orbblock)[2], const BasisInfoStruct &bis)
transform shell block indices to orbital block indices.
Definition: dft_common.cc:712
real hi[3]
Definition: dft_common.h:159
EXTERN_C void dft_init(void)
Definition: dft_common.cc:199
Definition: dft_common.h:61
int sync_threads(bool release, int nThreads)
creates or destroys a barrier for nThreads.
Definition: dft_common.cc:141
Functional library interface.
EXTERN_C int dft_get_num_threads()
Definition: dft_common.cc:207
virtual void getExps(int *maxl, int **nucbas, real(**aa)[2]) const
ergo_get_exps() generates a list of exponents for every center as in mol_info table: number of gaussi...
Definition: dft_common.cc:652
void * dal_malloc_(size_t sz, const char *func, unsigned line)
Definition: dft_common.cc:72
real fZZ
Definition: dft_common.h:66
Ergo specific implementation of molecule-grid interface.
Definition: dft_common.h:86
real ONER
Definition: dft_common.cc:69
real fRZ
Definition: dft_common.h:65
EXTERN_C void dftpot0_(FirstDrv *ds, const real *weight, const FunDensProp *dp)
Definition: dft_common.cc:770
virtual void getAtom(int icent, int *cnt, real(*coor)[3], int *charge, int *mult) const
Return atom data.
Definition: dft_common.cc:309
#define EXTERN_C
Definition: dft_common.h:37
real fG
Definition: dft_common.h:72
real lo[3]
Definition: dft_common.h:158
real FOURR
Definition: dft_common.cc:69