Actual source code: daload.c

  1: /*$Id: daload.c,v 1.23 2001/03/23 23:25:00 balay Exp $*/

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


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

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

 15:    Output Parameter:
 16: .    da - the DA object

 18:    Level: intermediate

 20: @*/
 21: int DALoad(PetscViewer viewer,int M,int N,int P,DA *da)
 22: {
 23:   int        ierr,info[8],nmax = 8,fd,i;
 24:   MPI_Comm   comm;
 25:   char       fieldnametag[32],fieldname[64];
 26:   PetscTruth isbinary,flag;

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

 34:   PetscViewerBinaryGetDescriptor(viewer,&fd);
 35:   PetscObjectGetComm((PetscObject)viewer,&comm);

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

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

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