Ejemplo n.º 1
0
/* NOTE: We output only the fluid cells */
void writeVtkOutput(const double * const collideField, const int * const flagField, 
        const char * filename, unsigned int t, int xlength, int rank, int x_proc) {
  int i, j, k;
  double velocity[3], density;
  /* len is used to set values in lexicographic order "[ Q * ( z*len*len + y*len + x) + i ]" */
  int len = xlength + 2;

  char szFileName[80];
  FILE *fp=NULL;
  sprintf( szFileName, "%s-rank%i.%i.vtk", filename, rank, t );
  fp = fopen( szFileName, "w");
  if( fp == NULL ){
    char szBuff[80];
    sprintf( szBuff, "Failed to open %s", szFileName );
    ERROR( szBuff );
    return;
  }

  write_vtkHeader(fp, xlength);
  write_vtkPointCoordinates(fp,xlength,rank,x_proc);

  fprintf(fp,"POINT_DATA %i \n", xlength*xlength*xlength );

  fprintf(fp,"\n");
  fprintf(fp, "VECTORS velocity float\n");
  for(k = 1; k < xlength+1; k++) {
    for(j = 1; j < xlength+1; j++) {
      for(i = 1; i < xlength+1; i++) {
        computeDensity (&collideField[ 19 * ( k*len*len + j*len + i) ], &density);
        computeVelocity(&collideField[ 19 * ( k*len*len + j*len + i) ], &density, velocity);
        fprintf(fp, "%f %f %f\n",  velocity[0], velocity[1], velocity[2]);
      }
    }
  }

  fprintf(fp,"\n");
  fprintf(fp, "SCALARS density float 1 \n");
  fprintf(fp, "LOOKUP_TABLE default \n");
  for(k = 1; k < xlength+1; k++) {
    for(j = 1; j < xlength+1; j++) {
      for(i = 1; i < xlength+1; i++) {
        computeDensity (&collideField[ 19 * ( k*len*len + j*len + i) ], &density);
        fprintf(fp, "%f\n",  density);
      }
    }
  }

  if(fclose(fp)){
    char szBuff[80];
    sprintf( szBuff, "Failed to close %s", szFileName );
    ERROR( szBuff );
  }
}
Ejemplo n.º 2
0
void write_vtkFile( const char *szProblem,int timeStepNumber, int gridsize, int imax, int jmax,
                    double dx, double dy, double *U) {
  
	char szFileName[80];
	FILE *fp=NULL;
	sprintf( szFileName, "%s.%i.vtk", szProblem, timeStepNumber );
	fp = fopen( szFileName, "w");
	if( fp == NULL )		       
	{
		char szBuff[80];
		sprintf( szBuff, "Failed to open %s", szFileName );
		ERROR( szBuff );
		return;
	}

	write_vtkHeader( fp, imax, jmax, dx, dy);
	write_vtkPointCoordinates(fp, imax, jmax, dx, dy);
  
	fprintf(fp,"POINT_DATA %i \n", (imax + 1)*(jmax + 1) );
	
    fprintf(fp,"\n");
    fprintf(fp, "VECTORS velocity float\n");
    for(int x = 0; x < jmax + 1; x++) {
        for(int y = 0; y < imax + 1; y++) {
        	// if (x < jmax || y < imax)
        	// {
        	// 	fprintf(fp, "%f %f 0\n", U[(x*gridsize + y)*3 + 1], U[(x*gridsize + y)*3 + 2] ); 
        	// }
        	// else
        	// {
        		fprintf(fp, "0 0 0\n"); 
        	// }
			
        }
    }

	fprintf(fp,"\n");
	fprintf(fp,"CELL_DATA %i \n", imax*jmax );
	fprintf(fp, "SCALARS waterhight float 1 \n"); 
	fprintf(fp, "LOOKUP_TABLE default \n");
	for(int x = 0; x < imax; x++) {
		for(int y = 0; y < jmax; y++) {
			fprintf(fp, "%f\n", U[(x*gridsize + y)*1]);
		}
	}

	if( fclose(fp) )
	{
		char szBuff[80];
		sprintf( szBuff, "Failed to close %s", szFileName );
		ERROR( szBuff );
	}
}
Ejemplo n.º 3
0
Archivo: visual.c Proyecto: huahbo/cfd3
void write_vtkFile(const char *szProblem, int timeStepNumber, int imax, int jmax,
		double dx, double dy, double **U,
		double **V, double **P) {

	int i, j;
	char szFileName[80];
	FILE *fp = NULL;
	sprintf(szFileName, "%s.%i.vtk", szProblem, timeStepNumber);
	fp = fopen(szFileName, "w");
	if (fp == NULL) {
		char szBuff[80];
		sprintf(szBuff, "Failed to open %s", szFileName);
		ERROR( szBuff );
		return;
	}

	write_vtkHeader(fp, imax, jmax);
	write_vtkPointCoordinates(fp, imax, jmax, dx, dy);

	fprintf(fp, "POINT_DATA %i \n", (imax + 1) * (jmax + 1));

	fprintf(fp, "\n");
	fprintf(fp, "VECTORS velocity float\n");
	for (j = 0; j < jmax + 1; j++) {
		for (i = 0; i < imax + 1; i++) {
			fprintf(fp, "%f %f 0\n", (U[i][j] + U[i][j + 1]) * 0.5,
					(V[i][j] + V[i + 1][j]) * 0.5);
		}
	}

	fprintf(fp, "\n");
	fprintf(fp, "CELL_DATA %i \n", ((imax) * (jmax)));
	fprintf(fp, "SCALARS pressure float 1 \n");
	fprintf(fp, "LOOKUP_TABLE default \n");
	for (j = 1; j < jmax + 1; j++) {
		for (i = 1; i < imax + 1; i++) {
			fprintf(fp, "%f\n", P[i][j]);
		}
	}

	if (fclose(fp)) {
		char szBuff[80];
		sprintf(szBuff, "Failed to close %s", szFileName);
		ERROR( szBuff );
	}
}
Ejemplo n.º 4
0
void write_vtkFile(const char *szProblem,
                   int    t,
                   int * length,
                   double *collideField,
                   int * flagField) {
  
    int x, y, z;
    char szFileName[80];
    FILE *fp=NULL;
    int n[3] = {length[0] + 2,length[1] + 2,length[2] + 2};
    double velocity[3];
    double density;
    double * el = NULL;

    sprintf( szFileName, "%s.%i.vtk", szProblem, t );
    fp = fopen( szFileName, "w");
    if( fp == NULL )
    {
        char szBuff[80];
        sprintf( szBuff, "Failed to open %s", szFileName );
        ERROR( szBuff );
        return;
    }

    write_vtkHeader(fp, length);
    write_vtkPointCoordinates(fp, length);

    fprintf(fp,"POINT_DATA %i \n", length[0]*length[1]*length[2]);
    fprintf(fp,"\n");
    fprintf(fp, "VECTORS velocity float\n");
    for(z = 1; z  <= length[0]; z++) {
        for(y = 1; y  <= length[1]; y++) {
            for(x = 1; x  <= length[2]; x++) {
                if (*getFlag(flagField, x, y, z, n) != OBSTACLE) {
                    el = getEl(collideField, x, y, z, 0, n);
                    computeDensity(el, &density);
                    computeVelocity(el, &density, velocity);
                    fprintf(fp, "%f %f %f\n", velocity[0], velocity[1], velocity[2]);
                } else {
                    fprintf(fp, "%f %f %f\n", 0.0, 0.0, 0.0); 
                }
            }
        }
    }

    fprintf(fp,"\n");

    fprintf(fp, "SCALARS density float 1 \n"); 
    fprintf(fp, "LOOKUP_TABLE default \n");

    for(z = 1; z  <= length[0]; z++) {
        for(y = 1; y  <= length[1]; y++) {
            for(x = 1; x  <= length[2]; x++) {
                if (*getFlag(flagField, x, y, z, n) != OBSTACLE) {
                    computeDensity(getEl(collideField, x, y, z, 0, n), &density);
                    fprintf(fp, "%f\n", density);
                } else {
                    fprintf(fp, "%f\n", 1.0);
                }
            }
        }
    }

    if( fclose(fp) )
    {
        char szBuff[80];
        sprintf( szBuff, "Failed to close %s", szFileName );
        ERROR( szBuff );
    }
}
Ejemplo n.º 5
0
void write_vtkFile(const char *szProblem, int t, int * length, double * collideField, int * my_pos, int my_rank, int * my_origin) {
    char szFileName[80];
    FILE *fp=NULL;
 
    int x, y, z;
    int node[3];
    int n[3] = { length[0] + 2, length[1] + 2, length[2] + 2 };
    double velocity[3];
    double density;
    double * el = NULL;

    sprintf( szFileName, "%s_%i.%i.vtk", szProblem, my_rank, t);
    fp = fopen( szFileName, "w");
    if( fp == NULL )		       
    {
        char szBuff[80];
        sprintf( szBuff, "Failed to open %s", szFileName );
        ERROR( szBuff );
        return;
    }

    write_vtkHeader(fp, length);
    write_vtkPointCoordinates(fp, length, my_pos, my_origin);

    fprintf(fp,"POINT_DATA %i \n", length[0] * length[1] * length[2]);
  
    fprintf(fp,"\n");
    fprintf(fp, "VECTORS velocity float\n");
    
    for(z = 1; z  <= length[2]; z++) {
        node[2] = z;
        for(y = 1; y  <= length[1]; y++) {
            node[1] = y;
            for(x = 1; x  <= length[0]; x++) {
                node[0] = x;
                el = getEl(collideField, node, 0, n);
                computeDensity(el, &density);
                computeVelocity(el, &density, velocity);
                fprintf(fp, "%f %f %f\n", velocity[0], velocity[1], velocity[2]);
            }
        }
    }

    fprintf(fp,"\n");

    fprintf(fp, "SCALARS density float 1 \n"); 
    fprintf(fp, "LOOKUP_TABLE default \n");

    for(z = 1; z <= length[2]; z++) {
        node[2] = z;
        for(y = 1; y <= length[1]; y++) {
            node[1] = y;
            for(x = 1; x <= length[0]; x++) {
                node[0] = x;
                computeDensity(getEl(collideField, node, 0, n), &density);
                fprintf(fp, "%f\n", density);
            }
        }
    }

    if( fclose(fp) )
    {
        char szBuff[80];
        sprintf( szBuff, "Failed to close %s", szFileName );
        ERROR( szBuff );
    }
}
Ejemplo n.º 6
0
void writeVtkOutput(const double * const collideField, const int * const flagField, const char * filename, unsigned int t, int *xlength)
{
    int x, y, z, currentCellIndex;
    double cellVelocity[3], cellDensity;

    char szFileName[80];
    FILE *fp=NULL;
    sprintf( szFileName, "%s.%i.vtk", filename, t );
    fp = fopen( szFileName, "w");
    if( fp == NULL )
    {
        char szBuff[80];
        sprintf( szBuff, "Failed to open %s", szFileName );
        ERROR( szBuff );
        return;
    }

    write_vtkHeader( fp, xlength);
    write_vtkPointCoordinates(fp, xlength);

    fprintf(fp,"POINT_DATA %i \n", (xlength[0]) * (xlength[1]) * (xlength[2]));

    fprintf(fp,"\n");
    fprintf(fp, "VECTORS velocity float\n");
    for(z = 1; z <= xlength[2]; z++)
        for (y = 1; y <= xlength[1]; y++)
            for (x = 1; x <= xlength[0]; x++)
            {
                currentCellIndex = (z * (xlength[0] + 2) * (xlength[1] + 2) + y * (xlength[0] + 2) + x);
                computeDensity(collideField + currentCellIndex, &cellDensity, (xlength[0] + 2) * (xlength[1] + 2) * (xlength[2] + 2));
                computeVelocity(collideField + currentCellIndex, &cellDensity, cellVelocity, (xlength[0] + 2) * (xlength[1] + 2) * (xlength[2] + 2));
                fprintf(fp, "%f %f %f\n", cellVelocity[0], cellVelocity[1], cellVelocity[2]);
            }


    fprintf(fp,"\n");

    fprintf(fp, "SCALARS density float 1 \n");
    fprintf(fp, "LOOKUP_TABLE default \n");
    for(z = 1; z <= xlength[2]; z++)
        for(y = 1; y <= xlength[1]; y++)
            for (x = 1; x <= xlength[0]; x++)
            {
                currentCellIndex = (z * (xlength[0] + 2) * (xlength[1] + 2) + y * (xlength[0] + 2) + x);
                computeDensity(collideField + currentCellIndex, &cellDensity, (xlength[0] + 2) * (xlength[1] + 2) * (xlength[2] + 2));
                fprintf(fp, "%f\n", cellDensity);
            }
 fprintf(fp, "SCALARS boundaryType integer 1 \n");
    fprintf(fp, "LOOKUP_TABLE default \n");
    for(z = 1; z <= xlength[2] ; z++)
        for(y = 1; y <= xlength[1] ; y++)
            for (x = 1; x <= xlength[0] ; x++)
            {
                currentCellIndex = (z * (xlength[0] + 2) * (xlength[1] + 2) + y * (xlength[0] + 2) + x);
                fprintf(fp, "%d\n", flagField[currentCellIndex]);
            }



    if( fclose(fp) )
    {
        char szBuff[80];
        sprintf( szBuff, "Failed to close %s", szFileName );
        ERROR( szBuff );
    }
}
Ejemplo n.º 7
0
void write_vtkFile(const char *szProblem,
		int    timeStepNumber,
		double xlength,
		double ylength,
		double zlength,
		int    imax,
		int    jmax,
		int    kmax,
		double dx,
		double dy,
		double dz,
		double ***U,
		double ***V,
		double ***W,
		double ***P,
		int ***Flag) {

	int i,j,k;
	double uVel,vVel,wVel;
	char szFileName[80];
	FILE *fp=NULL;
	sprintf( szFileName, "/media/norbert/940CB6150CB5F27A/Documents/simulation/%s.%i.vtk", szProblem, timeStepNumber );
	//sprintf( szFileName, "/media/norbert/940CB6150CB5F27A/Documents/simulation/%s.%i.vtk", szProblem, timeStepNumber );

	fp = fopen( szFileName, "w");
	if( fp == NULL )
	{
		char szBuff[80];
		sprintf( szBuff, "Failed to open %s", szFileName );
		ERROR( szBuff );
		return;
	}

	write_vtkHeader(fp, imax, jmax, kmax, dx, dy, dz);
	write_vtkPointCoordinates(fp, imax, jmax, kmax, dx, dy, dz);

	fprintf(fp,"POINT_DATA %i \n", (imax+1)*(jmax+1)*(kmax+1) );

	fprintf(fp,"\n");
	fprintf(fp, "VECTORS velocity float\n");

	for(k = 0; k < kmax+1; k++) {
		for(j = 0; j < jmax+1; j++) {
			for(i = 0; i < imax+1; i++) {
				//fprintf(fp, "%f %f %f\n", getValidValue((U[i][j][k] + U[i+1][j][k]) * 0.5), getValidValue((V[i][j][k] + V[i][j+1][k]) * 0.5), getValidValue((W[i][j][k] + W[i][j][k+1]) * 0.5) );
				//fprintf(fp, "%f %f %f\n", getValidValue((U[i][j][k] + U[i][j+1][k]) * 0.5), getValidValue((V[i][j][k] + V[i+1][j][k]) * 0.5), getValidValue((W[i][j][k] + W[i][j][k+1]) * 0.5) );
				uVel = getValidValue((U[i][j][k] + U[i][j+1][k] + U[i][j][k+1] + U[i][j+1][k+1]) * 0.25);
				vVel = getValidValue((V[i][j][k] + V[i+1][j][k] + V[i][j][k+1] + V[i+1][j][k+1]) * 0.25);
				wVel = getValidValue((W[i][j][k] + W[i+1][j][k] + W[i][j+1][k] + W[i+1][j+1][k]) * 0.25);

				fprintf(fp, "%f %f %f\n",uVel,vVel,wVel);
			}
		}
	}
	printf( "%f %f %f\n",uVel,vVel,wVel);
	fprintf(fp,"\n");
	fprintf(fp,"CELL_DATA %i \n", ((imax)*(jmax)*(kmax)) );
	fprintf(fp, "SCALARS pressure float 1 \n");
	fprintf(fp, "LOOKUP_TABLE default \n");
	for(k = 1; k < kmax+1; k++) {
		for(j = 1; j < jmax+1; j++) {
			for(i = 1; i < imax+1; i++) {
				fprintf(fp, "%f\n",getValidValue(P[i][j][k]));
			}
		}
	}


	fprintf(fp,"\n");
	fprintf(fp, "SCALARS flag short 1 \n");
	fprintf(fp, "LOOKUP_TABLE default \n");

	for(k = 1; k < kmax+1; k++) {
		for(j = 1; j < jmax+1; j++) {
			for(i = 1; i < imax+1; i++) {
				if(issurface(Flag[i][j][k]) && isfluid(Flag[i][j][k])){
					fprintf(fp, "20\n");
				}
				else{
					fprintf(fp, "%d\n",getcelltype(Flag[i][j][k]));
				}
			}
		}
	}

	if( fclose(fp) )
	{
		char szBuff[80];
		sprintf( szBuff, "Failed to close %s", szFileName );
		ERROR( szBuff );
	}
}
void write_vtkFile(const char *szProblem,
  int    timeStepNumber,
  int    il,
  int    ir,
  int    jb,
  int    jt,
  int    kf,
  int    kb,
  int    rank,
  double dx,
  double dy,
  double dz,
  double ***U,
  double ***V,
  double ***W,
  double ***P)
{
  char szFileName[80];
  FILE *fp=NULL;

  //filename = problem . timestep . subdomain_i . subdomain.j
  sprintf( szFileName, "%s.%i.%i.vtk", szProblem, rank, timeStepNumber );

  //open file for writing, will overwrite existing
  fp = fopen( szFileName, "w");

  //error check
  if( fp == NULL )
  {
    char szBuff[80];
    sprintf( szBuff, "Failed to open %s", szFileName );
    ERROR( szBuff );
    return;
  }

  //calculate the number of points in each dimension
  int icnt = ir-il+1;
  int jcnt = jt-jb+1;
  int kcnt = kb-kf+1;

  //write the header, containing point count and spatial distance
  write_vtkHeader(fp, icnt, jcnt, kcnt, dx, dy, dz);

  //write coordinates, starting from [il,jb]
  write_vtkPointCoordinates(fp, il, jb, kf, icnt, jcnt, kcnt, dx, dy, dz);

  //number of points
  fprintf(fp,"POINT_DATA %i \n", (icnt+1)*(jcnt+1)*(kcnt+1));
  fprintf(fp,"\n");

  //vectors U V W, which start from 0,0,0 if ijk_base = 1,1,1
  fprintf(fp, "VECTORS velocity float\n");

  for(int k=kf-1; k<=kb; k++)
  {
    for(int j=jb-1; j<=jt; j++)
    {
      for(int i=il-1; i<=ir; i++)
      {
        fprintf(fp, "%f %f %f\n", (U[i][j][k] + U[i][j+1][k]) * 0.5, (V[i][j][k] + V[i+1][j][k]) * 0.5, (W[i][j][k] + W[i][j][k+1]) * 0.5);
      }
    }
  }

  fprintf(fp,"\n");

  //number of cells
  fprintf(fp,"CELL_DATA %i \n", icnt*jcnt*kcnt);

  //scalars P
  fprintf(fp, "SCALARS pressure float 1 \n");
  fprintf(fp, "LOOKUP_TABLE default \n");

  for(int k=kf; k<=kb; k++)
  {
    for(int j=jb; j<=jt; j++)
    {
      for(int i=il; i<=ir; i++)
      {
        fprintf(fp, "%f\n", P[i][j][k] );
      }
    }
  }

  //close file
  if(fclose(fp))
  {
    char szBuff[80];
    sprintf( szBuff, "Failed to close %s", szFileName );
    ERROR( szBuff );
  }
}