| 1 | 
xsun | 
1185 | 
#include<stdio.h> | 
| 2 | 
  | 
  | 
#include<string.h> | 
| 3 | 
  | 
  | 
#include<stdlib.h> | 
| 4 | 
  | 
  | 
#include<math.h> | 
| 5 | 
  | 
  | 
#include<fftw.h> | 
| 6 | 
  | 
  | 
#include<mkl_lapack64.h> | 
| 7 | 
  | 
  | 
 | 
| 8 | 
  | 
  | 
//extern void dsyev(char *jobz, char *uplo, int *n, double *a, int *lda, | 
| 9 | 
  | 
  | 
//              double *w, double *work, int *lwork,int *info); | 
| 10 | 
  | 
  | 
 | 
| 11 | 
  | 
  | 
//void direct(double rcut, double box, int n, int nstep, int maxbin); | 
| 12 | 
  | 
  | 
 | 
| 13 | 
  | 
  | 
//double* dsyev_ctof(double **in, int rows, int cols); | 
| 14 | 
  | 
  | 
 | 
| 15 | 
  | 
  | 
//void dsyev_ftoc2(double *in, double **out, int rows, int cols); | 
| 16 | 
  | 
  | 
 | 
| 17 | 
  | 
  | 
// Structures to store our data: | 
| 18 | 
  | 
  | 
 | 
| 19 | 
  | 
  | 
inline double roundMe( double x ){ | 
| 20 | 
  | 
  | 
  return ( x >= 0 ) ? floor( x + 0.5 ) : ceil( x - 0.5 ); | 
| 21 | 
  | 
  | 
} | 
| 22 | 
  | 
  | 
 | 
| 23 | 
  | 
  | 
// coords holds the data for a single tethered dipole: | 
| 24 | 
  | 
  | 
struct coords{ | 
| 25 | 
  | 
  | 
  double pos[3]; // cartesian coords | 
| 26 | 
  | 
  | 
  double theta;  // orientational angle relative to z axis | 
| 27 | 
  | 
  | 
  double phi;    // orientational angle in x-y plane | 
| 28 | 
  | 
  | 
  double mu;     // dipole strength | 
| 29 | 
  | 
  | 
  char name[30]; // an identifier for the type of atom | 
| 30 | 
  | 
  | 
}; | 
| 31 | 
  | 
  | 
 | 
| 32 | 
  | 
  | 
// state holds the current "configuration" of the entire system | 
| 33 | 
  | 
  | 
struct system { | 
| 34 | 
  | 
  | 
  int    nAtoms;           // Number of Atoms in this configuration | 
| 35 | 
  | 
  | 
  struct coords *r;        // The set of coordinates for all atoms | 
| 36 | 
  | 
  | 
  double beta;             // beta = 1 /(kb*T) | 
| 37 | 
  | 
  | 
  double strength;         // strength of the dipoles (Debye) | 
| 38 | 
  | 
  | 
  double z0;               // default z axis position | 
| 39 | 
  | 
  | 
  double theta0;           // default theta angle | 
| 40 | 
  | 
  | 
  double kz;               // force constant for z displacement | 
| 41 | 
  | 
  | 
  double ktheta;           // force constant for theta displacement | 
| 42 | 
  | 
  | 
  int    nCycles;          // How many cycles to do in total | 
| 43 | 
  | 
  | 
  int    iCycle;           // How many cycles have we done? | 
| 44 | 
  | 
  | 
  int    nMoves;           // How many MC moves in each cycle | 
| 45 | 
  | 
  | 
  int    nSample;          // How many cycles between samples | 
| 46 | 
  | 
  | 
  double Hmat[2][2];       // The information about the size of the per. box | 
| 47 | 
  | 
  | 
  double HmatI[2][2];      // The inverse box | 
| 48 | 
  | 
  | 
  double energy;           // The current Energy | 
| 49 | 
  | 
  | 
  double dtheta;           // maximum size of a theta move | 
| 50 | 
  | 
  | 
  double deltaz;           // maximum size of a z move | 
| 51 | 
  | 
  | 
  double deltaphi;         // maximum size of a phi move | 
| 52 | 
  | 
  | 
  int    nAttempts;        // number of MC moves that have been attempted | 
| 53 | 
  | 
  | 
  int    nAccepts;         // number of MC moves that have been accepted | 
| 54 | 
  | 
  | 
  int    nx;               // number of unit cells in x direction | 
| 55 | 
  | 
  | 
  int    ny;               // number of unit cells in y direction | 
| 56 | 
  | 
  | 
  struct system *next;      // Next frame in the linked list | 
| 57 | 
  | 
  | 
}; | 
| 58 | 
  | 
  | 
 | 
| 59 | 
  | 
  | 
char *program_name; /* the name of the program */ | 
| 60 | 
  | 
  | 
 | 
| 61 | 
  | 
  | 
// Function prototypes: | 
| 62 | 
  | 
  | 
void usage(void); | 
| 63 | 
  | 
  | 
void invertMat2(double a[2][2], double b[2][2]); | 
| 64 | 
  | 
  | 
void wrapVector( double thePos[2], double Hmat[2][2], double HmatI[2][2]); | 
| 65 | 
  | 
  | 
 | 
| 66 | 
  | 
  | 
int main(argc, argv) | 
| 67 | 
  | 
  | 
     int argc; | 
| 68 | 
  | 
  | 
     char *argv[]; | 
