Example #1
0
char read_solution(double** solutiono, int* size, int* nshgo, int* ndofo,
		int nump, int rank, int timestep, int nSyncFiles, char* casedir)
{
	int iarray[10];
        const char* iformat = "binary";
        int ithree=3;
        int igeombc;
        char* fn;
	int nshg;
	int ndof;
	double* solution;
        phio_fp fp;
        if( nSyncFiles == 0 )
          posixio_setup(&fp, 'r');
        else if( nSyncFiles > 0 )
          syncio_setup_read(nSyncFiles, &fp);
        char rname[1024];
        phio_constructName(fp,"restart",rname);
        asprintf(&fn,"%s/%s%d.",casedir,rname,timestep);
        phio_openfile(fn, fp);

	phio_readheader(fp, "solution", (void*) iarray, &ithree, "integer", iformat);
	nshg = iarray[0];
	ndof = iarray[1];
	if(size != NULL)
		*size = nshg*ndof;
	solution = (double*) malloc(sizeof(double)*nshg*ndof);
	phio_readdatablock(fp, "solution", solution, size, "double", iformat);
	phio_closefile(fp);
	if(solutiono != NULL)
		*solutiono = solution;
	if(nshgo != NULL)
		*nshgo = nshg;
	if(ndofo != NULL)
		*ndofo = ndof;
	free(fn);
	return(0);
}
Example #2
0
void
Write_Restart(  int* pid,
                int* stepno,
                int* nshg,
                int* numVars,
                double* array1,
                double* array2 ) {

    const char* magic_name = "byteorder magic number";
    int magic_number = 362436;
    int isize, nitems;
    int iarray[10];
    int nfiles;
    int nfields;
    int numparts;
    int nprocs;
    int ione = 1;
    double iotime = 0;
    char filename[255];

    /*  First, count the number of fields to write and store the result in*/
    countfieldstowriterestart();

    /*  Retrieve and compute the parameters required for SyncIO*/
    nfiles = outpar.nsynciofiles;
    nfields = outpar.nsynciofieldswriterestart;
    numparts = workfc.numpe;
    nprocs = workfc.numpe;
    assert(numparts/nprocs == 1);/* Number of parts per proc ...*/

    bzero((void*)filename,255);

    iotime = TMRC();
    if(outpar.output_mode == -1 )
      streamio_setup_write(&f_descriptor, streamio_get_r());
    else if(outpar.output_mode == 0 )
      posixio_setup(&f_descriptor, 'w');
    else if(outpar.output_mode > 0 )
      syncio_setup_write(nfiles, nfields, numparts/nfiles, &f_descriptor);
    else
      exit(EXIT_FAILURE);
    phio_constructName(f_descriptor,"restart",filename);
    phstr_appendInt(filename, *stepno);
    phstr_appendStr(filename, ".");
    phio_openfile(filename, f_descriptor);

    field_flag=0;

    /* write the magic number*/
    phio_writeheader(f_descriptor, magic_name, (void*)&magic_number, &ione,
        &ione, "integer", phasta_iotype);
    phio_writedatablock(f_descriptor, magic_name, (void*)&magic_number,
        &ione, "integer", phasta_iotype );
    field_flag++;

    /* Write solution field ...*/
    isize = (*nshg)*(*numVars);
    nitems = 3;
    iarray[ 0 ] = (*nshg);
    iarray[ 1 ] = (*numVars);
    iarray[ 2 ] = (*stepno);

    phio_writeheader(f_descriptor, "solution", (void*)iarray, &nitems,
        &isize, "double", phasta_iotype);
    nitems = (*nshg)*(*numVars);
    phio_writedatablock(f_descriptor, "solution", (void*)(array1),
        &isize, "double", phasta_iotype );
    field_flag++;

    /* Write solution field ...*/
    isize = (*nshg)*(*numVars);
    nitems = 3;
    iarray[ 0 ] = (*nshg);
    iarray[ 1 ] = (*numVars);
    iarray[ 2 ] = (*stepno);
    phio_writeheader(f_descriptor, "time derivative of solution",
        (void*)iarray, &nitems, &isize, "double", phasta_iotype);
    nitems = (*nshg)*(*numVars);
    phio_writedatablock(f_descriptor, "time derivative of solution",
        (void*)(array2), &isize, "double", phasta_iotype );
    field_flag++;

    if (field_flag==nfields){
      phio_closefile(f_descriptor);
      if (*pid==0) {
        printf("\n");
      }
    }
    iotime = TMRC() - iotime;
    if (workfc.master == workfc.myrank)
      printf("time to write restart (seconds) %f\n",iotime);
}