~ubuntu-branches/ubuntu/quantal/psicode/quantal

« back to all changes in this revision

Viewing changes to src/bin/cints/DFT/xc_grad_fock.cc

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck, Michael Banck, Daniel Leidert
  • Date: 2009-02-23 00:12:02 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090223001202-rutldoy3dimfpesc
Tags: 3.4.0-1
* New upstream release.

[ Michael Banck ]
* debian/patches/01_DESTDIR.dpatch: Refreshed.
* debian/patches/02_FHS.dpatch: Removed, applied upstream.
* debian/patches/03_debian_docdir: Likewise.
* debian/patches/04_man.dpatch: Likewise.
* debian/patches/06_466828_fix_gcc_43_ftbfs.dpatch: Likewise.
* debian/patches/07_464867_move_executables: Fixed and refreshed.
* debian/patches/00list: Adjusted.
* debian/control: Improved description.
* debian/patches-held: Removed.
* debian/rules (install/psi3): Do not ship the ruby bindings for now.

[ Daniel Leidert ]
* debian/rules: Fix txtdir via DEB_MAKE_INSTALL_TARGET.
* debian/patches/01_DESTDIR.dpatch: Refreshed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*! \file xc_grad_fock.cc
 
2
    \ingroup CINTS
 
3
    \brief Enter brief description of file here 
 
4
*/
 
5
#include<cmath>
 
6
#include<cstring>
 
7
#include<cstdio>
 
8
#include<cstdlib>
 
9
#include<libipv1/ip_lib.h>
 
10
#include<libciomr/libciomr.h>
 
11
#include<libpsio/psio.h>
 
12
#include<libint/libint.h>
 
13
#include<pthread.h>
 
14
#include<libqt/qt.h>
 
15
 
 
16
#include"defines.h"
 
17
#define EXTERN
 
18
#include"global.h"
 
19
#include <stdexcept>
 
20
 
 
21
#include"dft_init.h"
 
22
#include"weighting.h"
 
23
#include"calc_den_fast.h"
 
24
#include"calc_den.h"
 
25
#include"calc_grad_fast.h"
 
26
#include"functional.h"
 
27
#include"physconst.h"
 
28
#include"grid_init.h"
 
29
#include"free_grid_structs.h"
 
30
#include"dcr.h"
 
31
#include"init_close_shell_info.h"
 
32
#include"calc_close_basis.h"
 
