~ubuntu-branches/ubuntu/karmic/psicode/karmic

« back to all changes in this revision

Viewing changes to src/bin/ccdensity/build_Z_UHF.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
 
2
    \ingroup CCDENSITY
 
3
    \brief Enter brief description of file here 
 
4
*/
 
5
#include <cstdio>
 
6
#include <cstdlib>
 
7
#include <cmath>
 
8
#include <libciomr/libciomr.h>
 
9
#include <libdpd/dpd.h>
 
10
#include <libqt/qt.h>
 
11
#include <psifiles.h>
 
12
#include <cmath>
 
13
#include "MOInfo.h"
 
14
#include "Params.h"
 
15
#include "Frozen.h"
 
16
#define EXTERN
 
17
#include "globals.h"
 
18
 
 
19
namespace psi { namespace ccdensity {
 
20
 
 
21
/* build_Z_UHF():  Solve the orbital Z-vector equations for UHF refs:
 
22
**
 
23
**    A(AI,BJ) D(orb)(B,J) = -X(A,I)
 
24
**
 
25
** where A(AI,EM) is the orbital Hessian computed in build_A(), X(A,I)
 
26
** is the orbital rotation gradient computed in build_X(), and
 
27
** D(orb)(E,M) is the final Z-vector we want. 
 
28
**
 
29
*/
 
30
 
 
31
void build_Z_UHF(void)
 
32
{
 
33
  dpdbuf4 A_AA, A_BB, A_AB;
 
34
  dpdfile2 X, D;
 
35
  double **A, *Z;
 
36
  int num_ai, a, i, ai, bj;
 
37
  int h, nirreps, count, dim_A, dim_B;
 
38
  int *ipiv, info;
 
39
  int *avirtpi, *aoccpi;
 
40
  int *bvirtpi, *boccpi;
 
41
 
 
42
  nirreps = moinfo.nirreps;
 
43
  aoccpi = moinfo.aoccpi; avirtpi = moinfo.avirtpi;
 
44
  boccpi = moinfo.boccpi; bvirtpi = moinfo.bvirtpi;
 
45
 
 
46
  /* compute the number of ai pairs */
 
47
  num_ai = 0;
 
48
  for(h=0; h < nirreps; h++) {
 
49
    num_ai += avirtpi[h] * aoccpi[h];
 
50
    num_ai += bvirtpi[h] * boccpi[h];
 
51
  }
 
52
 
 
53
  /* Place all the elements of the orbital rotation gradient, X, into a
 
54
     linear array, Z */
 
55
  Z = init_array(num_ai);
 
56
 
 
57
  dpd_file2_init(&X, CC_OEI, 0, 1, 0, "XAI");
 
58
  dpd_file2_mat_init(&X);
 
59
  dpd_file2_mat_rd(&X);
 
60
  for(h=0,count=0; h < nirreps; h++)
 
61
    for(a=0; a < X.params->rowtot[h]; a++)
 
62
      for(i=0; i < X.params->coltot[h]; i++) 
 
63
        Z[count++] = -X.matrix[h][a][i];
 
64
  dpd_file2_mat_close(&X);
 
65
  dpd_file2_close(&X);
 
66
 
 
67
  dpd_file2_init(&X, CC_OEI, 0, 3, 2, "Xai");
 
68
  dpd_file2_mat_init(&X);
 
69
  dpd_file2_mat_rd(&X);
 
70
  for(h=0; h < nirreps; h++)
 
71
    for(a=0; a < X.params->rowtot[h]; a++)
 
72
      for(i=0; i < X.params->coltot[h]; i++) 
 
73
        Z[count++] = -X.matrix[h][a][i];
 
74
  dpd_file2_mat_close(&X);
 
75
  dpd_file2_close(&X);
 
76
 
 
77
  /* Now, build the full MO Hessian */
 
78
  dpd_buf4_init(&A_AA, CC_MISC, 0, 21, 21, 21, 21, 0, "A(AI,BJ)");
 
79
  dpd_buf4_init(&A_BB, CC_MISC, 0, 31, 31, 31, 31, 0, "A(ai,bj)");
 
80
  dpd_buf4_init(&A_AB, CC_MISC, 0, 21, 31, 21, 31, 0, "A(AI,bj)");
 
81
 
 
82
 
 
83
  dim_A = A_AA.params->rowtot[0];
 
84
  dim_B = A_BB.params->rowtot[0];
 
85
 
 
86
  if(num_ai != dim_A + dim_B) { /* error */
 
87
    fprintf(outfile, "Problem: num_ai(%d) != dim_A + dim_b (%d)\n", num_ai,
 
88
            dim_A + dim_B);
 
89
    exit(PSI_RETURN_FAILURE);
 
90
  }
 
91
 
 
92
  A = block_matrix(num_ai, num_ai);
 
93
 
 
94
  dpd_buf4_mat_irrep_init(&A_AA, 0);
 
95
  dpd_buf4_mat_irrep_rd(&A_AA, 0);
 
96
  for(ai=0; ai < dim_A; ai++)
 
97
    for(bj=0; bj < dim_A; bj++)
 
98
      A[ai][bj] = A_AA.matrix[0][ai][bj];
 
99
  dpd_buf4_mat_irrep_close(&A_AA, 0);
 
100
 
 
101
  dpd_buf4_mat_irrep_init(&A_BB, 0);
 
102
  dpd_buf4_mat_irrep_rd(&A_BB, 0);
 
103
  for(ai=0; ai < dim_B; ai++)
 
104
    for(bj=0; bj < dim_B; bj++)
 
105
      A[ai+dim_A][bj+dim_A] = A_BB.matrix[0][ai][bj];
 
106
  dpd_buf4_mat_irrep_close(&A_BB, 0);
 
107
 
 
108
  dpd_buf4_mat_irrep_init(&A_AB, 0);
 
109
  dpd_buf4_mat_irrep_rd(&A_AB, 0);
 
110
  for(ai=0; ai < dim_A; ai++)
 
111
    for(bj=0; bj < dim_B; bj++)
 
112
      A[ai][bj+dim_A] = A[bj+dim_A][ai] = A_AB.matrix[0][ai][bj];
 
113
  dpd_buf4_mat_irrep_close(&A_AB, 0);
 
114
 
 
115
  dpd_buf4_close(&A_AA);
 
116
  dpd_buf4_close(&A_BB);
 
117
  dpd_buf4_close(&A_AB);
 
118
 
 
119
  /*
 
120
  ipiv = init_int_array(num_ai);
 
121
  info = C_DGESV(num_ai, 1, &(A[0][0]), num_ai, &(ipiv[0]), &(Z[0]), num_ai);
 
122
  if(info) {
 
123
    fprintf(outfile, "\nError in DGESV return in build_Z_UHF: %d.\n", info);
 
124
    exit(PSI_RETURN_FAILURE);
 
125
  }
 
126
 
 
127
  free(ipiv);
 
128
  free_block(A);
 
129
  */
 
130
  pople(A, Z, num_ai, 1, 1e-12, outfile, 0);
 
131
 
 
132
  /*
 
133
  for(ai=0; ai < num_ai; ai++) fprintf(outfile, "Z[%d] = %20.15f\n", ai, Z[ai]);
 
134
  */
 
135
 
 
136
  dpd_file2_init(&D, CC_OEI, 0, 1, 0, "D(orb)(A,I)");
 
137
  dpd_file2_scm(&D, 0.0);
 
138
  dpd_file2_mat_init(&D);
 
139
  for(h=0,count=0; h < nirreps; h++)
 
140
    for(a=0; a < D.params->rowtot[h]; a++)
 
141
      for(i=0; i < D.params->coltot[h]; i++) {
 
142
        if(fabs(Z[count]) > 1e3) D.matrix[h][a][i] = 0.0;
 
143
        else D.matrix[h][a][i] = Z[count];
 
144
        count++;
 
145
      }
 
146
  dpd_file2_mat_wrt(&D);
 
147
  dpd_file2_mat_close(&D);
 
148
  dpd_file2_close(&D);
 
149
 
 
150
  dpd_file2_init(&D, CC_OEI, 0, 3, 2, "D(orb)(a,i)");
 
151
  dpd_file2_scm(&D, 0.0);
 
152
  dpd_file2_mat_init(&D);
 
153
  for(h=0; h < nirreps; h++)
 
154
    for(a=0; a < D.params->rowtot[h]; a++) 
 
155
      for(i=0; i < D.params->coltot[h]; i++) {
 
156
        if(fabs(Z[count]) > 1e3) D.matrix[h][a][i] = 0.0;
 
157
        else D.matrix[h][a][i] = Z[count];
 
158
        count++;
 
159
      }
 
160
  dpd_file2_mat_wrt(&D);
 
161
  dpd_file2_mat_close(&D);
 
162
  dpd_file2_close(&D);
 
163
 
 
164
  /* We're done with Z */
 
165
  free(Z);
 
166
}
 
167
 
 
168
 
 
169
 
 
170
}} // namespace psi::ccdensity