ergo
dft_common.h
Go to the documentation of this file.
1 /* Ergo, version 3.7, a program for linear scaling electronic structure
2  * calculations.
3  * Copyright (C) 2018 Elias Rudberg, Emanuel H. Rubensson, Pawel Salek,
4  * and Anastasia Kruchinina.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * Primary academic reference:
20  * Ergo: An open-source program for linear-scaling electronic structure
21  * calculations,
22  * Elias Rudberg, Emanuel H. Rubensson, Pawel Salek, and Anastasia
23  * Kruchinina,
24  * SoftwareX 7, 107 (2018),
25  * <http://dx.doi.org/10.1016/j.softx.2018.03.005>
26  *
27  * For further information about Ergo, see <http://www.ergoscf.org>.
28  */
29 
37 #ifndef _DFT_COMMON_H_
38 #define _DFT_COMMON_H_
39 
40 #include <stdlib.h>
41 #include <vector>
42 
43 #ifdef __cplusplus
44 #define EXTERN_C extern "C"
45 #else
46 #define EXTERN_C
47 #endif
48 
49 #include "realtype.h"
50 #include "basisinfo.h"
51 #include "matrix_typedefs.h"
52 #include "functionals.h"
53 #include "grid_atomic.h"
54 
60 typedef struct {
61  real fR; /* d/drho F */
62  real fZ; /* d/zeta F */
63 } FirstDrv;
64 
65 /* SecondDrv: matrix of second order functional derivatives with
66  * respect to two parameters: density rho and SQUARE of the
67  * density gradient zeta. The derivatives are computed for alpha-alpha
68  * or beta-beta spin-orbital block (i.e. include triplet flag).
69  */
70 typedef struct {
71  real fR; /* d/drho F */
72  real fZ; /* d/dzeta F */
73  real fRR; /* d/drho^2 F */
74  real fRZ; /* d/(drho dzeta) F */
75  real fZZ; /* d/dzeta^2 F */
76  /* additional derivatives required by */
77  /* general linear response scheme */
78  real fRG; /* d/(drho dgamma) F */
79  real fZG; /* d/(dzeta dgamma) F */
80  real fGG; /* d/dgamma^2 F */
81  real fG; /* d/dgamma F */
82 } SecondDrv;
83 
84 
85 EXTERN_C void dftpot0_(FirstDrv *ds, const real* weight, const FunDensProp* dp);
86 EXTERN_C void dftpot1_(SecondDrv *ds, const real* w, const FunDensProp* dp,
87  const int* triplet);
88 
89 EXTERN_C void dft_init(void);
90 EXTERN_C int dft_setfunc(const char *line);
91 
92 class ShellTree;
93 
95 class ErgoMolInfo : public GridGenMolInfo {
98  public:
99  ErgoMolInfo(const BasisInfoStruct& bis_, const Molecule& mol);
100  virtual ~ErgoMolInfo();
101 
102  virtual void getAtom(int icent, int *cnt, real (*coor)[3],
103  int *charge, int *mult) const;
104  virtual void setShellRadii(real *shellRadii) const;
105  virtual void getBlocks(const real *center, real cellsz,
106  const real *rshell,
107  int *nblcnt, int (*iblcks)[2]) const;
108  void getBlocks1(const real *center, real cellsz,
109  const real *rshell,
110  int *nblcnt, int (*iblcks)[2]) const;
111  virtual void getExps(int *maxl, int **nucbas, real (**aa)[2]) const;
113 };
114 
115 EXTERN_C void ergoShellsToOrbs(const int *nshlbl, const int (*shlblock)[2],
116  int *norbbl, int (*orbblock)[2],
117  const BasisInfoStruct& bis);
118 
120 EXTERN_C void dft_set_num_threads(int nThreads);
121 
122 
123 EXTERN_C void dft_init(void);
124 
125 #define dal_new(sz,tp) (tp*)dal_malloc_((sz)*sizeof(tp),__FUNCTION__, __LINE__)
126 void* dal_malloc_(size_t sz, const char *func, unsigned line);
127 /* dal_malloc: usage discouraged */
128 #define dal_malloc(sz) dal_malloc_((sz),__FUNCTION__, __LINE__)
129 
130 /* useful constants for BLAS interfacing */
131 extern int ZEROI, ONEI, THREEI, FOURI;
132 extern real ZEROR, ONER, TWOR, FOURR;
133 
137 class Box {
138 public:
139  real getDistanceTo(const real* v) const;
140  int getMaxDim() const;
141  real size(int dim) const { return hi[dim]-lo[dim]; }
142 
143  bool overlapsWith(const real *center, real radius) const {
144  real d = getDistanceTo(center);
145  return d < radius;
146  }
147 
152  bool contains(const real *p) const {
153 #if 0
154  printf("B:(%8.2f %8.2f %8.2f)-(%8.2f %8.2f %8.2f): %8.2f %8.2f %8.2f ",
155  lo[0], lo[1], lo[2], hi[0], hi[1], hi[2],
156  p[0], p[1], p[2]);
157 #endif
158  for(int i=0; i<3; i++)
159  if(p[i]<lo[i] || p[i] >= hi[i]) {
160  //puts("F");
161  return false;
162  }
163  //puts("T");
164  return true;
165  }
166 
167  real lo[3];
168  real hi[3];
169 };
170 
171 template<typename Iterator>
172  void getBoundingBox(Box& box, Iterator start, Iterator end)
173 {
174  static const ergo_real OFF = 0.1;
175  if(start == end)
176  throw "BoundingBox called for empty set";
177 
178  real r = start->radius() + OFF;
179  for(int i=0; i<3; i++) {
180  box.lo[i] = start->center[i]-r;
181  box.hi[i] = start->center[i]+r;
182  }
183 
184  for(++start; start != end; ++start) {
185  real r = start->radius() + OFF;
186  for(int i=0; i<3; i++) {
187  real l = start->center[i]-r; if (l<box.lo[i]) box.lo[i] = l;
188  real h = start->center[i]+r; if (h>box.hi[i]) box.hi[i] = h;
189  }
190  }
191 }
192 
193 
194 int sync_threads(bool release, int nThreads);
195 
196 #endif /* _DFT_COMMON_H_ */
EXTERN_C void dft_set_num_threads(int nThreads)
Definition: dft_common.cc:226
int ZEROI
Definition: dft_common.cc:64
int ONEI
Definition: dft_common.cc:64
double ergo_real
Definition: realtype.h:69
const Molecule & molecule
Definition: dft_common.h:97
real fRG
Definition: dft_common.h:78
int getMaxDim() const
Return the index of the largest Cartesian dimension: 0 for x, 1 for y and 2 for z.
Definition: dft_common.cc:111
virtual ~ErgoMolInfo()
Definition: dft_common.cc:583
Definition: functionals.h:375
A vector of first order derivatives with respect to two parameters: density rho and SQUARE of the gra...
Definition: dft_common.h:60
bool contains(const real *p) const
Determines whether given point is inside the box.
Definition: dft_common.h:152
real getDistanceTo(const real *v) const
Returns the shortest distance of the border of the box to the specified point in space.
Definition: dft_common.cc:90
Code for setting up basis functions starting from shells.
real fZ
Definition: dft_common.h:62
Representation of a molecule as a set of nuclei and total charge.
Definition: molecule.h:87
real size(int dim) const
Definition: dft_common.h:141
ergo_real real
Definition: test.cc:46
real fZG
Definition: dft_common.h:79
int THREEI
Definition: dft_common.cc:64
Implements shared parts of the grid generation code.
Definition of the main floating-point datatype used; the ergo_real type.
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:352
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:648
real fRR
Definition: dft_common.h:73
real fR
Definition: dft_common.h:71
real fGG
Definition: dft_common.h:80
real ZEROR
Definition: dft_common.cc:65
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:593
ShellTree * shellTree
Definition: dft_common.h:112
real fZ
Definition: dft_common.h:72
Class that allows to find in NLogN time all shells that overlap with a given box. ...
Definition: dft_common.cc:386
bool overlapsWith(const real *center, real radius) const
Definition: dft_common.h:143
int FOURI
Definition: dft_common.cc:64
real TWOR
Definition: dft_common.cc:65
Definition: basisinfo.h:112
Class Box provides an ability to determine box containing all Objects.
Definition: dft_common.h:137
Header file with typedefs for matrix and vector types.
void getBoundingBox(Box &box, Iterator start, Iterator end)
Definition: dft_common.h:172
EXTERN_C int dft_setfunc(const char *line)
Definition: dft_common.cc:277
GridGenMolInfo is an abstract class providing information about the molecule so that the grid generat...
Definition: grid_interface.h:45
real fR
Definition: dft_common.h:61
ErgoMolInfo(const BasisInfoStruct &bis_, const Molecule &mol)
Ther standard constructor.
Definition: dft_common.cc:573
EXTERN_C void dftpot1_(SecondDrv *ds, const real *w, const FunDensProp *dp, const int *triplet)
Definition: dft_common.cc:776
int charge
Definition: grid_test.cc:51
const BasisInfoStruct & bis
Definition: dft_common.h:96
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:708
real hi[3]
Definition: dft_common.h:168
virtual void getAtom(int icent, int *cnt, real(*coor)[3], int *charge, int *mult) const
Return atom data.
Definition: dft_common.cc:305
EXTERN_C void dft_init(void)
Definition: dft_common.cc:195
Definition: dft_common.h:70
int sync_threads(bool release, int nThreads)
creates or destroys a barrier for nThreads.
Definition: dft_common.cc:137
Functional library interface.
EXTERN_C int dft_get_num_threads()
Definition: dft_common.cc:203
void * dal_malloc_(size_t sz, const char *func, unsigned line)
Definition: dft_common.cc:68
real fZZ
Definition: dft_common.h:75
Ergo specific implementation of molecule-grid interface.
Definition: dft_common.h:95
real ONER
Definition: dft_common.cc:65
real fRZ
Definition: dft_common.h:74
virtual void setShellRadii(real *shellRadii) const
Definition: dft_common.cc:317
EXTERN_C void dftpot0_(FirstDrv *ds, const real *weight, const FunDensProp *dp)
Definition: dft_common.cc:766
#define EXTERN_C
Definition: dft_common.h:46
real fG
Definition: dft_common.h:81
real lo[3]
Definition: dft_common.h:167
real FOURR
Definition: dft_common.cc:65