Ejemplo n.º 1
0
// Read part_struct data
void cgns_fill_parts(void)
{
  // Open cgns file and get cgns file index number fn
  char buf[FILE_NAME_SIZE];
  sprintf(buf, "%s/%s/%s", SIM_ROOT_DIR, OUTPUT_DIR, partFiles[partFileMap[tt]]);
  int fn;
  int ier = cg_open(buf, CG_MODE_READ, &fn);
  if (ier != 0 ) {
    printf("\nCGNS Error on file %s\n", buf);
    free_vars();
    cg_close(fn);
    cg_error_exit();
  }
  fflush(stdout);
  
  // Set base, zone, and solutions index numbers
  int bn = 1;
  int zn = 1;
  int sn = 1;

  // Read part coords
  double *x = malloc(nparts * sizeof(double));
  double *y = malloc(nparts * sizeof(double));
  double *z = malloc(nparts * sizeof(double));
  for (int p = 0; p < nparts; p++) {
    x[p] = 0;
    y[p] = 0;
    z[p] = 0;
  }

  cgsize_t range_min = 1;
  cgsize_t range_max = nparts;

  cg_coord_read(fn,bn,zn, "CoordinateX", RealDouble, &range_min, &range_max, x);
  cg_coord_read(fn,bn,zn, "CoordinateY", RealDouble, &range_min, &range_max, y);
  cg_coord_read(fn,bn,zn, "CoordinateZ", RealDouble, &range_min, &range_max, z);

  for (int p = 0; p < nparts; p++) {
    parts[p].x = x[p];
    parts[p].y = y[p];
    parts[p].z = z[p];
  }

  // Read part vel
  cg_field_read(fn,bn,zn,sn, "VelocityX", RealDouble, &range_min, &range_max, up);
  cg_field_read(fn,bn,zn,sn, "VelocityY", RealDouble, &range_min, &range_max, vp);
  cg_field_read(fn,bn,zn,sn, "VelocityZ", RealDouble, &range_min, &range_max, wp);

  // Calculate kinetic energy
  for (int p = 0; p < nparts; p++) {
    ke[p] = 0.5*(up[p]*up[p] + vp[p]*vp[p] + wp[p]*wp[p]);
    //ke[p] = 0.5*wp[p]*wp[p];
  }

  free(x);
  free(y);
  free(z);
  
  cg_close(fn);
}
int main()
{
/*
  dimension statements (note that tri-dimensional arrays
  r and p must be dimensioned exactly as [N-1][17-1][21-1] (N>=9) 
  for this particular case or else they will be read from 
  the CGNS file incorrectly!  Other options are to use 1-D 
  arrays, use dynamic memory, or pass index values to a 
  subroutine and dimension exactly there):
*/
    double r[8][16][20],p[8][16][20];
    cgsize_t isize[3][3],irmin[3],irmax[3];
    int index_file,index_base,index_zone,index_flow;
    char zonename[33],solname[33];
    GridLocation_t loc;

/* READ FLOW SOLUTION FROM CGNS FILE */
/* open CGNS file for read-only */
    if (cg_open("grid_c.cgns",CG_MODE_READ,&index_file)) cg_error_exit();
/* we know there is only one base (real working code would check!) */
    index_base=1;
/* we know there is only one zone (real working code would check!) */
    index_zone=1;
/* we know there is only one FlowSolution_t (real working code would check!) */
    index_flow=1;
/* get zone size (and name - although not needed here) */
    cg_zone_read(index_file,index_base,index_zone,zonename,isize[0]);
/* lower range index */
    irmin[0]=1;
    irmin[1]=1;
    irmin[2]=1;
/* upper range index - use cell dimensions */
/* checking GridLocation first (real working code would check */
/* to make sure there are no Rind cells also!): */
    cg_sol_info(index_file,index_base,index_zone,index_flow,solname,&loc);
    if (loc != CellCenter)
    {
      printf("\nError, GridLocation must be CellCenter! Currently: %s\n",
          GridLocationName[loc]);
      return 1;
    }
    irmax[0]=isize[1][0];
    irmax[1]=isize[1][1];
    irmax[2]=isize[1][2];
/* read flow solution */
    cg_field_read(index_file,index_base,index_zone,index_flow,"Density", \
                  RealDouble,irmin,irmax,r[0][0]);
    cg_field_read(index_file,index_base,index_zone,index_flow,"Pressure", \
                  RealDouble,irmin,irmax,p[0][0]);
/* close CGNS file */
    cg_close(index_file);
    printf("\nSuccessfully read flow solution from file grid_c.cgns\n");
    printf("  For example, r,p[7][15][19]= %f, %f\n",r[7][15][19],p[7][15][19]);
    printf("\nProgram successful... ending now\n");
    return 0;
}
int main()
{
    float r[9*17*21],p[9*17*21];
    cgsize_t isize[3][1],irmin,irmax;
    int index_file,index_base,index_zone,index_flow;
    char zonename[33],solname[33];
    GridLocation_t loc;

/* READ FLOW SOLUTION FROM CGNS FILE */
/* open CGNS file for read-only */
    if (cg_open("grid_c.cgns",CG_MODE_READ,&index_file)) cg_error_exit();
/* we know there is only one base (real working code would check!) */
    index_base=1;
/* we know there is only one zone (real working code would check!) */
    index_zone=1;
/* we know there is only one FlowSolution_t (real working code would check!) */
    index_flow=1;
/* get zone size (and name - although not needed here) */
    cg_zone_read(index_file,index_base,index_zone,zonename,isize[0]);
/* lower range index */
    irmin=1;
/* upper range index - use vertex dimensions */
/* checking GridLocation first (real working code would check */
/* to make sure there are no Rind cells also!): */
    cg_sol_info(index_file,index_base,index_zone,index_flow,solname,&loc);
    if (loc != Vertex)
    {
      printf("\nError, GridLocation must be Vertex! Currently: %s\n",
          GridLocationName[loc]);
      return 1;
    }
    irmax=isize[0][0];
/* read flow solution */
    cg_field_read(index_file,index_base,index_zone,index_flow,"Density", \
                  RealSingle,&irmin,&irmax,r);
    cg_field_read(index_file,index_base,index_zone,index_flow,"Pressure", \
                  RealSingle,&irmin,&irmax,p);
/* close CGNS file */
    cg_close(index_file);
    printf("\nSuccessfully read flow solution from file grid_c.cgns\n");
    printf("  For example, r,p[379] = %f, %f\n",r[379],p[379]);
    printf("               r,p[3212]= %f, %f\n",r[3212],p[3212]);
    printf("\nProgram successful... ending now\n");
    return 0;
}
Ejemplo n.º 4
0
// Read data
void cgns_fill_input(void)
{
  // Open cgns file and get cgns file index number fn
  char buf[FILE_NAME_SIZE];
  sprintf(buf, "%s/data/%s", ANALYSIS_DIR, files[fileMap[tt]]);
  int fn;
  int ier = cg_open(buf, CG_MODE_READ, &fn);
  if (ier != 0 ) {
    printf("CGNS Error - double check grid.cgns exists in output\n");
    cg_error_exit();
  }
  fflush(stdout);
  
  // Set base, zone, and solutions index numbers
  int bn = 1;
  int zn = 1;
  int sn = 1;

  // Size of array to pull
  cgsize_t range_min[3];
  range_min[0] = 1;
  range_min[1] = 1;
  range_min[2] = 1;
  cgsize_t range_max[3];
  range_max[0] = dom.xn;
  range_max[1] = dom.yn;
  range_max[2] = dom.zn;

  // Read and fill
  cg_field_read(fn,bn,zn,sn, "Volume Fraction Real", RealDouble, range_min, 
    range_max, volume_fraction);

  cg_close(fn);

  // Zero the averages
  for (int i = 0; i < dom.Gcc.s2; i++) {
    moving_avg[i] = 0.;
    stationary_avg[i] = 0.;
  }
}
Ejemplo n.º 5
0
// Read part_struct data
void cgns_fill_part_struct(void)
{
  // Open cgns file and get cgns file index number fn
  char buf[FILE_NAME_SIZE];
  sprintf(buf, "%s/%s/%s", ROOT_DIR, OUTPUT_DIR, partFiles[fileMap[tt]]);
  int fn;
  cg_open(buf, CG_MODE_READ, &fn);
  
  // Set base, zone, and solutions index numbers
  int bn = 1;
  int zn = 1;
  int sn = 1;

  // Read part coords
  double *x = malloc(nparts * sizeof(double));
  double *y = malloc(nparts * sizeof(double));
  double *z = malloc(nparts * sizeof(double));
  for (int p = 0; p < nparts; p++) {
    x[p] = 0;
    y[p] = 0;
    z[p] = 0;
  }

  cgsize_t range_min = 1;
  cgsize_t range_max = nparts;

  cg_coord_read(fn,bn,zn, "CoordinateX", RealDouble, &range_min, &range_max, x);
  cg_coord_read(fn,bn,zn, "CoordinateY", RealDouble, &range_min, &range_max, y);
  cg_coord_read(fn,bn,zn, "CoordinateZ", RealDouble, &range_min, &range_max, z);

  for (int p = 0; p < nparts; p++) {
    parts[p].x = x[p];
    parts[p].y = y[p];
    parts[p].z = z[p];
  }

  // Read part vel
  double *u = malloc(nparts * sizeof(double));
  double *v = malloc(nparts * sizeof(double));
  double *w = malloc(nparts * sizeof(double));
  for (int p = 0; p < nparts; p++) {
    w[p] = 0;
    v[p] = 0;
    w[p] = 0;
  }
  cg_field_read(fn,bn,zn,sn, "VelocityX", RealDouble, &range_min, &range_max, u);
  cg_field_read(fn,bn,zn,sn, "VelocityY", RealDouble, &range_min, &range_max, v);
  cg_field_read(fn,bn,zn,sn, "VelocityZ", RealDouble, &range_min, &range_max, w);

  for (int p = 0; p < nparts; p++) {
    parts[p].u = u[p];
    parts[p].v = v[p];
    parts[p].w = w[p];
  }

  // Read actual time
  cg_goto(fn, bn, "Zone_t", zn, "Etc", 0, "end");
  cg_array_read(1, &simTime[tt]);

  free(x);
  free(y);
  free(z);
  free(u);
  free(v);
  free(w);
  
  cg_close(fn);
}
Ejemplo n.º 6
0
// initialize part_struct
void parts_init(void)
{
  parts = (part_struct*) malloc(nparts * sizeof(part_struct));

  for(int p = 0; p < nparts; p++) {
    parts[p].x = -1.;
    parts[p].y = -1.;
    parts[p].z = -1.;
    parts[p].r = -1.;
    parts[p].bin = -1;
    parts[p].u = -1.;
    parts[p].v = -1.;
    parts[p].w = -1.;
    parts[p].flipCountX = 0.;
    parts[p].flipCountY = 0.;
    parts[p].flipCountZ = 0.;
  }

  // Open cgns file and get cgns file index number fn
  char buf[FILE_NAME_SIZE];
  sprintf(buf, "%s/%s/%s", ROOT_DIR, OUTPUT_DIR, partFiles[fileMap[0]]);
  int fn;
  cg_open(buf, CG_MODE_READ, &fn);
  
  // Set base, zone, and solutions index numbers
  int bn = 1;
  int zn = 1;
  int sn = 1;

  // Read part coords
  double *x = malloc(nparts * sizeof(double));
  double *y = malloc(nparts * sizeof(double));
  double *z = malloc(nparts * sizeof(double));
  for (int p = 0; p < nparts; p++) {
    x[p] = 0;
    y[p] = 0;
    z[p] = 0;
  }

  cgsize_t range_min = 1;
  cgsize_t range_max = nparts;

  cg_coord_read(fn,bn,zn, "CoordinateX", RealDouble, &range_min, &range_max, x);
  cg_coord_read(fn,bn,zn, "CoordinateY", RealDouble, &range_min, &range_max, y);
  cg_coord_read(fn,bn,zn, "CoordinateZ", RealDouble, &range_min, &range_max, z);

  for (int p = 0; p < nparts; p++) {
    parts[p].x = x[p];
    parts[p].y = y[p];
    parts[p].z = z[p];
  }

  // Read part radius
  double *r = malloc(nparts * sizeof(double));
  for (int p = 0; p < nparts; p++) {
    r[p] = 0;
  }

  cg_field_read(fn,bn,zn,sn, "Radius", RealDouble, &range_min, &range_max, r);

  for (int p = 0; p < nparts; p++) {
    parts[p].r = r[p];
  }

//  #ifdef DEBUG
//  for (int p = 0; p < nparts; p++) {
//    printf("  p = %d, (x,y,z); (%lf, %lf, %lf); %lf\n", p, x[p], y[p], z[p], 
//      r[p]);
//  }
//  #endif

  cg_close(fn);
  free(x);
  free(y);
  free(z);
  free(r);
}
Ejemplo n.º 7
0
// initialize part_struct
void parts_init(void)
{
  parts = (part_struct*) malloc(nparts * sizeof(part_struct));
  up = (double*) malloc(nparts * sizeof(double));
  vp = (double*) malloc(nparts * sizeof(double));
  wp = (double*) malloc(nparts * sizeof(double));
  ke = (double*) malloc(nparts * sizeof(double));

  for(int p = 0; p < nparts; p++) {
    parts[p].x = -1;
    parts[p].y = -1;
    parts[p].z = -1;
    parts[p].r = -1;
    up[p] = 0.;
    vp[p] = 0.;
    wp[p] = 0.;
    ke[p] = 0.;
  }

  // Open cgns file and get cgns file index number fn
  char buf[FILE_NAME_SIZE];
  sprintf(buf, "%s/%s/%s", SIM_ROOT_DIR, OUTPUT_DIR, partFiles[partFileMap[0]]);
  int fn;
  int ier = cg_open(buf, CG_MODE_READ, &fn);
  if (ier != 0 ) {
    printf("\nCGNS Error on file %s\n", buf);
    cg_error_exit();
  }
  fflush(stdout);
  
  // Set base, zone, and solutions index numbers
  int bn = 1;
  int zn = 1;
  int sn = 1;

  cgsize_t range_min = 1;
  cgsize_t range_max = nparts;

  // Read part radius
  double *r = malloc(nparts * sizeof(double));
  for (int p = 0; p < nparts; p++) {
    r[p] = 0;
  }

  ier = cg_field_read(fn,bn,zn,sn, "Radius", RealDouble, &range_min, &range_max, r);
  if (ier != 0 ) {
    printf("\nCGNS Error on file %s\n", buf);
    cg_error_exit();
  }
  fflush(stdout);

  meanR = 0.;
  for (int p = 0; p < nparts; p++) {
    parts[p].r = r[p];
    meanR += parts[p].r;
  }
  meanR /= nparts;

  cg_close(fn);
  free(r);
}
Ejemplo n.º 8
0
// Read data
void cgns_fill(void)
{
  // Open cgns file and get cgns file index number fn
  char buf[FILE_NAME_SIZE];
  sprintf(buf, "%s/output/%s", SIM_ROOT_DIR, files[fileMap[tt]]);
  int fn;
  int ier = cg_open(buf, CG_MODE_READ, &fn);
  if (ier != 0 ) {
    printf("CGNS Error - double check grid.cgns exists");
    printf(" in same directory as %s\n", buf);
    cg_error_exit();
  }
  fflush(stdout);
  
  // Set base, zone, and solutions index numbers
  int bn = 1;
  int zn = 1;
  int sn = 1;

  // Size of array to pull
  cgsize_t range_min = 1;
  cgsize_t range_max = nparts;;

  // Read and fill
  cg_field_read(fn,bn,zn,sn, "VelocityX", RealDouble, &range_min, 
    &range_max, up);
  cg_field_read(fn,bn,zn,sn, "VelocityY", RealDouble, &range_min, 
    &range_max, vp);
  cg_field_read(fn,bn,zn,zn, "VelocityZ", RealDouble, &range_min, 
    &range_max, wp);
  cg_field_read(fn,bn,zn,sn, "AngularVelocityX", RealDouble, &range_min, 
    &range_max, ox);
  cg_field_read(fn,bn,zn,sn, "AngularVelocityY", RealDouble, &range_min, 
    &range_max, oy);
  cg_field_read(fn,bn,zn,zn, "AngularVelocityZ", RealDouble, &range_min, 
    &range_max, oz);

  // Calculate mean
  double up_mean = 0.;
  double vp_mean = 0.;
  double wp_mean = 0.;
  double inparts = 1./nparts;
  for (int p = 0; p < nparts; p++) {
    up_mean += inparts*up[p];
    vp_mean += inparts*vp[p];
    wp_mean += inparts*wp[p];
  }

  for (int p = 0; p < nparts; p++) {
    // subtract mean
    up[p] -= up_mean;
    vp[p] -= vp_mean;
    wp[p] -= wp_mean;

    // Calculate temperatures
    T_perp[p] = mass*(up[p]*up[p] + vp[p]*vp[p]);
    T_z[p]    = mass*(wp[p]*wp[p]);
    T[p]      = (T_perp[p] + T_z[p])/3.;

    // Speed
    U[p] = sqrt(up[p]*up[p] + vp[p]*vp[p] + wp[p]*wp[p]);

    // Ke
    ke_rot[p] = 0.5*meanI*(ox[p]*ox[p] + oy[p]*oy[p] + oz[p]*oz[p]);
    ke_trans[p] = 1.5*T[p];
    ke[p] = ke_rot[p] + ke_trans[p];
  }

  cg_close(fn);
}
Ejemplo n.º 9
0
// Read domain
void domain_init(void)
{
  int fret = 0;
  fret = fret;  // prevent compiler warning

  // read nparts from part.config
  char fname[FILE_NAME_SIZE] = "";
  sprintf(fname, "%s/input/part.config", SIM_ROOT_DIR);
  FILE *infile = fopen(fname, "r");
  if (infile == NULL) {
    printf("Could not open file %s\n", fname);
    exit(EXIT_FAILURE);
  }
  fret = fscanf(infile, "n %d\n", &nparts);
  fclose(infile);

  // Set up variables
  up = (double*) malloc(nparts * sizeof(double));
  vp = (double*) malloc(nparts * sizeof(double));
  wp = (double*) malloc(nparts * sizeof(double));
  ox = (double*) malloc(nparts * sizeof(double));
  oy = (double*) malloc(nparts * sizeof(double));
  oz = (double*) malloc(nparts * sizeof(double));
  U = (double*) malloc(nparts * sizeof(double));
  ke = (double*) malloc(nparts * sizeof(double));
  ke_rot = (double*) malloc(nparts * sizeof(double));
  ke_trans = (double*) malloc(nparts * sizeof(double));
  T = (double*) malloc(nparts * sizeof(double));
  T_perp = (double*) malloc(nparts * sizeof(double));
  T_z = (double*) malloc(nparts * sizeof(double));
  for (int i = 0; i < nparts; i++) {
    up[i] = 0.; 
    vp[i] = 0.;
    wp[i] = 0.;
    ox[i] = 0.;
    oy[i] = 0.;
    oz[i] = 0.;
    U[i] = 0.;
    ke[i] = 0.;
    ke_rot[i] = 0.;
    ke_trans[i] = 0.;
    T[i] = 0.;
    T_perp[i] = 0.;
    T_z[i] = 0.;
  }
  hist_U = (int*) malloc(nBins * sizeof(int));
  hist_ke = (int*) malloc(nBins * sizeof(int));
  hist_ke_rot = (int*) malloc(nBins * sizeof(int));
  hist_ke_trans = (int*) malloc(nBins * sizeof(int));
  hist_T = (int*) malloc(nBins * sizeof(int));
  hist_T_perp = (int*) malloc(nBins * sizeof(int));
  hist_T_z = (int*) malloc(nBins * sizeof(int));
  hist_ux = (int*) malloc(nBins * sizeof(int));
  hist_vy = (int*) malloc(nBins * sizeof(int));
  hist_wz = (int*) malloc(nBins * sizeof(int));
  for (int i = 0; i < nBins; i++) {
    hist_U[i] = 0;
    hist_ke[i] = 0;
    hist_ke_rot[i] = 0;
    hist_ke_trans[i] = 0;
    hist_T[i] = 0;
    hist_T_perp[i] = 0;
    hist_T_z[i] = 0;
    hist_ux[i] = 0;
    hist_vy[i] = 0;
    hist_wz[i] = 0;
  }

  // Init parts
  char buf[FILE_NAME_SIZE];
  sprintf(buf, "%s/%s/%s", SIM_ROOT_DIR,OUTPUT_DIR, files[fileMap[0]]);
  int fn;
  cg_open(buf, CG_MODE_READ, &fn);

  // SEt base, zone, soln
  int bn = 1;
  int zn = 1;
  int sn = 1;

  cgsize_t range_min = 1;
  cgsize_t range_max = nparts;

  // Read part radius
  double *r = malloc(nparts * sizeof(double));
  double *rho = malloc(nparts * sizeof(double));
  cg_field_read(fn,bn,zn,sn, "Radius", RealDouble, &range_min, &range_max, r);
  cg_field_read(fn,bn,zn,sn, "Density", RealDouble, &range_min, &range_max, rho);

  // Calculate meanR, rho, meanI, mass
  meanR = 0.;
  double meanRho = 0.;
  for (int p = 0; p < nparts; p++) {
    meanR += r[p];
    meanRho += rho[p];
  }
  meanR /= nparts;
  meanRho /= nparts;
  mass = 4./3.*PI*meanR*meanR*meanR * meanRho;
  meanI = 2.*mass*meanR*meanR/5.;

  cg_close(fn);
  free(r);
  free(rho);
}