Actual source code: daload.c
2: #include src/dm/da/daimpl.h
7: /*@C
8: DALoad - Creates an appropriate DA and loads its global vector from a file.
10: Input Parameter:
11: + viewer - a binary viewer (created with PetscViewerBinaryOpen())
12: . M - number of processors in x direction
13: . N - number of processors in y direction
14: - P - number of processors in z direction
16: Output Parameter:
17: . da - the DA object
19: Level: intermediate
21: @*/
22: PetscErrorCode DALoad(PetscViewer viewer,PetscInt M,PetscInt N,PetscInt P,DA *da)
23: {
25: PetscInt info[8],nmax = 8,i;
26: int fd;
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: PetscViewerBinaryGetDescriptor(viewer,&fd);
38: PetscObjectGetComm((PetscObject)viewer,&comm);
40: PetscOptionsGetIntArray(PETSC_NULL,"-daload_info",info,&nmax,&flag);
41: if (!flag) {
42: SETERRQ(PETSC_ERR_FILE_UNEXPECTED,"No DA information in file");
43: }
44: if (nmax != 8) {
45: SETERRQ1(PETSC_ERR_FILE_UNEXPECTED,"Wrong number of items in DA information in file: %D",nmax);
46: }
47: if (info[0] == 1) {
48: DACreate1d(comm,(DAPeriodicType) info[7],info[1],info[4],info[5],0,da);
49: } else if (info[0] == 2) {
50: DACreate2d(comm,(DAPeriodicType) info[7],(DAStencilType) info[6],info[1],info[2],M,N,info[4],
51: info[5],0,0,da);
52: } else if (info[0] == 3) {
53: DACreate3d(comm,(DAPeriodicType) info[7],(DAStencilType) info[6],info[1],info[2],info[3],M,N,P,
54: info[4],info[5],0,0,0,da);
55: } else {
56: SETERRQ1(PETSC_ERR_FILE_UNEXPECTED,"Dimension in info file is not 1, 2, or 3 it is %D",info[0]);
57: }
58: for (i=0; i<info[4]; i++) {
59: sprintf(fieldnametag,"-daload_fieldname_%d",(int)i);
60: PetscOptionsGetString(PETSC_NULL,fieldnametag,fieldname,64,&flag);
61: if (flag) {
62: DASetFieldName(*da,i,fieldname);
63: }
64: }
66: /*
67: Read in coordinate information if kept in file
68: */
69: PetscOptionsHasName(PETSC_NULL,"-daload_coordinates",&flag);
70: if (flag) {
71: DA dac;
72: Vec natural,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: }
84: DACreateNaturalVector(dac,&natural);
85: PetscObjectSetOptionsPrefix((PetscObject)natural,"coor_");
86: VecLoadIntoVector(viewer,natural);
87: VecGetLocalSize(natural,&mlocal);
88: VecCreateMPI(comm,mlocal,PETSC_DETERMINE,&global);
89: DANaturalToGlobalBegin(dac,natural,INSERT_VALUES,global);
90: DANaturalToGlobalEnd(dac,natural,INSERT_VALUES,global);
91: VecDestroy(natural);
92: DADestroy(dac);
93: DASetCoordinates(*da,global);
94: }
95: return(0);
96: }