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

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

 36:   PetscViewerBinaryGetDescriptor(viewer,&fd);
 37:   PetscObjectGetComm((PetscObject)viewer,&comm);

 39:   PetscOptionsGetIntArray(PETSC_NULL,"-daload_info",info,&nmax,&flag);
 40:   if (!flag) {
 41:     SETERRQ(1,"No DA information in file");
 42:   }
 43:   if (nmax != 8) {
 44:     SETERRQ1(1,"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(1,"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",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 natural,global;
 72:     int 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:     }
 83:     DACreateNaturalVector(dac,&natural);
 84:     VecLoadIntoVector(viewer,natural);
 85:     VecGetLocalSize(natural,&mlocal);
 86:     VecCreateMPI(comm,mlocal,PETSC_DETERMINE,&global);
 87:     DANaturalToGlobalBegin(dac,natural,INSERT_VALUES,global);
 88:     DANaturalToGlobalEnd(dac,natural,INSERT_VALUES,global);
 89:     VecDestroy(natural);
 90:     DADestroy(dac);
 91:     DASetCoordinates(*da,global);
 92:   }
 93:   return(0);
 94: }