[petsc-users] DMDACoor3d and VecView
Roc Wang
pengxwang at hotmail.com
Thu May 23 21:25:51 CDT 2013
Thanks, I followed the src/dm/examples/tests/ex14.c and ex13.c. There is still error. Please take a look at the followings:
//The portion of writing vector in Solver program /* write da, solution Vec Coordinate Da and Vec cda in binary format */ ierr = PetscLogEventRegister("Generate Vector",VEC_CLASSID,&VECTOR_WRITE);CHKERRQ(ierr); ierr = PetscLogEventBegin(VECTOR_WRITE,0,0,0,0);CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_WORLD,"writing vector in binary to vector.bin ...\n");CHKERRQ(ierr); ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,"vector.bin",FILE_MODE_WRITE,&viewer);CHKERRQ(ierr); ierr = DMView(da,viewer);CHKERRQ(ierr); ierr = VecView(x,viewer);CHKERRQ(ierr);
ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr); ierr = PetscLogEventEnd(VECTOR_WRITE,0,0,0,0);CHKERRQ(ierr);
//The portion of reading vector in the post-processing program/* Read new vector in binary format */ DM da; Vec uu; ierr = PetscLogEventRegister("Read Vector",VEC_CLASSID,&VECTOR_READ);CHKERRQ(ierr); ierr = PetscLogEventBegin(VECTOR_READ,0,0,0,0);CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_WORLD,"reading vector in binary from vector.bin ...\n");CHKERRQ(ierr); ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,"vector.bin",FILE_MODE_READ,&viewer);CHKERRQ(ierr);
//ierr = DMCreate(PETSC_COMM_WORLD,&da);CHKERRQ(ierr); //NOTE A
ierr = DMLoad(da,viewer);CHKERRQ(ierr); ierr = DMCreateGlobalVector(da,&uu);CHKERRQ(ierr); ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr); ierr = PetscLogEventEnd(VECTOR_READ,0,0,0,0);CHKERRQ(ierr);
If the line of ierr = DMCreate(PETSC_COMM_WORLD,&da);CHKERRQ(ierr); //NOTE A is commented out, the error is like:[2]PETSC ERROR: --------------------- Error Message ------------------------------------[2]PETSC ERROR: Invalid argument![2]PETSC ERROR: Wrong type of object: Parameter # 1![2]PETSC ERROR: ------------------------------------------------------------------------
If with ierr = DMCreate(PETSC_COMM_WORLD,&da);CHKERRQ(ierr); //NOTE A, the error is like:[0]PETSC ERROR: --------------------- Error Message ------------------------------------[0]PETSC ERROR: Arguments are incompatible![0]PETSC ERROR: Cannot change block size 3 to 1![0]PETSC ERROR: ------------------------------------------------------------------------
> From: jedbrown at mcs.anl.gov
> To: pengxwang at hotmail.com; petsc-users at mcs.anl.gov
> Subject: RE: [petsc-users] DMDACoor3d and VecView
> Date: Thu, 23 May 2013 11:31:59 -0500
>
> Roc Wang <pengxwang at hotmail.com> writes:
>
> >> From: jedbrown at mcs.anl.gov
> >> To: pengxwang at hotmail.com; petsc-users at mcs.anl.gov
> >> Subject: Re: [petsc-users] DMDACoor3d and VecView
> >> Date: Thu, 23 May 2013 10:10:19 -0500
> >>
> >> Roc Wang <pengxwang at hotmail.com> writes:
> >>
> >> > The coordinates of nodes are needed to plot the 3-D distributions of
> >> > the solution. The matrix and the vector are managed with DMDA, so the
> >> > array for the coordinates can be obtained by
> >> > DMDAGetCoordinateDA(da,&cda) and DMDAVecGetArray(cda,gc,&coors).
> >> > Here, coors is defined as DMDACoor3d ***coors. Since the function
> >> > VecVeiw can only output one vector, Vec sol, to a binary file , the
> >> > array of coordinates must be output to another file and thus must be
> >> > read separately.
> >>
> >> Not true, just read them in the same order you wrote them.
> >
> > Does this mean I can save the vectors in the same binary file? If yes, whether the following procedure is correct?
> > /* writing vectors in solver program */
> > DM cda;
> > Vec gc;
> > ierr = DMDAGetCoordinateDA(da,&cda);CHKERRQ(ierr);
> > ierr = DMDAGetCoordinates(cda, &gc);CHKERRQ(ierr);
> >
> >
> > ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,"vector.bin",FILE_MODE_WRITE,&viewer);CHKERRQ(ierr);
> > ierr = VecView(sol,viewer);CHKERRQ(ierr); //write solution vector
> > ierr = VecView(gc,viewer);CHKERRQ(ierr); //write coordinate vector
> > ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
> >
> > /* reading vectors in a stand-along program */
> > ierr = VecCreate(PETSC_COMM_WORLD,&sol);CHKERRQ(ierr);
> > ierr = VecCreate(PETSC_COMM_WORLD,&gc);CHKERRQ(ierr);
>
> Create your DM and coordinate DM, then
>
> DMCreateGlobalVector(da,&sol);
> DMCreateGlobalVector(cda,&gc);
>
> then below
>
> > ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,"vector.bin",FILE_MODE_READ,&viewer);CHKERRQ(ierr);
> > ierr = VecLoad(sol,viewer);CHKERRQ(ierr); //read solution vector
> > ierr = VecLoad(gc,viewer);CHKERRQ(ierr); //read coordinate vector
> > ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
>
> Alternatively, write the DM too so that you can load it instead of
> making it from out-of-band knowledge of sizes:
>
> ierr = DMView(da,viewer);CHKERRQ(ierr);
> ierr = VecView(global,viewer);CHKERRQ(ierr);
> ierr = DMView(cda,viewer);CHKERRQ(ierr);
> ierr = VecView(gc,viewer);CHKERRQ(ierr);
>
> and read with
>
> ierr = DMLoad(da,bviewer);CHKERRQ(ierr);
> ierr = DMCreateGlobalVector(da,&sol);CHKERRQ(ierr);
> ierr = VecLoad(sol,viewer);CHKERRQ(ierr);
> ierr = DMLoad(cda,viewer);CHKERRQ(ierr);
> ierr = DMCreateGlobalVector(cda,&gc);CHKERRQ(ierr);
> ierr = VecLoad(gc,viewer);CHKERRQ(ierr);
>
> See src/dm/examples/tests/ex14.c and ex13.c.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20130523/b88edcf6/attachment.html>
More information about the petsc-users
mailing list