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

« back to all changes in this revision

Viewing changes to src/lib/libdpd/buf4_mat_irrep_wrt.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 DPD
 
3
    \brief Enter brief description of file here 
 
4
*/
 
5
#include <cstdio>
 
6
#include <cstdlib>
 
7
#include <libqt/qt.h>
 
8
#include "dpd.h"
 
9
 
 
10
extern "C" {
 
11
 
 
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().
 
15
**
 
16
** Arguments:
 
17
**   dpdbuf4 *Buf: A pointer to the dpdbuf where the data is
 
18
**                       stored.
 
19
**   int irrep: The irrep number to be written.
 
20
**
 
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
 
23
** disabled.
 
24
**
 
25
** T. Daniel Crawford
 
26
** December 1996
 
27
**
 
28
** Modified for caching.
 
29
** TDC
 
30
** September 1999
 
31
*/
 
32
 
 
33
int dpd_buf4_mat_irrep_wrt(dpdbuf4 *Buf, int irrep)
 
34
{
 
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;
 
42
  int permute;
 
43
  double value;
 
44
  long int size;
 
45
 
 
46
  all_buf_irrep = Buf->file.my_irrep;
 
47
 
 
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);
 
52
 
 
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;
 
58
 
 
59
  /* Exit if buffer is antisymmetrized */
 
60
  if(Buf->anti) {
 
61
      printf("\n\tCannot write antisymmetrized buffer\n");
 
62
      printf(  "\tback to original DPD file!\n");
 
63
      exit(PSI_RETURN_FAILURE);
 
64
    }
 
65
 
 
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) &&
 
69
          (b_res == f_res)) {
 
70
      if(f_perm_pq && !b_perm_pq) method = 21;
 
71
      else if(!f_perm_pq && b_perm_pq) method = 23;
 
72
      else {
 
73
          printf("\n\tInvalid second-level method!\n");
 
74
          exit(PSI_RETURN_FAILURE);
 
75
        }
 
76
    }
 
77
  else if((b_perm_pq == f_perm_pq) && (b_perm_rs != f_perm_rs) &&
 
78
          (b_peq == f_peq)) {
 
79
      if(f_perm_rs && !b_perm_rs) method = 31;
 
80
      else if(!f_perm_rs && b_perm_rs) method = 33;
 
81
      else {
 
82
          printf("\n\tInvalid third-level method!\n");
 
83
          exit(PSI_RETURN_FAILURE);
 
84
        }
 
85
    }
 
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;
 
90
        }
 
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;
 
94
        }
 
95
      else {
 
96
          printf("\n\tInvalid fourth-level method!\n");
 
97
          exit(PSI_RETURN_FAILURE);
 
98
        }
 
99
    }
 
100
  else {
 
101
      printf("\n\tInvalid method in dpd_buf_mat_irrep_rd!\n");
 
102
      exit(PSI_RETURN_FAILURE);
 
103
    }
 
104
 
 
105
 
 
106
  switch(method) {
 
107
  case 12: /* No change in pq or rs */
 
108
 
 
109
#ifdef DPD_TIMER
 
110
      timer_on("buf_wrt_12");
 
111
#endif
 
112
 
 
113
      if(Buf->file.incore && size) {
 
114
          dpd_file4_cache_dirty(&(Buf->file));
 
115
        }
 
116
/*
 
117
          memcpy((void *) &(Buf->file.matrix[irrep][0][0]),
 
118
                 (const void *) &(Buf->matrix[irrep][0][0]),
 
119
                 sizeof(double)*rowtot*coltot);
 
120
*/
 
121
      else {
 
122
          Buf->file.matrix[irrep] = Buf->matrix[irrep];
 
123
          dpd_file4_mat_irrep_wrt(&(Buf->file), irrep);
 
124
        }
 
125
 
 
126
#ifdef DPD_TIMER
 
127
      timer_off("buf_wrt_12");
 
128
#endif
 
129
      
 
130
      break;
 
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);
 
134
 
 
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;
 
141
 
 
142
          /* Loop over the columns in the dpdbuf */
 
143
          for(rs=0; rs < coltot; rs++) {
 
144
              bufrs = rs;
 
145
 
 
146
              value = Buf->matrix[irrep][bufpq][bufrs];
 
147
 
 
148
              /* Assign the value */
 
149
              Buf->file.matrix[irrep][filerow][rs] = value;
 
150
            }
 
151
 
 
152
          /* Write out the row */
 
153
          dpd_file4_mat_irrep_row_wrt(&(Buf->file), irrep, pq);
 
154
        }
 
155
 
 
156
      /* Close the input buffer */
 
157
      dpd_file4_mat_irrep_row_close(&(Buf->file), irrep);
 
158
 
 
159
      break;
 
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);
 
166
 
 
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];
 
172
 
 
173
          filerow = Buf->file.incore ? pq : 0;
 
174
 
 
175
          /* Set the permutation operator's value */
 
