Example #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);
}
Example #2
0
void lp_close(lp_prob *p)
{
#ifndef COMPILE_IN_LP
   int s_bufid;
   
   /* Send back the timing data for the whole algorithm */
   s_bufid = init_send(DataInPlace);
   send_char_array((char *)&p->comp_times, sizeof(node_times));
   send_msg(p->tree_manager, LP__TIMING);
   freebuf(s_bufid);
#else
#pragma omp critical (timing_update)
{
   p->tm->comp_times.communication    += p->comp_times.communication;
   p->tm->comp_times.lp               += p->comp_times.lp;
   p->tm->comp_times.separation       += p->comp_times.separation;
   p->tm->comp_times.fixing           += p->comp_times.fixing;
   p->tm->comp_times.pricing          += p->comp_times.pricing;
   p->tm->comp_times.strong_branching += p->comp_times.strong_branching;
}
#endif
#ifdef COMPILE_IN_CG
   cg_close(p->cgp);
#endif
#ifndef COMPILE_IN_TM
   free_lp(p);
#endif
}
Example #3
0
// read number of particles from cgns file
int cgns_read_nparts(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[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 index nuber and zone index number (only one, so is 1)
  int bn = 1;
  int zn = 1;

  // Read zone to find cgsize_t *size, or nparts
  char zonename[FILE_NAME_SIZE] = "";
  cgsize_t nparts = 0;
  ier = cg_zone_read(fn, bn, zn, zonename, &nparts);
  if (ier != 0 ) {
    printf("\nCGNS Error on file %s\n", buf);
    cg_error_exit();
  }
  fflush(stdout);

  cg_close(fn);

  return nparts;
}
Example #4
0
int main()
{
    int index_file,index_base,ndescriptors,n;
    char *text,name[33];

/* READ DESCRIPTOR FROM EXISTING 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;
/* go to base node */
    cg_goto(index_file,index_base,"end");
/* find out how many descriptors are here: */
    cg_ndescriptors(&ndescriptors);
    for (n=1; n <= ndescriptors; n++)
    {
/* read descriptor */
      cg_descriptor_read(n,name,&text);
      printf("\nThe descriptor is:\n\n%s\n",text);
    }
/* close CGNS file */
    cg_close(index_file);
    printf("\nSuccessfully read descriptors from file grid_c.cgns\n");
    return 0;
}
/**
 *  Dibuje el triángulo formado por los vértices [(-1,-1,-2), (1,-1,-2), (0,1,-2)].
 */
int main(int argc, char* argv[])
{
// Crear una ventana de 500x500 pixels:

	int cw = 500;
	int ch = 500;

	cg_init(cw, ch, NULL);

	// Utilizando la función glGetString, imprima por consola el número de versión de OpenGL que utiliza su sistema.
	printf("GL Version: %s\n", glGetString(GL_VERSION));

	// specifies the red, green, blue, and alpha values used by glClear to clear the color buffers.
	glClearColor(1.0f, 1.0f, 1.0f, 0.0f);

	// Actualizar la pantalla:
	glMatrixMode(GL_MODELVIEW);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();
	glMatrixMode(GL_PROJECTION);
	glViewport(0,0,cw, ch);
	glFrustum(-1,1,-1,1,1,1000);

	glClear(GL_COLOR_BUFFER_BIT);
	glPointSize(10.0f);

	glBegin(GL_TRIANGLES);
		glColor3f(0.3f, 0.8f, 0.1f);
		glVertex3f(-1.0f, -1.0f, -2.0f);
		glVertex3f(0.0f,1.0f, -2.0f);
		glVertex3f(-2.0f, 1.0f, -2.0f);
	glEnd();


	cg_repaint();

	int done = 0;

	while (!done)
	{
		SDL_Event event;
		while(SDL_PollEvent(&event))
		{
			switch (event.type)
			{
				case SDL_KEYDOWN:
					if (event.key.keysym.sym != SDLK_ESCAPE)
						break;
				case SDL_QUIT : done = 1;
			}
		}

		cg_repaint();
	}
	// Liberar recursos:
	cg_close();

	return 0;
}
void file::close( const char* caller )
{
	int ier = cg_close( _fileindex );
	check_error( caller, "cg_close", ier );
	//_basenode.erase( _basenode.begin(), _basenode.end() );
	_fileindex = 0;
	_valid = false;
}
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()
{
    int index_file,index_base,index_zone,nbocos,ib;
    int normalindex[3],ndataset;
    int i,normallist;
    char boconame[33];
    BCType_t ibocotype;
    PointSetType_t iptset;
    DataType_t normaldatatype;
    cgsize_t npts,normallistflag;
    cgsize_t ipnts[maxpnts][3];

/* READ BOUNDARY CONDITIONS FROM EXISTING 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;
/* find out number of BCs that exist under this zone */
    cg_nbocos(index_file,index_base,index_zone,&nbocos);
/* do loop over the total number of BCs */
    for (ib=1; ib <= nbocos; ib++)
    {
/* get BC info */
      cg_boco_info(index_file,index_base,index_zone,ib,boconame,&ibocotype,
                   &iptset,&npts,normalindex,&normallistflag,&normaldatatype,&ndataset);
      if (iptset != PointList)
      {
        printf("\nError.  For this program, BCs must be set up as PointList type %s\n",
            PointSetTypeName[iptset]);
        return 1;
      }
      printf("\nBC number: %i\n",ib);
      printf("   name= %s\n",boconame);
      printf("   type= %s\n",BCTypeName[ibocotype]);
      printf("   no of pts= %i\n",(int)npts);
      if (npts > maxpnts)
      {
        printf("\nError.  Must increase maxpnts to at least %i\n",(int)npts);
        return 1;
      }
/* read point list in here (nothing done with them in this program) */
      cg_boco_read(index_file,index_base,index_zone,ib,ipnts[0],&normallist);
      printf("      (these points read here, but only some printed out:)\n");
      for (i=0; i < 10; i++)
      {
        printf("    ipnts[%i][0], [%i][1], [%i][2]=%i,%i,%i\n",
               i,i,i,(int)ipnts[i][0],(int)ipnts[i][1],(int)ipnts[i][2]);
      }
    }
/* close CGNS file */
    cg_close(index_file);
    printf("\nSuccessfully read BCs (PointList format) from file grid_c.cgns\n");
    return 0;
}
Example #9
0
static PyObject *
cc_close (PyObject *self, PyObject *args)
{
	int hid = 0, code = 0, ret = 0;

	if (!PyArg_ParseTuple(args, "ii", &hid, &code)) {
		return NULL;
	}
	Py_BEGIN_ALLOW_THREADS
	ret = cg_close (hid, code) ;
	Py_END_ALLOW_THREADS
	return Py_BuildValue("i", ret);
}
Example #10
0
int main()
{
    double r[9*17*21],p[9*17*21];
    int ni,nj,nk,i,j,k,index_file,index_base,index_zone,index_flow,index_field,iset;
    char solname[33];

    printf("\nProgram write_flowvert_unst\n");

/* create fake flow solution AT CELL CENTERS for simple example: */
    ni=21;
    nj=17;
    nk=9;
    iset=0;
    for (k=0; k < nk; k++)
    {
      for (j=0; j < nj; j++)
      {
        for (i=0; i < ni; i++)
        {
          r[iset]=(float)i;
          p[iset]=(float)j;
          iset=iset+1;
        }
      }
    }
    printf("\ncreated simple 3-D rho and p flow solution\n");

/* WRITE FLOW SOLUTION TO EXISTING CGNS FILE */
/* open CGNS file for modify */
    if (cg_open("grid_c.cgns",CG_MODE_MODIFY,&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;
/* define flow solution node name (user can give any name) */
    strcpy(solname,"FlowSolution");
/* create flow solution node */
    cg_sol_write(index_file,index_base,index_zone,solname,Vertex,&index_flow);
/* write flow solution (user must use SIDS-standard names here) */
    cg_field_write(index_file,index_base,index_zone,index_flow,
        RealDouble,"Density",r,&index_field);
    cg_field_write(index_file,index_base,index_zone,index_flow,
        RealDouble,"Pressure",p,&index_field);
/* close CGNS file */
    cg_close(index_file);
    printf("\nSuccessfully added Vertex flow solution data to file grid_c.cgns (unstructured)\n");
    printf("\nNote:  if the original CGNS file already had a FlowSolution_t node,");
    printf("\n          it has been overwritten\n");
    return 0;
}
Example #11
0
int main()
{
    int itranfrm[3];
    int index_file,index_base,nzone,index_zone,n1to1,index_conn;
    char donorname[33],connectname[33];
    cgsize_t ipnts[2][3],ipntsdonor[2][3];

/* READ 1-TO-1 CONNECTIVITY INFORMATION FROM EXISTING 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;
/* get number of zones (should be 2 for our case) */
    cg_nzones(index_file,index_base,&nzone);
    if (nzone != 2)
    {
      printf("\nError. This program expects 2 zones. %d read.\n",nzone);
      return 1;
    }
/* loop over zones */
    for (index_zone=1; index_zone <= nzone; ++index_zone)
    {
/* find out how many 1-to-1 interfaces there are in this zone */
/* (for this program, there should only be one) */
      cg_n1to1(index_file,index_base,index_zone,&n1to1);
      if (n1to1 != 1)
      {
        printf("\nError.  Expecting one 1-to-1 interface. %i read\n",n1to1);
        return 1;
      }
      index_conn=n1to1;
/* read 1-to-1 info */
      cg_1to1_read(index_file,index_base,index_zone,index_conn,connectname,donorname,
                   ipnts[0],ipntsdonor[0],itranfrm);
      printf("\nIn zone %i:\n",index_zone);
      printf("   donor name=%s\n",donorname);
      printf("   range (this zone)=%i,%i,%i,%i,%i,%i\n",(int)ipnts[0][0],
              (int)ipnts[0][1],(int)ipnts[0][2],(int)ipnts[1][0],
              (int)ipnts[1][1],(int)ipnts[1][2]);
      printf("   range (donor zone)=%i,%i,%i,%i,%i,%i\n",(int)ipntsdonor[0][0],
              (int)ipntsdonor[0][1],(int)ipntsdonor[0][2],(int)ipntsdonor[1][0],
              (int)ipntsdonor[1][1],(int)ipntsdonor[1][2]);
      printf("   transform=%i,%i,%i\n",itranfrm[0],itranfrm[1],itranfrm[2]);
    }
/* close CGNS file */
    cg_close(index_file);
    printf("\nSuccessfully read 1-to-1 connectivity info from file grid_c.cgns\n");
    return 0;
}
int main()
{
    double data;
    int index_file,index_base,narrays,n,idim;
    char *state,arrayname[33];
    DataClass_t id;
    DataType_t idata;
    cgsize_t idimvec;

/* READ NONDIMENSIONAL INFO */
/* 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;
/* read DataClass under Base */
    cg_goto(index_file,index_base,"end");
    cg_dataclass_read(&id);
    printf("\nDataClass = %s\n",DataClassName[id]);
    if (id != NormalizedByUnknownDimensional)
    {
      printf("\nError!  Expecting NormalizedByUnknownDimensional\n");
      return 1;
    }
/* read ReferenceState under Base */
    cg_state_read(&state);
    printf("\nReferenceState = %s\n",state);
/* Go to ReferenceState node, read Mach array and its dataclass */
    cg_goto(index_file,index_base,"ReferenceState_t",1,"end");
/* find out how many data arrays */
    cg_narrays(&narrays);
    for (n=1; n <= narrays; n++)
    {
      cg_array_info(n,arrayname,&idata,&idim,&idimvec);
      if (idim != 1 || idimvec != 1)
      {
        printf("\nError! expecting idim,idimvec=1,1\n");
        printf("   they are idim,idimvec= %i, %i\n",idim,(int)idimvec);
        return 1;
      }
      cg_array_read_as(n,RealDouble,&data);
      printf("Variable=%s\n",arrayname);
      printf("    data=%18.8f\n",data);
    }
/* close CGNS file */
    cg_close(index_file);
    printf("\nSuccessfully read nondimensional info from file grid_c.cgns\n");
    return 0;
}
Example #13
0
int main()
{
    float cl[ntt];
    int index_file,index_base,narrays,index_array,ndim;
    char arrayname[33];
    DataType_t itype;
    cgsize_t idim;

    /* READ CONVERGENCE HISTORY INFORMATION FROM EXISTING 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;
    /* go to base node */
    cg_goto(index_file,index_base,"end");
    /* go to history node (we assume it exists and that there is only one -  */
    /* real working code would check!) */
    cg_goto(index_file,index_base,"ConvergenceHistory_t",1,"end");
    /* find out how many arrays are here (there should be only one!): */
    cg_narrays(&narrays);
    index_array=narrays;
    /* some checks: */
    if (narrays != 1)
    {
        printf("\nError!  Expecting only one array, read %i\n",narrays);
        return 1;
    }
    cg_array_info(index_array,arrayname,&itype,&ndim,&idim);
    if (idim > ntt)
    {
        printf("\nError! must increase ntt to at least %i\n",(int)idim);
        return 1;
    }
    if (strcmp(arrayname,"CoefLift") != 0)
    {
        printf("\nError!  expecting CoefLift, read %s\n",arrayname);
        return 1;
    }
    /* read lift coefficient array */
    cg_array_read_as(index_array,RealSingle,cl);
    /* close CGNS file */
    cg_close(index_file);
    printf("\nSuccessfully read cl history from file grid_c.cgns\n");
    printf("   values are: %f, %f, %f, %f, %f\n",cl[0],cl[1],cl[2],cl[3],cl[4]);
    printf("               %f, %f, %f, %f, %f\n",cl[5],cl[6],cl[7],cl[8],cl[9]);
    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;
}
Example #15
0
// read number of particles from cgns file
int cgns_read_nparts(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[0]]);
  int fn;
  cg_open(buf, CG_MODE_READ, &fn);

  // Set base index nuber and zone index number (only one, so is 1)
  int bn = 1;
  int zn = 1;

  // Read zone to find cgsize_t *size, or nparts
  char zonename[FILE_NAME_SIZE] = "";
  cgsize_t nparts = 0;
  cg_zone_read(fn, bn, zn, zonename, &nparts);

  cg_close(fn);

  return nparts;
}
Example #16
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.;
  }
}
Example #17
0
/*@C
  DMPlexCreateCGNS - Create a DMPlex mesh from a CGNS file.

  Collective on comm

  Input Parameters:
+ comm  - The MPI communicator
. filename - The name of the CGNS file
- interpolate - Create faces and edges in the mesh

  Output Parameter:
. dm  - The DM object representing the mesh

  Note: http://www.grc.nasa.gov/WWW/cgns/CGNS_docs_current/index.html

  Level: beginner

.keywords: mesh,CGNS
.seealso: DMPlexCreate(), DMPlexCreateCGNS(), DMPlexCreateExodus()
@*/
PetscErrorCode DMPlexCreateCGNSFromFile(MPI_Comm comm, const char filename[], PetscBool interpolate, DM *dm)
{
  PetscMPIInt    rank;
  PetscErrorCode ierr;
#if defined(PETSC_HAVE_CGNS)
  int cgid = -1;
#endif

  PetscFunctionBegin;
  PetscValidCharPointer(filename, 2);
  ierr = MPI_Comm_rank(comm, &rank);CHKERRQ(ierr);
#if defined(PETSC_HAVE_CGNS)
  if (!rank) {
    ierr = cg_open(filename, CG_MODE_READ, &cgid);CHKERRQ(ierr);
    if (cgid <= 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_LIB, "cg_open(\"%s\",...) did not return a valid file ID", filename);
  }
  ierr = DMPlexCreateCGNS(comm, cgid, interpolate, dm);CHKERRQ(ierr);
  if (!rank) {ierr = cg_close(cgid);CHKERRQ(ierr);}
#else
  SETERRQ(comm, PETSC_ERR_SUP, "Loading meshes requires CGNS support. Reconfigure using --with-cgns-dir");
#endif
  PetscFunctionReturn(0);
}
int main ()
{
    int n, nn, i, j, k, ni, nj, nk;
    int dims[3], grind[2], erind[2];

    num_coord = NUM_I * NUM_J * NUM_K;
    num_element = (NUM_I - 1) * (NUM_J - 1) * (NUM_K - 1);
    xcoord = (float *) malloc(4 * num_coord * sizeof(float));
    nmap = (int *) malloc((num_coord + 8 * num_element) * sizeof(int));
    if (NULL == xcoord || NULL == nmap) {
        fprintf(stderr, "malloc failed for data\n");
        exit(1);
    }
    ycoord = xcoord + num_coord;
    zcoord = ycoord + num_coord;
    solution = zcoord + num_coord;
    elements = nmap + num_coord;

    for (n = 0; n < num_coord; n++)
        solution[n] = (float)n;

    unlink("rind.cgns");
    if (cg_open("rind.cgns", CG_MODE_WRITE, &cgfile))
        cg_error_exit();

    /*--- structured grid with rind ---*/

    printf ("writing structured base with rind\n");
    fflush (stdout);

    for (n = 0, k = 0; k < NUM_K; k++) {
        for (j = 0; j < NUM_J; j++) {
            for (i = 0; i < NUM_I; i++) {
                compute_coord(n++, i, j, k);
            }
        }
    }

    if (cg_base_write(cgfile, "Structured", CellDim, PhyDim, &cgbase) ||
        cg_goto(cgfile, cgbase, "end") ||
        cg_dataclass_write(NormalizedByUnknownDimensional) ||
        cg_zone_write(cgfile, cgbase, "Zone", size, Structured, &cgzone))
        cg_error_exit();

    /* can't use cg_coord_write to write rind coordinates
       need to use cg_grid_write to create the node, cg_goto to set
       position at the node, then write rind and coordinates as an array */

    dims[0] = NUM_I;
    dims[1] = NUM_J;
    dims[2] = NUM_K;

    if (cg_grid_write(cgfile, cgbase, cgzone, "GridCoordinates", &cggrid) ||
        cg_goto(cgfile, cgbase, "Zone_t", cgzone,
            "GridCoordinates_t", cggrid, "end") ||
        cg_rind_write(rind) ||
        cg_array_write("CoordinateX", RealSingle, 3, dims, xcoord) ||
        cg_array_write("CoordinateY", RealSingle, 3, dims, ycoord) ||
        cg_array_write("CoordinateZ", RealSingle, 3, dims, zcoord))
        cg_error_exit();

    /* a similiar technique is used for the solution with rind,
       but we use cg_field_write instead of cg_array_write
       and the solution dimensions come from the zone sizes */

    if (cg_sol_write(cgfile, cgbase, cgzone, "VertexSolution",
            Vertex, &cgsol) ||
        cg_goto(cgfile, cgbase, "Zone_t", cgzone,
            "FlowSolution_t", cgsol, "end") ||
        cg_rind_write(rind) ||
        cg_field_write(cgfile, cgbase, cgzone, cgsol, RealSingle,
            "Density", solution, &cgfld))
        cg_error_exit();

    /*--- unstructured with rind ---*/

    printf ("writing unstructured base with rind\n");
    fflush (stdout);

    /* rind here has dimension rind[2], so need to put all the
       rind coordinates at the beginning and/or end of the array.
       Just for grins, I'll put some at both ends, although
       it's probably best to put the rind coordinates at the end.
       I'll use the nmap array for building elements */

    ni = size[0] + rind[0];
    nj = size[1] + rind[2];
    nk = size[2] + rind[4];

    for (n = 0, i = 0; i < rind[0]; i++) {
        for (k = 0; k < NUM_K; k++) {
            for (j = 0; j < NUM_J; j++) {
                compute_coord (n, i, j, k);
                nn = INDEX(i, j, k);
                nmap[nn] = ++n;
            }
        }
    }
    for (j = 0; j < rind[2]; j++) {
        for (k = 0; k < NUM_K; k++) {
            for (i = rind[0]; i < ni; i++) {
                compute_coord (n, i, j, k);
                nn = INDEX(i, j, k);
                nmap[nn] = ++n;
            }
        }
    }
    for (k = 0; k < rind[4]; k++) {
        for (j = rind[2]; j < nj; j++) {
            for (i = rind[0]; i < ni; i++) {
                compute_coord (n, i, j, k);
                nn = INDEX(i, j, k);
                nmap[nn] = ++n;
            }
        }
    }
    grind[0] = n;

    for (k = rind[4]; k < nk; k++) {
        for (j = rind[2]; j < nj; j++) {
            for (i = rind[0]; i < ni; i++) {
                compute_coord (n, i, j, k);
                nn = INDEX(i, j, k);
                nmap[nn] = ++n;
            }
        }
    }
    grind[1] = num_coord - n;

    for (i = ni; i < NUM_I; i++) {
        for (k = 0; k < NUM_K; k++) {
            for (j = 0; j < NUM_J; j++) {
                compute_coord (n, i, j, k);
                nn = INDEX(i, j, k);
                nmap[nn] = ++n;
            }
        }
    }
    for (j = nj; j < NUM_J; j++) {
        for (k = 0; k < NUM_K; k++) {
            for (i = rind[0]; i < ni; i++) {
                compute_coord (n, i, j, k);
                nn = INDEX(i, j, k);
                nmap[nn] = ++n;
            }
        }
    }
    for (k = nk; k < NUM_K; k++) {
        for (j = rind[2]; j < nj; j++) {
            for (i = rind[0]; i < ni; i++) {
                compute_coord (n, i, j, k);
                nn = INDEX(i, j, k);
                nmap[nn] = ++n;
            }
        }
    }

    /* rind elements are like the coordinates, they need to go
       at the beginning and/or end of the element array, although
       at the end is probably best */

    for (n = 0, i = 0; i < rind[0]; i++) {
        for (k = 0; k < NUM_K - 1; k++) {
            for (j = 0; j < NUM_J - 1; j++) {
                compute_element(n++, i, j, k);
            }
        }
    }
    for (j = 0; j < rind[2]; j++) {
        for (k = 0; k < NUM_K - 1; k++) {
            for (i = rind[0]; i < ni - 1; i++) {
                compute_element(n++, i, j, k);
            }
        }
    }
    for (k = 0; k < rind[4]; k++) {
        for (j = rind[2]; j < nj - 1; j++) {
            for (i = rind[0]; i < ni - 1; i++) {
                compute_element(n++, i, j, k);
            }
        }
    }
    erind[0] = n;

    for (k = rind[4]; k < nk - 1; k++) {
        for (j = rind[2]; j < nj - 1; j++) {
            for (i = rind[0]; i < ni - 1; i++) {
                compute_element(n++, i, j, k);
            }
        }
    }
    erind[1] = num_element - n;

    for (i = ni - 1; i < NUM_I - 1; i++) {
        for (k = 0; k < NUM_K - 1; k++) {
            for (j = 0; j < NUM_J - 1; j++) {
                compute_element(n++, i, j, k);
            }
        }
    }
    for (j = nj - 1; j < NUM_J - 1; j++) {
        for (k = 0; k < NUM_K - 1; k++) {
            for (i = rind[0]; i < ni - 1; i++) {
                compute_element(n++, i, j, k);
            }
        }
    }
    for (k = nk - 1; k < NUM_K - 1; k++) {
        for (j = rind[2]; j < nj - 1; j++) {
            for (i = rind[0]; i < ni - 1; i++) {
                compute_element(n++, i, j, k);
            }
        }
    }

    /* create base, zone and write coordinates.
       As for the structured case, the rind coordinates
       and elements are not included in the zone totals */

    dims[0] = num_coord - grind[0] - grind[1];
    dims[1] = num_element - erind[0] - erind[1];
    dims[2] = 0;

    if (cg_base_write(cgfile, "Unstructured", CellDim, PhyDim, &cgbase) ||
        cg_goto(cgfile, cgbase, "end") ||
        cg_dataclass_write(NormalizedByUnknownDimensional) ||
        cg_zone_write(cgfile, cgbase, "Zone", dims, Unstructured, &cgzone) ||
        cg_grid_write(cgfile, cgbase, cgzone, "GridCoordinates", &cggrid) ||
        cg_goto(cgfile, cgbase, "Zone_t", cgzone,
            "GridCoordinates_t", cggrid, "end") ||
        cg_rind_write(grind) ||
        cg_array_write("CoordinateX", RealSingle, 1, &num_coord, xcoord) ||
        cg_array_write("CoordinateY", RealSingle, 1, &num_coord, ycoord) ||
        cg_array_write("CoordinateZ", RealSingle, 1, &num_coord, zcoord))
        cg_error_exit();

    /* to write the elements with rind elements,
       write all the elements, then use goto to add rind */

    if (cg_section_write(cgfile, cgbase, cgzone, "Elements", HEXA_8,
            1, num_element, 0, elements, &cgsect) ||
        cg_goto(cgfile, cgbase, "Zone_t", cgzone,
            "Elements_t", cgsect, "end") ||
        cg_rind_write(erind))
        cg_error_exit();

    /* write solution a vertices with rind */

    if (cg_sol_write(cgfile, cgbase, cgzone, "VertexSolution",
            Vertex, &cgsol) ||
        cg_goto(cgfile, cgbase, "Zone_t", cgzone,
            "FlowSolution_t", cgsol, "end") ||
        cg_rind_write(grind) ||
        cg_field_write(cgfile, cgbase, cgzone, cgsol, RealSingle,
            "Density", solution, &cgfld))
        cg_error_exit();

    cg_close(cgfile);
    return 0;
}
Example #19
0
/**
 * 2. Determinación de superficies ocultas por medio de Z-Buffer y optimización por Backface culling.
 */
