<html>
<head>
</head>
<body class='hmmessage'><div dir='ltr'>

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