33
 
 
34
namespace psi { namespace CINTS {
 
35
 
 
36
void xc_grad_fock(void){
 
37
  int i,j,k,l,m,n,q,s,t,u;
 
38
  int ua, atom, ua_deg;
 
39
  int rpoints;
 
40
  int ang_points;
 
41
  int num_ao;
 
42
  int point_count=0;
 
43
  int dum;
 
44
  int num;
 
45
  int moff,noff,mtmp,ntmp;
 
46
  int am2shell1,am2shell2;
 
47
  int shell_type1,shell_type2;
 
48
  int ioff1,ioff2;
 
49
  int chek = 1;
 
50
  int close_shells;
 
51
  int close_aos;
 
52
  int tmp;
 
53
  
 
54
  int nstri;
 
55
  double temp;
 
56
  double *temp_arr;
 
57
  double *omega_arr;
 
58
  double **tmpmat1;
 
59
  double *Gtri;  /* Total and open-shell 
 
60
                             G matrices and lower 
 
61
                             triagonal form in SO basis */  
 
62
  double r;
 
63
  double rind;
 
64
  double rpoints_double;
 
65
  double ua_deg_d;
 
66
  double bragg;
 
67
  double qr;
 
68
  double drdq;
 
69
  double jacobian;
 
70
  double xa,ya,za;
 
71
  double Becke_weight;
 
72
  double ang_quad;
 
73
  double four_pi_div_by_rps;
 
74
  double den_val=0.0;
 
75
  double exch_pval=0.0;
 
76
  double exch_gval=0.0;
 
77
  double corr_pval=0.0;
 
78
  double corr_gval=0.0;
 
79
  double exch_eval=0.0;
 
80
  double corr_eval=0.0;
 
81
  double pval = 0.0;
 
82
  double gval = 0.0;
 
83
  double eval = 0.0;
 
84
  double bas1 = 0.0;
 
85
  double bas2 = 0.0;
 
86
  double vvalbas = 0.0;
 
87
  double dpx,dpy,dpz;
 
88
  
 
89
  struct coordinates geom;
 
90
  struct den_info_s den_info;
 
91
  struct xc_info_s xc_info;
 
92
  
 
93
  struct atomic_grid_s *atm_grd;
 
94
  struct leb_chunk_s *chnk;
 
95
  leb_sphere_t *sphr;
 
96
  leb_point_t *pnt;
 
97
  
 
98
  
 
99
  num_ao = BasisSet.num_ao;
 
100
  
 
101
  DFT_options.basis = (double *)malloc(sizeof(double)*num_ao);
 
102
  DFT_options.gradx = (double *)malloc(sizeof(double)*num_ao);
 
103
  DFT_options.grady = (double *)malloc(sizeof(double)*num_ao);
 
104
  DFT_options.gradz = (double *)malloc(sizeof(double)*num_ao);
 
105
  DFT_options.gamma_basis = (double *)malloc(sizeof(double)*num_ao);
 
106
  omega_arr = (double *)malloc(sizeof(double)*num_ao);
 
107
  
 
108
  G = init_matrix(num_ao,num_ao);
 
109
  
 
110
  /* ----Initialize Close shell data structure ---- */
 
111
  
 
112
  DFT_options.close_shell_info = init_close_shell_info();
 
113
 
 
114
  timer_init();
 
115
  timer_on("DFT");
 
116
  
 
117
  grid_init();
 
118
  
 
119
/*-------------------------------------------------------
 
120
    Loop over symmetry-unique atoms only since integration
 
121
    domains around symm.-unique atoms are equivalent
 
122
    We are NOT employing the symmetry of angular grids
 
123
    about atoms in special positions (on symm. elements)
 
124
    like Handy & co. do
 
125
   -------------------------------------------------------*/
 
126
  for(ua=0;ua<Symmetry.num_unique_atoms;ua++){
 
127
      atm_grd = &(DFT_options.grid.atomic_grid[ua]);
 
128
      
 
129
      atom = atm_grd->atom_num;
 
130
      
 
131
/*--- Cheap trick to get degeneracies of each unique atom ---*/
 
132
      
 
133
      ua_deg = atm_grd->atom_degen;
 
134
      ua_deg_d = (double) ua_deg;
 
135
 
 
136
      xa = atm_grd->atom_center.x;
 
137
      ya = atm_grd->atom_center.y;
 
138
      za = atm_grd->atom_center.z;
 
139
      
 
140
      bragg = atm_grd->Bragg_radii;
 
141
      
 
142
      for(j=0;j<atm_grd->chunk_num;j++){
 
143
          chnk = &(atm_grd->leb_chunk[j]);
 
144
          timer_on("close basis");
 
145
          
 
146
          calc_close_basis(ua,j);
 
147
          
 
148
          close_shells = DFT_options.close_shell_info.num_close_shells;
 
149
          close_aos = DFT_options.close_shell_info.num_close_aos;
 
150
          timer_off("close basis");
 
151
          for(k=0;k<chnk->size;k++){
 
152
              
 
153
              sphr = &(chnk->spheres[k]);
 
154
              
 
155
              r = sphr->r*bragg;
 
156
              /*r = 0.87895;*/
 
157
              
 
158
              
 
159
              drdq = sphr->drdq*bragg*bragg*bragg;
 
160
              
 
161
              for(l=0;l<sphr->n_ang_points;l++){
 
162
                  pnt = &(sphr->points[l]);
 
163
                  /* ----------------------------------
 
164
                     Calculate the cartesian points of the point
 
165
                     relative to the center of mass
 
166
                     -------------------------------------*/
 
167
                  geom.x = bragg*pnt->p_cart.x+xa;
 
168
                  geom.y = bragg*pnt->p_cart.y+ya;
 
169
                  geom.z = bragg*pnt->p_cart.z+za;
 
170
                  
 
171
                  /*-----------------------------------
 
172
                    Calculate the weighting funtion 
 
173
                    ----------------------------------*/
 
174
                  Becke_weight = weight_calc(atom,geom,3);
 
175
                  
 
176
                  if(Becke_weight> WEIGHT_CUTOFF){
 
177
                      /*-----------------------------------
 
178
                        Get the density information for this 
 
179
                        point
 
180
                        ----------------------------------*/
 
181
                      timer_on("DEN1");
 
182
                      /*den_info = DFT_options.den_calc(geom,ua);*/
 
183
                      den_info = calc_grad_fast(geom,ua);
 
184
                      
 
185
                      timer_off("DEN1");
 
186
                      
 
187
                      if(den_info.den > DEN_CUTOFF){
 
188
                          /*-------------------------------------
 
189
                            Weight from Lebedev
 
190
                            -----------------------------------*/
 
191
                      
 
192
                          ang_quad = 4.0*_pi*pnt->ang_weight;
 
193
                      
 
194
                          /*------------------------------------
 
195
                            Calculate the potential functional
 
196
                            and energy functional at this
 
197
                            point
 
198
                            -----------------------------------*/
 
199
                          /*fprintf(outfile,"\nua_deg = %10.10lf",ua_deg_d);*/
 
200
                          den_val += 2.0*ua_deg_d*drdq*ang_quad
 
201
                              *Becke_weight*den_info.den;
 
202
                          
 
203
                          xc_info.exch_info = DFT_options.
 
204
                              exchange_func(den_info);
 
205
                          
 
206
                          xc_info.corr_info = DFT_options.
 
207
                              correlation_func(den_info);
 
208
                         
 
209
                          exch_pval = ua_deg_d*drdq*ang_quad
 
210
                              *Becke_weight*xc_info.exch_info.dpval;
 
211
                          exch_gval = ua_deg_d*drdq*ang_quad
 
212
                              *Becke_weight*xc_info.exch_info.dgval;
 
213
         
 
214
                          corr_pval = ua_deg_d*drdq*ang_quad
 
215
                              *Becke_weight*xc_info.corr_info.dpval;
 
216
                          corr_gval = ua_deg_d*drdq*ang_quad
 
217
                              *Becke_weight*xc_info.corr_info.dgval;
 
218
 
 
219
                          pval = exch_pval+corr_pval;
 
220
                          gval = exch_gval+corr_gval;
 
221
                          
 
222
                          exch_eval += ua_deg_d*drdq*ang_quad
 
223
                              *Becke_weight*xc_info.exch_info.eval;
 
224
                          corr_eval += ua_deg_d*drdq*ang_quad
 
225
                              *Becke_weight*xc_info.corr_info.eval;
 
226
                          eval += ua_deg_d*drdq*ang_quad
 
227
                              *Becke_weight*(xc_info.exch_info.eval+
 
228
                                             xc_info.corr_info.eval);
 
229
                          
 
230
                          /*------------------------------------
 
231
                            Update the G matrix
 
232
                            -----------------------------------*/
 
233
                          timer_on("FOCK");
 
234
                          t=0;
 
235
                          
 
236
                          /* Form omega array <  p+dphiu  > */
 
237
                          
 
238
                          dpx = den_info.gradx;
 
239
                          dpy = den_info.grady;
 
240
                          dpz = den_info.gradz;
 
241
                          
 
242
                          /* Omega is the df/dgamma * delp . delp(basu*basv) */
 
243
                          /* See Benny Johnson's Thesis page 109 */
 
244
                          
 
245
                          /*for(m=0;m<close_aos;m++){
 
246
                              omega_arr[m] = 2.0*gval*(dpx*DFT_options.gradx[m]
 
247
                                                       +dpy*DFT_options.grady[m]
 
248
                                                       +dpz*DFT_options.gradz[m]);
 
249
                          }
 
250
                         
 
251
                      for(m=0;m<close_aos;m++){
 
252
                              bas1 = pval*DFT_options.basis[m]
 
253
                                  + omega_arr[m];
 
254
                              moff = DFT_options.close_shell_info.
 
255
                                  aos_close_to_chunk[m];
 
256
                              for(n=m;n<close_aos;n++){
 
257
                                  bas2 = bas1*DFT_options.basis[n]
 
258
                                      +DFT_options.basis[m]*omega_arr[n];
 
259
                                  noff = DFT_options.close_shell_info.
 
260
                                      aos_close_to_chunk[n];
 
261
                                  if(noff > moff)
 
262
                                      G[moff][noff] += bas2;
 
263
                                  else
 
264
                                      G[noff][moff] += bas2;
 
265
                              }
 
266
                          }*/
 
267
                      /*fprintf(outfile,"\ngval = %10.10lf",gval);*/
 
268
                      for(m=0;m<close_aos;m++){
 
269
                          for(n=0;n<close_aos;n++){
 
270
                              moff = DFT_options.close_shell_info.
 
271
                                  aos_close_to_chunk[m];
 
272
                              noff = DFT_options.close_shell_info.
 
273
                                      aos_close_to_chunk[n];
 
274
                              bas1 = pval*DFT_options.basis[m]
 
275
                                  *DFT_options.basis[n];
 
276
                              bas2 = 2.0*gval*((dpx*DFT_options.gradx[m]+
 
277
                                              dpy*DFT_options.grady[m]+
 
278
                                              dpz*DFT_options.gradz[m])*
 
279
                                             DFT_options.basis[n]
 
280
                                             +(dpx*DFT_options.gradx[n]+
 
281
                                              dpy*DFT_options.grady[n]+
 
282
                                              dpz*DFT_options.gradz[n])*
 
283
                                             DFT_options.basis[m]);
 
284
                              /*fprintf(outfile,"\nbas1 = %10.10lf bas2 = %10.10lf\n\n\n",bas1,bas2);*/
 
285
                              G[moff][noff] += pval*DFT_options.basis[m]
 
286
                                  *DFT_options.basis[n]
 
287
                                  +2.0*gval*((dpx*DFT_options.gradx[m]+
 
288
                                              dpy*DFT_options.grady[m]+
 
289
                                              dpz*DFT_options.gradz[m])*
 
290
                                             DFT_options.basis[n]
 
291
                                             +(dpx*DFT_options.gradx[n]+
 
292
                                              dpy*DFT_options.grady[n]+
 
293
                                              dpz*DFT_options.gradz[n])*
 
294
                                             DFT_options.basis[m]);
 
295
                          }
 
296
                      }
 
297
                      timer_off("FOCK");      
 
298
                      
 
299
                      }
 
300
                  }
 
301
              }  
 
302
          }
 
303
      }
 
304
  }
 
305
  
 
306
  free_close_shell_info(DFT_options.close_shell_info);
 
307
  print_mat(G,num_ao,num_ao,outfile);
 
308
  for(m=0;m<num_ao;m++)
 
309
      for(n=m;n<num_ao;n++)
 
310
          G[n][m]=G[m][n];
 
311
  
 
312
  timer_off("DFT");
 
313
  timer_done();
 
314
  
 
315
  
 
316
  /*----------------------
 
317
    Unsort the Fock matrix
 
318
    back to shell ordering
 
319
    ---------------------*/
 
320
  
 
321
  
 
322
/*----------------------
 
323
  Transform to SO basis
 
324
  ----------------------*/
 
325
  if (Symmetry.nirreps > 1 || BasisSet.puream) {
 
326
      tmpmat1 = block_matrix(Symmetry.num_so,BasisSet.num_ao);
 
327
      mmult(Symmetry.usotao,0,G,0,tmpmat1,0,Symmetry.num_so,BasisSet.num_ao,BasisSet.num_ao,0);
 
328
      mmult(tmpmat1,0,Symmetry.usotao,1,G,0,Symmetry.num_so,BasisSet.num_ao,Symmetry.num_so,0);
 
329
      if (UserOptions.reftype == rohf || UserOptions.reftype == uhf) {
 
330
          mmult(Symmetry.usotao,0,Go,0,tmpmat1,0,Symmetry.num_so,BasisSet.num_ao,BasisSet.num_ao,0);
 
331
          mmult(tmpmat1,0,Symmetry.usotao,1,Go,0,Symmetry.num_so,BasisSet.num_ao,Symmetry.num_so,0);
 
332
      }
 
333
      free_block(tmpmat1);
 
334
  }
 
335
  
 
336
  /*-------------------------
 
337
    Write G-matrices to disk
 
338
    -------------------------*/
 
339
  
 
340
  nstri = ioff[Symmetry.num_so];
 
341
  Gtri = init_array(nstri);
 
342
  sq_to_tri(G,Gtri,Symmetry.num_so);
 
343
  free_block(G);
 
344
  fprintf(outfile,"\nDFT_energy = %10.10lf",eval);
 
345
  fprintf(outfile,"\nX-Energy = %10.10lf",exch_eval);
 
346
  fprintf(outfile,"\nC-Energy = %10.10lf",corr_eval);
 
347
  fprintf(outfile,"\ntrace of density = %10.10lf\n",den_val);
 
348
  
 
349
  psio_open(IOUnits.itapDSCF, PSIO_OPEN_OLD);
 
350
  psio_write_entry(IOUnits.itapDSCF,"DFT X-energy",
 
351
                   (char *) &(exch_eval), sizeof(double));
 
352
  psio_write_entry(IOUnits.itapDSCF,"DFT C-energy",
 
353
                   (char *) &(corr_eval), sizeof(double));
 
354
  psio_write_entry(IOUnits.itapDSCF,"DFT XC-energy",
 
355
                   (char *) &(eval), sizeof(double));
 
356
  psio_write_entry(IOUnits.itapDSCF,"DFT Den",
 
357
                   (char *) &(den_val), sizeof(double));
 
358
  
 
359
  psio_write_entry(IOUnits.itapDSCF, "Total XC G-matrix"
 
360
                   , (char *) Gtri, sizeof(double)*nstri);
 
361
  free(Gtri);
 
362
 
 
363
  /*-- Cleanup the DFT stuff and close files --*/
 
364
  cleanup_grid_type(DFT_options.grid);
 
365
  psio_close(IOUnits.itapDSCF, 1);
 
366
  return;
 
367
}
 
368
};}