| 69 | 
  | 
  | 
{ | 
| 70 | 
  | 
  | 
  FILE *in_file; | 
| 71 | 
  | 
  | 
  char in_name[500]; | 
| 72 | 
  | 
  | 
  char *eof_test, *foo; | 
| 73 | 
  | 
  | 
  char read_buffer[1000]; | 
| 74 | 
  | 
  | 
  //int lineCount = 0; | 
| 75 | 
  | 
  | 
  int lineCount; | 
| 76 | 
  | 
  | 
  int nAtoms; | 
| 77 | 
  | 
  | 
  double *mag, *newmag; | 
| 78 | 
  | 
  | 
  int *present_in_old; | 
| 79 | 
  | 
  | 
  double *ux, *uy, *uz, p1; | 
| 80 | 
  | 
  | 
  double aLat, bLat; | 
| 81 | 
  | 
  | 
  int cells; | 
| 82 | 
  | 
  | 
  double sumZ, sumUx, sumUy, sumUz, sumP; | 
| 83 | 
  | 
  | 
  double interpsum, value; | 
| 84 | 
  | 
  | 
  int ninterp, px, py, newp; | 
| 85 | 
  | 
  | 
  int i, j, k, l, nloops; | 
| 86 | 
  | 
  | 
  int newx, newy, newindex, index; | 
| 87 | 
  | 
  | 
  int new_i, new_j, new_index; | 
| 88 | 
  | 
  | 
  int N, nframes; | 
| 89 | 
  | 
  | 
  double freq_x, freq_y, zero_freq_x, zero_freq_y, freq; | 
| 90 | 
  | 
  | 
  double maxfreqx, maxfreqy, maxfreq, dfreq; | 
| 91 | 
  | 
  | 
  double dx, dy, dx1, dy1, xTemp, yTemp, pt1x, pt1y, pt2x, pt2y; | 
| 92 | 
  | 
  | 
  int nx, ny; | 
| 93 | 
  | 
  | 
  int *samples; | 
| 94 | 
  | 
  | 
  double *bin, binmin, binmax, delr; | 
| 95 | 
  | 
  | 
  double *x, *y, *z; | 
| 96 | 
  | 
  | 
  double dh2, dh, sumh2, sumh, averh2, averh, t, delta, gamma, hi, proj; | 
| 97 | 
  | 
  | 
  double *corrhist, *h2hist; | 
| 98 | 
  | 
  | 
  double vrhist[100][500]; | 
| 99 | 
  | 
  | 
  double sum_vrhist[1000], ave_vrhist[1000]; | 
| 100 | 
  | 
  | 
  int vrsamp[1000][1000]; | 
| 101 | 
  | 
  | 
  int *ophist; | 
| 102 | 
  | 
  | 
  double d[2], hcorr; | 
| 103 | 
  | 
  | 
  double hsum, hsum_temp, h2sum, have, h2ave, fluc, bigL, smallA, areaPerMolecule, area, h, h2; | 
| 104 | 
  | 
  | 
  int nbins, nbins2, opbin, whichbinx, whichbiny, whichbin2, n1, n2, n3, n4, m, selfx, selfy; | 
| 105 | 
  | 
  | 
 | 
| 106 | 
  | 
  | 
  int which; | 
| 107 | 
  | 
  | 
  double omat[3][3]; | 
| 108 | 
  | 
  | 
  double wrapMat[9];     | 
| 109 | 
  | 
  | 
  double onethird, ordvals[5000]; | 
| 110 | 
  | 
  | 
  double max; | 
| 111 | 
  | 
  | 
  double director[3][1000], vr[3][1000]; | 
| 112 | 
  | 
  | 
  double sum_director[3], ave_director[3], sum_vr[3], ave_vr[3]; | 
| 113 | 
  | 
  | 
  double orderpar[1000]; | 
| 114 | 
  | 
  | 
  double sum_orderpar, ave_orderpar; | 
| 115 | 
  | 
  | 
  char job, uplo; | 
| 116 | 
  | 
  | 
  int ndiag; | 
| 117 | 
  | 
  | 
  int nfilled; | 
| 118 | 
  | 
  | 
  double evals[100]; | 
| 119 | 
  | 
  | 
  int lwork; | 
| 120 | 
  | 
  | 
  double* work; | 
| 121 | 
  | 
  | 
  int ifail; | 
| 122 | 
  | 
  | 
  int done; | 
| 123 | 
  | 
  | 
  char current_flag; | 
| 124 | 
  | 
  | 
   | 
| 125 | 
  | 
  | 
  lineCount = 0; | 
| 126 | 
  | 
  | 
   | 
| 127 | 
  | 
  | 
  program_name = argv[0]; | 
| 128 | 
  | 
  | 
  if (argc >= 2) | 
| 129 | 
  | 
  | 
    strcpy(in_name, argv[1]); | 
| 130 | 
  | 
  | 
/*   | 
| 131 | 
  | 
  | 
  for(i = 1; i < argc; i++){ | 
| 132 | 
  | 
  | 
    if(argv[i][0] == '-'){ | 
| 133 | 
  | 
  | 
      done = 0; | 
| 134 | 
  | 
  | 
      j = 1; | 
| 135 | 
  | 
  | 
      current_flag = argv[i][j]; | 
| 136 | 
  | 
  | 
      while( (current_flag != '\0') && ( !done ) ){ | 
| 137 | 
  | 
  | 
        switch(current_flag){ | 
| 138 | 
  | 
  | 
          case 'i': | 
| 139 | 
  | 
  | 
            i++; | 
| 140 | 
  | 
  | 
            strcpy( in_name, argv[i] ); | 
| 141 | 
  | 
  | 
            done = 1; | 
| 142 | 
  | 
  | 
            break; | 
| 143 | 
  | 
  | 
        } | 
| 144 | 
  | 
  | 
      } | 
| 145 | 
  | 
  | 
    } | 
| 146 | 
  | 
  | 
  } | 
| 147 | 
  | 
  | 
*/ | 
| 148 | 
  | 
  | 
 | 
| 149 | 
  | 
  | 
  struct system* state; | 
| 150 | 
  | 
  | 
  struct system* temp_state; | 
| 151 | 
  | 
  | 
  struct coords* r; | 
| 152 | 
  | 
  | 
 | 
| 153 | 
  | 
  | 
  lwork = 9; | 
| 154 | 
  | 
  | 
 | 
| 155 | 
  | 
  | 
  work = (double *) malloc(lwork * sizeof(double)); | 
| 156 | 
  | 
  | 
 | 
| 157 | 
  | 
  | 
  onethird = 1.0 / 3.0; | 
| 158 | 
  | 
  | 
  ndiag = 3; | 
| 159 | 
  | 
  | 
  nfilled = 3; | 
| 160 | 
  | 
  | 
  job = 'V'; | 
| 161 | 
  | 
  | 
  uplo = 'U'; | 
| 162 | 
  | 
  | 
  ifail = 0; | 
| 163 | 
  | 
  | 
   | 
| 164 | 
  | 
  | 
  nbins = 30; | 
| 165 | 
  | 
  | 
  nbins2 = 30; | 
| 166 | 
  | 
  | 
  binmin = 0.0; | 
| 167 | 
  | 
  | 
  binmax = 1.0; | 
| 168 | 
  | 
  | 
  delr = (binmax - binmin) / (double) nbins2; | 
| 169 | 
  | 
  | 
  corrhist = (double *) calloc(nbins*nbins, sizeof(double)); | 
| 170 | 
  | 
  | 
  h2hist = (double *) calloc(nbins*nbins, sizeof(double)); | 
| 171 | 
  | 
  | 
  ophist = (int *) calloc(nbins2, sizeof(int)); | 
| 172 | 
  | 
  | 
  hsum = 0.0; | 
| 173 | 
  | 
  | 
  h2sum = 0.0; | 
| 174 | 
  | 
  | 
  sum_orderpar = 0.0; | 
| 175 | 
  | 
  | 
  ave_orderpar = 0.0; | 
| 176 | 
  | 
  | 
 | 
| 177 | 
  | 
  | 
  for(i = 0; i < 3; i++){ | 
| 178 | 
  | 
  | 
    for(j = 0; j < 1000; j++){ | 
| 179 | 
  | 
  | 
      director[i][j] = 0.0; | 
| 180 | 
  | 
  | 
      vr[i][j] = 0.0; | 
| 181 | 
  | 
  | 
    } | 
| 182 | 
  | 
  | 
  } | 
| 183 | 
  | 
  | 
   | 
| 184 | 
  | 
  | 
  for(i = 0; i < 1000; i++){ | 
| 185 | 
  | 
  | 
    sum_vrhist[i] = 0.0; | 
| 186 | 
  | 
  | 
    ave_vrhist[i] = 0.0; | 
| 187 | 
  | 
  | 
  } | 
| 188 | 
  | 
  | 
 | 
| 189 | 
  | 
  | 
  for(i = 0; i < 3; i++){ | 
| 190 | 
  | 
  | 
    sum_director[i] = 0.0; | 
| 191 | 
  | 
  | 
    ave_director[i] = 0.0; | 
| 192 | 
  | 
  | 
    sum_vr[i] = 0.0; | 
| 193 | 
  | 
  | 
    ave_vr[i] = 0.0; | 
| 194 | 
  | 
  | 
  } | 
| 195 | 
  | 
  | 
 | 
| 196 | 
  | 
  | 
  for (i = 0; i < nbins; i++) { | 
| 197 | 
  | 
  | 
    for (j = 0; j < nbins; j++) { | 
| 198 | 
  | 
  | 
      corrhist[nbins * i + j] = 0.0; | 
| 199 | 
  | 
  | 
      h2hist[nbins * i + j] = 0.0; | 
| 200 | 
  | 
  | 
    } | 
| 201 | 
  | 
  | 
  } | 
| 202 | 
  | 
  | 
 | 
| 203 | 
  | 
  | 
  for (i = 0; i < 100; i++) { | 
| 204 | 
  | 
  | 
    for (j = 0; j < 500; j++) { | 
| 205 | 
  | 
  | 
      vrhist[i][j] = 0.0; | 
| 206 | 
  | 
  | 
    } | 
| 207 | 
  | 
  | 
  } | 
| 208 | 
  | 
  | 
 | 
| 209 | 
  | 
  | 
  for(i = 0; i < nbins2; i++){ | 
| 210 | 
  | 
  | 
    ophist[i] = 0; | 
| 211 | 
  | 
  | 
  } | 
| 212 | 
  | 
  | 
 | 
| 213 | 
  | 
  | 
  t = 300; | 
| 214 | 
  | 
  | 
 | 
| 215 | 
  | 
  | 
  in_file = fopen(in_name, "r"); | 
| 216 | 
  | 
  | 
  if(in_file == NULL){ | 
| 217 | 
  | 
  | 
    printf("Cannot open file \"%s\" for reading.\n", in_name); | 
| 218 | 
  | 
  | 
    exit(8); | 
| 219 | 
  | 
  | 
  } | 
| 220 | 
  | 
  | 
 | 
| 221 | 
  | 
  | 
  nframes = 0; | 
| 222 | 
  | 
  | 
  n1 = 0; | 
| 223 | 
  | 
  | 
  n2 = 0; | 
| 224 | 
  | 
  | 
  n3 = 0; | 
| 225 | 
  | 
  | 
  n4 = 0; | 
| 226 | 
  | 
  | 
    | 
| 227 | 
  | 
  | 
  // start reading the first frame | 
| 228 | 
  | 
  | 
 | 
| 229 | 
  | 
  | 
  eof_test = fgets(read_buffer, sizeof(read_buffer), in_file); | 
| 230 | 
  | 
  | 
  nAtoms = atoi(read_buffer); | 
| 231 | 
  | 
  | 
  ux = (double *) calloc(nAtoms, sizeof(double)); | 
| 232 | 
  | 
  | 
  uy = (double *) calloc(nAtoms, sizeof(double)); | 
| 233 | 
  | 
  | 
  uz = (double *) calloc(nAtoms, sizeof(double)); | 
| 234 | 
  | 
  | 
  lineCount++; | 
| 235 | 
  | 
  | 
 | 
| 236 | 
  | 
  | 
  for(i = 0; i < nAtoms; i++){ | 
| 237 | 
  | 
  | 
    ux[i] = 0.0;  | 
| 238 | 
  | 
  | 
    uy[i] = 0.0; | 
| 239 | 
  | 
  | 
    uz[i] = 0.0; | 
| 240 | 
  | 
  | 
  } | 
| 241 | 
  | 
  | 
   | 
| 242 | 
  | 
  | 
  state = (struct system *) malloc(sizeof(struct system)); | 
| 243 | 
  | 
  | 
  state->next = NULL; | 
| 244 | 
  | 
  | 
  state->strength = 7.0; | 
| 245 | 
  | 
  | 
 | 
| 246 | 
  | 
  | 
  while(eof_test != NULL){ | 
| 247 | 
  | 
  | 
     | 
| 248 | 
  | 
  | 
    nframes++; | 
| 249 | 
  | 
  | 
    (void)sscanf(read_buffer, "%d", &state->nAtoms); | 
| 250 | 
  | 
  | 
    N = 2 * state->nAtoms;     | 
| 251 | 
  | 
  | 
 | 
| 252 | 
  | 
  | 
    state->r = (struct coords *)calloc(N, sizeof(struct coords)); | 
| 253 | 
  | 
  | 
 | 
| 254 | 
  | 
  | 
    for(i = 0; i < 3; i++){ | 
| 255 | 
  | 
  | 
      for(j = 0; j < 3; j++){ | 
| 256 | 
  | 
  | 
        omat[i][j] = 0.0; | 
| 257 | 
  | 
  | 
      } | 
| 258 | 
  | 
  | 
    } | 
| 259 | 
  | 
  | 
 | 
| 260 | 
  | 
  | 
    // read and the comment line and grab the time and box dimensions | 
| 261 | 
  | 
  | 
     | 
| 262 | 
  | 
  | 
    eof_test = fgets(read_buffer, sizeof(read_buffer), in_file); | 
| 263 | 
  | 
  | 
    lineCount++; | 
| 264 | 
  | 
  | 
    if(eof_test == NULL){ | 
| 265 | 
  | 
  | 
      printf("error in reading file at line: %d\n", lineCount); | 
| 266 | 
  | 
  | 
      exit(8); | 
| 267 | 
  | 
  | 
    } | 
| 268 | 
  | 
  | 
     | 
| 269 | 
  | 
  | 
    foo = strtok( read_buffer, " ,;\t\n" ); | 
| 270 | 
  | 
  | 
    (void)sscanf( read_buffer, "%d", &state->iCycle ); | 
| 271 | 
  | 
  | 
 | 
| 272 | 
  | 
  | 
    foo = strtok(NULL, " ,;\t\0"); | 
| 273 | 
  | 
  | 
    if(foo == NULL){ | 
| 274 | 
  | 
  | 
      printf("error in reading file at line: %d\n", lineCount); | 
| 275 | 
  | 
  | 
      exit(8); | 
| 276 | 
  | 
  | 
    } | 
| 277 | 
  | 
  | 
    (void)sscanf(foo, "%d", &state->nx); | 
| 278 | 
  | 
  | 
 | 
| 279 | 
  | 
  | 
    nx = state->nx; | 
| 280 | 
  | 
  | 
 | 
| 281 | 
  | 
  | 
    foo = strtok(NULL, " ,;\t\0"); | 
| 282 | 
  | 
  | 
    if(foo == NULL){ | 
| 283 | 
  | 
  | 
      printf("error in reading file at line: %d\n", lineCount); | 
| 284 | 
  | 
  | 
      exit(8); | 
| 285 | 
  | 
  | 
    } | 
| 286 | 
  | 
  | 
    (void)sscanf(foo, "%d", &state->ny); | 
| 287 | 
  | 
  | 
    | 
| 288 | 
  | 
  | 
    ny = state->ny; | 
| 289 | 
  | 
  | 
 | 
| 290 | 
  | 
  | 
    foo = strtok(NULL, " ,;\t\0"); | 
| 291 | 
  | 
  | 
    if(foo == NULL){ | 
| 292 | 
  | 
  | 
      printf("error in reading file at line: %d\n", lineCount); | 
| 293 | 
  | 
  | 
      exit(8); | 
| 294 | 
  | 
  | 
    } | 
| 295 | 
  | 
  | 
    (void)sscanf(foo, "%lf",&state->Hmat[0][0]); | 
| 296 | 
  | 
  | 
     | 
| 297 | 
  | 
  | 
    foo = strtok(NULL, " ,;\t\0"); | 
| 298 | 
  | 
  | 
    if(foo == NULL){ | 
| 299 | 
  | 
  | 
      printf("error in reading file at line: %d\n", lineCount); | 
| 300 | 
  | 
  | 
      exit(8); | 
| 301 | 
  | 
  | 
    } | 
| 302 | 
  | 
  | 
    (void)sscanf(foo, "%lf",&state->Hmat[1][0]); | 
| 303 | 
  | 
  | 
     | 
| 304 | 
  | 
  | 
    foo = strtok(NULL, " ,;\t\0"); | 
| 305 | 
  | 
  | 
    if(foo == NULL){ | 
| 306 | 
  | 
  | 
      printf("error in reading file at line: %d\n", lineCount); | 
| 307 | 
  | 
  | 
      exit(8); | 
| 308 | 
  | 
  | 
    } | 
| 309 | 
  | 
  | 
    (void)sscanf(foo, "%lf",&state->Hmat[0][1]); | 
| 310 | 
  | 
  | 
     | 
| 311 | 
  | 
  | 
    foo = strtok(NULL, " ,;\t\0"); | 
| 312 | 
  | 
  | 
    if(foo == NULL){ | 
| 313 | 
  | 
  | 
      printf("error in reading file at line: %d\n", lineCount); | 
| 314 | 
  | 
  | 
      exit(8); | 
| 315 | 
  | 
  | 
    } | 
| 316 | 
  | 
  | 
    (void)sscanf(foo, "%lf",&state->Hmat[1][1]); | 
| 317 | 
  | 
  | 
 | 
| 318 | 
  | 
  | 
    //Find HmatI: | 
| 319 | 
  | 
  | 
 | 
| 320 | 
  | 
  | 
    invertMat2(state->Hmat, state->HmatI); | 
| 321 | 
  | 
  | 
     | 
| 322 | 
  | 
  | 
    // Length of the two box vectors: | 
| 323 | 
  | 
  | 
 | 
| 324 | 
  | 
  | 
    dx = sqrt(pow(state->Hmat[0][0], 2) + pow(state->Hmat[1][0], 2)); | 
| 325 | 
  | 
  | 
    dy = sqrt(pow(state->Hmat[0][1], 2) + pow(state->Hmat[1][1], 2)); | 
| 326 | 
  | 
  | 
 | 
| 327 | 
  | 
  | 
    aLat = dx / (double)(state->nx); | 
| 328 | 
  | 
  | 
    bLat = dy / (double)(state->ny); | 
| 329 | 
  | 
  | 
  | 
| 330 | 
  | 
  | 
    // FFT stuff depends on nx and ny, so delay allocation until we have | 
| 331 | 
  | 
  | 
    // that information | 
| 332 | 
  | 
  | 
     | 
| 333 | 
  | 
  | 
    for (i=0;i<state->nAtoms;i++){ | 
| 334 | 
  | 
  | 
       | 
| 335 | 
  | 
  | 
      eof_test = fgets(read_buffer, sizeof(read_buffer), in_file); | 
| 336 | 
  | 
  | 
      lineCount++; | 
| 337 | 
  | 
  | 
      if(eof_test == NULL){ | 
| 338 | 
  | 
  | 
        printf("error in reading file at line: %d\n", lineCount); | 
| 339 | 
  | 
  | 
        exit(8); | 
| 340 | 
  | 
  | 
      } | 
| 341 | 
  | 
  | 
       | 
| 342 | 
  | 
  | 
      foo = strtok(read_buffer, " ,;\t\0"); | 
| 343 | 
  | 
  | 
      (void)strcpy(state->r[i].name, foo); //copy the atom name | 
| 344 | 
  | 
  | 
       | 
| 345 | 
  | 
  | 
      // next we grab the positions | 
| 346 | 
  | 
  | 
       | 
| 347 | 
  | 
  | 
      foo = strtok(NULL, " ,;\t\0"); | 
| 348 | 
  | 
  | 
      if(foo == NULL){ | 
| 349 | 
  | 
  | 
        printf("error in reading postition x from %s\n" | 
| 350 | 
  | 
  | 
               "natoms  = %d, line = %d\n", | 
| 351 | 
  | 
  | 
               in_name, state->nAtoms, lineCount ); | 
| 352 | 
  | 
  | 
        exit(8); | 
| 353 | 
  | 
  | 
      } | 
| 354 | 
  | 
  | 
      (void)sscanf( foo, "%lf", &state->r[i].pos[0] ); | 
| 355 | 
  | 
  | 
       | 
| 356 | 
  | 
  | 
      foo = strtok(NULL, " ,;\t\0"); | 
| 357 | 
  | 
  | 
      if(foo == NULL){ | 
| 358 | 
  | 
  | 
        printf("error in reading postition y from %s\n" | 
| 359 | 
  | 
  | 
               "natoms  = %d, line = %d\n", | 
| 360 | 
  | 
  | 
               in_name, state->nAtoms, lineCount ); | 
| 361 | 
  | 
  | 
        exit(8); | 
| 362 | 
  | 
  | 
      } | 
| 363 | 
  | 
  | 
      (void)sscanf( foo, "%lf", &state->r[i].pos[1] ); | 
| 364 | 
  | 
  | 
       | 
| 365 | 
  | 
  | 
      foo = strtok(NULL, " ,;\t\0"); | 
| 366 | 
  | 
  | 
      if(foo == NULL){ | 
| 367 | 
  | 
  | 
        printf("error in reading postition z from %s\n" | 
| 368 | 
  | 
  | 
               "natoms  = %d, line = %d\n", | 
| 369 | 
  | 
  | 
               in_name, state->nAtoms, lineCount ); | 
| 370 | 
  | 
  | 
        exit(8); | 
| 371 | 
  | 
  | 
      } | 
| 372 | 
  | 
  | 
      (void)sscanf( foo, "%lf", &state->r[i].pos[2] ); | 
| 373 | 
  | 
  | 
       | 
| 374 | 
  | 
  | 
      foo = strtok(NULL, " ,;\t\0"); | 
| 375 | 
  | 
  | 
      if(foo == NULL){ | 
| 376 | 
  | 
  | 
        printf("error in reading angle phi from %s\n" | 
| 377 | 
  | 
  | 
               "natoms  = %d, line = %d\n", | 
| 378 | 
  | 
  | 
               in_name, state->nAtoms, lineCount ); | 
| 379 | 
  | 
  | 
        exit(8); | 
| 380 | 
  | 
  | 
      } | 
| 381 | 
  | 
  | 
      (void)sscanf( foo, "%lf", &state->r[i].phi ); | 
| 382 | 
  | 
  | 
       | 
| 383 | 
  | 
  | 
      foo = strtok(NULL, " ,;\t\0"); | 
| 384 | 
  | 
  | 
      if(foo == NULL){ | 
| 385 | 
  | 
  | 
        printf("error in reading unit vector x from %s\n" | 
| 386 | 
  | 
  | 
               "natoms  = %d, line = %d\n", | 
| 387 | 
  | 
  | 
               in_name, state->nAtoms, lineCount ); | 
| 388 | 
  | 
  | 
        exit(8); | 
| 389 | 
  | 
  | 
      } | 
| 390 | 
  | 
  | 
      (void)sscanf( foo, "%lf", &ux[i] ); | 
| 391 | 
  | 
  | 
       | 
| 392 | 
  | 
  | 
      foo = strtok(NULL, " ,;\t\0"); | 
| 393 | 
  | 
  | 
      if(foo == NULL){ | 
| 394 | 
  | 
  | 
        printf("error in reading unit vector y from %s\n" | 
| 395 | 
  | 
  | 
               "natoms  = %d, line = %d\n", | 
| 396 | 
  | 
  | 
               in_name, state->nAtoms, lineCount ); | 
| 397 | 
  | 
  | 
        exit(8); | 
| 398 | 
  | 
  | 
      } | 
| 399 | 
  | 
  | 
      (void)sscanf( foo, "%lf", &uy[i] ); | 
| 400 | 
  | 
  | 
       | 
| 401 | 
  | 
  | 
      foo = strtok(NULL, " ,;\t\0"); | 
| 402 | 
  | 
  | 
      if(foo == NULL){ | 
| 403 | 
  | 
  | 
        printf("error in reading unit vector z from %s\n" | 
| 404 | 
  | 
  | 
               "natoms  = %d, line = %d\n", | 
| 405 | 
  | 
  | 
               in_name, state->nAtoms, lineCount ); | 
| 406 | 
  | 
  | 
        exit(8); | 
| 407 | 
  | 
  | 
      } | 
| 408 | 
  | 
  | 
      (void)sscanf( foo, "%lf", &uz[i] ); | 
| 409 | 
  | 
  | 
       | 
| 410 | 
  | 
  | 
      state->r[i].theta = acos(uz[i]); | 
| 411 | 
  | 
  | 
       | 
| 412 | 
  | 
  | 
      // The one parameter not stored in the dump file is the dipole strength | 
| 413 | 
  | 
  | 
      state->r[i].mu = state->strength; | 
| 414 | 
  | 
  | 
    } | 
| 415 | 
  | 
  | 
     | 
| 416 | 
  | 
  | 
    hsum_temp = 0.0; | 
| 417 | 
  | 
  | 
    for (i = 0; i < state->nAtoms; i++) { | 
| 418 | 
  | 
  | 
       | 
| 419 | 
  | 
  | 
      h = state->r[i].pos[2]; | 
| 420 | 
  | 
  | 
      h2 = pow(h,2); | 
| 421 | 
  | 
  | 
 | 
| 422 | 
  | 
  | 
      hsum_temp += h; | 
| 423 | 
  | 
  | 
      hsum += h; | 
| 424 | 
  | 
  | 
      h2sum += h2; | 
| 425 | 
  | 
  | 
 | 
| 426 | 
  | 
  | 
      n1++; | 
| 427 | 
  | 
  | 
    } | 
| 428 | 
  | 
  | 
 | 
| 429 | 
  | 
  | 
    for(i = 0; i < state->nAtoms; i++){ | 
| 430 | 
  | 
  | 
     | 
| 431 | 
  | 
  | 
      omat[0][0] += ux[i] * ux[i] - onethird; | 
| 432 | 
  | 
  | 
      omat[0][1] += ux[i] * uy[i]; | 
| 433 | 
  | 
  | 
      omat[0][2] += ux[i] * uz[i]; | 
| 434 | 
  | 
  | 
      omat[1][0] += uy[i] * ux[i]; | 
| 435 | 
  | 
  | 
      omat[1][1] += uy[i] * uy[i] - onethird; | 
| 436 | 
  | 
  | 
      omat[1][2] += uy[i] * uz[i]; | 
| 437 | 
  | 
  | 
      omat[2][0] += uz[i] * ux[i]; | 
| 438 | 
  | 
  | 
      omat[2][1] += uz[i] * uy[i]; | 
| 439 | 
  | 
  | 
      omat[2][2] += uz[i] * uz[i] - onethird; | 
| 440 | 
  | 
  | 
 | 
| 441 | 
  | 
  | 
    } | 
| 442 | 
  | 
  | 
 | 
| 443 | 
  | 
  | 
    for(i = 0; i < 3; i++){ | 
| 444 | 
  | 
  | 
      for(j = 0; j < 3; j++){ | 
| 445 | 
  | 
  | 
        omat[i][j] /= (double) state->nAtoms; | 
| 446 | 
  | 
  | 
      } | 
| 447 | 
  | 
  | 
    } | 
| 448 | 
  | 
  | 
     | 
| 449 | 
  | 
  | 
    //    temp_array = dsyev_ctof(omat, nfilled, nfilled); | 
| 450 | 
  | 
  | 
     | 
| 451 | 
  | 
  | 
    for(j=0;j<3;j++) | 
| 452 | 
  | 
  | 
            for(i=0;i<3;i++) | 
| 453 | 
  | 
  | 
                    wrapMat[i+j*3] = omat[i][j]; | 
| 454 | 
  | 
  | 
     | 
| 455 | 
  | 
  | 
    ifail = 0; | 
| 456 | 
  | 
  | 
    dsyev(&job, &uplo, &nfilled, wrapMat, &ndiag, evals, work, &lwork, &ifail); | 
| 457 | 
  | 
  | 
 | 
| 458 | 
  | 
  | 
    for(j=0;j<3;j++) | 
| 459 | 
  | 
  | 
            for(i=0;i<3;i++) | 
| 460 | 
  | 
  | 
                    omat[i][j] = wrapMat[i+j*3]; | 
| 461 | 
  | 
  | 
                             | 
| 462 | 
  | 
  | 
    //dsyev_ftoc2(temp_array, omat, nfilled, nfilled); | 
| 463 | 
  | 
  | 
   | 
| 464 | 
  | 
  | 
    //free(temp_array); | 
| 465 | 
  | 
  | 
   | 
| 466 | 
  | 
  | 
    max = 0.0; | 
| 467 | 
  | 
  | 
    for(j = 0; j < 3; j++){ | 
| 468 | 
  | 
  | 
      if(fabs(evals[j]) > max){ | 
| 469 | 
  | 
  | 
        which = j; | 
| 470 | 
  | 
  | 
        max = fabs(evals[j]); | 
| 471 | 
  | 
  | 
      } | 
| 472 | 
  | 
  | 
    } | 
| 473 | 
  | 
  | 
     | 
| 474 | 
  | 
  | 
    director[0][nframes-1] = omat[0][which]; | 
| 475 | 
  | 
  | 
    director[1][nframes-1] = omat[1][which]; | 
| 476 | 
  | 
  | 
    director[2][nframes-1] = omat[2][which]; | 
| 477 | 
  | 
  | 
     | 
| 478 | 
  | 
  | 
    vr[0][nframes-1] = fabs(director[1][nframes-1]); | 
| 479 | 
  | 
  | 
    vr[1][nframes-1] = fabs(-director[0][nframes-1]); | 
| 480 | 
  | 
  | 
    vr[2][nframes-1] = 0; | 
| 481 | 
  | 
  | 
     | 
| 482 | 
  | 
  | 
    orderpar[nframes-1] = 1.5 * max; | 
| 483 | 
  | 
  | 
    printf("%d\t%lf\n", state->iCycle, orderpar[nframes-1]); | 
| 484 | 
  | 
  | 
 | 
| 485 | 
  | 
  | 
    opbin = (int) (orderpar[nframes-1] / delr); | 
| 486 | 
  | 
  | 
    if(opbin < nbins2) ophist[opbin] += 1; | 
| 487 | 
  | 
  | 
 | 
| 488 | 
  | 
  | 
/*     for(i = 0; i < state->nAtoms; i++){ */ | 
| 489 | 
  | 
  | 
/*       proj = vr[0][nframes-1] * state->r[i].pos[0] + vr[1][nframes-1] * state->r[i].pos[1]; */ | 
| 490 | 
  | 
  | 
/*       hi = state->r[i].pos[2]  - hsum_temp / (double) state->nAtoms; */ | 
| 491 | 
  | 
  | 
       | 
| 492 | 
  | 
  | 
/*       whichbin2 = (int) ((proj / (vr[0][nframes-1] * dx + vr[1][nframes-1] * dy)) * nbins2); */ | 
| 493 | 
  | 
  | 
/*       vrhist[whichbin2][nframes-1] += hi; */ | 
| 494 | 
  | 
  | 
/*       vrsamp[whichbin2][nframes-1]++; */ | 
| 495 | 
  | 
  | 
/*     } */ | 
| 496 | 
  | 
  | 
     | 
| 497 | 
  | 
  | 
/*     for(i = 0; i < state->nAtoms; i++){ */ | 
| 498 | 
  | 
  | 
/*       for(j = 0; j < state->nAtoms; j++){ */ | 
| 499 | 
  | 
  | 
         | 
| 500 | 
  | 
  | 
/*      d[0] = state->r[j].pos[0] - state->r[i].pos[0]; */ | 
| 501 | 
  | 
  | 
/*      d[1] = state->r[j].pos[1] - state->r[i].pos[1]; */ | 
| 502 | 
  | 
  | 
         | 
| 503 | 
  | 
  | 
/*      wrapVector(d, state->Hmat, state->HmatI); */ | 
| 504 | 
  | 
  | 
         | 
| 505 | 
  | 
  | 
/*      whichbinx = (int) ((nbins-1) * (dx/2.0 + d[0]) / dx); */ | 
| 506 | 
  | 
  | 
/*      whichbiny = (int) ((nbins-1) * (dy/2.0 + d[1]) / dy); */ | 
| 507 | 
  | 
  | 
 | 
| 508 | 
  | 
  | 
/*      //if (i == j) { */ | 
| 509 | 
  | 
  | 
/*        //printf("whichbinx = %i, whichbiny = %i\n", whichbinx, whichbiny); */ | 
| 510 | 
  | 
  | 
/*      //} */ | 
| 511 | 
  | 
  | 
 | 
| 512 | 
  | 
  | 
/*      //printf("d0 = %lf, d1 = %lf\n", d[0], d[1]); */ | 
| 513 | 
  | 
  | 
/*      //printf("wx = %d, wy = %d\n", whichbinx, whichbiny); */ | 
| 514 | 
  | 
  | 
 | 
| 515 | 
  | 
  | 
/*      if (whichbinx >= nbins || whichbiny >= nbins) { */ | 
| 516 | 
  | 
  | 
/*        printf("off by one error\n"); */ | 
| 517 | 
  | 
  | 
/*        printf("whichbinx = %i, whichbiny = %i\n", whichbinx, whichbiny); */ | 
| 518 | 
  | 
  | 
/*        exit(0); */ | 
| 519 | 
  | 
  | 
/*      } */ | 
| 520 | 
  | 
  | 
/*      if (whichbinx < 0 || whichbiny < 0) { */ | 
| 521 | 
  | 
  | 
/*        printf("off by one error\n"); */ | 
| 522 | 
  | 
  | 
/*        printf("whichbinx = %i, whichbiny = %i\n", whichbinx, whichbiny); */ | 
| 523 | 
  | 
  | 
/*        exit(0); */ | 
| 524 | 
  | 
  | 
/*      } */ | 
| 525 | 
  | 
  | 
 | 
| 526 | 
  | 
  | 
/*      hcorr = state->r[j].pos[2] * state->r[i].pos[2]; */ | 
| 527 | 
  | 
  | 
 | 
| 528 | 
  | 
  | 
/*      corrhist[nbins * whichbinx + whichbiny] += hcorr; */ | 
| 529 | 
  | 
  | 
 | 
| 530 | 
  | 
  | 
/*      dh = state->r[j].pos[2] - state->r[i].pos[2]; */ | 
| 531 | 
  | 
  | 
/*      dh2 = pow(dh, 2); */ | 
| 532 | 
  | 
  | 
 | 
| 533 | 
  | 
  | 
/*      h2hist[nbins * whichbinx + whichbiny] += dh2; */ | 
| 534 | 
  | 
  | 
 | 
| 535 | 
  | 
  | 
/*      n2++; */ | 
| 536 | 
  | 
  | 
/*       } */ | 
| 537 | 
  | 
  | 
/*     } */ | 
| 538 | 
  | 
  | 
 | 
| 539 | 
  | 
  | 
    temp_state = state->next; | 
| 540 | 
  | 
  | 
    state->next = NULL; | 
| 541 | 
  | 
  | 
   | 
| 542 | 
  | 
  | 
    if (temp_state != NULL) { | 
| 543 | 
  | 
  | 
      free(temp_state->r); | 
| 544 | 
  | 
  | 
      free(temp_state); | 
| 545 | 
  | 
  | 
    } | 
| 546 | 
  | 
  | 
 | 
| 547 | 
  | 
  | 
    // Make a new frame | 
| 548 | 
  | 
  | 
   | 
| 549 | 
  | 
  | 
    temp_state = (struct system *) malloc(sizeof(struct system)); | 
| 550 | 
  | 
  | 
    temp_state->next = state; | 
| 551 | 
  | 
  | 
    state = temp_state; | 
| 552 | 
  | 
  | 
    eof_test = fgets(read_buffer, sizeof(read_buffer), in_file); | 
| 553 | 
  | 
  | 
    lineCount++; | 
| 554 | 
  | 
  | 
  } | 
| 555 | 
  | 
  | 
 | 
| 556 | 
  | 
  | 
 | 
| 557 | 
  | 
  | 
/*   have = hsum / (double) n1; */ | 
| 558 | 
  | 
  | 
/*   h2ave = h2sum / (double) n1; */ | 
| 559 | 
  | 
  | 
/*   fluc = h2ave - pow(have, 2); */ | 
| 560 | 
  | 
  | 
 | 
| 561 | 
  | 
  | 
/*   printf("# <h> = %lf\n", have); */ | 
| 562 | 
  | 
  | 
/*   printf("# <h2> = %lf\n", h2ave); */ | 
| 563 | 
  | 
  | 
/*   printf("# sigma(h) = %lf\n", sqrt(h2ave - have * have)); */ | 
| 564 | 
  | 
  | 
/*   printf("# fluctuation = %lf\n", fluc); */ | 
| 565 | 
  | 
  | 
 | 
| 566 | 
  | 
  | 
/*   for(i = 0; i < nframes; i++){ */ | 
| 567 | 
  | 
  | 
/*     sum_orderpar += orderpar[i]; */ | 
| 568 | 
  | 
  | 
/*   } */ | 
| 569 | 
  | 
  | 
/*   ave_orderpar = sum_orderpar / (double) nframes;   */ | 
| 570 | 
  | 
  | 
   | 
| 571 | 
  | 
  | 
/*   for(i = 0; i < nframes; i++){ */ | 
| 572 | 
  | 
  | 
/*     sum_director[0] += director[0][i]; */ | 
| 573 | 
  | 
  | 
/*     sum_director[1] += director[1][i]; */ | 
| 574 | 
  | 
  | 
/*     sum_director[2] += director[2][i]; */ | 
| 575 | 
  | 
  | 
/*   } */ | 
| 576 | 
  | 
  | 
/*   ave_director[0] = sum_director[0] / (double) nframes; */ | 
| 577 | 
  | 
  | 
/*   ave_director[1] = sum_director[1] / (double) nframes; */ | 
| 578 | 
  | 
  | 
/*   ave_director[2] = sum_director[2] / (double) nframes; */ | 
| 579 | 
  | 
  | 
 | 
| 580 | 
  | 
  | 
/*   for(i = 0; i < nframes; i++){ */ | 
| 581 | 
  | 
  | 
/*     sum_vr[0] += vr[0][i]; */ | 
| 582 | 
  | 
  | 
/*     sum_vr[1] += vr[1][i]; */ | 
| 583 | 
  | 
  | 
/*     sum_vr[2] += vr[2][i]; */ | 
| 584 | 
  | 
  | 
/*   } */ | 
| 585 | 
  | 
  | 
/*   ave_vr[0] = sum_vr[0] / (double) nframes; */ | 
| 586 | 
  | 
  | 
/*   ave_vr[1] = sum_vr[1] / (double) nframes; */ | 
| 587 | 
  | 
  | 
/*   ave_vr[2] = sum_vr[2] / (double) nframes; */ | 
| 588 | 
  | 
  | 
 | 
| 589 | 
  | 
  | 
/*   printf("# orderparameter = %lf\n", ave_orderpar); */ | 
| 590 | 
  | 
  | 
/*   printf("# director axis is ( %lf\t%lf\t%lf )\n", */ | 
| 591 | 
  | 
  | 
/*                ave_director[0], ave_director[1], ave_director[2]);   */ | 
| 592 | 
  | 
  | 
/*   printf("# vr axis is ( %lf\t%lf\t%lf )\n", ave_vr[0], ave_vr[1], ave_vr[2]);   */ | 
| 593 | 
  | 
  | 
 | 
| 594 | 
  | 
  | 
/*   for(i = 0; i < nbins2; i++){ */ | 
| 595 | 
  | 
  | 
/*     for(j = 0; j < nframes; j++){ */ | 
| 596 | 
  | 
  | 
/*       sum_vrhist[i] += vrhist[i][j]; */ | 
| 597 | 
  | 
  | 
/*     } */ | 
| 598 | 
  | 
  | 
/*   } */ | 
| 599 | 
  | 
  | 
 | 
| 600 | 
  | 
  | 
/*   dx = sqrt(pow(state->Hmat[0][0], 2) + pow(state->Hmat[1][0], 2)); */ | 
| 601 | 
  | 
  | 
/*   dy = sqrt(pow(state->Hmat[0][1], 2) + pow(state->Hmat[1][1], 2)); */ | 
| 602 | 
  | 
  | 
   | 
| 603 | 
  | 
  | 
/*   area = dx * dy; */ | 
| 604 | 
  | 
  | 
 | 
| 605 | 
  | 
  | 
/*   bigL = sqrt(area); */ | 
| 606 | 
  | 
  | 
 | 
| 607 | 
  | 
  | 
/*   areaPerMolecule = area / (double) state->nAtoms; */ | 
| 608 | 
  | 
  | 
 | 
| 609 | 
  | 
  | 
/*   smallA = sqrt(areaPerMolecule); */ | 
| 610 | 
  | 
  | 
 | 
| 611 | 
  | 
  | 
/*   gamma = t * log(bigL / smallA)  / (2.0 * M_PI * fluc); */ | 
| 612 | 
  | 
  | 
 | 
| 613 | 
  | 
  | 
/*   printf("# first gamma estimate = %lf\n", gamma); */ | 
| 614 | 
  | 
  | 
 | 
| 615 | 
  | 
  | 
/*   printf("# \n"); */ | 
| 616 | 
  | 
  | 
   | 
| 617 | 
  | 
  | 
/*   for(i = 0; i < nbins2; i++){ */ | 
| 618 | 
  | 
  | 
/*     ave_vrhist[i] = sum_vrhist[i] / (double) nframes; */ | 
| 619 | 
  | 
  | 
/*     printf("%lf\t%lf\n", (double) i * (ave_vr[0] * dx + ave_vr[1] * dy) / (double) nbins2, */ | 
| 620 | 
  | 
  | 
/*                 ave_vrhist[i]); */ | 
| 621 | 
  | 
  | 
/*   } */ | 
| 622 | 
  | 
  | 
   | 
| 623 | 
  | 
  | 
/*   selfx = (int) ((double)nbins / 2.0); */ | 
| 624 | 
  | 
  | 
/*   selfy = (int) ((double)nbins / 2.0); */ | 
| 625 | 
  | 
  | 
 | 
| 626 | 
  | 
  | 
/*   for (i = 0; i < nbins; i++) { */ | 
| 627 | 
  | 
  | 
/*     for (j = 0; j < nbins; j++) { */ | 
| 628 | 
  | 
  | 
/*       printf("%lf\t", h2hist[nbins * i + j] / (double) n2); */ | 
| 629 | 
  | 
  | 
/*     } */ | 
| 630 | 
  | 
  | 
/*     printf("\n"); */ | 
| 631 | 
  | 
  | 
/*   } */ | 
| 632 | 
  | 
  | 
 | 
| 633 | 
  | 
  | 
  free(work); | 
| 634 | 
  | 
  | 
  free(corrhist); | 
| 635 | 
  | 
  | 
  free(h2hist); | 
| 636 | 
  | 
  | 
  free(ux); | 
| 637 | 
  | 
  | 
  free(uy); | 
| 638 | 
  | 
  | 
  free(uz); | 
| 639 | 
  | 
  | 
  return 1; | 
| 640 | 
  | 
  | 
 | 
| 641 | 
  | 
  | 
} | 
| 642 | 
  | 
  | 
 | 
