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