int main(int argc, char* argv[])
{
	// Crear una ventana de 750x750 pixels.
	int cw = 750;
	int ch = 750;

	cg_init(cw, ch, NULL);

	// Actualizar la pantalla:
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glMatrixMode(GL_PROJECTION);
	glViewport(0,0,cw, ch);
	glFrustum(-1,1,-1,1,1,1000);

	Obj* obj = obj_load("../Models/knight.obj");

	float ang = 0.0f;
	float pitch = 0.0f;
	float ang_vel = 1.0f;

	char done = 0;
	char wireframe = 0;
	char bfc = 0;
	glEnable(GL_DEPTH_TEST);
	char zbuff = 1;
	unsigned char key_pressed[1024];
	memset(key_pressed, 0, 1024);

	while (!done)
	{
		SDL_Event event;
		while(SDL_PollEvent(&event))
		{
			switch (event.type)
			{
				case SDL_KEYDOWN:
					key_pressed[event.key.keysym.sym] = 1;

					if (event.key.keysym.sym == SDLK_z)
					{
						zbuff = !zbuff;
						if(zbuff)
							glEnable(GL_DEPTH_TEST);
						else
							glDisable(GL_DEPTH_TEST);
						break;
					}
					else if (event.key.keysym.sym == SDLK_b)
					{
						bfc = !bfc;
						if(bfc)
						{
							glEnable(GL_CULL_FACE);
							glCullFace(GL_BACK);
							glFrontFace(GL_CW);
						}
						else
							glDisable(GL_CULL_FACE);
						break;
					}
					else if (event.key.keysym.sym == SDLK_m)
					{
						wireframe = !wireframe;
						if(wireframe)
							glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
						else
							glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
						break;
					}
					else if (event.key.keysym.sym != SDLK_ESCAPE)
						break;
				case SDL_QUIT :
					done = 1;
					break;
				case SDL_KEYUP:
					key_pressed[event.key.keysym.sym] = 0;

			}
		}

		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		glTranslatef(0.0f, 0.0f, -50.0f);
		glRotatef(pitch, 1.0f, 0.0f, 0.0f);
		glRotatef(ang, 0.0f, 1.0f, 0.0f);
		glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);

		if(key_pressed[SDLK_RIGHT]) ang += ang_vel;
		if(key_pressed[SDLK_LEFT]) ang -= ang_vel;
		if(key_pressed[SDLK_UP]) pitch += ang_vel;
		if(key_pressed[SDLK_DOWN]) pitch -= ang_vel;

		glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
		obj_render(obj);
		cg_repaint();
	}

	// Liberar recursos:
	obj_free(obj);
	cg_close();

	return 0;
}
Example #20
0
void COutput::SetCGNS_Connectivity(CConfig *config, CGeometry *geometry, unsigned short iZone) {
  
#ifdef HAVE_CGNS
  
	/*--- local CGNS variables ---*/
	int cgns_file, element_dims, physical_dims, cgns_err;
	int cgns_section;
	unsigned long iExtIter = config->GetExtIter();
	string base_file, buffer, elements_name;
	stringstream name, results_file;
	bool unsteady = config->GetUnsteady_Simulation();
	cgsize_t isize[3][1], elem_start, elem_end;
  
	/*--- Create CGNS base file name ---*/
	base_file = config->GetFlow_FileName();
  
	/*--- Add CGNS extension. ---*/
	base_file = base_file.append(".cgns");
  
	/*--- Create CGNS results file name ---*/
	if (unsteady) {
    
		buffer = config->GetFlow_FileName();
    
		results_file.str(string()); results_file << buffer;
		if (((int)iExtIter >= 0) && ((int)iExtIter < 10))			results_file << "_0000" << iExtIter;
		if (((int)iExtIter >= 10) && ((int)iExtIter < 100))		results_file << "_000" << iExtIter;
		if (((int)iExtIter >= 100) && ((int)iExtIter < 1000))		results_file << "_00" << iExtIter;
		if (((int)iExtIter >= 1000) && ((int)iExtIter < 10000))	results_file << "_0" << iExtIter;
		if ((int)iExtIter >= 10000)							results_file << iExtIter;
		results_file << ".cgns";
	}
  
	/*--- Write base file if not already done ---*/
	if (!wrote_base_file) {
    
    /*--- Write base file ---*/
		cgns_err = cg_open((char *)base_file.c_str(), CG_MODE_WRITE, &cgns_file);
		if (cgns_err) cg_error_print();
    
		element_dims = geometry->GetnDim();		// Currently only all-2D or all-3D zones permitted
		physical_dims = element_dims;
    
		/*--- write CGNS base data (one base assumed currently) ---*/
		cgns_err = cg_base_write(cgns_file,"SU2 Base", element_dims, physical_dims, &cgns_base);
		if (cgns_err) cg_error_print();
    
		/*--- write CGNS descriptor data ---*/
		cgns_err = cg_goto(cgns_file, cgns_base,"end");
		if (cgns_err) cg_error_print();
    
		cgns_err = cg_equationset_write(physical_dims);
		if (cgns_err) cg_error_print();
    
		/*--- Write governing equations to CGNS file ---*/
		cgns_err = cg_goto(cgns_file, cgns_base,"FlowEquationSet_t",1,"end");
		if (cgns_err) cg_error_print();
    switch (config->GetKind_Solver()) {
      case EULER:
        cgns_err = cg_governing_write(Euler); break;
      case NAVIER_STOKES:
        cgns_err = cg_governing_write(NSLaminar); break;
      case RANS:
        cgns_err = cg_governing_write(NSTurbulent); break;
      default:
        break; // cgns_err = cg_governing_write(CG_UserDefined);
    }
    if (cgns_err) cg_error_print();
    
		if (unsteady) cgns_err = cg_simulation_type_write(cgns_file, cgns_base, TimeAccurate);
		else cgns_err = cg_simulation_type_write(cgns_file, cgns_base, NonTimeAccurate);
		if (cgns_err) cg_error_print();
    
		cgns_err = cg_descriptor_write("Solver Information","SU2");
		if (cgns_err) cg_error_print();
		
		isize[0][0] = (cgsize_t)geometry->GetGlobal_nPointDomain(); //;				// vertex size
		isize[1][0] = (cgsize_t)nGlobal_Elem;				// cell size
		isize[2][0] = 0;						// boundary vertex size (zero if elements not sorted)
    
		/*--- write CGNS zone data ---*/
		cgns_err = cg_zone_write(cgns_file, cgns_base,"SU2 Zone", isize[0],Unstructured, &cgns_zone);
		if (cgns_err) cg_error_print();

    cgns_err = cg_goto(cgns_file, cgns_base,"Zone_t", cgns_zone,"end");
		if (cgns_err) cg_error_print();
    
    		/*--- Reference Note: CGNS element type list:
     NODE, BAR_2, BAR_3, TRI_3, TRI_6, QUAD_4, QUAD_8, QUAD_9, TETRA_4, TETRA_10, PYRA_5,
     PYRA_14, PENTA_6, PENTA_15, PENTA_18, HEXA_8, HEXA_20, HEXA_27, MIXED, PYRA_13, NGON_n, NFACE_n ---*/
    
		/*--- Write a CGNS section for each element type ---*/
		// ier = cg_section_write(int fn, int B, int Z, char *ElementSectionName, ElementType_t type,
    // cgsize_t start, cgsize_t end, int nbndry, cgsize_t *Elements, int *S);
		
    if (nGlobal_Tria > 0) {
			elem_start = 1; elem_end = (int)nGlobal_Tria;
			cgns_err = cg_section_write(cgns_file, cgns_base, cgns_zone,
                                  "Triangle Elements", TRI_3, elem_start, elem_end,
                                  0,(cgsize_t *)Conn_Tria, &cgns_section);
    }
		if (nGlobal_Quad > 0) {
			elem_start = 1; elem_end = (int)nGlobal_Quad;
			cgns_err = cg_section_write(cgns_file, cgns_base, cgns_zone,"Quadrilateral Elements", QUAD_4,
                                  elem_start, elem_end,0,(cgsize_t *)Conn_Quad, &cgns_section);
		}
		if (nGlobal_Tetr > 0) {
			elem_start = 1; elem_end = (int)nGlobal_Tetr;
			cgns_err = cg_section_write(cgns_file, cgns_base, cgns_zone,"Tetrahedral Elements", TETRA_4,
                                  elem_start, elem_end,0,(cgsize_t *)Conn_Tetr, &cgns_section);
		}
		if (nGlobal_Hexa > 0) {
			elem_start = 1; elem_end = (int)nGlobal_Hexa;
			cgns_err = cg_section_write(cgns_file, cgns_base, cgns_zone,"Hexahedral Elements", HEXA_8,
                                  elem_start, elem_end,0,(cgsize_t *)Conn_Hexa, &cgns_section);
		}
		if (nGlobal_Pyra > 0) {
			elem_start = 1; elem_end = (int)nGlobal_Pyra;
			cgns_err = cg_section_write(cgns_file, cgns_base, cgns_zone,"Pyramid Elements", PYRA_5,
                                  elem_start, elem_end,0,(cgsize_t *)Conn_Pyra, &cgns_section);
		}
		if (nGlobal_Pris > 0) {
			elem_start = 1; elem_end = (int)nGlobal_Pris;
			cgns_err = cg_section_write(cgns_file, cgns_base, cgns_zone,"Prism Elements", PENTA_6,
                                  elem_start, elem_end,0,(cgsize_t *)Conn_Pris, &cgns_section);
		}
		if (nGlobal_Line > 0) {
			elem_start = 1; elem_end = (int)nGlobal_Line;
			cgns_err = cg_section_write(cgns_file, cgns_base, cgns_zone,"Line Elements", BAR_2,
                                  elem_start, elem_end,0,(cgsize_t *)Conn_Line, &cgns_section);
		}
		if (cgns_err) cg_error_print();
    
    
		cgns_err = cg_close(cgns_file);
		if (cgns_err) cg_error_print();
    
	}
  
#else // Not built with CGNS support
  
	cout << "CGNS file requested but SU2 was built without CGNS support. No file written" << "\n"; 
  
#endif
  
}
Example #21
0
int main (int argc, char *argv[])
{
    int i, n, ib, nb, nz, nv, celldim, phydim;
    int nn, type, *elems = 0, idata[5];
    cgsize_t ne;
    char *p, basename[33], title[65];
    float value, *var;
    SOLUTION *sol;
    FILE *fp;

    if (argc < 2)
        print_usage (usgmsg, NULL);

    ib = 0;
    basename[0] = 0;
    while ((n = getargs (argc, argv, options)) > 0) {
        switch (n) {
            case 'a':
                ascii = 1;
                break;
            case 'b':
                ib = atoi (argarg);
                break;
            case 'B':
                strncpy (basename, argarg, 32);
                basename[32] = 0;
                break;
            case 'w':
                weighting = 1;
                break;
            case 'S':
                usesol = atoi (argarg);
                break;
        }
    }

    if (argind > argc - 2)
        print_usage (usgmsg, "CGNSfile and/or Tecplotfile not given");
    if (!file_exists (argv[argind]))
        FATAL (NULL, "CGNSfile does not exist or is not a file");

    /* open CGNS file */

    printf ("reading CGNS file from %s\n", argv[argind]);
    nb = open_cgns (argv[argind], 1);
    if (!nb)
        FATAL (NULL, "no bases found in CGNS file");
    if (*basename && 0 == (ib = find_base (basename)))
        FATAL (NULL, "specified base not found");
    if (ib > nb) FATAL (NULL, "base index out of range");
    cgnsbase = ib ? ib : 1;
    if (cg_base_read (cgnsfn, cgnsbase, basename, &celldim, &phydim))
        FATAL (NULL, NULL);
    if (celldim != 3 || phydim != 3)
        FATAL (NULL, "cell and physical dimension must be 3");
    printf ("  using base %d - %s\n", cgnsbase, basename);

    if (NULL == (p = strrchr (argv[argind], '/')) &&
        NULL == (p = strrchr (argv[argind], '\\')))
        strncpy (title, argv[argind], sizeof(title));
    else
        strncpy (title, ++p, sizeof(title));
    title[sizeof(title)-1] = 0;
    if ((p = strrchr (title, '.')) != NULL)
        *p = 0;

    read_zones ();
    if (!nZones)
        FATAL (NULL, "no zones in the CGNS file");
    
    /* verify dimensions fit in an integer */

    for (nz = 0; nz < nZones; nz++) {
        if (Zones[nz].nverts > CG_MAX_INT32)
	    FATAL(NULL, "zone size too large to write with integers");
	if (Zones[nz].type == CGNS_ENUMV(Unstructured)) {
            count_elements (nz, &ne, &type);
            if (ne > CG_MAX_INT32)
	        FATAL(NULL, "too many elements to write with integers");
        }
     }

    nv = 3 + check_solution ();

    /* open Tecplot file */

    printf ("writing %s Tecplot data to <%s>\n",
        ascii ? "ASCII" : "binary", argv[++argind]);
    if (NULL == (fp = fopen (argv[argind], ascii ? "w+" : "w+b")))
        FATAL (NULL, "couldn't open Tecplot output file");

    /* write file header */

    if (ascii)
        fprintf (fp, "TITLE = \"%s\"\n", title);
    else {
        fwrite ("#!TDV75 ", 1, 8, fp);
        i = 1;
        write_ints (fp, 1, &i);
        write_string (fp, title);
    }

    /* write variables */

    if (ascii) {
        fprintf (fp, "VARIABLES = \"X\", \"Y\", \"Z\"");
        if (usesol) {
            sol = Zones->sols;
            for (n = 0; n < sol->nflds; n++)
                fprintf (fp, ",\n\"%s\"", sol->flds[n].name);
        }
    }
    else {
        write_ints (fp, 1, &nv);
        write_string (fp, "X");
        write_string (fp, "Y");
        write_string (fp, "Z");
        if (usesol) {
            sol = Zones->sols;
            for (n = 0; n < sol->nflds; n++)
                write_string (fp, sol->flds[n].name);
        }
    }

    /* write zones */

    if (!ascii) {
        for (nz = 0; nz < nZones; nz++) {
            if (Zones[nz].type == CGNS_ENUMV(Structured)) {
                idata[0] = 0;          /* BLOCK */
                idata[1] = -1;         /* color not specified */
                idata[2] = (int)Zones[nz].dim[0];
                idata[3] = (int)Zones[nz].dim[1];
                idata[4] = (int)Zones[nz].dim[2];
            }
            else {
                count_elements (nz, &ne, &type);
                idata[0] = 2;          /* FEBLOCK */
                idata[1] = -1;         /* color not specified */
                idata[2] = (int)Zones[nz].dim[0];
                idata[3] = (int)ne;
                idata[4] = type;
            }
            value = 299.0;
            write_floats (fp, 1, &value);
            write_string (fp, Zones[nz].name);
            write_ints (fp, 5, idata);
        }
        value = 357.0;
        write_floats (fp, 1, &value);
    }

    for (nz = 0; nz < nZones; nz++) {
        printf ("  zone %d...", nz+1);
        fflush (stdout);
        read_zone_grid (nz+1);
        ne = 0;
        type = 2;
        nn = (int)Zones[nz].nverts;
        var = (float *) malloc (nn * sizeof(float));
        if (NULL == var)
            FATAL (NULL, "malloc failed for temp float array");
        if (Zones[nz].type == CGNS_ENUMV(Unstructured))
            elems = volume_elements (nz, &ne, &type);

        if (ascii) {
            if (Zones[nz].type == CGNS_ENUMV(Structured))
                fprintf (fp, "\nZONE T=\"%s\", I=%d, J=%d, K=%d, F=BLOCK\n",
                    Zones[nz].name, (int)Zones[nz].dim[0],
                    (int)Zones[nz].dim[1], (int)Zones[nz].dim[2]);
            else
                fprintf (fp, "\nZONE T=\"%s\", N=%d, E=%d, F=FEBLOCK, ET=%s\n",
                    Zones[nz].name, nn, (int)ne, type == 2 ? "TETRAHEDRON" : "BRICK");
        }
        else {
            value = 299.0;
            write_floats (fp, 1, &value);
            i = 0;
            write_ints (fp, 1, &i);
            i = 1;
            for (n = 0; n < nv; n++)
                write_ints (fp, 1, &i);
        }

        for (n = 0; n < nn; n++)
            var[n] = (float)Zones[nz].verts[n].x;
        write_floats (fp, nn, var);
        for (n = 0; n < nn; n++)
            var[n] = (float)Zones[nz].verts[n].y;
        write_floats (fp, nn, var);
        for (n = 0; n < nn; n++)
            var[n] = (float)Zones[nz].verts[n].z;
        write_floats (fp, nn, var);

        if (usesol) {
            read_solution_field (nz+1, usesol, 0);
            sol = &Zones[nz].sols[usesol-1];
            if (sol->location != CGNS_ENUMV(Vertex))
                cell_vertex_solution (nz+1, usesol, weighting);
            for (nv = 0; nv < sol->nflds; nv++) {
                for (n = 0; n < nn; n++)
                    var[n] = (float)sol->flds[nv].data[n];
                write_floats (fp, nn, var);
            }
        }

        free (var);

        if (Zones[nz].type == CGNS_ENUMV(Unstructured)) {
            if (!ascii) {
                i = 0;
                write_ints (fp, 1, &i);
            }
            nn = 1 << type;
            for (i = 0, n = 0; n < ne; n++, i += nn)
                write_ints (fp, nn, &elems[i]);
            free (elems);
        }
        puts ("done");
    }

    fclose (fp);
    cg_close (cgnsfn);
    return 0;
}
Example #22
0
void COutput::SetCGNS_Solution(CConfig *config, CGeometry *geometry, unsigned short iZone) {
  
#ifdef HAVE_CGNS
  
	/*--- local CGNS variables ---*/
	int cgns_file, cgns_flow, cgns_field, cgns_err;
//  int element_dims;
	unsigned long jVar, iVar, iExtIter = config->GetExtIter();
	string base_file, buffer, elements_name;
	stringstream name, results_file;
	bool unsteady = config->GetUnsteady_Simulation();
  
  bool compressible = (config->GetKind_Regime() == COMPRESSIBLE);
  
	/*--- Create CGNS base file name ---*/
	base_file = config->GetFlow_FileName();
  
	/*--- Add CGNS extension. ---*/
	base_file = base_file.append(".cgns");
  
	/*--- Create CGNS results file name ---*/
	if (unsteady) {
    
		buffer = config->GetFlow_FileName();
    
		results_file.str(string()); results_file << buffer;
		if (((int)iExtIter >= 0) && ((int)iExtIter < 10))			results_file << "_0000" << iExtIter;
		if (((int)iExtIter >= 10) && ((int)iExtIter < 100))		results_file << "_000" << iExtIter;
		if (((int)iExtIter >= 100) && ((int)iExtIter < 1000))		results_file << "_00" << iExtIter;
		if (((int)iExtIter >= 1000) && ((int)iExtIter < 10000))	results_file << "_0" << iExtIter;
		if ((int)iExtIter >= 10000)							results_file << iExtIter;
		results_file << ".cgns";
	}
    
		if (!unsteady) {
      
      /*--- Write base file ---*/
      cgns_err = cg_open((char *)base_file.c_str(), CG_MODE_MODIFY, &cgns_file);
      if (cgns_err) cg_error_print();
      
//      element_dims = geometry->GetnDim();		// Currently (release 2.0) only all-2D or all-3D zones permitted
      
      /*--- write CGNS descriptor data ---*/
      cgns_err = cg_goto(cgns_file, cgns_base,"end");
      if (cgns_err) cg_error_print();
      
			/*--- Create a CGNS solution node ---*/
			cgns_err = cg_sol_write(cgns_file, cgns_base, cgns_zone,"Solution", Vertex, &cgns_flow);
			if (cgns_err) cg_error_print();
      
			cgns_err = cg_goto(cgns_file, cgns_base,"Zone_t", cgns_zone,"FlowSolution_t", cgns_flow,"end");
			if (cgns_err) cg_error_print();
      
			cgns_err = cg_gridlocation_write(Vertex);
			if (cgns_err) cg_error_print();
		}

    
		//wrote_CGNS_base = true;
    else {
	
	/*--- Set up results file for this time step if necessary ---*/
    
		cgns_err = cg_open((char *)results_file.str().c_str(), CG_MODE_MODIFY, &cgns_file);
    
//		element_dims = geometry->GetnDim();		// Currently (release 2.0) only all-2D or all-3D zones permitted
//    
//		/*--- write CGNS base data (one base assumed currently) ---*/
//		cgns_err = cg_base_write(cgns_file,"SU2 Base", element_dims, physical_dims, &cgns_base);
//		if (cgns_err) cg_error_print();
    
//		/*--- write CGNS zone data ---*/
//		cgns_err = cg_zone_write(cgns_file, cgns_base,"SU2 Zone", isize[0],Unstructured, &cgns_zone);
//		if (cgns_err) cg_error_print();
    
		cgns_err = cg_goto(cgns_file, cgns_base_results,"Zone_t", cgns_zone_results,"end");
		if (cgns_err) cg_error_print();
    
		/*--- Write a CGNS solution node for this time step ---*/
		cgns_err = cg_sol_write(cgns_file, cgns_base_results, cgns_zone_results,"Solution", Vertex, &cgns_flow);
		if (cgns_err) cg_error_print();
    
		cgns_err = cg_goto(cgns_file, cgns_base_results,"Zone_t", cgns_zone_results,"FlowSolution_t", cgns_flow,"end");
		if (cgns_err) cg_error_print();
    
		cgns_err = cg_gridlocation_write(Vertex);
		if (cgns_err) cg_error_print();
    
      cgns_base = cgns_base_results;
      cgns_zone = cgns_zone_results;
	}
//	else {
//    
//		/*--- Open CGNS file for soltuion writing ---*/
//		cgns_err = cg_open((char *)base_file.c_str(), CG_MODE_MODIFY, &cgns_file);
//		cgns_base = 1; cgns_zone = 1; cgns_flow = 1;	// fix for multiple zones
//    
//	}
	
	/*	Reference Note on solution variables:
   index 0 --> (nVar_Consv-1)			= Conservative Variables
   nVar_Consv --> (2*nVar_Consv-1)		= Conservative Variable Residuals
   (2*nVar_Consv-1)+					= Additional p, M, T, laminar, eddy depending on solver used */
  
	/*--- Write conservative variables to CGNS file ---*/
	for (iVar = 0; iVar < nVar_Consv; iVar++) {
		name.str(string()); name << "Conservative Variable " << iVar+1;
		cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,(char *)name.str().c_str(), Data[iVar], &cgns_field);
		if (cgns_err) cg_error_print();
	}
  
  /*--- Write primitive variable residuals to CGNS file ---*/
  if (config->GetWrt_Limiters()) {
    for (jVar = 0; jVar < nVar_Consv; jVar++) {
      name.str(string()); name << "Primitive Limiter " << jVar+1;
      cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,(char *)name.str().c_str(), Data[iVar], &cgns_field); iVar++;
      if (cgns_err) cg_error_print();
    }
  }
  
	/*--- Write conservative variable residuals to CGNS file ---*/
  if (config->GetWrt_Residuals()) {
    for (jVar = 0; jVar < nVar_Consv; jVar++) {
      name.str(string()); name << "Conservative Residual " << jVar+1;
      cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,(char *)name.str().c_str(), Data[iVar], &cgns_field); iVar++;
      if (cgns_err) cg_error_print();
    }
  }
  
	/*--- Write grid velocities to CGNS file, if applicable ---*/
	if (config->GetGrid_Movement()) {
		cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,"Grid Velocity X", Data[iVar], &cgns_field); iVar++;
		if (cgns_err) cg_error_print();
		cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,"Grid Velocity Y", Data[iVar], &cgns_field); iVar++;
		if (cgns_err) cg_error_print();
		if (geometry->GetnDim() == 3) {
			cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,"Grid Velocity Z", Data[iVar], &cgns_field); iVar++;
			if (cgns_err) cg_error_print();
		}
	}
  
	if (compressible) {
		switch (config->GetKind_Solver()) {
        
        /*--- Write pressure and Mach data to CGNS file ---*/
      case EULER:
        cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,"Pressure", Data[iVar], &cgns_field); iVar++;
        if (cgns_err) cg_error_print();
        cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,"Mach", Data[iVar], &cgns_field); iVar++;
        if (cgns_err) cg_error_print();
        break;
        
        /*--- Write temperature and laminar viscosity to CGNS file, if applicable ---*/
      case NAVIER_STOKES:
        cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,"Pressure", Data[iVar], &cgns_field); iVar++;
        if (cgns_err) cg_error_print();
        cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,"Mach", Data[iVar], &cgns_field); iVar++;
        if (cgns_err) cg_error_print();
        cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,"Temperature", Data[iVar], &cgns_field); iVar++;
        if (cgns_err) cg_error_print();
        cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,"Viscosity", Data[iVar], &cgns_field); iVar++;
        if (cgns_err) cg_error_print();
        break;
        
        /*--- Write eddy viscosity to CGNS file, if applicable ---*/
      case RANS:
        cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,"Pressure", Data[iVar], &cgns_field); iVar++;
        if (cgns_err) cg_error_print();
        cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,"Mach", Data[iVar], &cgns_field); iVar++;
        if (cgns_err) cg_error_print();
        cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,"Temperature", Data[iVar], &cgns_field); iVar++;
        if (cgns_err) cg_error_print();
        cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,"Viscosity", Data[iVar], &cgns_field); iVar++;
        if (cgns_err) cg_error_print();
        cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,"Eddy Viscosity", Data[iVar], &cgns_field); iVar++;
        if (cgns_err) cg_error_print();
        break;
        
      default:
        cout << "Error: Unrecognized equation type \n"; 
        exit(EXIT_FAILURE); break;
		}
	}	
  
	/*--- Close CGNS file ---*/
	cgns_err = cg_close(cgns_file);
	if (cgns_err) cg_error_print();
  