| 643 | 
  | 
  | 
double matDet2(double a[2][2]) { | 
| 644 | 
  | 
  | 
 | 
| 645 | 
  | 
  | 
  double determinant; | 
| 646 | 
  | 
  | 
 | 
| 647 | 
  | 
  | 
  determinant = (a[0][0] * a[1][1]) - (a[0][1] * a[1][0]); | 
| 648 | 
  | 
  | 
 | 
| 649 | 
  | 
  | 
  return determinant; | 
| 650 | 
  | 
  | 
} | 
| 651 | 
  | 
  | 
 | 
| 652 | 
  | 
  | 
 | 
| 653 | 
  | 
  | 
void invertMat2(double a[2][2], double b[2][2]) { | 
| 654 | 
  | 
  | 
 | 
| 655 | 
  | 
  | 
  double determinant; | 
| 656 | 
  | 
  | 
 | 
| 657 | 
  | 
  | 
  determinant = matDet2( a ); | 
| 658 | 
  | 
  | 
 | 
| 659 | 
  | 
  | 
  if (determinant == 0.0) { | 
| 660 | 
  | 
  | 
    printf("Can't invert a matrix with a zero determinant!\n"); | 
| 661 | 
  | 
  | 
  } | 
| 662 | 
  | 
  | 
 | 
| 663 | 
  | 
  | 
  b[0][0] =  a[1][1] / determinant; | 
| 664 | 
  | 
  | 
  b[0][1] = -a[0][1] / determinant; | 
| 665 | 
  | 
  | 
  b[1][0] = -a[1][0] / determinant; | 
| 666 | 
  | 
  | 
  b[1][1] =  a[0][0] / determinant; | 
| 667 | 
  | 
  | 
} | 
| 668 | 
  | 
  | 
 | 
