<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'><br><br><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 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> 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>> <br>> > The problem is that the array of coordinates is local array and the<br>> > number of processes in the post-processing program must be same as<br>> > that in the solver. <br>> <br>> DMGetCoordinates() returns a global Vec. Store that, not the local Vec.<br>> <br>> From the names, you must have an older version of PETSc. Please upgrade<br>> to petsc-3.4.<br></div> </div></body>
</html>