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  DALoad(PetscViewer viewer,PetscInt M,PetscInt N,PetscInt P,DA *da)
 24: {
 26:   PetscInt       info[8],nmax = 8,i;
 27:   MPI_Comm       comm;
 28:   char           fieldnametag[32],fieldname[64];
 29:   PetscTruth     isbinary,flag;

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

 37:   PetscObjectGetComm((PetscObject)viewer,&comm);

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

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

 74:     if (info[0] == 1) {
 75:       DACreate1d(comm,DA_NONPERIODIC,info[1],1,0,0,&dac);
 76:     } else if (info[0] == 2) {
 77:       DACreate2d(comm,DA_NONPERIODIC,DA_STENCIL_BOX,info[1],info[2],M,N,2,
 78:                       0,0,0,&dac);
 79:     } else if (info[0] == 3) {
 80:       DACreate3d(comm,DA_NONPERIODIC,DA_STENCIL_BOX,info[1],info[2],info[3],M,N,P,
 81:                         3,0,0,0,0,&dac);
 82:     }

 84:     /* this nonsense is so that the vector set to DASetCoordinates() does NOT have a DA */
 85:     /* We should change the handling of coordinates so there is always a coordinate DA when there is a coordinate vector */
 86:     DACreateGlobalVector(dac,&tmpglobal);
 87:     PetscObjectSetOptionsPrefix((PetscObject)tmpglobal,"coor_");
 88:     VecLoadIntoVector(viewer,tmpglobal);
 89:     VecGetLocalSize(tmpglobal,&mlocal);
 90:     VecCreateMPI(comm,mlocal,PETSC_DETERMINE,&global);
 91:     VecCopy(tmpglobal,global);
 92:     VecDestroy(tmpglobal);
 93:     DADestroy(dac);
 94:     DASetCoordinates(*da,global);
 95:   }
 96:   return(0);
 97: }