int main(int argc, char **args) { PetscErrorCode ierr; ierr = DCellInit(); CHKERRQ(ierr); PetscReal dx = 1; iCoor size = {1625,1145,0}; // iCoor size = {253,341,0}; int fd; Coor dh = {dx,dx,dx}; iCoor pos = {0,0,0}; Grid chip; ierr = GridCreate(dh,pos,size,1,&chip); CHKERRQ(ierr); ierr = PetscInfo(0,"Reading image file\n"); CHKERRQ(ierr); ierr = PetscBinaryOpen("/scratch/n/BL Big",FILE_MODE_READ,&fd); CHKERRQ(ierr); ierr = PetscBinaryRead(fd,chip->v1,size.x*size.y,PETSC_DOUBLE); CHKERRQ(ierr); ierr = PetscBinaryClose(fd); CHKERRQ(ierr); ierr = PetscInfo(0,"Writing image file\n"); CHKERRQ(ierr); ierr = GridWrite(chip,0); CHKERRQ(ierr); FluidField fluid; ierr = FluidFieldCreate(PETSC_COMM_WORLD, &fluid); CHKERRQ(ierr); ierr = FluidFieldSetDims(fluid,size); CHKERRQ(ierr); ierr = FluidFieldSetDx(fluid,dx); CHKERRQ(ierr); ierr = FluidFieldSetMask(fluid, chip); CHKERRQ(ierr); ierr = FluidFieldSetup(fluid); CHKERRQ(ierr); ierr = SetPressureBC(fluid); CHKERRQ(ierr); ierr = KSPSolve(fluid->ksp,fluid->rhs,fluid->vel); CHKERRQ(ierr); ierr = FluidFieldWrite( fluid,0); CHKERRQ(ierr); ierr = FluidFieldDestroy(fluid); CHKERRQ(ierr); ierr = GridDestroy(chip); CHKERRQ(ierr); ierr = DCellFinalize(); CHKERRQ(ierr); return 0; }
PetscErrorCode HeaderlessBinaryReadCheck(DM dm,const char name[]) { PetscErrorCode ierr; int fdes; PetscScalar buffer[DMDA_I*DMDA_J*DMDA_K*3]; PetscInt len,d,i,j,k,M,N; PetscMPIInt rank; PetscBool dataverified = PETSC_TRUE; PetscFunctionBeginUser; ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr); ierr = DMDAGetInfo(dm,NULL,&M,&N,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);CHKERRQ(ierr); len = DMDA_I*DMDA_J*DMDA_K*3; if (!rank) { ierr = PetscBinaryOpen(name,FILE_MODE_READ,&fdes);CHKERRQ(ierr); ierr = PetscBinaryRead(fdes,buffer,len,PETSC_SCALAR);CHKERRQ(ierr); ierr = PetscBinaryClose(fdes);CHKERRQ(ierr); for (k=0; k<DMDA_K; k++) { for (j=0; j<DMDA_J; j++) { for (i=0; i<DMDA_I; i++) { for (d=0; d<3; d++) { PetscScalar v,test_value_s,test_value; PetscInt index; test_value_s = dmda_i_val[i]*((PetscScalar)i) + dmda_j_val[j]*((PetscScalar)(i+j*M)) + dmda_k_val[k]*((PetscScalar)(i + j*M + k*M*N)); test_value = 3.0 * test_value_s + (PetscScalar)d; index = 3*(i + j*M + k*M*N) + d; v = PetscAbsScalar(test_value-buffer[index]); #if defined(PETSC_USE_COMPLEX) if ((PetscRealPart(v) > 1.0e-10) || (PetscImaginaryPart(v) > 1.0e-10)) { ierr = PetscPrintf(PETSC_COMM_SELF,"ERROR: Difference > 1.0e-10 occurred (delta = (%+1.12e,%+1.12e) [loc %D,%D,%D(%D)])\n",(double)PetscRealPart(test_value),(double)PetscImaginaryPart(test_value),i,j,k,d);CHKERRQ(ierr); dataverified = PETSC_FALSE; } #else if (PetscRealPart(v) > 1.0e-10) { ierr = PetscPrintf(PETSC_COMM_SELF,"ERROR: Difference > 1.0e-10 occurred (delta = %+1.12e [loc %D,%D,%D(%D)])\n",(double)PetscRealPart(test_value),i,j,k,d);CHKERRQ(ierr); dataverified = PETSC_FALSE; } #endif } } } } if (dataverified) { ierr = PetscPrintf(PETSC_COMM_SELF,"Headerless read of data verified for: %s\n",name);CHKERRQ(ierr); } } PetscFunctionReturn(0); }
void PETSC_STDCALL petscbinaryclose_(int *fd, int *__ierr ){ *__ierr = PetscBinaryClose(*fd); }