176
          permute = ((p < q) && (b_perm_pq < 0) ? -1 : 1);
 
177
 
 
178
          /* Loop over the columns in the dpdbuf */
 
179
          for(rs=0; rs < coltot; rs++) {
 
180
              bufrs = rs;
 
181
 
 
182
              value = Buf->matrix[irrep][bufpq][bufrs];
 
183
 
 
184
              /* Assign the value */
 
185
              Buf->file.matrix[irrep][filerow][rs] = permute*value;
 
186
            }
 
187
 
 
188
          /* Write out the row */
 
189
          dpd_file4_mat_irrep_row_wrt(&(Buf->file), irrep, pq);
 
190
        }
 
191
 
 
192
      /* Close the input buffer */
 
193
      dpd_file4_mat_irrep_row_close(&(Buf->file), irrep);
 
194
 
 
195
      break;
 
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);
 
199
 
 
200
      /* Loop over rows in the dpdbuf/dpdfile */
 
201
      for(pq=0; pq < rowtot; pq++) {
 
202
          bufpq = pq;
 
203
 
 
204
          filerow = Buf->file.incore ? pq : 0;
 
205
 
 
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];
 
211
 
 
212
              value = Buf->matrix[irrep][bufpq][bufrs];
 
213
 
 
214
              /* Assign the value */
 
215
              Buf->file.matrix[irrep][filerow][rs] = value;
 
216
            }
 
217
 
 
218
          /* Write out the row */
 
219
          dpd_file4_mat_irrep_row_wrt(&(Buf->file), irrep, pq);
 
220
        }
 
221
 
 
222
      /* Close the input buffer */
 
223
      dpd_file4_mat_irrep_row_close(&(Buf->file), irrep);
 
224
 
 
225
      break;
 
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);
 
232
 
 
233
      /* Loop over rows in the dpdbuf/dpdfile */
 
234
      for(pq=0; pq < rowtot; pq++) {
 
235
          bufpq = pq;
 
236
 
 
237
          filerow = Buf->file.incore ? pq : 0;
 
238
 
 
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];
 
244
 
 
245
              value = Buf->matrix[irrep][bufpq][bufrs];
 
246
 
 
247
              /* Assign the value */
 
248
              Buf->file.matrix[irrep][filerow][rs] = value;
 
249
            }
 
250
 
 
251
          /* Write out the row */
 
252
          dpd_file4_mat_irrep_row_wrt(&(Buf->file), irrep, pq);
 
253
        }
 
254
 
 
255
      /* Close the input buffer */
 
256
      dpd_file4_mat_irrep_row_close(&(Buf->file), irrep);
 
257
 
 
258
      break;
 
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);
 
262
 
 
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];
 
268
 
 
269
          filerow = Buf->file.incore ? pq : 0;
 
270
 
 
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];
 
276
 
 
277
              value = Buf->matrix[irrep][bufpq][bufrs];
 
278
 
 
279
              /* Assign the value */
 
280
              Buf->file.matrix[irrep][filerow][rs] = value;
 
281
            }
 
282
 
 
283
          /* Write out the row */
 
284
          dpd_file4_mat_irrep_row_wrt(&(Buf->file), irrep, pq);
 
285
        }
 
286
 
 
287
      /* Close the input buffer */
 
288
      dpd_file4_mat_irrep_row_close(&(Buf->file), irrep);
 
289
 
 
290
      break;
 
291
  case 42: /* Pack pq; unpack rs */
 
292
      printf("\n\tHaven't programmed method 42 yet!\n");
 
293
      exit(PSI_RETURN_FAILURE);
 
294
 
 
295
      break;
 
296
  case 43: /* Unpack pq; pack rs */
 
297
      printf("\n\tHaven't programmed method 43 yet!\n");
 
298
      exit(PSI_RETURN_FAILURE);
 
299
 
 
300
      break;
 
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);
 
307
 
 
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];
 
313
 
 
314
          filerow = Buf->file.incore ? pq : 0;
 
315
 
 
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];
 
321
 
 
322
              value = Buf->matrix[irrep][bufpq][bufrs];
 
323
 
 
324
              /* Assign the value */
 
325
              Buf->file.matrix[irrep][filerow][rs] = value;
 
326
            }
 
327
 
 
328
          /* Write out the row */
 
329
          dpd_file4_mat_irrep_row_wrt(&(Buf->file), irrep, pq);
 
330
        }
 
331
 
 
332
      /* Close the input buffer */
 
333
      dpd_file4_mat_irrep_row_close(&(Buf->file), irrep);
 
334
 
 
335
      break;
 
336
  default:  /* Error trapping */
 
337
      printf("\n\tInvalid switch case in dpd_buf_mat_irrep_rd!\n");
 
338
      exit(PSI_RETURN_FAILURE);
 
339
      break;
 
340
    }
 
341
  
 
342
  return 0;
 
343
 
 
344
}
 
345
 
 
346
} /* extern "C" */