#else // Not built with CGNS support
  
	cout << "CGNS file requested but SU2 was built without CGNS support. No file written" << "\n"; 
  
#endif
  
}
int main()
{
    int index_file,index_base,index_zone;
    int nelem_start,nelem_end,icount,index_bc,ibc,n;
    cgsize_t ipnts[maxcount];

/* WRITE BOUNDARY CONDITIONS TO EXISTING CGNS FILE */
/* open CGNS file for modify */
    if (cg_open("grid_c.cgns",CG_MODE_MODIFY,&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 that for the unstructured zone, the following face elements */
/* have been defined as inflow (real working code would check!): */
    nelem_start=2561;
    nelem_end=2688;
    icount=0;
    for (n=nelem_start; n <= nelem_end; n++)
    {
      ipnts[icount]=n;
      icount=icount+1;
    }
    if (icount > maxcount)
    {
      printf("\nError. Need to increase maxcount to at least %i\n",icount);
      return 1;
    }
/* write boundary conditions for ilo face */
    cg_boco_write(index_file,index_base,index_zone,"Ilo",BCTunnelInflow,
        PointList,icount,ipnts,&index_bc);
/* we know that for the unstructured zone, the following face elements */
/* have been defined as outflow (real working code would check!): */
    nelem_start=2689;
    nelem_end=2816;
    icount=0;
    for (n=nelem_start; n <= nelem_end; n++)
    {
      ipnts[icount]=n;
      icount=icount+1;
    }
    if (icount > maxcount)
    {
      printf("\nError. Need to increase maxcount to at least %i\n",icount);
      return 1;
    }
/* write boundary conditions for ihi face */
    cg_boco_write(index_file,index_base,index_zone,"Ihi",BCExtrapolate,
        PointList,icount,ipnts,&index_bc);
/* we know that for the unstructured zone, the following face elements */
/* have been defined as walls (real working code would check!): */
    nelem_start=2817;
    nelem_end=3776;
    icount=0;
    for (n=nelem_start; n <= nelem_end; n++)
    {
      ipnts[icount]=n;
      icount=icount+1;
    }
    if (icount > maxcount)
    {
      printf("\nError. Need to increase maxcount to at least %i\n",icount);
      return 1;
    }
/* write boundary conditions for wall faces */
    cg_boco_write(index_file,index_base,index_zone,"Walls",BCWallInviscid,
        PointList,icount,ipnts,&index_bc);

/* the above are all face-center locations for the BCs - must indicate this, */
/* otherwise Vertices will be assumed! */
    for (ibc=1; ibc <= index_bc; ibc++)
    {
/*    (the following call positions you in BC_t - it assumes there */
/*    is only one Zone_t and one ZoneBC_t - real working code would check!) */
      cg_goto(index_file,index_base,"Zone_t",1,"ZoneBC_t",1,"BC_t",ibc,"end");
      cg_gridlocation_write(FaceCenter);
    }
/* close CGNS file */
    cg_close(index_file);
    printf("\nSuccessfully added FaceCenter BCs (PointList) to unstructured grid file grid_c.cgns\n");
    return 0;
}
int main()
{
/*
  dimension statements (note that tri-dimensional arrays
  r and p must be dimensioned exactly as [N-1][17-1+2][21-1+2] (N>=9)
  for this particular case or else they will be written to 
  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):
  Rind cells are stored in array locations [k][0][i], [k][17][i], [k][j][0], [k][j][21]
*/
    double r[8][18][22],p[8][18][22];
    int ni,nj,nk,i,j,k,kk,index_file,index_base,index_zone,index_flow,index_field;
    int irinddata[6];
    char solname[33];

/* create fake flow solution AT CELL CENTERS for simple example: */
    ni=20;
    nj=16;
    nk=8;
    for (k=0; k < nk; k++)
    {
      for (j=0; j < nj; j++)
      {
        for (i=0; i < ni; i++)
        {
          r[k][j+1][i+1]=(float)i;
          p[k][j+1][i+1]=(float)j;
        }
      }
    }
/* create rind cell data: */
    for (k=0; k < nk; k++)
    {
      kk=k+1;
      for (j=0; j <= nj+1; j++)
      {
        r[k][j][0]=999.+(float)j+(5.*(float)kk);
        p[k][j][0]=999.+(float)j+(5.*(float)kk)+1.;
        r[k][j][ni+1]=-999.-(float)j-(5.*(float)kk);
        p[k][j][ni+1]=-999.-(float)j-(5.*(float)kk)-1.;
      }
    }
    for (k=0; k < nk; k++)
    {
      kk=k+1;
      for (i=0; i <= ni+1; i++)
      {
        r[k][0][i]=888.+(float)i+(5.*(float)kk);
        p[k][0][i]=888.+(float)i+(5.*(float)kk)+1.;
        r[k][nj+1][i]=-888.-(float)i-(5.*(float)kk);
        p[k][nj+1][i]=-888.-(float)i-(5.*(float)kk)-1.;
      }
    }
    printf("\ncreated simple 3-D rho and p flow solution with rind data\n");

/* WRITE FLOW SOLUTION TO EXISTING CGNS FILE */
/* open CGNS file for modify */
    if (cg_open("grid_c.cgns",CG_MODE_MODIFY,&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;
/* define flow solution node name (user can give any name) */
    strcpy(solname,"FlowSolution");
/* create flow solution node (NOTE USE OF CellCenter HERE) */
    cg_sol_write(index_file,index_base,index_zone,solname,CellCenter,&index_flow);
/* go to position within tree at FlowSolution_t node */
    cg_goto(index_file,index_base,"Zone_t",index_zone,"FlowSolution_t",index_flow,"end");
/* write rind information under FlowSolution_t node (ilo,ihi,jlo,jhi,klo,khi) */
    irinddata[0]=1;
    irinddata[1]=1;
    irinddata[2]=1;
    irinddata[3]=1;
    irinddata[4]=0;
    irinddata[5]=0;
    cg_rind_write(irinddata);
/* write flow solution (user must use SIDS-standard names here) */
    cg_field_write(index_file,index_base,index_zone,index_flow,
        RealDouble,"Density",r[0][0],&index_field);
    cg_field_write(index_file,index_base,index_zone,index_flow,
        RealDouble,"Pressure",p[0][0],&index_field);
/* close CGNS file */
    cg_close(index_file);
    printf("\nSuccessfully added flow solution data to file grid_c.cgns\n");
    printf("\nNote:  if the original CGNS file already had a FlowSolution_t node,");
    printf("\n          it has been overwritten\n");
    return 0;
}
Example #25
0
int main (int argc, char *argv[])
{
    int j, n;
    cgsize_t ne;
    int fnum, bnum, znum, snum, cnum;
    cgsize_t size[3];
    float exp[5];
    char *outfile = "elemtest.cgns";

    unlink (outfile);

    if (cg_open (outfile, CG_MODE_WRITE, &fnum) ||
        cg_base_write (fnum, "Base", 3, 3, &bnum) ||
        cg_goto(fnum, bnum, NULL) ||
        cg_dataclass_write(CGNS_ENUMV(NormalizedByDimensional)))
        cg_error_exit ();

    for (n = 0; n < 5; n++)
        exp[n] = (float)0.0;
    exp[1] = (float)1.0;

    /* zone with linear elements */

    size[0] = 11;
    size[1] = 12;
    size[2] = 0;
    if (cg_zone_write (fnum, bnum, "1:Linear", size,
            CGNS_ENUMV(Unstructured), &znum) ||
        cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble),
            "CoordinateX", xc, &cnum) ||
        cg_goto(fnum, bnum, "Zone_t", znum, "GridCoordinates", 0,
            "CoordinateX", 0, NULL) ||
        cg_exponents_write(CGNS_ENUMV(RealSingle), exp) ||
        cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble),
            "CoordinateY", yc, &cnum) ||
        cg_gopath(fnum, "../CoordinateY") ||
        cg_exponents_write(CGNS_ENUMV(RealSingle), exp) ||
        cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble),
            "CoordinateZ", zc, &cnum) ||
        cg_gopath(fnum, "../CoordinateZ") ||
        cg_exponents_write(CGNS_ENUMV(RealSingle), exp))
        cg_error_exit ();
    ne = j = 0;

    /* NGON_n first so polyhedra face references are correct */

    if (cg_section_write (fnum, bnum, znum, "NGON_n", CGNS_ENUMV(NGON_n),
            ne+1, ne+npoly, 0, poly, &snum))
        cg_error_exit();
    ne += npoly;

    /* NODE */

    if (cg_section_write (fnum, bnum, znum, "NODE", CGNS_ENUMV(NODE),
            ne+1, ne+1, 0, node, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(NODE);
    elems[j++] = node[0];

    /* BAR_2 */

    if (cg_section_write (fnum, bnum, znum, "BAR_2", CGNS_ENUMV(BAR_2),
            ne+1, ne+1, 0, bar, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(BAR_2);
    for (n = 0; n < 2; n++)
        elems[j++] = bar[n];

    /* TRI_3 */

    if (cg_section_write (fnum, bnum, znum, "TRI_3", CGNS_ENUMV(TRI_3),
            ne+1, ne+1, 0, tri, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(TRI_3);
    for (n = 0; n < 3; n++)
        elems[j++] = tri[n];

    /* QUAD_4 */

    if (cg_section_write (fnum, bnum, znum, "QUAD_4", CGNS_ENUMV(QUAD_4),
            ne+1, ne+1, 0, quad9, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(QUAD_4);
    for (n = 0; n < 4; n++)
        elems[j++] = quad9[n];

    /* TETRA_4 */

    if (cg_section_write (fnum, bnum, znum, "TETRA_4", CGNS_ENUMV(TETRA_4),
            ne+1, ne+1, 0, tetra, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(TETRA_4);
    for (n = 0; n < 4; n++)
        elems[j++] = tetra[n];

    /* PYRA_5 */

    if (cg_section_write (fnum, bnum, znum, "PYRA_5", CGNS_ENUMV(PYRA_5),
            ne+1, ne+1, 0, pyra, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(PYRA_5);
    for (n = 0; n < 5; n++)
        elems[j++] = pyra[n];

    /* PENTA_6 */

    if (cg_section_write (fnum, bnum, znum, "PENTA_6", CGNS_ENUMV(PENTA_6),
            ne+1, ne+1, 0, penta, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(PENTA_6);
    for (n = 0; n < 6; n++)
        elems[j++] = penta[n];

    /* HEXA_8 */

    if (cg_section_write (fnum, bnum, znum, "HEXA_8", CGNS_ENUMV(HEXA_8),
            ne+1, ne+1, 0, hexa, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(HEXA_8);
    for (n = 0; n < 8; n++)
        elems[j++] = hexa[n];

    /* MIXED */

    if (cg_section_write (fnum, bnum, znum, "MIXED", CGNS_ENUMV(MIXED),
            ne+1, ne+8, 0, elems, &snum))
        cg_error_exit ();
    ne += 8;

    /* NFACE_n */

    if (cg_section_write (fnum, bnum, znum, "NFACE_n", CGNS_ENUMV(NFACE_n),
            ne+1, ne+nface, 0, face, &snum))
        cg_error_exit ();

    /* zone with quadratic elements */

    size[0] = 42;
    size[1] = 8;
    size[2] = 0;
    if (cg_zone_write (fnum, bnum, "2:Quadratic", size,
            CGNS_ENUMV(Unstructured), &znum) ||
        cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble),
            "CoordinateX", xc, &cnum) ||
        cg_goto(fnum, bnum, "Zone_t", znum, "GridCoordinates", 0,
            "CoordinateX", 0, NULL) ||
        cg_exponents_write(CGNS_ENUMV(RealSingle), exp) ||
        cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble),
            "CoordinateY", yc, &cnum) ||
        cg_gopath(fnum, "../CoordinateY") ||
        cg_exponents_write(CGNS_ENUMV(RealSingle), exp) ||
        cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble),
            "CoordinateZ", zc, &cnum) ||
        cg_gopath(fnum, "../CoordinateZ") ||
        cg_exponents_write(CGNS_ENUMV(RealSingle), exp))
        cg_error_exit ();
    ne = j = 0;

    /* BAR_3 */

    if (cg_section_write (fnum, bnum, znum, "BAR_3", CGNS_ENUMV(BAR_3),
            ne+1, ne+1, 0, bar, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(BAR_3);
    for (n = 0; n < 3; n++)
        elems[j++] = bar[n];

    /* TRI_6 */

    if (cg_section_write (fnum, bnum, znum, "TRI_6", CGNS_ENUMV(TRI_6),
            ne+1, ne+1, 0, tri, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(TRI_6);
    for (n = 0; n < 6; n++)
        elems[j++] = tri[n];

    /* QUAD_8 */

    if (cg_section_write (fnum, bnum, znum, "QUAD_8", CGNS_ENUMV(QUAD_8),
            ne+1, ne+1, 0, quad9, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(QUAD_8);
    for (n = 0; n < 8; n++)
        elems[j++] = quad9[n];

    /* TETRA_10 */

    if (cg_section_write (fnum, bnum, znum, "TETRA_10", CGNS_ENUMV(TETRA_10),
            ne+1, ne+1, 0, tetra, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(TETRA_10);
    for (n = 0; n < 10; n++)
        elems[j++] = tetra[n];

    /* PYRA_13 */

    if (cg_section_write (fnum, bnum, znum, "PYRA_13", CGNS_ENUMV(PYRA_13),
            ne+1, ne+1, 0, pyra, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(PYRA_13);
    for (n = 0; n < 13; n++)
        elems[j++] = pyra[n];

    /* PENTA_15 */

    if (cg_section_write (fnum, bnum, znum, "PENTA_15", CGNS_ENUMV(PENTA_15),
            ne+1, ne+1, 0, penta, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(PENTA_15);
    for (n = 0; n < 15; n++)
        elems[j++] = penta[n];

    /* HEXA_20 */

    if (cg_section_write (fnum, bnum, znum, "HEXA_20", CGNS_ENUMV(HEXA_20),
            ne+1, ne+1, 0, hexa, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(HEXA_20);
    for (n = 0; n < 20; n++)
        elems[j++] = hexa[n];

    /* MIXED */

    if (cg_section_write (fnum, bnum, znum, "MIXED", CGNS_ENUMV(MIXED),
            ne+1, ne+7, 0, elems, &snum))
        cg_error_exit ();
    ne += 7;

    /* zone with quadratic elements with mid-nodes */

    size[0] = 42;
    size[1] = 8;
    size[2] = 0;
    if (cg_zone_write (fnum, bnum, "3:Quadratic with mid-nodes", size,
            CGNS_ENUMV(Unstructured), &znum) ||
        cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble),
            "CoordinateX", xc, &cnum) ||
        cg_goto(fnum, bnum, "Zone_t", znum, "GridCoordinates", 0,
            "CoordinateX", 0, NULL) ||
        cg_exponents_write(CGNS_ENUMV(RealSingle), exp) ||
        cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble),
            "CoordinateY", yc, &cnum) ||
        cg_gopath(fnum, "../CoordinateY") ||
        cg_exponents_write(CGNS_ENUMV(RealSingle), exp) ||
        cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble),
            "CoordinateZ", zc, &cnum) ||
        cg_gopath(fnum, "../CoordinateZ") ||
        cg_exponents_write(CGNS_ENUMV(RealSingle), exp))
        cg_error_exit ();
    ne = j = 0;

    /* QUAD_9 */

    if (cg_section_write (fnum, bnum, znum, "QUAD_9", CGNS_ENUMV(QUAD_9),
            ne+1, ne+1, 0, quad9, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(QUAD_9);
    for (n = 0; n < 9; n++)
        elems[j++] = quad9[n];

    /* TETRA_10 */

    if (cg_section_write (fnum, bnum, znum, "TETRA_10", CGNS_ENUMV(TETRA_10),
            ne+1, ne+1, 0, tetra, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(TETRA_10);
    for (n = 0; n < 10; n++)
        elems[j++] = tetra[n];

    /* PYRA_14 */

    if (cg_section_write (fnum, bnum, znum, "PYRA_14", CGNS_ENUMV(PYRA_14),
            ne+1, ne+1, 0, pyra, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(PYRA_14);
    for (n = 0; n < 14; n++)
        elems[j++] = pyra[n];

    /* PENTA_18 */

    if (cg_section_write (fnum, bnum, znum, "PENTA_18", CGNS_ENUMV(PENTA_18),
            ne+1, ne+1, 0, penta, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(PENTA_18);
    for (n = 0; n < 18; n++)
        elems[j++] = penta[n];

    /* HEXA_27 */

    if (cg_section_write (fnum, bnum, znum, "HEXA_27", CGNS_ENUMV(HEXA_27),
            ne+1, ne+1, 0, hexa, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(HEXA_27);
    for (n = 0; n < 27; n++)
        elems[j++] = hexa[n];

    /* MIXED */

    if (cg_section_write (fnum, bnum, znum, "MIXED", CGNS_ENUMV(MIXED),
            ne+1, ne+5, 0, elems, &snum))
        cg_error_exit ();
    ne += 5;

    /* zone with cubic elements */

    size[0] = 55;
    size[1] = 8;
    size[2] = 0;
    if (cg_zone_write (fnum, bnum, "4:Cubic", size,
            CGNS_ENUMV(Unstructured), &znum) ||
        cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble),
            "CoordinateX", x3, &cnum) ||
        cg_goto(fnum, bnum, "Zone_t", znum, "GridCoordinates", 0,
            "CoordinateX", 0, NULL) ||
        cg_exponents_write(CGNS_ENUMV(RealSingle), exp) ||
        cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble),
            "CoordinateY", y3, &cnum) ||
        cg_gopath(fnum, "../CoordinateY") ||
        cg_exponents_write(CGNS_ENUMV(RealSingle), exp) ||
        cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble),
            "CoordinateZ", zc, &cnum) ||
        cg_gopath(fnum, "../CoordinateZ") ||
        cg_exponents_write(CGNS_ENUMV(RealSingle), exp))
        cg_error_exit ();
    ne = j = 0;

    /* BAR_4 */

    if (cg_section_write (fnum, bnum, znum, "BAR_4", CGNS_ENUMV(BAR_4),
            ne+1, ne+1, 0, bar4, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(BAR_4);
    for (n = 0; n < 4; n++)
        elems[j++] = bar4[n];

    /* TRI_9 */

    if (cg_section_write (fnum, bnum, znum, "TRI_9", CGNS_ENUMV(TRI_9),
            ne+1, ne+1, 0, tri9, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(TRI_9);
    for (n = 0; n < 9; n++)
        elems[j++] = tri9[n];

    /* QUAD_12 */

    if (cg_section_write (fnum, bnum, znum, "QUAD_12", CGNS_ENUMV(QUAD_12),
            ne+1, ne+1, 0, quad12, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(QUAD_12);
    for (n = 0; n < 12; n++)
        elems[j++] = quad12[n];

    /* TETRA_16 */

    if (cg_section_write (fnum, bnum, znum, "TETRA_16", CGNS_ENUMV(TETRA_16),
            ne+1, ne+1, 0, tetra16, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(TETRA_16);
    for (n = 0; n < 16; n++)
        elems[j++] = tetra16[n];

    /* PYRA_21 */

    if (cg_section_write (fnum, bnum, znum, "PYRA_21", CGNS_ENUMV(PYRA_21),
            ne+1, ne+1, 0, pyra21, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(PYRA_21);
    for (n = 0; n < 21; n++)
        elems[j++] = pyra21[n];

    /* PENTA_24 */

    if (cg_section_write (fnum, bnum, znum, "PENTA_24", CGNS_ENUMV(PENTA_24),
            ne+1, ne+1, 0, penta24, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(PENTA_24);
    for (n = 0; n < 24; n++)
        elems[j++] = penta24[n];

    /* HEXA_32 */

    if (cg_section_write (fnum, bnum, znum, "HEXA_32", CGNS_ENUMV(HEXA_32),
            ne+1, ne+1, 0, hexa32, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(HEXA_32);
    for (n = 0; n < 32; n++)
        elems[j++] = hexa32[n];

    /* MIXED */

    if (cg_section_write (fnum, bnum, znum, "MIXED", CGNS_ENUMV(MIXED),
            ne+1, ne+7, 0, elems, &snum))
        cg_error_exit ();
    ne += 7;

    if (cg_close (fnum)) cg_error_exit ();
    return 0;
}
Example #26
0
void COutput::SetCGNS_Coordinates(CConfig *config, CGeometry *geometry, unsigned short iZone) {
  
#ifdef HAVE_CGNS
  
	/*--- local CGNS variables ---*/
	int cgns_file, cgns_coord, element_dims, physical_dims, cgns_err;
	unsigned long iExtIter = config->GetExtIter();
	string base_file, buffer, elements_name;
	stringstream name, results_file;
	bool unsteady = config->GetUnsteady_Simulation();
	cgsize_t isize[3][1];
  
	/*--- Create CGNS base file name ---*/
	base_file = config->GetFlow_FileName();
  
	/*--- Add CGNS extension. ---*/
	base_file = base_file.append(".cgns");
  
	/*--- Create CGNS results file name ---*/
	if (unsteady) {
    
		buffer = config->GetFlow_FileName();
    
		results_file.str(string()); results_file << buffer;
		if (((int)iExtIter >= 0) && ((int)iExtIter < 10))			results_file << "_0000" << iExtIter;
		if (((int)iExtIter >= 10) && ((int)iExtIter < 100))		results_file << "_000" << iExtIter;
		if (((int)iExtIter >= 100) && ((int)iExtIter < 1000))		results_file << "_00" << iExtIter;
		if (((int)iExtIter >= 1000) && ((int)iExtIter < 10000))	results_file << "_0" << iExtIter;
		if ((int)iExtIter >= 10000)							results_file << iExtIter;
		results_file << ".cgns";
	}
  
	/*--- Write base file if not already done ---*/
	if (!wrote_base_file) {
    
		/*--- Write base file ---*/
		cgns_err = cg_open((char *)base_file.c_str(), CG_MODE_MODIFY, &cgns_file);
		if (cgns_err) cg_error_print();
    
		element_dims = geometry->GetnDim();		// Currently (release 2.0) only all-2D or all-3D zones permitted
		physical_dims = element_dims;
		
		isize[0][0] = (cgsize_t)nGlobal_Poin;				// vertex size
		isize[1][0] = (cgsize_t)nGlobal_Elem;				// cell size
		isize[2][0] = 0;						// boundary vertex size (zero if elements not sorted)
    
    cgns_err = cg_goto(cgns_file, cgns_base,"Zone_t", cgns_zone,"end");
		if (cgns_err) cg_error_print();
//    
//    cgns_err = cg_goto(cgns_file, cgns_base, cgns_zone,"end");
//		if (cgns_err) cg_error_print();
    
		/*--- write CGNS node coordinates ---*/
		cgns_err = cg_coord_write(cgns_file, cgns_base, cgns_zone, RealDouble,"x", Coords[0], &cgns_coord);
		if (cgns_err) cg_error_print();
		cgns_err = cg_coord_write(cgns_file, cgns_base, cgns_zone, RealDouble,"y", Coords[1], &cgns_coord);
		if (cgns_err) cg_error_print();
		if (geometry->GetnDim() == 3) {
			cgns_err = cg_coord_write(cgns_file, cgns_base, cgns_zone, RealDouble,"z", Coords[2], &cgns_coord);
			if (cgns_err) cg_error_print();
		}
    
		cgns_err = cg_close(cgns_file);
		if (cgns_err) cg_error_print();
    
        wrote_base_file = true;
    
	}
	
	/*--- Set up results file for this time step if necessary ---*/
	if (unsteady) {
    
		cgns_err = cg_open((char *)results_file.str().c_str(), CG_MODE_WRITE, &cgns_file);

		element_dims = geometry->GetnDim();		// Currently only all-2D or all-3D zones permitted
		physical_dims = element_dims;

    /*--- write CGNS base data (one base assumed currently) ---*/
		cgns_err = cg_base_write(cgns_file,"SU2 Base", element_dims, physical_dims, &cgns_base_results);
		if (cgns_err) cg_error_print();

		isize[0][0] = (cgsize_t)geometry->GetGlobal_nPointDomain();				// vertex size
		isize[1][0] = (cgsize_t)nGlobal_Elem;				// cell size
		isize[2][0] = 0;						// boundary vertex size (zero if elements not sorted)

		/*--- write CGNS zone data ---*/
		cgns_err = cg_zone_write(cgns_file, cgns_base_results,"SU2 Zone", isize[0],Unstructured, &cgns_zone_results);
		if (cgns_err) cg_error_print();

		cgns_err = cg_goto(cgns_file, cgns_base_results,"Zone_t", cgns_zone_results,"end");
		if (cgns_err) cg_error_print();

    /*--- Write CGNS node coordinates, if appliciable ---*/
		if (config->GetGrid_Movement()) {
      
			/*--- write CGNS node coordinates ---*/
			cgns_err = cg_coord_write(cgns_file, cgns_base_results, cgns_zone_results, RealDouble,"x", Coords[0], &cgns_coord);
			if (cgns_err) cg_error_print();
			cgns_err = cg_coord_write(cgns_file, cgns_base_results, cgns_zone_results, RealDouble,"y", Coords[1], &cgns_coord);
			if (cgns_err) cg_error_print();
			if (geometry->GetnDim() == 3) {
				cgns_err = cg_coord_write(cgns_file, cgns_base_results, cgns_zone_results, RealDouble,"z", Coords[2], &cgns_coord);
				if (cgns_err) cg_error_print();
			}
		}
		else {
			/*--- Write a CGNS link for the node coordinates ---*/
			cgns_err = cg_link_write("GridCoordinates",(char *)base_file.c_str(),"/SU2 Base/SU2 Zone/GridCoordinates");
			if (cgns_err) cg_error_print();
		}
    
		/*--- Write a CGNS link for each element type connectivity ---*/
		if (nGlobal_Tria > 0) cgns_err = cg_link_write("Triangle Elements",(char *)base_file.c_str(),"/SU2 Base/SU2 Zone/Triangle Elements");
		if (nGlobal_Quad > 0) cgns_err = cg_link_write("Quadrilateral Elements",(char *)base_file.c_str(),"/SU2 Base/SU2 Zone/Quadrilateral Elements");
		if (nGlobal_Tetr > 0) cgns_err = cg_link_write("Tetrahedral Elements",(char *)base_file.c_str(),"/SU2 Base/SU2 Zone/Tetrahedral Elements");
		if (nGlobal_Hexa > 0) cgns_err = cg_link_write("Hexahedral Elements",(char *)base_file.c_str(),"/SU2 Base/SU2 Zone/Hexahedral Elements");
		if (nGlobal_Pyra > 0) cgns_err = cg_link_write("Pyramid Elements",(char *)base_file.c_str(),"/SU2 Base/SU2 Zone/Pyramid Elements");
		if (nGlobal_Pris > 0) cgns_err = cg_link_write("Prism Elements",(char *)base_file.c_str(),"/SU2 Base/SU2 Zone/Prism Elements");
		if (nGlobal_Line > 0) cgns_err = cg_link_write("Line Elements",(char *)base_file.c_str(),"/SU2 Base/SU2 Zone/Line Elements");
		if (cgns_err) cg_error_print();

    
    /*--- Close CGNS file ---*/
    cgns_err = cg_close(cgns_file);
    if (cgns_err) cg_error_print();
    
	}


  
#else // Not built with CGNS support
  
	cout << "CGNS file requested but SU2 was built without CGNS support. No file written" << "\n"; 
  
#endif
  
}
Example #27
0
int main (int argc, char **argv)
{
    int n, nz, nzones = 50;
    double start, finish;
    char name[33], linkpath[33];
    char fname[33], linkfile[33];

    for (n = 0; n < 3; n++) {
        size[n]   = NUM_SIDE;
        size[n+3] = NUM_SIDE - 1;
        size[n+6] = 0;
    }
    if (argc > 1)
        nzones = atoi (argv[1]);
    printf ("number of zones  = %d\n", nzones);

    for (nz = 1; nz <= nzones; nz++) {
        sprintf (fname, "zone%d.cgns", nz);
        unlink (fname);
    }

    printf ("creating zones ...");
    fflush (stdout);
    start = elapsed_time ();
    for (nz = 1; nz <= nzones; nz++) {
        sprintf (fname, "zone%d.cgns", nz);
        if (cg_open (fname, CG_MODE_WRITE, &cgfile) ||
            cg_base_write (cgfile, "Base", 3, 3, &cgbase) ||
            cg_zone_write (cgfile, cgbase, "Zone", size, Structured,
                &cgzone) ||
            cg_coord_write(cgfile, cgbase, cgzone, RealSingle,
                "CoordinateX", coord, &cgcoord) ||
            cg_coord_write(cgfile, cgbase, cgzone, RealSingle,
                "CoordinateY", coord, &cgcoord) ||
            cg_coord_write(cgfile, cgbase, cgzone, RealSingle,
                "CoordinateZ", coord, &cgcoord))
            cg_error_exit();
        if (cg_close(cgfile)) cg_error_exit();
    }
    finish = elapsed_time ();
    printf (" %g secs\n", finish - start);

    strcpy (fname, "links.cgns");
    unlink (fname);
    strcpy (linkpath, "/Base/Zone");
    printf ("creating link file ...");
    fflush (stdout);
    start = elapsed_time ();
    if (cg_open (fname, CG_MODE_WRITE, &cgfile) ||
        cg_base_write (cgfile, "Base", 3, 3, &cgbase))
        cg_error_exit();
    for (nz = 1; nz <= nzones; nz++) {
        sprintf (name, "Zone%d", nz);
        sprintf (linkfile, "zone%d.cgns", nz);
        if (cg_goto (cgfile, cgbase, "end") ||
            cg_link_write (name, linkfile, linkpath))
            cg_error_exit();
    }
    cg_close (cgfile);
    finish = elapsed_time ();
    printf (" %g secs\n", finish - start);
    printf ("file size        = %g Mb\n", file_size(fname));

    printf ("opening link file  ...");
    fflush (stdout);
    start = elapsed_time ();
    if (cg_open (fname, CG_MODE_READ, &cgfile)) cg_error_exit();
    finish = elapsed_time ();
    printf (" %g secs\n", finish - start);
    cg_close (cgfile);

#if 0
    printf ("opening link file  ...");
    fflush (stdout);
    start = elapsed_time ();
    if (cg_open (fname, CG_MODE_READ, &cgfile)) cg_error_exit();
    finish = elapsed_time ();
    printf (" %g secs\n", finish - start);
    cg_close (cgfile);
#endif

    return 0;
}
int main()
{
    int ilo[2],ihi[2],jlo[2],jhi[2],klo[2],khi[2];
    int icount,j,k;
    int index_file,index_base,nzone,index_zone,nconns,n1to1,index_conn,iz;
    char donorname[33],zonename0[33],zonename1[33],zn[33];
    cgsize_t isize[3][3],ipnts[maxcount][3],ipntsdonor[maxcount][3];

/* WRITE GENERAL CONNECTIVITY INFORMATION TO EXISTING CGNS FILE */
/* open CGNS file for modify */
    if (cg_open("grid_c.cgns",CG_MODE_MODIFY,&index_file)) cg_error_exit();
/* we know there is only one base (real working code would check!) */
    index_base=1;
/* get number of zones (should be 2 for our case) */
    cg_nzones(index_file,index_base,&nzone);
    if (nzone != 2)
    {
      printf("\nError. This program expects 2 zones. %d read.\n",nzone);
      return 1;
    }

/* loop over zones to get zone sizes and names */
    for (index_zone=0; index_zone < nzone; ++index_zone)
    {
      iz=index_zone+1;
      cg_zone_read(index_file,index_base,iz,zn,isize[0]);
      if (index_zone == 0)
      {
        strcpy(zonename0,zn);
      }
      else
      {
        strcpy(zonename1,zn);
      }
      ilo[index_zone]=1;
      ihi[index_zone]=isize[0][0];
      jlo[index_zone]=1;
      jhi[index_zone]=isize[0][1];
      klo[index_zone]=1;
      khi[index_zone]=isize[0][2];
    }
/* loop over zones again */
    for (index_zone=0; index_zone < nzone; ++index_zone)
    {
      iz=index_zone+1;
/* for this program, there should be no existing connectivity info: */
      cg_nconns(index_file,index_base,iz,&nconns);
      if (nconns != 0)
      {
        printf("\nError. This program expects no interfaces yet. %d read.\n",nconns);
        return 1;
      }
      cg_n1to1(index_file,index_base,iz,&n1to1);
      if (n1to1 != 0)
      {
        printf("\nError. This program expects no interfaces yet. %d read.\n",n1to1);
        return 1;
      }
/* set up point lists */
      if (index_zone == 0)
      {
        strcpy(donorname,zonename1);
        icount=0;
        for (j=jlo[index_zone]; j <= jhi[index_zone]; j++)
        {
          for (k=klo[index_zone]; k <= khi[index_zone]; k++)
          {
            ipnts[icount][0]=ihi[0];
            ipnts[icount][1]=j;
            ipnts[icount][2]=k;
            ipntsdonor[icount][0]=ilo[1];
            ipntsdonor[icount][1]=j;
            ipntsdonor[icount][2]=k;
            icount=icount+1;
          }
        }
        if (icount > maxcount)
        {
          printf("\nError. Need to increase maxcount to at least %i\n",icount);
          return 1;
        }
      }
      else
      {
        strcpy(donorname,zonename0);
        icount=0;
        for (j=jlo[index_zone]; j <= jhi[index_zone]; j++)
        {
          for (k=klo[index_zone]; k <= khi[index_zone]; k++)
          {
            ipnts[icount][0]=ilo[1];
            ipnts[icount][1]=j;
            ipnts[icount][2]=k;
            ipntsdonor[icount][0]=ihi[0];
            ipntsdonor[icount][1]=j;
            ipntsdonor[icount][2]=k;
            icount=icount+1;
          }
        }
        if (icount > maxcount)
        {
          printf("\nError. Need to increase maxcount to at least %i\n",icount);
          return 1;
        }
      }
/* write integer connectivity info (user can give any name) */
      cg_conn_write(index_file,index_base,iz,"GenInterface",Vertex,Abutting1to1,
          PointList,icount,ipnts[0],donorname,Structured,
          PointListDonor,Integer,icount,ipntsdonor[0],&index_conn);
    }
/* close CGNS file */
    cg_close(index_file);
    printf("\nSuccessfully added 1-to-1 connectivity info to file grid_c.cgns (using GENERAL method)\n"); 
    return 0;
}
Example #29
0
int main(int argc, char* argv[])
{
    int cw = 750;
    int ch = 750;

    cg_init(cw, ch, NULL);

    glClearColor(0,0,1,1);
    // Actualizar la pantalla:
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glMatrixMode(GL_PROJECTION);
    glViewport(0,0,cw, ch);
    glFrustum(-1,1,-1,1,1,1000);

    glEnable(GL_LIGHTING);

    // glEnable(GL_NORMALIZE);
    float l0[] = {1.0f,1.0f,1.0f,1.0f};
    float la[] = {0.10f,0.10f,0.10f,1.0f};
    float l0p[]= {1.0f,1.0f,1.0f,1.0f};
    float ls[] = {1.0f,1.0f,1.0f,1.0f};
    glLightfv(GL_LIGHT0, GL_AMBIENT, la);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, l0);
    glLightfv(GL_LIGHT0, GL_POSITION, l0p);
    glLightfv(GL_LIGHT0, GL_SPECULAR, ls);
    glEnable(GL_LIGHT0);

    float cyan[] = {1.0f, 1.0f, 1.0f, 1.f};
    glMaterialfv(GL_FRONT, GL_DIFFUSE, cyan);
    glMaterialfv(GL_FRONT, GL_SPECULAR, ls);
    glMateriali(GL_FRONT, GL_SHININESS, 16);

    float ang = 0.0f;
    float pitch = 0.0f;
    float ang_vel = 1.0f;


    char done = 0;
    char wireframe = 0;
    char bfc = 0;
    glEnable(GL_DEPTH_TEST);
    char zbuff = 1;
    unsigned char key_pressed[1024];
    memset(key_pressed, 0, 1024);

    char use_shader = 0;
    char specular = 0;
    Shader gouraud = shader_new("shaders/gouraud_vp.glsl", "shaders/gouraud_fp.glsl");
    GLint uniform_especular = shader_get_unif_loc(gouraud, "especular");
    GLint uniform_tex = shader_get_unif_loc(gouraud, "tex");

    Obj* objPtr ;
    int example = atoi(argv[1]);

    if (example==1 || example==3)
        objPtr = obj_load("../Models/knight_texturas.obj");
    else if (example==2)
        objPtr = obj_load("../Models/box_texturas.obj");

    //Cargo la imagen de disco usando SDL_image
    SDL_Surface* surface; // = IMG_Load("../Models/knight.png");

    if (example==1 )
        surface = IMG_Load("../Models/knight.png");
    else if (example==2)
        surface = IMG_Load("../Models/box.jpg");
    else if (example==3)
        surface = IMG_Load("../Models/knight_good.png");


//    Obj* objPtr = obj_load("../Models/knight_texturas.obj");
//    Obj* objPtr = obj_load("../Models/box_texturas.obj");

    //Cargo la imagen de disco usando SDL_image
//    SDL_Surface* surface = IMG_Load("../Models/knight.png");
//    SDL_Surface* surface = IMG_Load("../Models/knight_good.png");
//    SDL_Surface* surface = IMG_Load("../Models/box.jpg");

    if (surface==NULL) { //Si falla la carga de la imagen, despliego el mensaje de error correspondiente y termino el programa.
        printf("Error: \"%s\"\n", SDL_GetError());
        return 1;
    }

    GLuint texture;
    //Creo un espacio para alojar una textura en memoria de video
    glGenTextures(1,&texture);
    //Activo la textura nro 0
    glActiveTexture(GL_TEXTURE0);
    //Habilito la carga para la textura recien creada
    glBindTexture(GL_TEXTURE_2D,texture);

    //Cargo los datos de la imagen en la textura.
    glTexImage2D(GL_TEXTURE_2D,
                 0,
                 GL_RGBA,
                 surface->w,
                 surface->h,
                 0,
                 GL_RGB,GL_UNSIGNED_BYTE,
                 surface->pixels);
    //Luego de copiada la imagen a memoria de video, puedo liberarla sin problemas
    SDL_FreeSurface(surface);

    //Seteo el filtro a usar cuando se mapea la textura a una superficie mas chica (GL_LINEAR = filtro bilineal)
    glTexParameteri(GL_TEXTURE_2D,
                    GL_TEXTURE_MIN_FILTER,
                    GL_LINEAR);
    //Seteo el filtro a usar cuando se mapea la textura a una superficie mas grande (GL_LINEAR = filtro bilineal)
    glTexParameteri(GL_TEXTURE_2D,
                    GL_TEXTURE_MAG_FILTER,
                    GL_LINEAR);

    //Seteo el comportamiento cuando encuentro coordenadas de textura fuera del rango [0,1]
    //GL_REPEAT es el comportamiento por defecto.
    glTexParameteri(GL_TEXTURE_2D,
                    GL_TEXTURE_WRAP_S,
                    GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D,
                    GL_TEXTURE_WRAP_T,
                    GL_REPEAT);

    while (!done)
    {

        SDL_Event event;
        while(SDL_PollEvent(&event))
        {
            switch (event.type)
            {
            case SDL_KEYDOWN:
                key_pressed[event.key.keysym.sym] = 1;
                if (event.key.keysym.sym == SDLK_p)
                {
                    use_shader = !use_shader;
                    break;
                }
                else if (event.key.keysym.sym == SDLK_s)
                {
                    specular = !specular;
                    break;
                }
                else if (event.key.keysym.sym == SDLK_z)
                {
                    zbuff = !zbuff;
                    if(zbuff)
                        glEnable(GL_DEPTH_TEST);
                    else
                        glDisable(GL_DEPTH_TEST);
                    break;
                }
                else if (event.key.keysym.sym == SDLK_m)
                {
                    wireframe = !wireframe;
                    if(wireframe)
                        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
                    else
                        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
                    break;
                }
                else if (event.key.keysym.sym == SDLK_b)
                {
                    bfc = !bfc;
                    if(bfc)
                    {
                        glEnable(GL_CULL_FACE);
                        glCullFace(GL_BACK);
                        glFrontFace(GL_CW);
                    }
                    else
                        glDisable(GL_CULL_FACE);
                    break;
                }
                else if (event.key.keysym.sym != SDLK_ESCAPE)
                    break;
            case SDL_QUIT :
                done = 1;
                break;
            case SDL_KEYUP:
                key_pressed[event.key.keysym.sym] = 0;

            }
        }

        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

        if (example==1 || example==3)
            glTranslatef(0.0f, 0.0f, -50.0f);
        else if (example==2)
            glTranslatef(0.0f, 0.0f, -2.0f);

//        glTranslatef(0.0f, 0.0f, -50.0f);
//        glTranslatef(0.0f, 0.0f, -2.0f);

        glRotatef(pitch, 1.0f, 0.0f, 0.0f);
        glRotatef(ang, 0.0f, 1.0f, 0.0f);

        glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);

        if(key_pressed[SDLK_RIGHT]) ang += ang_vel;
        if(key_pressed[SDLK_LEFT]) ang -= ang_vel;
        if(key_pressed[SDLK_UP]) pitch += ang_vel;
        if(key_pressed[SDLK_DOWN]) pitch -= ang_vel;

        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

        //Informo a OpenGL que para todas las operaciones a continuaci�n utilice las texturas 2D cargadas
        glEnable(GL_TEXTURE_2D);

        if(use_shader)
        {
            shader_use(gouraud);
            glUniform1i(uniform_especular, specular);
            //Le digo al shader que el sampler2D de nombre "tex" se corresponde con GL_TEXTURE0
            //que es donde cargu� mi textura.
            glUniform1i(uniform_tex, 0);
            //Luego asocio la textura con el id "texture"
            glBindTexture(GL_TEXTURE_2D,texture);
            obj_render2(objPtr);
            shader_stop(gouraud);
        }
        else
        {
            glBindTexture(GL_TEXTURE_2D,texture);
            obj_render2(objPtr);
        }

        cg_repaint();
    } // while

    // Liberar recursos:
    obj_free(objPtr);
    shader_free(gouraud);
    glDeleteTextures(1,&texture);
    cg_close();

    return 0;
}
/*---------- PostProcesssing --------------------------------------
 * Post-Analysis of CFD Data
 * Developed only for CFD-Tutor with single base - single zone 2D
 * -------------------------------------------------------------*/
int PostProcessing(const char *file) {
    int visual;
    int nbases, ncoords, celldim, phydim;
    char basename[33];
    ZONE *z;
    int i, j, nz;
    SOLUTION *s;

    /* Checks for existance of file */
    if (!file_exists(file))
        FATAL(NULL, "File does not exist");

    /* Read CGNS file */
    printf("Reading CGNS file from %s\n", file);
    fflush(stdout);

    /* Open CGNS File */
    nbases = open_cgns(file, 0);
    if (!nbases)
        FATAL(NULL, "No bases in CGNS file");

    cg_version(cgnsfn, &Version);
    printf("File version = %lf\n", Version);

    printf("No of Bases = %d\n", nbases);

    if (nbases == 1)
        cgnsbase = 1;
    else {
        printf("Give base No to Post-Processed : ");
        scanf("%d", &cgnsbase);

        if (cgnsbase < 1 || cgnsbase > nbases)
            FATAL(NULL, "Invailed base index");
    }

    if (cg_base_read(cgnsfn, cgnsbase, basename, &celldim, &phydim) ||
            cg_nzones(cgnsfn, cgnsbase, &nZones))
        FATAL(NULL, NULL);

    if (celldim != 2 || phydim != 2)
        FATAL(NULL, "Not A 2D Grid");

    if (nZones > 1)
        FATAL(NULL, "Not A Single Zone");


    printf("Base Number = %d\n", cgnsbase);
    printf("Base Name = %s\n", basename);
    printf("Cell Dimension = %d\n", celldim);
    printf("Physical Dimension = %d\n", phydim);

    read_cgns();

    printf("No of Zones = %d\n", nZones);

    /* Print Zone Information */
    for (z = Zones, nz = 1; nz <= nZones; nz++, z++) {
        printf("Zone No = %d\n", z->id);
        printf("Zone Name = %s\n", z->name);
        if (cg_ncoords(cgnsfn, cgnsbase, nz, &ncoords))
            FATAL("Post-Processing ncoords", NULL);
        if (ncoords != 2)
            FATAL(NULL, "No 3D Support Now");

        print_ZoneType(z->type);
        switch (z->type) {
            case 2:
                /* For Structured Grid */
                printf("Dimensions = %d x %d x %d\n", z->dim[0], z->dim[1], z->dim[2]);
                break;
            case 3:
                /* For Unstructured Grid */
                printf("No of Nodes = %d\n", z->dim[0]);
                printf("No of Cells = %d\n", z->dim[1]);
                break;
            default:
                /* Unknown Type Grids */
                FATAL(NULL, "Unknown Grid Type");
        }
    }

    /* Print Available Solution Fields */
    for (z = Zones, nz = 1; nz <= nZones; nz++, z++) {
        if (z->nsols) {
            printf("No of Solutions Nodes = %d\n", z->nsols);
            for (s = z->sols, i = 1; i <= z->nsols; i++, s++) {
                printf("Solution Node = %d\n", i);

                if (s->nflds == 0)
                    FATAL(NULL, "No Solution Fields: Exiting");

                printf("\tNo of Fields = %d\n", s->nflds);
                for (j = 0; j < s->nflds; j++) {
                    printf("\tField = %s\n", s->flds[j].name);
                }
            }
        } else
            FATAL(NULL, "No Solution Node Available: Exiting");
    }

    /* Initialize Data Structure Only Once */
    for (z = Zones, nz = 1; nz <= nZones; nz++, z++)
        InitializeGrid_2D(z);


    /* Do Post-Processing Operation Below */
    /*****************/

    /* Post Analysis Function Calls */
    for (z = Zones, nz = 1; nz <= nZones; nz++, z++) {
        InitializeSolutionCGNS_2D(z);
        InitializeSolution_2D();
        GetSolutionList_2D();

        /* Visual Mode Option */
        printf("Goto Visual Mode (0/1):");
        scanf("%d", &visual);

        if (visual == 1)
            Graphics_2D();
        else {
            GetFluidProperties();
            GetReferenceQuantities();
            PostAnalysis_2D();
        }
    }

    /*****************/
    /* Do Post-Processing Operation Above */

    /* Close cgns Interface */
    if (cg_close(cgnsfn))
        FATAL(NULL, NULL);

    return 0;
}