amp_write.cc

Go to the documentation of this file.
00001 
00006 #include <stdio.h>
00007 #include <stdlib.h>
00008 #include <string.h>
00009 #include <math.h>
00010 #include <libdpd/dpd.h>
00011 #include "MOInfo.h"
00012 #include "Params.h"
00013 #include "Local.h"
00014 #define EXTERN
00015 #include "globals.h"
00016 
00017 namespace psi { namespace ccresponse {
00018 
00019 struct onestack {
00020     double value;
00021     int i;
00022     int a;
00023 };
00024 
00025 struct twostack {
00026     double value;
00027     int i; int j;
00028     int a; int b;
00029 };
00030 
00031 void onestack_insert(struct onestack *stack, double value, int i, int a, 
00032     int level, int stacklen);
00033 void twostack_insert(struct twostack *stack, double value, int i, int j, 
00034     int a, int b, int level, int stacklen);
00035 void amp_write_T1(dpdfile2 *T1, int length, char *label, FILE *outfile);
00036 void amp_write_T2(dpdbuf4 *T2, int length, char *label, FILE *outfile);
00037 
00038 void amp_write(char *pert, char *cart, int irrep, double omega)
00039 {
00040   dpdfile2 T1;
00041   dpdbuf4 T2;
00042   char lbl[32];
00043 
00044   if(params.ref == 0) { 
00045     sprintf(lbl, "X_%s_%1s_IA (%5.3f)", pert, cart, omega);
00046     dpd_file2_init(&T1, CC_OEI, irrep, 0, 1, lbl);
00047     amp_write_T1(&T1, params.num_amps, "\n\tLargest XIA Amplitudes:\n", outfile);
00048     dpd_file2_close(&T1);
00049 
00050     sprintf(lbl, "X_%s_%1s_IjAb (%5.3f)", pert, cart, omega);
00051     dpd_buf4_init(&T2, CC_LR, irrep, 0, 5, 0, 5, 0, lbl);
00052     amp_write_T2(&T2, params.num_amps, "\n\tLargest XIjAb Amplitudes:\n", outfile);
00053     dpd_buf4_close(&T2);
00054   }
00055 }
00056 
00057 void amp_write_T1(dpdfile2 *T1, int length, char *label, FILE *outfile)
00058 {
00059   int m, h, nirreps, Gia;
00060   int i, I, a, A, numt1;
00061   int num2print=0;
00062   double value;
00063   struct onestack *t1stack;
00064 
00065   nirreps = T1->params->nirreps;
00066   Gia = T1->my_irrep;
00067 
00068   t1stack = (struct onestack *) malloc(length * sizeof(struct onestack));
00069   for(m=0; m < length; m++) { t1stack[m].value = 0; t1stack[m].i = 0; t1stack[m].a = 0; }
00070 
00071   dpd_file2_mat_init(T1);
00072   dpd_file2_mat_rd(T1);
00073 
00074   numt1 = 0;
00075   for(h=0; h < nirreps; h++) {
00076 
00077     numt1 += T1->params->rowtot[h] * T1->params->coltot[h^Gia];
00078 
00079     for(i=0; i < T1->params->rowtot[h]; i++) {
00080       I = T1->params->roworb[h][i];
00081       for(a=0; a < T1->params->coltot[h^Gia]; a++) {
00082         A = T1->params->colorb[h][a];
00083         value = T1->matrix[h][i][a];
00084         for(m=0; m < length; m++) {
00085           if((fabs(value) - fabs(t1stack[m].value)) > 1e-12) {
00086             onestack_insert(t1stack, value, I, A, m, length);
00087             break;
00088           }
00089         }
00090       }
00091     }
00092   }
00093 
00094   dpd_file2_mat_close(T1);
00095 
00096   for(m=0; m < ((numt1 < length) ? numt1 : length); m++)
00097     if(fabs(t1stack[m].value) > 1e-8) num2print++;
00098 
00099   if(num2print) fprintf(outfile, "%s", label);
00100 
00101   for(m=0; m < ((numt1 < length) ? numt1 : length); m++)
00102     if(fabs(t1stack[m].value) > 1e-8)
00103       fprintf(outfile, "\t        %3d %3d %20.10f\n", t1stack[m].i, t1stack[m].a, t1stack[m].value);
00104 
00105   free(t1stack);
00106 }
00107 
00108 void onestack_insert(struct onestack *stack, double value, int i, int a, int level, int stacklen)
00109 {
00110   int l;
00111   struct onestack temp;
00112 
00113   temp = stack[level];
00114 
00115   stack[level].value = value;
00116   stack[level].i = i;
00117   stack[level].a = a;
00118 
00119   value = temp.value;
00120   i = temp.i;
00121   a = temp.a;
00122 
00123   for(l=level; l < stacklen-1; l++) {
00124     temp = stack[l+1];
00125 
00126     stack[l+1].value = value;
00127     stack[l+1].i = i;
00128     stack[l+1].a = a;
00129 
00130     value = temp.value;
00131     i = temp.i;
00132     a = temp.a;
00133   }
00134 }
00135 
00136 void amp_write_T2(dpdbuf4 *T2, int length, char *label, FILE *outfile)
00137 {
00138   int m, h, nirreps, Gijab, numt2;
00139   int ij, ab, i, j, a, b;
00140   int num2print=0;
00141   double value;
00142   struct twostack *t2stack;
00143 
00144   nirreps = T2->params->nirreps;
00145   Gijab = T2->file.my_irrep;
00146 
00147   t2stack = (struct twostack *) malloc(length * sizeof(struct twostack));
00148   for(m=0; m < length; m++) { 
00149     t2stack[m].value = 0; 
00150     t2stack[m].i = 0; t2stack[m].j = 0;
00151     t2stack[m].a = 0; t2stack[m].b = 0;
00152   }
00153 
00154   numt2 = 0;
00155   for(h=0; h < nirreps; h++) {
00156     dpd_buf4_mat_irrep_init(T2, h);
00157     dpd_buf4_mat_irrep_rd(T2, h);
00158 
00159     numt2 += T2->params->rowtot[h] * T2->params->coltot[h^Gijab];
00160 
00161     for(ij=0; ij < T2->params->rowtot[h]; ij++) {
00162       i = T2->params->roworb[h][ij][0];
00163       j = T2->params->roworb[h][ij][1];
00164       for(ab=0; ab < T2->params->coltot[h^Gijab]; ab++) {
00165         a = T2->params->colorb[h^Gijab][ab][0];
00166         b = T2->params->colorb[h^Gijab][ab][1];
00167 
00168         value = T2->matrix[h][ij][ab];
00169 
00170         for(m=0; m < length; m++) {
00171           if((fabs(value) - fabs(t2stack[m].value)) > 1e-12) {
00172             twostack_insert(t2stack, value, i, j, a, b, m, length);
00173             break;
00174           }
00175         }
00176       }
00177     }
00178 
00179     dpd_buf4_mat_irrep_close(T2, h);
00180   }
00181 
00182   for(m=0; m < ((numt2 < length) ? numt2 : length); m++)
00183     if(fabs(t2stack[m].value) > 1e-8) num2print++;
00184 
00185   if(num2print) fprintf(outfile, "%s", label);
00186 
00187   for(m=0; m < ((numt2 < length) ? numt2 : length); m++)
00188     if(fabs(t2stack[m].value) > 1e-8)
00189       fprintf(outfile, "\t%3d %3d %3d %3d %20.10f\n", t2stack[m].i, t2stack[m].j, 
00190               t2stack[m].a, t2stack[m].b, t2stack[m].value);
00191 
00192   free(t2stack);
00193 }
00194 
00195 void twostack_insert(struct twostack *stack, double value, int i, int j, int a, int b, 
00196                      int level, int stacklen)
00197 {
00198   int l;
00199   struct twostack temp;
00200 
00201   temp = stack[level];
00202 
00203   stack[level].value = value;
00204   stack[level].i = i;
00205   stack[level].j = j;
00206   stack[level].a = a;
00207   stack[level].b = b;
00208 
00209   value = temp.value;
00210   i = temp.i;
00211   j = temp.j;
00212   a = temp.a;
00213   b = temp.b;
00214 
00215   for(l=level; l < stacklen-1; l++) {
00216     temp = stack[l+1];
00217 
00218     stack[l+1].value = value;
00219     stack[l+1].i = i;
00220     stack[l+1].j = j;
00221     stack[l+1].a = a;
00222     stack[l+1].b = b;
00223 
00224     value = temp.value;
00225     i = temp.i;
00226     j = temp.j;
00227     a = temp.a;
00228     b = temp.b;
00229   }
00230 }
00231 
00232 
00233 }} // namespace psi::ccresponse

Generated on Wed Feb 13 16:35:39 2008 for PSI by  doxygen 1.5.4