3
\brief Enter brief description of file here
12
/* dpd_buf4_mat_irrep_wrt(): Writes an entire irrep from disk into a dpd
13
** four-index buffer using the "rules" specified when the buffer was
14
** initialized by dpd_buf4_init().
17
** dpdbuf4 *Buf: A pointer to the dpdbuf where the data is
19
** int irrep: The irrep number to be written.
21
** The case numbers are the same as those from buf4_mat_irrep_rd().
22
** Unpacking indices on the write has not been tested, and should be currently
28
** Modified for caching.
33
int dpd_buf4_mat_irrep_wrt(dpdbuf4 *Buf, int irrep)
35
int method, filerow, all_buf_irrep;
36
int pq, rs; /* dpdfile row and column indices */
37
int p, q, r, s; /* orbital indices */
38
int bufpq, bufrs; /* Input dpdbuf row and column indices */
39
int rowtot, coltot; /* dpdfile row and column dimensions */
40
int b_perm_pq, b_perm_rs, b_peq, b_res;
41
int f_perm_pq, f_perm_rs, f_peq, f_res;
46
all_buf_irrep = Buf->file.my_irrep;
48
/* Row and column dimensions in the DPD file */
49
rowtot = Buf->file.params->rowtot[irrep];
50
coltot = Buf->file.params->coltot[irrep^all_buf_irrep];
51
size = ((long) rowtot) * ((long) coltot);
53
/* Index packing information */
54
b_perm_pq = Buf->params->perm_pq; b_perm_rs = Buf->params->perm_rs;
55
f_perm_pq = Buf->file.params->perm_pq; f_perm_rs = Buf->file.params->perm_rs;
56
b_peq = Buf->params->peq; b_res = Buf->params->res;
57
f_peq = Buf->file.params->peq; f_res = Buf->file.params->res;
59
/* Exit if buffer is antisymmetrized */
61
printf("\n\tCannot write antisymmetrized buffer\n");
62
printf( "\tback to original DPD file!\n");
63
exit(PSI_RETURN_FAILURE);
66
if((b_perm_pq == f_perm_pq) && (b_perm_rs == f_perm_rs) &&
67
(b_peq == f_peq) && (b_res == f_res)) method = 12;
68
else if((b_perm_pq != f_perm_pq) && (b_perm_rs == f_perm_rs) &&
70
if(f_perm_pq && !b_perm_pq) method = 21;
71
else if(!f_perm_pq && b_perm_pq) method = 23;
73
printf("\n\tInvalid second-level method!\n");
74
exit(PSI_RETURN_FAILURE);
77
else if((b_perm_pq == f_perm_pq) && (b_perm_rs != f_perm_rs) &&
79
if(f_perm_rs && !b_perm_rs) method = 31;
80
else if(!f_perm_rs && b_perm_rs) method = 33;
82
printf("\n\tInvalid third-level method!\n");
83
exit(PSI_RETURN_FAILURE);
86
else if((b_perm_pq != f_perm_pq) && (b_perm_rs != f_perm_rs)) {
87
if(f_perm_pq && !b_perm_pq) {
88
if(f_perm_rs && !b_perm_rs) method = 41;
89
else if(!f_perm_rs && b_perm_rs) method = 42;
91
else if(!f_perm_pq && b_perm_pq) {
92
if(f_perm_rs && !b_perm_rs) method = 43;
93
else if(!f_perm_rs && b_perm_rs) method = 45;
96
printf("\n\tInvalid fourth-level method!\n");
97
exit(PSI_RETURN_FAILURE);
101
printf("\n\tInvalid method in dpd_buf_mat_irrep_rd!\n");
102
exit(PSI_RETURN_FAILURE);
107
case 12: /* No change in pq or rs */
110
timer_on("buf_wrt_12");
113
if(Buf->file.incore && size) {
114
dpd_file4_cache_dirty(&(Buf->file));
117
memcpy((void *) &(Buf->file.matrix[irrep][0][0]),
118
(const void *) &(Buf->matrix[irrep][0][0]),
119
sizeof(double)*rowtot*coltot);
122
Buf->file.matrix[irrep] = Buf->matrix[irrep];
123
dpd_file4_mat_irrep_wrt(&(Buf->file), irrep);
127
timer_off("buf_wrt_12");
131
case 21: /* Pack pq; no change in rs */
132
/* Prepare the output buffer for the output DPD file */
133
dpd_file4_mat_irrep_row_init(&(Buf->file), irrep);
135
/* Loop over rows in the dpdfile */
136
for(pq=0; pq < rowtot; pq++) {
137
p = Buf->file.params->roworb[irrep][pq][0];
138
q = Buf->file.params->roworb[irrep][pq][1];
139
bufpq = Buf->params->rowidx[p][q];
140
filerow = Buf->file.incore ? pq : 0;
142
/* Loop over the columns in the dpdbuf */
143
for(rs=0; rs < coltot; rs++) {
146
value = Buf->matrix[irrep][bufpq][bufrs];
148
/* Assign the value */
149
Buf->file.matrix[irrep][filerow][rs] = value;
152
/* Write out the row */
153
dpd_file4_mat_irrep_row_wrt(&(Buf->file), irrep, pq);
156
/* Close the input buffer */
157
dpd_file4_mat_irrep_row_close(&(Buf->file), irrep);
160
case 23: /* Unpack pq; no change in rs */
161
/* I don't know if I'll ever use this, so I'll avoid it for now */
162
printf("\n\tShould you be using method %d?\n", method);
163
exit(PSI_RETURN_FAILURE);
164
/* Prepare the output buffer for the output DPD file */
165
dpd_file4_mat_irrep_row_init(&(Buf->file), irrep);
167
/* Loop over rows in the dpdfile */
168
for(pq=0; pq < rowtot; pq++) {
169
p = Buf->file.params->roworb[irrep][pq][0];
170
q = Buf->file.params->roworb[irrep][pq][1];
171
bufpq = Buf->params->rowidx[p][q];
173
filerow = Buf->file.incore ? pq : 0;
175
/* Set the permutation operator's value */
176
permute = ((p < q) && (b_perm_pq < 0) ? -1 : 1);
178
/* Loop over the columns in the dpdbuf */
179
for(rs=0; rs < coltot; rs++) {
182
value = Buf->matrix[irrep][bufpq][bufrs];
184
/* Assign the value */
185
Buf->file.matrix[irrep][filerow][rs] = permute*value;
188
/* Write out the row */
189
dpd_file4_mat_irrep_row_wrt(&(Buf->file), irrep, pq);
192
/* Close the input buffer */
193
dpd_file4_mat_irrep_row_close(&(Buf->file), irrep);
196
case 31: /* No change in pq; pack rs */
197
/* Prepare the output buffer for the output DPD file */
198
dpd_file4_mat_irrep_row_init(&(Buf->file), irrep);
200
/* Loop over rows in the dpdbuf/dpdfile */
201
for(pq=0; pq < rowtot; pq++) {
204
filerow = Buf->file.incore ? pq : 0;
206
/* Loop over the columns in the dpdfile */
207
for(rs=0; rs < coltot; rs++) {
208
r = Buf->file.params->colorb[irrep^all_buf_irrep][rs][0];
209
s = Buf->file.params->colorb[irrep^all_buf_irrep][rs][1];
210
bufrs = Buf->params->colidx[r][s];
212
value = Buf->matrix[irrep][bufpq][bufrs];
214
/* Assign the value */
215
Buf->file.matrix[irrep][filerow][rs] = value;
218
/* Write out the row */
219
dpd_file4_mat_irrep_row_wrt(&(Buf->file), irrep, pq);
222
/* Close the input buffer */
223
dpd_file4_mat_irrep_row_close(&(Buf->file), irrep);
226
case 33: /* No change in pq; unpack rs */
227
/* I'm not sure if I'll ever need this, so I'm removing it for now */
228
printf("\n\tShould you be using method %d?\n", method);
229
exit(PSI_RETURN_FAILURE);
230
/* Prepare the output buffer for the output DPD file */
231
dpd_file4_mat_irrep_row_init(&(Buf->file), irrep);
233
/* Loop over rows in the dpdbuf/dpdfile */
234
for(pq=0; pq < rowtot; pq++) {
237
filerow = Buf->file.incore ? pq : 0;
239
/* Loop over the columns in the dpdfile */
240
for(rs=0; rs < coltot; rs++) {
241
r = Buf->file.params->colorb[irrep^all_buf_irrep][rs][0];
242
s = Buf->file.params->colorb[irrep^all_buf_irrep][rs][1];
243
bufrs = Buf->params->colidx[r][s];
245
value = Buf->matrix[irrep][bufpq][bufrs];
247
/* Assign the value */
248
Buf->file.matrix[irrep][filerow][rs] = value;
251
/* Write out the row */
252
dpd_file4_mat_irrep_row_wrt(&(Buf->file), irrep, pq);
255
/* Close the input buffer */
256
dpd_file4_mat_irrep_row_close(&(Buf->file), irrep);
259
case 41: /* Pack pq and rs */
260
/* Prepare the output buffer for the output DPD file */
261
dpd_file4_mat_irrep_row_init(&(Buf->file), irrep);
263
/* Loop over rows in the dpdfile */
264
for(pq=0; pq < rowtot; pq++) {
265
p = Buf->file.params->roworb[irrep][pq][0];
266
q = Buf->file.params->roworb[irrep][pq][1];
267
bufpq = Buf->params->rowidx[p][q];
269
filerow = Buf->file.incore ? pq : 0;
271
/* Loop over the columns in the dpdfile */
272
for(rs=0; rs < coltot; rs++) {
273
r = Buf->file.params->colorb[irrep^all_buf_irrep][rs][0];
274
s = Buf->file.params->colorb[irrep^all_buf_irrep][rs][1];
275
bufrs = Buf->params->colidx[r][s];
277
value = Buf->matrix[irrep][bufpq][bufrs];
279
/* Assign the value */
280
Buf->file.matrix[irrep][filerow][rs] = value;
283
/* Write out the row */
284
dpd_file4_mat_irrep_row_wrt(&(Buf->file), irrep, pq);
287
/* Close the input buffer */
288
dpd_file4_mat_irrep_row_close(&(Buf->file), irrep);
291
case 42: /* Pack pq; unpack rs */
292
printf("\n\tHaven't programmed method 42 yet!\n");
293
exit(PSI_RETURN_FAILURE);
296
case 43: /* Unpack pq; pack rs */
297
printf("\n\tHaven't programmed method 43 yet!\n");
298
exit(PSI_RETURN_FAILURE);
301
case 45: /* Unpack pq and rs */
302
/* I'm not sure if I'll ever need this, so I'm removing it for now */
303
printf("\n\tShould you be using method %d?\n", method);
304
exit(PSI_RETURN_FAILURE);
305
/* Prepare the output buffer for the output DPD file */
306
dpd_file4_mat_irrep_row_init(&(Buf->file), irrep);
308
/* Loop over rows in the dpdfile */
309
for(pq=0; pq < rowtot; pq++) {
310
p = Buf->file.params->roworb[irrep][pq][0];
311
q = Buf->file.params->roworb[irrep][pq][1];
312
bufpq = Buf->params->rowidx[p][q];
314
filerow = Buf->file.incore ? pq : 0;
316
/* Loop over the columns in the dpdfile */
317
for(rs=0; rs < coltot; rs++) {
318
r = Buf->file.params->colorb[irrep^all_buf_irrep][rs][0];
319
s = Buf->file.params->colorb[irrep^all_buf_irrep][rs][1];
320
bufrs = Buf->params->colidx[r][s];
322
value = Buf->matrix[irrep][bufpq][bufrs];
324
/* Assign the value */
325
Buf->file.matrix[irrep][filerow][rs] = value;
328
/* Write out the row */
329
dpd_file4_mat_irrep_row_wrt(&(Buf->file), irrep, pq);
332
/* Close the input buffer */
333
dpd_file4_mat_irrep_row_close(&(Buf->file), irrep);
336
default: /* Error trapping */
337
printf("\n\tInvalid switch case in dpd_buf_mat_irrep_rd!\n");
338
exit(PSI_RETURN_FAILURE);