Actual source code: daload.c

      1: #define PETSCDM_DLL

     3:  #include src/dm/da/daimpl.h

      8: /*@C
      9:       DALoad - Creates an appropriate DA and loads its global vector from a file.

     11:    Input Parameter:
     12: +    viewer - a binary viewer (created with PetscViewerBinaryOpen())
     13: .    M - number of processors in x direction
     14: .    N - number of processors in y direction
     15: -    P - number of processors in z direction

     17:    Output Parameter:
     18: .    da - the DA object

     20:    Level: intermediate

     22: @*/
     23: PetscErrorCode PETSCDM_DLLEXPORT DALoad(PetscViewer viewer,PetscInt M,PetscInt N,PetscInt P,DA *da)
     24: {
     26:   PetscInt       info[8],nmax = 8,i;
     27:   int            fd;
     28:   MPI_Comm       comm;
     29:   char           fieldnametag[32],fieldname[64];
     30:   PetscTruth     isbinary,flag;

     35:   PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_BINARY,&isbinary);
     36:   if (!isbinary) SETERRQ(PETSC_ERR_ARG_WRONG,"Must be binary viewer");

     38:   PetscViewerBinaryGetDescriptor(viewer,&fd);
     39:   PetscObjectGetComm((PetscObject)viewer,&comm);

     41:   PetscOptionsGetIntArray(PETSC_NULL,"-daload_info",info,&nmax,&flag);
     42:   if (!flag) {
     43:     SETERRQ(PETSC_ERR_FILE_UNEXPECTED,"No DA information in file");
     44:   }
     45:   if (nmax != 8) {
     46:     SETERRQ1(PETSC_ERR_FILE_UNEXPECTED,"Wrong number of items in DA information in file: %D",nmax);
     47:   }
     48:   if (info[0] == 1) {
     49:     DACreate1d(comm,(DAPeriodicType) info[7],info[1],info[4],info[5],0,da);
     50:   } else if (info[0] == 2) {
     51:     DACreate2d(comm,(DAPeriodicType) info[7],(DAStencilType) info[6],info[1],info[2],M,N,info[4],
     52:                       info[5],0,0,da);
     53:   } else if (info[0] == 3) {
     54:     DACreate3d(comm,(DAPeriodicType) info[7],(DAStencilType) info[6],info[1],info[2],info[3],M,N,P,
     55:                       info[4],info[5],0,0,0,da);
     56:   } else {
     57:     SETERRQ1(PETSC_ERR_FILE_UNEXPECTED,"Dimension in info file is not 1, 2, or 3 it is %D",info[0]);
     58:   }
     59:   for (i=0; i<info[4]; i++) {
     60:     sprintf(fieldnametag,"-daload_fieldname_%d",(int)i);
     61:     PetscOptionsGetString(PETSC_NULL,fieldnametag,fieldname,64,&flag);
     62:     if (flag) {
     63:       DASetFieldName(*da,i,fieldname);
     64:     }
     65:   }

     67:   /*
     68:     Read in coordinate information if kept in file
     69:   */
     70:   PetscOptionsHasName(PETSC_NULL,"-daload_coordinates",&flag);
     71:   if (flag) {
     72:     DA  dac;
     73:     Vec natural,global;
     74:     PetscInt mlocal;

     76:     if (info[0] == 1) {
     77:       DACreate1d(comm,DA_NONPERIODIC,info[1],1,0,0,&dac);
     78:     } else if (info[0] == 2) {
     79:       DACreate2d(comm,DA_NONPERIODIC,DA_STENCIL_BOX,info[1],info[2],M,N,2,
     80:                       0,0,0,&dac);
     81:     } else if (info[0] == 3) {
     82:       DACreate3d(comm,DA_NONPERIODIC,DA_STENCIL_BOX,info[1],info[2],info[3],M,N,P,
     83:                         3,0,0,0,0,&dac);
     84:     }
     85:     DACreateNaturalVector(dac,&natural);
     86:     PetscObjectSetOptionsPrefix((PetscObject)natural,"coor_");
     87:     VecLoadIntoVector(viewer,natural);
     88:     VecGetLocalSize(natural,&mlocal);
     89:     VecCreateMPI(comm,mlocal,PETSC_DETERMINE,&global);
     90:     DANaturalToGlobalBegin(dac,natural,INSERT_VALUES,global);
     91:     DANaturalToGlobalEnd(dac,natural,INSERT_VALUES,global);
     92:     VecDestroy(natural);
     93:     DADestroy(dac);
     94:     DASetCoordinates(*da,global);
     95:   }
     96:   return(0);
     97: }