| 669 | 
  | 
  | 
void matVecMul2(double m[2][2], double inVec[2], double outVec[2]) { | 
| 670 | 
  | 
  | 
  double a0, a1, a2; | 
| 671 | 
  | 
  | 
 | 
| 672 | 
  | 
  | 
  a0 = inVec[0];  a1 = inVec[1]; | 
| 673 | 
  | 
  | 
 | 
| 674 | 
  | 
  | 
  outVec[0] = m[0][0]*a0 + m[0][1]*a1; | 
| 675 | 
  | 
  | 
  outVec[1] = m[1][0]*a0 + m[1][1]*a1; | 
| 676 | 
  | 
  | 
} | 
| 677 | 
  | 
  | 
 | 
| 678 | 
  | 
  | 
void wrapVector( double thePos[2], double Hmat[2][2], double HmatInv[2][2]){ | 
| 679 | 
  | 
  | 
 | 
| 680 | 
  | 
  | 
  int i; | 
| 681 | 
  | 
  | 
  double scaled[2]; | 
| 682 | 
  | 
  | 
 | 
| 683 | 
  | 
  | 
  // calc the scaled coordinates. | 
| 684 | 
  | 
  | 
 | 
| 685 | 
  | 
  | 
  matVecMul2(HmatInv, thePos, scaled); | 
| 686 | 
  | 
  | 
   | 
| 687 | 
  | 
  | 
  for(i=0; i<2; i++) | 
| 688 | 
  | 
  | 
    scaled[i] -= roundMe(scaled[i]); | 
| 689 | 
  | 
  | 
   | 
| 690 | 
  | 
  | 
  // calc the wrapped real coordinates from the wrapped scaled coordinates | 
| 691 | 
  | 
  | 
   | 
| 692 | 
  | 
  | 
  matVecMul2(Hmat, scaled, thePos); | 
| 693 | 
  | 
  | 
   | 
| 694 | 
  | 
  | 
} | 
| 695 | 
  | 
  | 
 | 
