ergo
dft_common.h
Go to the documentation of this file.
1/* Ergo, version 3.8.2, a program for linear scaling electronic structure
2 * calculations.
3 * Copyright (C) 2023 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
60typedef 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 */
70typedef 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
85EXTERN_C void dftpot0_(FirstDrv *ds, const real* weight, const FunDensProp* dp);
86EXTERN_C void dftpot1_(SecondDrv *ds, const real* w, const FunDensProp* dp,
87 const int* triplet);
88
89EXTERN_C void dft_init(void);
90EXTERN_C int dft_setfunc(const char *line);
91
92class ShellTree;
93
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
115EXTERN_C void ergoShellsToOrbs(const int *nshlbl, const int (*shlblock)[2],
116 int *norbbl, int (*orbblock)[2],
117 const BasisInfoStruct& bis);
118
120EXTERN_C void dft_set_num_threads(int nThreads);
121
122
123EXTERN_C void dft_init(void);
124
125#define dal_new(sz,tp) (tp*)dal_malloc_((sz)*sizeof(tp),__FUNCTION__, __LINE__)
126void* 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 */
131extern int ZEROI, ONEI, THREEI, FOURI;
133
137class Box {
138public:
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
169};
170
171template<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
194int sync_threads(bool release, int nThreads);
195
196#endif /* _DFT_COMMON_H_ */
Code for setting up basis functions starting from shells.
Class Box provides an ability to determine box containing all Objects.
Definition: dft_common.h:137
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
real hi[3]
Definition: dft_common.h:168
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
real lo[3]
Definition: dft_common.h:167
real size(int dim) const
Definition: dft_common.h:141
bool overlapsWith(const real *center, real radius) const
Definition: dft_common.h:143
bool contains(const real *p) const
Determines whether given point is inside the box.
Definition: dft_common.h:152
Ergo specific implementation of molecule-grid interface.
Definition: dft_common.h:95
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 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
virtual ~ErgoMolInfo()
Definition: dft_common.cc:583
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
const BasisInfoStruct & bis
Definition: dft_common.h:96
ShellTree * shellTree
Definition: dft_common.h:112
virtual void setShellRadii(real *shellRadii) const
Definition: dft_common.cc:317
virtual void getAtom(int icent, int *cnt, real(*coor)[3], int *charge, int *mult) const
Return atom data.
Definition: dft_common.cc:305
const Molecule & molecule
Definition: dft_common.h:97
GridGenMolInfo is an abstract class providing information about the molecule so that the grid generat...
Definition: grid_interface.h:45
Representation of a molecule as a set of nuclei and total charge.
Definition: molecule.h:87
Class that allows to find in NLogN time all shells that overlap with a given box.
Definition: dft_common.cc:386
ergo_real real
Definition: test.cc:46
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
EXTERN_C void dftpot1_(SecondDrv *ds, const real *w, const FunDensProp *dp, const int *triplet)
Definition: dft_common.cc:776
real ZEROR
Definition: dft_common.cc:65
int sync_threads(bool release, int nThreads)
creates or destroys a barrier for nThreads.
Definition: dft_common.cc:137
EXTERN_C void dft_init(void)
Definition: dft_common.cc:195
real FOURR
Definition: dft_common.h:132
EXTERN_C int dft_get_num_threads()
Definition: dft_common.cc:203
int FOURI
Definition: dft_common.h:131
int ZEROI
Definition: dft_common.cc:64
EXTERN_C void dft_set_num_threads(int nThreads)
Definition: dft_common.cc:226
EXTERN_C int dft_setfunc(const char *line)
Definition: dft_common.cc:277
void getBoundingBox(Box &box, Iterator start, Iterator end)
Definition: dft_common.h:172
int THREEI
Definition: dft_common.h:131
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
int ONEI
Definition: dft_common.h:131
void * dal_malloc_(size_t sz, const char *func, unsigned line)
Definition: dft_common.cc:68
real TWOR
Definition: dft_common.h:132
real ONER
Definition: dft_common.h:132
Functional library interface.
Implements shared parts of the grid generation code.
int charge
Definition: grid_test.cc:51
Header file with typedefs for matrix and vector types.
Definition of the main floating-point datatype used; the ergo_real type.
double ergo_real
Definition: realtype.h:69
Definition: basisinfo.h:112
A vector of first order derivatives with respect to two parameters: density rho and SQUARE of the gra...
Definition: dft_common.h:60
real fR
Definition: dft_common.h:61
real fZ
Definition: dft_common.h:62
Definition: functionals.h:375
Definition: dft_common.h:70
real fRR
Definition: dft_common.h:73
real fRG
Definition: dft_common.h:78
real fG
Definition: dft_common.h:81
real fRZ
Definition: dft_common.h:74
real fGG
Definition: dft_common.h:80
real fR
Definition: dft_common.h:71
real fZZ
Definition: dft_common.h:75
real fZ
Definition: dft_common.h:72
real fZG
Definition: dft_common.h:79