Actual source code: daload.c
1: #define PETSCDM_DLL
3: #include private/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: flag = PETSC_FALSE;
69: PetscOptionsGetTruth(PETSC_NULL,"-daload_coordinates",&flag,PETSC_NULL);
70: if (flag) {
71: DA dac;
72: Vec tmpglobal,global;
73: PetscInt mlocal;
75: if (info[0] == 1) {
76: DACreate1d(comm,DA_NONPERIODIC,info[1],1,0,0,&dac);
77: } else if (info[0] == 2) {
78: DACreate2d(comm,DA_NONPERIODIC,DA_STENCIL_BOX,info[1],info[2],M,N,2,
79: 0,0,0,&dac);
80: } else if (info[0] == 3) {
81: DACreate3d(comm,DA_NONPERIODIC,DA_STENCIL_BOX,info[1],info[2],info[3],M,N,P,
82: 3,0,0,0,0,&dac);
83: }
85: /* this nonsense is so that the vector set to DASetCoordinates() does NOT have a DA */
86: /* We should change the handling of coordinates so there is always a coordinate DA when there is a coordinate vector */
87: DACreateGlobalVector(dac,&tmpglobal);
88: PetscObjectSetOptionsPrefix((PetscObject)tmpglobal,"coor_");
89: VecLoadIntoVector(viewer,tmpglobal);
90: VecGetLocalSize(tmpglobal,&mlocal);
91: VecCreateMPI(comm,mlocal,PETSC_DETERMINE,&global);
92: VecCopy(tmpglobal,global);
93: VecDestroy(tmpglobal);
94: DADestroy(dac);
95: DASetCoordinates(*da,global);
96: VecDestroy(global);
97: }
98: return(0);
99: }