| 696 | 
  | 
  | 
/* double* dsyev_ctof(double **in, int rows, int cols) */ | 
| 697 | 
  | 
  | 
/* { */ | 
| 698 | 
  | 
  | 
/*   double *out; */ | 
| 699 | 
  | 
  | 
/*   int i, j; */ | 
| 700 | 
  | 
  | 
 | 
| 701 | 
  | 
  | 
/*   out = (double *) calloc(rows * cols,  sizeof(double)); */ | 
| 702 | 
  | 
  | 
   | 
| 703 | 
  | 
  | 
/*   if (!out){ */ | 
| 704 | 
  | 
  | 
/*     printf("Fail to allocate memory\n"); */ | 
| 705 | 
  | 
  | 
/*     exit(1);  */ | 
| 706 | 
  | 
  | 
/*   }  */ | 
| 707 | 
  | 
  | 
 | 
| 708 | 
  | 
  | 
/*   for (i = 0; i < rows; i++) */ | 
| 709 | 
  | 
  | 
/*     for (j = 0; j < cols; j++) */ | 
| 710 | 
  | 
  | 
/*       out[i+j*cols] = in[i][j]; */ | 
| 711 | 
  | 
  | 
   | 
| 712 | 
  | 
  | 
/*   return(out); */ | 
| 713 | 
  | 
  | 
