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

« back to all changes in this revision

Viewing changes to src/bin/ccresponse/compute_X.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 CCRESPONSE
 
3
    \brief Enter brief description of file here 
 
4
*/
 
5
#include <cstdio>
 
6
#include <cstdlib>
 
7
#include <cstring>
 
8
#include <cmath>
 
9
#include <libdpd/dpd.h>
 
10
#include <psifiles.h>
 
11
#include "MOInfo.h"
 
12
#include "Params.h"
 
13
#include "Local.h"
 
14
#define EXTERN
 
15
#include "globals.h"
 
16
 
 
17
namespace psi { namespace ccresponse {
 
18
 
 
19
void init_X(const char *pert, const char *cart, int irrep, double omega);
 
20
void sort_X(const char *pert, const char *cart, int irrep, double omega);
 
21
void cc2_sort_X(const char *pert, const char *cart, int irrep, double omega);
 
22
void X1_build(const char *pert, const char *cart, int irrep, double omega);
 
23
void X2_build(const char *pert, const char *cart, int irrep, double omega);
 
24
void cc2_X1_build(const char *pert, const char *cart, int irrep, double omega);
 
25
void cc2_X2_build(const char *pert, const char *cart, int irrep, double omega);
 
26
double converged(const char *pert, const char *cart, int irrep, double omega);
 
27
void save_X(const char *pert, const char *cart, int irrep, double omega);
 
28
void print_X(const char *pert, const char *cart, int irrep, double omega);
 
29
void update_X(const char *pert, const char *cart, int irrep, double omega);
 
30
void diis(int iter, const char *pert, const char *cart, int irrep, double omega);
 
31
double pseudopolar(const char *pert, const char *cart, int irrep, double omega);
 
32
void cleanup(void);
 
33
void exit_io(void);
 
34
void amp_write(const char *pert, const char *cart, int irrep, double omega);
 
35
 
 
36
void compute_X(const char *pert, const char *cart, int irrep, double omega)
 
37
{
 
38
  int i, iter=0, done=0;
 
39
  double rms, polar, X2_norm;
 
40
  char lbl[32];
 
41
  dpdbuf4 X2;
 
42
 
 
43
  fprintf(outfile, "\n\tComputing %s-%1s-Perturbed Wave Function (%5.3f E_h).\n", pert, cart, omega);
 
44
  init_X(pert, cart, irrep, omega);
 
45
  fprintf(outfile, "\tIter   Pseudopolarizability       RMS \n");
 
46
  fprintf(outfile, "\t----   --------------------   -----------\n");
 
47
  fflush(outfile);
 
48
 
 
49
  if (!strcmp(params.wfn,"CC2"))
 
50
    cc2_sort_X(pert, cart, irrep, omega);
 
51
  else
 
52
    sort_X(pert, cart, irrep, omega);
 
53
  polar = -2.0*pseudopolar(pert, cart, irrep, omega);
 
54
  fprintf(outfile, "\t%4d   %20.12f\n", iter, polar);
 
55
  fflush(outfile);
 
56
 
 
57
  for(iter=1; iter <= params.maxiter; iter++) {
 
58
 
 
59
    if (!strcmp(params.wfn,"CC2")) {
 
60
      cc2_sort_X(pert, cart, irrep, omega);
 
61
      cc2_X1_build(pert, cart, irrep, omega);
 
62
      cc2_X2_build(pert, cart, irrep, omega);
 
63
    }
 
64
    else {
 
65
      sort_X(pert, cart, irrep, omega);
 
66
      X1_build(pert, cart, irrep, omega);
 
67
      X2_build(pert, cart, irrep, omega);
 
68
    }
 
69
    update_X(pert, cart, irrep, omega);
 
70
    rms = converged(pert, cart, irrep, omega);
 
71
    if(rms <= params.convergence) {
 
72
      done = 1;
 
73
      save_X(pert, cart, irrep, omega);
 
74
      if (!strcmp(params.wfn,"CC2"))
 
75
        cc2_sort_X(pert, cart, irrep, omega);
 
76
      else
 
77
        sort_X(pert, cart, irrep, omega);
 
78
      fprintf(outfile, "\t-----------------------------------------\n");
 
79
      fprintf(outfile, "\tConverged %s-%1s-Perturbed Wfn to %4.3e\n", pert, cart, rms);
 
80
      if(params.print & 2) {
 
81
        sprintf(lbl, "X_%s_%1s_IjAb (%5.3f)", pert, cart, omega);
 
82
        dpd_buf4_init(&X2, CC_LR, irrep, 0, 5, 0, 5, 0, lbl);
 
83
        X2_norm = dpd_buf4_dot_self(&X2);
 
84
        dpd_buf4_close(&X2);
 
85
        X2_norm = sqrt(X2_norm);
 
86
        fprintf(outfile, "\tNorm of the converged X2 amplitudes %20.15f\n", X2_norm);
 
87
        amp_write(pert, cart, irrep, omega);
 
88
      }
 
89
      fflush(outfile);
 
90
      break;
 
91
    }
 
92
    if(params.diis) diis(iter, pert, cart, irrep, omega);
 
93
    save_X(pert, cart, irrep, omega);
 
94
    if (!strcmp(params.wfn,"CC2"))
 
95
      cc2_sort_X(pert, cart, irrep, omega);
 
96
    else
 
97
      sort_X(pert, cart, irrep, omega);
 
98
 
 
99
    polar = -2.0*pseudopolar(pert, cart, irrep, omega);
 
100
    fprintf(outfile, "\t%4d   %20.12f    %4.3e\n", iter, polar, rms);
 
101
    fflush(outfile);
 
102
 
 
103
  }
 
104
  if(!done) {
 
105
    fprintf(outfile, "\t *** Failed to Converge Perturbed Wave Function to %2.1e.\n", params.convergence);
 
106
    fflush(outfile);
 
107
    dpd_close(0);
 
108
    cleanup();
 
109
    exit_io();
 
110
    exit(PSI_RETURN_FAILURE);
 
111
  }
 
112
 
 
113
  /* Clean up disk space */
 
114
  psio_close(CC_DIIS_AMP, 0);
 
115
  psio_close(CC_DIIS_ERR, 0);
 
116
 
 
117
  psio_open(CC_DIIS_AMP, 0);
 
118
  psio_open(CC_DIIS_ERR, 0);
 
119
 
 
120
  for(i=CC_TMP; i <= CC_TMP11; i++) {
 
121
    psio_close(i,0);
 
122
    psio_open(i,0);
 
123
  }
 
124
 
 
125
  /*  print_X(pert, cart, irrep, omega); */
 
126
}
 
127
 
 
128
}} // namespace psi::ccresponse