3d_sort.cc

Go to the documentation of this file.
00001 
00008 /* dpd_3d_sort(): Sorts a 3-index array stored as a two-by-one index
00009 ** array, (ab,c), into any desired ordering.
00010 **
00011 ** Arguments:
00012 **   double ***Win, ***Wout:  The input and output arrays,
00013 **   respectively.  The leading dimension is the number of irreps in
00014 **   the point group.  The memory for these obviously must be
00015 **   provided by the caller.
00016 **
00017 **   int nirreps: The number of irreps in the point group.
00018 **
00019 **   int *rowtot, **rowidx, ***roworb: The integer lookup arrays for,
00020 **   respectively, the total number of rows per irrep, the row index for
00021 **   a given pair of orbitals, and the orbitals associated with a
00022 **   given row index.  These generally come from the original DPD
00023 **   buf4 whose elements are being sorted here.
00024 **
00025 **   int *asym, *bsym: Integer lookup arrays for the orbital
00026 **   symmetries of the a and b compound indices on the row.
00027 **
00028 **   int *aoff, *boff: Integer lookup arrays for the orbital offsets
00029 **   by irrep of the a and b compound indices on the row.
00030 **
00031 **   int *cpi, *coff: Integer lookup arrays for the number of
00032 **   orbitals per irrep and the orbital offset by irrep for the c
00033 **   column index.
00034 **
00035 **   int **rowidx_out: Integer lookup array for the row index for a
00036 **   given pair of orbitals for the target ordering.
00037 **
00038 **   enum pattern index: One of acb, cab, cba, bac, bca.
00039 **
00040 **   int sum: Boolean to indicate if the contents of Wout should be
00041 **   overwritten or accumulated.
00042 **
00043 **  Originally written by TDC for (T) correction code, June 2001.
00044 **  Moved to libdpd for use by (T) and CC3 codes by TDC, July 2004.
00045 */
00046 
00047 #include <stdio.h>
00048 #include "dpd.h"
00049 
00050 extern "C" {
00051         
00052 void dpd_3d_sort(double ***Win, double ***Wout, int nirreps, int h, int *rowtot, int **rowidx, 
00053                  int ***roworb, int *asym, int *bsym, int *aoff, int *boff,
00054                  int *cpi, int *coff, int **rowidx_out, enum pattern index, int sum)
00055 {
00056   int Ga, Gb, Gc;
00057   int Gab, Gac, Gca, Gcb, Gbc, Gba;
00058   int A, B, C, a, b, c;
00059   int ab, ac, ca, cb, bc, ba;
00060 
00061   switch(index) {
00062 
00063   case abc:
00064     fprintf(stderr, "\ndpd_3d_sort: abc pattern is invalid.\n");
00065     dpd_error("3d_sort", stderr);
00066     break;
00067 
00068   case acb:
00069     for(Gab=0; Gab < nirreps; Gab++) {
00070       Gc = h ^ Gab;
00071 
00072       for(ab=0; ab < rowtot[Gab]; ab++) {
00073 
00074         A = roworb[Gab][ab][0];
00075         B = roworb[Gab][ab][1];
00076 
00077         Ga = asym[A]; Gb = bsym[B];
00078         Gac = Ga ^ Gc;
00079 
00080         b = B - boff[Gb];
00081 
00082         for(c=0; c < cpi[Gc]; c++) {
00083           C = coff[Gc] + c;
00084 
00085           ac = rowidx_out[A][C];
00086 
00087           if(sum) Wout[Gac][ac][b] += Win[Gab][ab][c];
00088           else Wout[Gac][ac][b] = Win[Gab][ab][c];
00089         }
00090       }
00091     }
00092 
00093     break;
00094 
00095   case cab:
00096     for(Gab=0; Gab < nirreps; Gab++) {
00097       Gc = h ^ Gab;
00098 
00099       for(ab=0; ab < rowtot[Gab]; ab++) {
00100 
00101         A = roworb[Gab][ab][0];
00102         B = roworb[Gab][ab][1];
00103 
00104         Ga = asym[A]; Gb = bsym[B];
00105         Gca = Ga ^ Gc;
00106 
00107         b = B - boff[Gb];
00108 
00109         for(c=0; c < cpi[Gc]; c++) {
00110           C = coff[Gc] + c;
00111 
00112           ca = rowidx_out[C][A];
00113 
00114           if(sum) Wout[Gca][ca][b] += Win[Gab][ab][c];
00115           else Wout[Gca][ca][b] = Win[Gab][ab][c];
00116         }
00117       }
00118     }
00119 
00120     break;
00121 
00122   case cba:
00123     for(Gab=0; Gab < nirreps; Gab++) {
00124       Gc = h ^ Gab;
00125 
00126       for(ab=0; ab < rowtot[Gab]; ab++) {
00127 
00128         A = roworb[Gab][ab][0];
00129         B = roworb[Gab][ab][1];
00130 
00131         Ga = asym[A]; Gb = bsym[B];
00132         a = A - aoff[Ga];
00133 
00134         Gcb = Gc ^ Gb;
00135 
00136         for(c=0; c < cpi[Gc]; c++) {
00137           C = coff[Gc] + c;
00138 
00139           cb = rowidx_out[C][B];
00140 
00141           if(sum) Wout[Gcb][cb][a] += Win[Gab][ab][c];
00142           else Wout[Gcb][cb][a] = Win[Gab][ab][c];
00143         }
00144       }
00145     }
00146 
00147     break;
00148 
00149   case bca:
00150     for(Gab=0; Gab < nirreps; Gab++) {
00151       Gc = h ^ Gab;
00152 
00153       for(ab=0; ab < rowtot[Gab]; ab++) {
00154 
00155         A = roworb[Gab][ab][0];
00156         B = roworb[Gab][ab][1];
00157 
00158         Ga = asym[A]; Gb = bsym[B];
00159         a = A - aoff[Ga];
00160 
00161         Gbc = Gb ^ Gc;
00162 
00163         for(c=0; c < cpi[Gc]; c++) {
00164           C = coff[Gc] + c;
00165 
00166           bc = rowidx_out[B][C];
00167 
00168           if(sum) Wout[Gbc][bc][a] += Win[Gab][ab][c];
00169           else Wout[Gbc][bc][a] = Win[Gab][ab][c];
00170         }
00171       }
00172     }
00173 
00174     break;
00175 
00176   case bac:
00177     for(Gab=0; Gab < nirreps; Gab++) {
00178       Gc = h ^ Gab;
00179       Gba = Gab;
00180 
00181       for(ab=0; ab < rowtot[Gab]; ab++) {
00182 
00183         A = roworb[Gab][ab][0];
00184         B = roworb[Gab][ab][1];
00185 
00186         ba = rowidx_out[B][A];
00187 
00188         for(c=0; c < cpi[Gc]; c++) {
00189           C = coff[Gc] + c;
00190 
00191           if(sum) Wout[Gba][ba][c] += Win[Gab][ab][c];
00192           else Wout[Gba][ba][c] = Win[Gab][ab][c];
00193         }
00194       }
00195     }
00196 
00197     break;
00198 
00199   }
00200 }
00201 
00202 } /* extern "C" */

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