/* } */ | 
| 714 | 
  | 
  | 
 | 
| 715 | 
  | 
  | 
/* void dsyev_ftoc2(double *in, double **out, int rows, int cols) */ | 
| 716 | 
  | 
  | 
/* { */ | 
| 717 | 
  | 
  | 
/*   int i, j; */ | 
| 718 | 
  | 
  | 
 | 
| 719 | 
  | 
  | 
/*   for (i = 0; i < rows; i++) */ | 
| 720 | 
  | 
  | 
/*     for (j = 0; j < cols; j++) */ | 
| 721 | 
  | 
  | 
/*       out[i][j] = in[i+j*cols]; */ | 
| 722 | 
  | 
  | 
/* } */ | 
| 723 | 
  | 
  | 
/* void direct(double rcut, double box, int n, int nstep, int maxbin){ */ | 
| 724 | 
  | 
  | 
 | 
| 725 | 
  | 
  | 
/*   int bin, maxbin, nbins, i, j, k, n, bind, which; */ | 
| 726 | 
  | 
  | 
/*   int hist[maxbin], histd[maxbin], startstep; */ | 
| 727 | 
  | 
  | 
/*   int nstep, stopstep, ndiag, nfilled, ifail, lwork; */ | 
| 728 | 
  | 
  | 
