amp_write.cc

Go to the documentation of this file.
00001 
00005 #include <stdio.h>
00006 #include <stdlib.h>
00007 #include <math.h>
00008 #include <libdpd/dpd.h>
00009 
00010 namespace psi { namespace cceom {
00011 
00012 struct onestack {
00013     double value;
00014     int i;
00015     int a;
00016 };
00017 
00018 struct twostack {
00019     double value;
00020     int i; int j;
00021     int a; int b;
00022 };
00023 
00024 void onestack_insert(struct onestack *stack, double value, int i, int a, int level, int stacklen);
00025 void twostack_insert(struct twostack *stack, double value, int i, int j, int a, int b, 
00026                      int level, int stacklen);
00027 
00028 void amp_write_T1(dpdfile2 *T1, int length, FILE *outfile)
00029 {
00030   int m, h, nirreps, Gia;
00031   int i, I, a, A, numt1;
00032   double value;
00033   struct onestack *t1stack;
00034 
00035   nirreps = T1->params->nirreps;
00036   Gia = T1->my_irrep;
00037 
00038   t1stack = (struct onestack *) malloc(length * sizeof(struct onestack));
00039   for(m=0; m < length; m++) { t1stack[m].value = 0; t1stack[m].i = 0; t1stack[m].a = 0; }
00040 
00041   dpd_file2_mat_init(T1);
00042   dpd_file2_mat_rd(T1);
00043 
00044   numt1 = 0;
00045   for(h=0; h < nirreps; h++) {
00046 
00047     numt1 += T1->params->rowtot[h] * T1->params->coltot[h^Gia];
00048 
00049     for(i=0; i < T1->params->rowtot[h]; i++) {
00050       I = T1->params->roworb[h][i];
00051       for(a=0; a < T1->params->coltot[h^Gia]; a++) {
00052         A = T1->params->colorb[h^Gia][a];
00053         value = T1->matrix[h][i][a];
00054         for(m=0; m < length; m++) {
00055           if((fabs(value) - fabs(t1stack[m].value)) > 1e-12) {
00056             onestack_insert(t1stack, value, I, A, m, length);
00057             break;
00058           }
00059         }
00060       }
00061     }
00062   }
00063 
00064   dpd_file2_mat_close(T1);
00065 
00066   for(m=0; m < ((numt1 < length) ? numt1 : length); m++)
00067     if(fabs(t1stack[m].value) > 1e-6)
00068       fprintf(outfile, "\t        %3d %3d %20.10f\n", t1stack[m].i, t1stack[m].a, t1stack[m].value);
00069 
00070   free(t1stack);
00071 }
00072 
00073 void onestack_insert(struct onestack *stack, double value, int i, int a, int level, int stacklen)
00074 {
00075   int l;
00076   struct onestack temp;
00077 
00078   temp = stack[level];
00079 
00080   stack[level].value = value;
00081   stack[level].i = i;
00082   stack[level].a = a;
00083 
00084   value = temp.value;
00085   i = temp.i;
00086   a = temp.a;
00087 
00088   for(l=level; l < stacklen-1; l++) {
00089     temp = stack[l+1];
00090 
00091     stack[l+1].value = value;
00092     stack[l+1].i = i;
00093     stack[l+1].a = a;
00094 
00095     value = temp.value;
00096     i = temp.i;
00097     a = temp.a;
00098   }
00099 }
00100 
00101 void amp_write_T2(dpdbuf4 *T2, int length, FILE *outfile)
00102 {
00103   int m, h, nirreps, Gijab, numt2;
00104   int ij, ab, i, j, a, b;
00105   double value;
00106   struct twostack *t2stack;
00107 
00108   nirreps = T2->params->nirreps;
00109   Gijab = T2->file.my_irrep;
00110 
00111   t2stack = (struct twostack *) malloc(length * sizeof(struct twostack));
00112   for(m=0; m < length; m++) { 
00113     t2stack[m].value = 0; 
00114     t2stack[m].i = 0; t2stack[m].j = 0;
00115     t2stack[m].a = 0; t2stack[m].b = 0;
00116   }
00117 
00118   numt2 = 0;
00119   for(h=0; h < nirreps; h++) {
00120     dpd_buf4_mat_irrep_init(T2, h);
00121     dpd_buf4_mat_irrep_rd(T2, h);
00122 
00123     numt2 += T2->params->rowtot[h] * T2->params->coltot[h^Gijab];
00124 
00125     for(ij=0; ij < T2->params->rowtot[h]; ij++) {
00126       i = T2->params->roworb[h][ij][0];
00127       j = T2->params->roworb[h][ij][1];
00128       for(ab=0; ab < T2->params->coltot[h^Gijab]; ab++) {
00129         a = T2->params->colorb[h^Gijab][ab][0];
00130         b = T2->params->colorb[h^Gijab][ab][1];
00131 
00132         value = T2->matrix[h][ij][ab];
00133 
00134         for(m=0; m < length; m++) {
00135           if((fabs(value) - fabs(t2stack[m].value)) > 1e-12) {
00136             twostack_insert(t2stack, value, i, j, a, b, m, length);
00137             break;
00138           }
00139         }
00140       }
00141     }
00142 
00143     dpd_buf4_mat_irrep_close(T2, h);
00144   }
00145 
00146   for(m=0; m < ((numt2 < length) ? numt2 : length); m++)
00147     if(fabs(t2stack[m].value) > 1e-6)
00148       fprintf(outfile, "\t%3d %3d %3d %3d %20.10f\n", t2stack[m].i, t2stack[m].j, 
00149               t2stack[m].a, t2stack[m].b, t2stack[m].value);
00150 
00151   free(t2stack);
00152 }
00153 
00154 void twostack_insert(struct twostack *stack, double value, int i, int j, int a, int b, 
00155                      int level, int stacklen)
00156 {
00157   int l;
00158   struct twostack temp;
00159 
00160   temp = stack[level];
00161 
00162   stack[level].value = value;
00163   stack[level].i = i;
00164   stack[level].j = j;
00165   stack[level].a = a;
00166   stack[level].b = b;
00167 
00168   value = temp.value;
00169   i = temp.i;
00170   j = temp.j;
00171   a = temp.a;
00172   b = temp.b;
00173 
00174   for(l=level; l < stacklen-1; l++) {
00175     temp = stack[l+1];
00176 
00177     stack[l+1].value = value;
00178     stack[l+1].i = i;
00179     stack[l+1].j = j;
00180     stack[l+1].a = a;
00181     stack[l+1].b = b;
00182 
00183     value = temp.value;
00184     i = temp.i;
00185     j = temp.j;
00186     a = temp.a;
00187     b = temp.b;
00188   }
00189 }
00190 
00191 
00192 }} // namespace psi::cceom

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