~ubuntu-branches/ubuntu/precise/psicode/precise

« back to all changes in this revision

Viewing changes to src/lib/libdpd/buf4_mat_irrep_row_wrt.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck
  • Date: 2006-09-10 14:01:33 UTC
  • Revision ID: james.westby@ubuntu.com-20060910140133-ib2j86trekykfsfv
Tags: upstream-3.2.3
ImportĀ upstreamĀ versionĀ 3.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include "dpd.h"
 
3
 
 
4
int dpd_buf4_mat_irrep_row_wrt(dpdbuf4 *Buf, int irrep, int pq)
 
5
{
 
6
  int method, filerow, all_buf_irrep;
 
7
  int rs;  /* dpdfile row and column indices */
 
8
  int p, q, r, s;  /* orbital indices */
 
9
  int bufpq, bufrs;  /* Input dpdbuf row and column indices */
 
10
  int filepq;
 
11
  int rowtot, coltot;  /* dpdfile row and column dimensions */
 
12
  int b_perm_pq, b_perm_rs, b_peq, b_res;
 
13
  int f_perm_pq, f_perm_rs, f_peq, f_res;
 
14
  int permute;
 
15
  double value; 
 
16
 
 
17
  all_buf_irrep = Buf->file.my_irrep;
 
18
  /* Row and column dimensions in the DPD file */
 
19
  rowtot = Buf->file.params->rowtot[irrep];
 
20
  coltot = Buf->file.params->coltot[irrep^all_buf_irrep];
 
21
 
 
22
  /* Index packing information */
 
23
  b_perm_pq = Buf->params->perm_pq; b_perm_rs = Buf->params->perm_rs;
 
24
  f_perm_pq = Buf->file.params->perm_pq; f_perm_rs = Buf->file.params->perm_rs;
 
25
  b_peq = Buf->params->peq; b_res = Buf->params->res;
 
26
  f_peq = Buf->file.params->peq; f_res = Buf->file.params->res;
 
27
 
 
28
  /* Exit if buffer is antisymmetrized */
 
29
  if(Buf->anti) {
 
30
      fprintf(stderr, "\n\tCannot write antisymmetrized buffer\n");
 
31
      fprintf(stderr,   "\tback to original DPD file!\n");
 
32
      exit(PSI_RETURN_FAILURE);
 
33
    }
 
34
 
 
35
  if((b_perm_pq == f_perm_pq) && (b_perm_rs == f_perm_rs) &&
 
36
     (b_peq == f_peq) && (b_res == f_res))   method = 12;
 
37
  else if((b_perm_pq != f_perm_pq) && (b_perm_rs == f_perm_rs) &&
 
38
          (b_res == f_res)) {
 
39
      if(f_perm_pq && !b_perm_pq) method = 21;
 
40
      else if(!f_perm_pq && b_perm_pq) method = 23;
 
41
      else {
 
42
          fprintf(stderr, "\n\tInvalid second-level method!\n");
 
43
          exit(PSI_RETURN_FAILURE);
 
44
        }
 
45
    }
 
46
  else if((b_perm_pq == f_perm_pq) && (b_perm_rs != f_perm_rs) &&
 
47
          (b_peq == f_peq)) {
 
48
      if(f_perm_rs && !b_perm_rs) method = 31;
 
49
      else if(!f_perm_rs && b_perm_rs) method = 33;
 
50
      else {
 
51
          fprintf(stderr, "\n\tInvalid third-level method!\n");
 
52
          exit(PSI_RETURN_FAILURE);
 
53
        }
 
54
    }
 
55
  else if((b_perm_pq != f_perm_pq) && (b_perm_rs != f_perm_rs)) {
 
56
      if(f_perm_pq && !b_perm_pq) {
 
57
          if(f_perm_rs && !b_perm_rs) method = 41;
 
58
          else if(!f_perm_rs && b_perm_rs) method = 42;
 
59
        }
 
60
      else if(!f_perm_pq && b_perm_pq) {
 
61
          if(f_perm_rs && !b_perm_rs) method = 43;
 
62
          else if(!f_perm_rs && b_perm_rs) method = 45;
 
63
        }
 
64
      else {
 
65
          fprintf(stderr, "\n\tInvalid fourth-level method!\n");
 
66
          exit(PSI_RETURN_FAILURE);
 
67
        }
 
68
    }
 
69
  else {
 
70
      fprintf(stderr, "\n\tInvalid method in dpd_buf_mat_irrep_rd!\n");
 
71
      exit(PSI_RETURN_FAILURE);
 
72
    }
 
73
 
 
74
 
 
75
  switch(method) {
 
76
  case 12: /* No change in pq or rs */
 
77
 
 
78
      if(Buf->file.incore) {
 
79
          for(rs=0; rs < rowtot; rs++)
 
80
              Buf->file.matrix[irrep][pq][rs] = Buf->matrix[irrep][0][rs];
 
81
          dpd_file4_cache_dirty(&(Buf->file));
 
82
        }
 
83
      else {
 
84
          Buf->file.matrix[irrep] = Buf->matrix[irrep];
 
85
          dpd_file4_mat_irrep_row_wrt(&(Buf->file), irrep, pq);
 
86
        }
 
87
      
 
88
      break;
 
89
  case 21: /* Pack pq; no change in rs */
 
90
      /* Prepare the output buffer for the output DPD file */
 
91
      dpd_file4_mat_irrep_row_init(&(Buf->file), irrep);
 
92
 
 
93
      p = Buf->file.params->roworb[irrep][pq][0];
 
94
      q = Buf->file.params->roworb[irrep][pq][1];
 
95
      filepq = Buf->file.params->rowidx[p][q];
 
96
 
 
97
      filerow = Buf->file.incore ? filepq : 0;
 
98
 
 
99
      /* Loop over the columns in the dpdbuf */
 
100
      for(rs=0; rs < coltot; rs++) {
 
101
          bufrs = rs;
 
102
 
 
103
          value = Buf->matrix[irrep][0][bufrs];
 
104
 
 
105
          /* Assign the value */
 
106
          Buf->file.matrix[irrep][filerow][rs] = value;
 
107
        }
 
108
 
 
109
      /* Write out the row */
 
110
      dpd_file4_mat_irrep_row_wrt(&(Buf->file), irrep, filepq);
 
111
 
 
112
      /* Close the input buffer */
 
113
      dpd_file4_mat_irrep_row_close(&(Buf->file), irrep);
 
114
 
 
115
      break;
 
116
  case 23: /* Unpack pq; no change in rs */
 
117
      /* I don't know if I'll ever use this, so I'll avoid it for now */
 
118
      fprintf(stderr, "\n\tShould you be using method %d?\n", method);
 
119
      exit(PSI_RETURN_FAILURE);
 
120
 
 
121
      break;
 
122
  case 31: /* No change in pq; pack rs */
 
123
      /* Prepare the output buffer for the output DPD file */
 
124
      dpd_file4_mat_irrep_row_init(&(Buf->file), irrep);
 
125
 
 
126
      filerow = Buf->file.incore ? pq : 0;
 
127
 
 
128
      /* Loop over the columns in the dpdfile */
 
129
      for(rs=0; rs < coltot; rs++) {
 
130
          r = Buf->file.params->colorb[irrep^all_buf_irrep][rs][0];
 
131
          s = Buf->file.params->colorb[irrep^all_buf_irrep][rs][1];
 
132
          bufrs = Buf->params->colidx[r][s];
 
133
 
 
134
          value = Buf->matrix[irrep][0][bufrs];
 
135
 
 
136
          /* Assign the value */
 
137
          Buf->file.matrix[irrep][filerow][rs] = value;
 
138
        }
 
139
 
 
140
      /* Write out the row */
 
141
      dpd_file4_mat_irrep_row_wrt(&(Buf->file), irrep, pq);
 
142
 
 
143
      /* Close the input buffer */
 
144
      dpd_file4_mat_irrep_row_close(&(Buf->file), irrep);
 
145
 
 
146
      break;
 
147
  case 33: /* No change in pq; unpack rs */
 
148
      /* I'm not sure if I'll ever need this, so I'm removing it for now */
 
149
      fprintf(stderr, "\n\tShould you be using method %d?\n", method);
 
150
      exit(PSI_RETURN_FAILURE);
 
151
 
 
152
      break;
 
153
  case 41: /* Pack pq and rs */
 
154
      /* Prepare the output buffer for the output DPD file */
 
155
      dpd_file4_mat_irrep_row_init(&(Buf->file), irrep);
 
156
 
 
157
      p = Buf->file.params->roworb[irrep][pq][0];
 
158
      q = Buf->file.params->roworb[irrep][pq][1];
 
159
      filepq = Buf->file.params->rowidx[p][q];
 
160
 
 
161
      filerow = Buf->file.incore ? filepq : 0;
 
162
 
 
163
 
 
164
      /* Loop over the columns in the dpdfile */
 
165
      for(rs=0; rs < coltot; rs++) {
 
166
          r = Buf->file.params->colorb[irrep^all_buf_irrep][rs][0];
 
167
          s = Buf->file.params->colorb[irrep^all_buf_irrep][rs][1];
 
168
          bufrs = Buf->params->colidx[r][s];
 
169
 
 
170
          value = Buf->matrix[irrep][0][bufrs];
 
171
 
 
172
          /* Assign the value */
 
173
          Buf->file.matrix[irrep][filerow][rs] = value;
 
174
        }
 
175
 
 
176
      /* Write out the row */
 
177
      dpd_file4_mat_irrep_row_wrt(&(Buf->file), irrep, filepq);
 
178
 
 
179
      /* Close the input buffer */
 
180
      dpd_file4_mat_irrep_row_close(&(Buf->file), irrep);
 
181
 
 
182
      break;
 
183
  case 42: /* Pack pq; unpack rs */
 
184
      fprintf(stderr, "\n\tHaven't programmed method 42 yet!\n");
 
185
      exit(PSI_RETURN_FAILURE);
 
186
 
 
187
      break;
 
188
  case 43: /* Unpack pq; pack rs */
 
189
      fprintf(stderr, "\n\tHaven't programmed method 43 yet!\n");
 
190
      exit(PSI_RETURN_FAILURE);
 
191
 
 
192
      break;
 
193
  case 45: /* Unpack pq and rs */
 
194
      /* I'm not sure if I'll ever need this, so I'm removing it for now */
 
195
      fprintf(stderr, "\n\tShould you be using method %d?\n", method);
 
196
      exit(PSI_RETURN_FAILURE);
 
197
 
 
198
      break;
 
199
  default:  /* Error trapping */
 
200
      fprintf(stderr, "\n\tInvalid switch case in dpd_buf_mat_irrep_rd!\n");
 
201
      exit(PSI_RETURN_FAILURE);
 
202
      break;
 
203
    }
 
204
  
 
205
  return 0;
 
206
 
 
207
}