/*   double delr, rijsp, rxij, ryij, rzij, rij; */ | 
| 729 | 
  | 
  | 
/*   double delrd, rijsqd, rijd, orderpar[1000], nideal; */ | 
| 730 | 
  | 
  | 
/*   double omat[3][3], evals[100], cons, rlower; */ | 
| 731 | 
  | 
  | 
/*   double rcut, box, dens, director[3][1000], rupper; */ | 
| 732 | 
  | 
  | 
/*   double rx[1000][1000], ry[1000][1000], rz[1000][1000]; */ | 
| 733 | 
  | 
  | 
/*   double ux[1000][1000], uy[1000][1000], uz[1000][1000]; */ | 
| 734 | 
  | 
  | 
/*   double vx[1000][1000], vy[1000][1000], vz[1000][1000]; */ | 
| 735 | 
  | 
  | 
/*   double jx[1000][1000], jy[1000][1000], jz[1000][1000]; */ | 
| 736 | 
  | 
  | 
/*   double grd[5000], gr[5000], max, binmin, binmax; */ | 
| 737 | 
  | 
  | 
/*   double onethird, ordvals[5000]; */ | 
| 738 | 
  | 
  | 
/*   char job, uplo; */ | 
| 739 | 
  | 
  | 
/*   int ndiag; */ | 
| 740 | 
  | 
  | 
