3
\brief Enter brief description of file here
8
#include <libciomr/libciomr.h>
9
#include <libdpd/dpd.h>
19
namespace psi { namespace ccdensity {
21
/* build_Z_UHF(): Solve the orbital Z-vector equations for UHF refs:
23
** A(AI,BJ) D(orb)(B,J) = -X(A,I)
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.
31
void build_Z_UHF(void)
33
dpdbuf4 A_AA, A_BB, A_AB;
36
int num_ai, a, i, ai, bj;
37
int h, nirreps, count, dim_A, dim_B;
39
int *avirtpi, *aoccpi;
40
int *bvirtpi, *boccpi;
42
nirreps = moinfo.nirreps;
43
aoccpi = moinfo.aoccpi; avirtpi = moinfo.avirtpi;
44
boccpi = moinfo.boccpi; bvirtpi = moinfo.bvirtpi;
46
/* compute the number of ai pairs */
48
for(h=0; h < nirreps; h++) {
49
num_ai += avirtpi[h] * aoccpi[h];
50
num_ai += bvirtpi[h] * boccpi[h];
53
/* Place all the elements of the orbital rotation gradient, X, into a
55
Z = init_array(num_ai);
57
dpd_file2_init(&X, CC_OEI, 0, 1, 0, "XAI");
58
dpd_file2_mat_init(&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);
67
dpd_file2_init(&X, CC_OEI, 0, 3, 2, "Xai");
68
dpd_file2_mat_init(&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);
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)");
83
dim_A = A_AA.params->rowtot[0];
84
dim_B = A_BB.params->rowtot[0];
86
if(num_ai != dim_A + dim_B) { /* error */
87
fprintf(outfile, "Problem: num_ai(%d) != dim_A + dim_b (%d)\n", num_ai,
89
exit(PSI_RETURN_FAILURE);
92
A = block_matrix(num_ai, num_ai);
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);
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);
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);
115
dpd_buf4_close(&A_AA);
116
dpd_buf4_close(&A_BB);
117
dpd_buf4_close(&A_AB);
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);
123
fprintf(outfile, "\nError in DGESV return in build_Z_UHF: %d.\n", info);
124
exit(PSI_RETURN_FAILURE);
130
pople(A, Z, num_ai, 1, 1e-12, outfile, 0);
133
for(ai=0; ai < num_ai; ai++) fprintf(outfile, "Z[%d] = %20.15f\n", ai, Z[ai]);
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];
146
dpd_file2_mat_wrt(&D);
147
dpd_file2_mat_close(&D);
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];
160
dpd_file2_mat_wrt(&D);
161
dpd_file2_mat_close(&D);
164
/* We're done with Z */
170
}} // namespace psi::ccdensity