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

« back to all changes in this revision

Viewing changes to src/bin/cis/U.c

  • 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
 
#include <math.h>
2
 
#include <libdpd/dpd.h>
3
 
#define EXTERN
4
 
#include "globals.h"
5
 
 
6
 
void local_filter_U2(dpdbuf4 *T2, double lambda);
7
 
 
8
 
int U_build(int irrep, int root, double lambda, enum Spin spin)
9
 
{
10
 
  char lbl[32];
11
 
  int iter, h, nirreps, row, col;
12
 
  double energy, conv, rms, value;
13
 
  dpdfile2 F;
14
 
  dpdbuf4 Z, U, Unew, D;
15
 
 
16
 
  nirreps = moinfo.nirreps;
17
 
 
18
 
  timer_on("Uijab");
19
 
 
20
 
  if(params.ref == 0) { /** RHF **/
21
 
 
22
 
    /* build initial guess amplitudes */
23
 
    sprintf(lbl, "ZIjAb[%d]", irrep);
24
 
    dpd_buf4_init(&Z, CC_MISC, irrep, 0, 5, 0, 5, 0, lbl);
25
 
    sprintf(lbl, "UIjAb[%d]", irrep);
26
 
    dpd_buf4_copy(&Z, CC_MISC, lbl);
27
 
    dpd_buf4_close(&Z);
28
 
 
29
 
    sprintf(lbl, "UIjAb[%d]", irrep);
30
 
    dpd_buf4_init(&U, CC_MISC, irrep, 0, 5, 0, 5, 0, lbl);
31
 
    if(params.local) local_filter_U2(&U, lambda);
32
 
    else {
33
 
      sprintf(lbl, "dIjAb[%d]", irrep);
34
 
      dpd_buf4_init(&D, CC_MISC, irrep, 0, 5, 0, 5, 0, lbl);
35
 
      dpd_buf4_dirprd(&D, &U);
36
 
      dpd_buf4_close(&D);
37
 
    }
38
 
 
39
 
    sprintf(lbl, "New UIjAb[%d]", irrep);
40
 
    dpd_buf4_copy(&U, CC_MISC, lbl);
41
 
    dpd_buf4_close(&U);
42
 
 
43
 
    /*
44
 
    fprintf(outfile, "\n\tSolving for U2(%d)[%d] wave function:\n", root, irrep);
45
 
    fprintf(outfile,   "\t-------------------------------------\n");
46
 
    */
47
 
 
48
 
    conv = 0;
49
 
    for(iter=0; iter < params.maxiter; iter++) {
50
 
 
51
 
      sprintf(lbl, "ZIjAb[%d]", irrep);
52
 
      dpd_buf4_init(&Z, CC_MISC, irrep, 0, 5, 0, 5, 0, lbl);
53
 
      sprintf(lbl, "New UIjAb[%d] Increment", irrep);
54
 
      dpd_buf4_copy(&Z, CC_MISC, lbl);
55
 
      dpd_buf4_close(&Z);
56
 
 
57
 
      sprintf(lbl, "New UIjAb[%d] Increment", irrep);
58
 
      dpd_buf4_init(&Unew, CC_MISC, irrep, 0, 5, 0, 5, 0, lbl);
59
 
      sprintf(lbl, "UIjAb[%d]", irrep);
60
 
      dpd_buf4_init(&U, CC_MISC, irrep, 0, 5, 0, 5, 0, lbl);
61
 
 
62
 
      dpd_buf4_axpy(&U, &Unew, -lambda);
63
 
 
64
 
      dpd_file2_init(&F, CC_OEI, 0, 0, 0, "fIJ");
65
 
      dpd_contract424(&U, &F, &Unew, 1, 0, 1, -1, 1);
66
 
      dpd_contract244(&F, &U, &Unew, 0, 0, 0, -1, 1);
67
 
      dpd_file2_close(&F);
68
 
 
69
 
      dpd_file2_init(&F, CC_OEI, 0, 1, 1, "fAB");
70
 
      dpd_contract244(&F, &U, &Unew, 1, 2, 1, 1, 1);
71
 
      dpd_contract424(&U, &F, &Unew, 3, 1, 0, 1, 1);
72
 
      dpd_file2_close(&F);
73
 
 
74
 
      dpd_buf4_close(&U);
75
 
 
76
 
      if(params.local) local_filter_U2(&Unew, lambda);
77
 
      else {
78
 
        sprintf(lbl, "dIjAb[%d]", irrep);
79
 
        dpd_buf4_init(&D, CC_MISC, irrep, 0, 5, 0, 5, 0, lbl);
80
 
        dpd_buf4_dirprd(&D, &Unew);
81
 
        dpd_buf4_close(&D);
82
 
      }
83
 
 
84
 
      rms = 0.0;
85
 
      for(h=0; h < nirreps; h++) {
86
 
        dpd_buf4_mat_irrep_init(&Unew, h);
87
 
        dpd_buf4_mat_irrep_rd(&Unew, h);
88
 
 
89
 
        for(row=0; row < U.params->rowtot[h]; row++)
90
 
          for(col=0; col < U.params->coltot[h^irrep]; col++) {
91
 
            value = Unew.matrix[h][row][col];
92
 
            rms += value * value;
93
 
          }
94
 
 
95
 
        dpd_buf4_mat_irrep_close(&Unew, h);
96
 
      }
97
 
      dpd_buf4_close(&Unew);
98
 
      rms = sqrt(rms);
99
 
 
100
 
      sprintf(lbl, "New UIjAb[%d]", irrep);
101
 
      dpd_buf4_init(&Unew, CC_MISC, irrep, 0, 5, 0, 5, 0, lbl);
102
 
      sprintf(lbl, "New UIjAb[%d] Increment", irrep);
103
 
      dpd_buf4_init(&U, CC_MISC, irrep, 0, 5, 0, 5, 0, lbl);
104
 
      dpd_buf4_axpy(&U, &Unew, 1);
105
 
      dpd_buf4_close(&U);
106
 
 
107
 
      /*      fprintf(outfile, "\titer = %d   RMS = %4.3e\n", iter, rms); */
108
 
      if(rms < params.convergence) {
109
 
        conv = 1;
110
 
        fprintf(outfile, "\tU2(%d)[%d] iterations converged. iter = %d   RMS = %4.3e\n", 
111
 
                root, irrep, iter, rms);
112
 
        break;
113
 
      }
114
 
      else {
115
 
        sprintf(lbl, "New UIjAb[%d]", irrep);
116
 
        dpd_buf4_init(&U, CC_MISC, irrep, 0, 5, 0, 5, 0, lbl);
117
 
        sprintf(lbl, "UIjAb[%d]", irrep);
118
 
        dpd_buf4_copy(&U, CC_MISC, lbl);
119
 
        dpd_buf4_close(&U);
120
 
      }
121
 
    }
122
 
 
123
 
    if(!conv) {
124
 
      fprintf(outfile, "\n\tU2(%d)[%d] iterative procedure failed. RMS = %4.3e\n", root, irrep, rms);
125
 
      sprintf(lbl, "UIjAb[%d]", irrep);
126
 
      dpd_buf4_init(&U, CC_MISC, irrep, 0, 5, 0, 5, 0, lbl);
127
 
      dpd_buf4_scm(&U, 0.0);
128
 
      dpd_buf4_close(&U);
129
 
      return 1;
130
 
      fflush(outfile);
131
 
    }
132
 
    fflush(outfile);
133
 
 
134
 
  }
135
 
  else if(params.ref == 0) { /** UHF **/
136
 
 
137
 
    /* U(IJ,AB) <-- Z(IJ,AB) * D(IJ,AB) */
138
 
    sprintf(lbl, "ZIJAB[%d]", irrep);
139
 
    dpd_buf4_init(&Z, CC_MISC, irrep, 2, 7, 2, 7, 0, lbl);
140
 
    sprintf(lbl, "UIJAB[%d]", irrep);
141
 
    dpd_buf4_copy(&Z, CC_MISC, lbl);
142
 
    dpd_buf4_close(&Z);
143
 
 
144
 
    sprintf(lbl, "UIJAB[%d]", irrep);
145
 
    dpd_buf4_init(&U, CC_MISC, irrep, 2, 7, 2, 7, 0, lbl);
146
 
    sprintf(lbl, "dIJAB[%d]", irrep);
147
 
    dpd_buf4_init(&D, CC_MISC, irrep, 1, 6, 1, 6, 0, lbl);
148
 
    dpd_buf4_dirprd(&D, &U);
149
 
    dpd_buf4_close(&D);
150
 
    dpd_buf4_close(&U);
151
 
 
152
 
    /* U(ij,ab) <-- Z(ij,ab) * D(ij,ab) */
153
 
    sprintf(lbl, "Zijab[%d]", irrep);
154
 
    dpd_buf4_init(&Z, CC_MISC, irrep, 12, 17, 12, 17, 0, lbl);
155
 
    sprintf(lbl, "Uijab[%d]", irrep);
156
 
    dpd_buf4_copy(&Z, CC_MISC, lbl);
157
 
    dpd_buf4_close(&Z);
158
 
 
159
 
    sprintf(lbl, "Uijab[%d]", irrep);
160
 
    dpd_buf4_init(&U, CC_MISC, irrep, 12, 17, 12, 17, 0, lbl);
161
 
    sprintf(lbl, "dijab[%d]", irrep);
162
 
    dpd_buf4_init(&D, CC_MISC, irrep, 11, 16, 11, 16, 0, lbl);
163
 
    dpd_buf4_dirprd(&D, &U);
164
 
    dpd_buf4_close(&D);
165
 
    dpd_buf4_close(&U);
166
 
 
167
 
    /* U(Ij,Ab) <-- Z(Ij,Ab) * D(Ij,Ab) */
168
 
    sprintf(lbl, "ZIjAb[%d]", irrep);
169
 
    dpd_buf4_init(&Z, CC_MISC, irrep, 22, 28, 22, 28, 0, lbl);
170
 
    sprintf(lbl, "UIjAb[%d]", irrep);
171
 
    dpd_buf4_copy(&Z, CC_MISC, lbl);
172
 
    dpd_buf4_close(&Z);
173
 
 
174
 
    sprintf(lbl, "UIjAb[%d]", irrep);
175
 
    dpd_buf4_init(&U, CC_MISC, irrep, 22, 28, 22, 28, 0, lbl);
176
 
    sprintf(lbl, "dIjAb[%d]", irrep);
177
 
    dpd_buf4_init(&D, CC_MISC, irrep, 22, 28, 22, 28, 0, lbl);
178
 
    dpd_buf4_dirprd(&D, &U);
179
 
    dpd_buf4_close(&D);
180
 
    dpd_buf4_close(&U);
181
 
  }
182
 
 
183
 
  timer_off("Uijab");
184
 
 
185
 
  return 0;
186
 
}