/*   int nfilled; */ | 
| 741 | 
  | 
  | 
/*   double omat[3][3]; */ | 
| 742 | 
  | 
  | 
/*   double evals[100]; */ | 
| 743 | 
  | 
  | 
/*   double work[]; */ | 
| 744 | 
  | 
  | 
/*   int lwork; */ | 
| 745 | 
  | 
  | 
/*   int ifail; */ | 
| 746 | 
  | 
  | 
 | 
| 747 | 
  | 
  | 
/*   lwork = 9; */ | 
| 748 | 
  | 
  | 
/*   work = (double *)calloc(lwork, sizeof(double)); */ | 
| 749 | 
  | 
  | 
 | 
| 750 | 
  | 
  | 
/*   onethird = 1.0 / 3.0; */ | 
| 751 | 
  | 
  | 
/*   ndiag = 3; */ | 
| 752 | 
  | 
  | 
/*   nfilled = 3; */ | 
| 753 | 
  | 
  | 
/*   job = 'V'; */ | 
| 754 | 
  | 
  | 
/*   uplo = 'U'; */ | 
| 755 | 
  | 
  | 
/*   ifail = 0; */ | 
| 756 | 
  | 
  | 
 | 
| 757 | 
  | 
  | 
/*   binmin = 0.0; */ | 
| 758 | 
  | 
  | 
/*   binmax = 1.0; */ | 
| 759 | 
  | 
  | 
/*   delr = (binmax - binmin) / (double) maxbin; */ | 
| 760 | 
  | 
  | 
 | 
| 761 | 
  | 
  | 
/*   for(i = 0; i < maxbin; i++){ */ | 
| 762 | 
  | 
  | 
 | 
| 763 | 
  | 
  | 
/*     ordvals(i) = 0.0; */ | 
| 764 | 
  | 
  | 
/*     hist(i) = 0.0; */ | 
| 765 | 
  | 
  | 
     | 
| 766 | 
  | 
  | 
/*   } */ | 
| 767 | 
  | 
  | 
 | 
| 768 | 
  | 
  | 
/*   for(i = 0; i < stopstep; i++){ */ | 
| 769 | 
  | 
  | 
 | 
| 770 | 
  | 
  | 
/*     for(j = 0; j < 3; j++){ */ | 
| 771 | 
  | 
  | 
/*       for(k = 0; k < 3; k++){ */ | 
| 772 | 
  | 
  | 
/*         omat[j][k] = 0.0; */ | 
| 773 | 
  | 
  | 
/*       } */ | 
| 774 | 
  | 
  | 
/*     } */ | 
| 775 | 
  | 
  | 
     | 
| 776 | 
  | 
  | 
/*     for(j = 0; j < n; j++){ */ | 
| 777 | 
  | 
  | 
     | 
| 778 | 
  | 
  | 
/*       omat[1][1] = omat[1][1] + ux[j][i] * ux[j][i] - onethird; */ | 
| 779 | 
  | 
  | 
/*       omat[1][2] = omat[1][2] + ux[j][i] * uy[j][i]; */ | 
| 780 | 
  | 
  | 
/*       omat[1][3] = omat[1][3] + ux[j][i] * uz[j][i]; */ | 
| 781 | 
  | 
  | 
/*       omat[2][1] = omat[2][1] + uy[j][i] * ux[j][i]; */ | 
| 782 | 
  | 
  | 
/*       omat[2][2] = omat[2][2] + uy[j][i] * uy[j][i] - onethird; */ | 
| 783 | 
  | 
  | 
/*       omat[2][3] = omat[2][3] + uy[j][i] * uz[j][i]; */ | 
| 784 | 
  | 
  | 
/*       omat[3][1] = omat[3][1] + uz[j][i] * ux[j][i]; */ | 
| 785 | 
  | 
  | 
/*       omat[3][2] = omat[3][2] + uz[j][i] * uy[j][i]; */ | 
| 786 | 
  | 
  | 
/*       omat[3][3] = omat[3][3] + uz[j][i] * uz[j][i] - onethird; */ | 
| 787 | 
  | 
  | 
     | 
| 788 | 
  | 
  | 
/*     } */ | 
| 789 | 
  | 
  | 
 | 
| 790 | 
  | 
  | 
   | 
| 791 | 
  | 
  | 
/*     for(j = 0; j < 3; j++){ */ | 
| 792 | 
  | 
  | 
/*       for(k = 0; k < 3; k++){ */ | 
| 793 | 
  | 
  | 
/*         omat[j][k] = omat[j][k] / (double) n; */ | 
| 794 | 
  | 
  | 
/*       } */ | 
| 795 | 
  | 
  | 
/*     } */ | 
| 796 | 
  | 
  | 
 | 
| 797 | 
  | 
  | 
/*     dsyev_(job, uplo, nfilled, omat, ndiag, evals, work, lwork, ifail); */ | 
| 798 | 
  | 
  | 
 | 
| 799 | 
  | 
  | 
/*     max = 0.0; */ | 
| 800 | 
  | 
  | 
/*     for(j = 0; j < 3; j++){ */ | 
| 801 | 
  | 
  | 
/*       if(fabs(evals(j)) > max){ */ | 
| 802 | 
  | 
  | 
/*         which = j; */ | 
| 803 | 
  | 
  | 
/*         max = fabs(evals(j)); */ | 
| 804 | 
  | 
  | 
/*       } */ | 
| 805 | 
  | 
  | 
/*     } */ | 
| 806 | 
  | 
  | 
     | 
| 807 | 
  | 
  | 
/*     director[1][i] = omat[1][which]; */ | 
| 808 | 
  | 
  | 
/*     director[2][i] = omat[2][which]; */ | 
| 809 | 
  | 
  | 
/*     director[3][i] = omat[3][which]; */ | 
| 810 | 
  | 
  | 
 | 
| 811 | 
  | 
  | 
/*     orderpar(i) = 1.5 * max; */ | 
| 812 | 
  | 
  | 
 | 
| 813 | 
  | 
  | 
/*     bin = (int) (orderpar(i) / delr) + 1; */ | 
| 814 | 
  | 
  | 
 | 
| 815 | 
  | 
  | 
/*     if(bin < maxbin) */ | 
| 816 | 
  | 
  | 
/*       hist(bin) = hist(bin) + 1; */ | 
| 817 | 
  | 
  | 
/*   } */ | 
| 818 | 
  | 
  | 
   | 
| 819 | 
  | 
  | 
/*   cons = 1.0; */ | 
| 820 | 
  | 
  | 
/*   for(bin = 0; bin < maxbin; bin++){ */ | 
| 821 | 
  | 
  | 
     | 
| 822 | 
  | 
  | 
/*     rlower = (double) (bin - 1) * delr; */ | 
| 823 | 
  | 
  | 
/*     rupper = rlower + delr; */ | 
| 824 | 
  | 
  | 
/*     ordvals(bin) = rlower + (delr / 2.0); */ | 
| 825 | 
  | 
  | 
/*     nideal = cons * (pow(rupper, 3) - pow(rlower, 3)); */ | 
| 826 | 
  | 
  | 
/*     gr(bin) = (double) (hist(bin)) / (double) nstep /nideal; */ | 
| 827 | 
  | 
  | 
     | 
| 828 | 
  | 
  | 
/*   } */ | 
| 829 | 
  | 
  | 
/* } */ |