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

« back to all changes in this revision

Viewing changes to src/bin/ccdensity/build_Z_UHF.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck
  • Date: 2006-09-10 14:01:33 UTC
  • Revision ID: james.westby@ubuntu.com-20060910140133-ib2j86trekykfsfv
Tags: upstream-3.2.3
ImportĀ upstreamĀ versionĀ 3.2.3

Show diffs side-by-side

added added

removed removed

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