<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><div>Hi, <br><br></div>I'm trying to understand <a href="https://github.com/haplav/petsc-tut-it4i-2018/blob/master/exercises/ex6.c" target="_blank">this example</a> from a tutorial. DM is used as an alternative to setting up the matrix and vector separately (as was done in the <a href="https://github.com/haplav/petsc-tut-it4i-2018/blob/master/exercises/ex5.c" target="_blank">previous example</a>). <br><br></div><div>Since DMDACreate1d was used to create the mesh, can someone explain this logic more clearly :<br>
<pre> /*
Gets an array containing the indices (in local coordinates)
of all the local elements.
nel - number of local elements
nen - number of one element's nodes
e - the local indices of the elements' vertices
*/
ierr = DMDAGetElements(da, &nel, &nen, &e);CHKERRQ(ierr);
/*
Assemble matrix and RHS
*/
value[0] = 1.0; value[1] = -1.0; value[2] = -1.0; value[3] = 1.0;
bvalue[0] = 1.0; bvalue[1] = 1.0;
for (i=0; i<nel; i++) {
ierr = MatSetValuesLocal(A, 2, e+nen*i, 2, e+nen*i, value, ADD_VALUES);CHKERRQ(ierr);
//TODO use VecSetValuesLocal() to set the values
}
ierr = DMDARestoreElements(da, &nel, &nen, &e);CHKERRQ(ierr);</pre>
<br></div><div>The dm was created using
<pre> ierr = MPI_Allreduce(&n, &N, 1, MPI_INT, MPI_SUM, PETSC_COMM_WORLD);CHKERRQ(ierr);
ierr = DMDACreate1d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,N,1,1,NULL,&da);CHKERRQ(ierr);</pre>
<br>Using n = 3 and I get the following results when I print the values of nel,nen and e using this statement<br><span style="font-family:monospace,monospace">PetscPrintf(PETSC_COMM_SELF,"nel : %d,nen : %d, e elements : %d,%d,%d,%d,%d,%d,%d,%d ,rank %d\n",nel,nen,e[0],e[1],e[2],e[3],e[4],e[5],e[6],e[7],rank);<br></span><br></div><div>The output comes out as :<br></div><div><span style="font-family:monospace,monospace"><br>[sajid@xrm exercises]$ mpirun -np 4 ./ex6<br>nel : 2,nen : 2, e elements : 0,1,1,2,1936617321,0,3,0 ,rank 0<br>nel : 3,nen : 2, e elements : 0,1,1,2,2,3,4,0 ,rank 1<br>nel : 3,nen : 2, e elements : 0,1,1,2,2,3,4,0 ,rank 2<br>nel : 3,nen : 2, e elements : 0,1,1,2,2,3,3,0 ,rank 3<br></span><br>Does this mean that I'm supposed to read the first 4 elements for rank 0 as row0, col0, row1, col1? <br><br></div><div>And how does differ If I'm creating a vector using DMCreate1d ?<br></div><div><br><br></div><div><div><div>Thank You, <br></div><div><div dir="ltr" class="gmail-m_6196790192981320259m_-5647328829973479608gmail_signature"><div dir="ltr"><div style="font-size:12.8px">Sajid Ali<br></div><div style="font-size:12.8px">Applied Physics<br></div><div style="font-size:12.8px">Northwestern University</div></div></div></div></div></div></div></div></div></div></div></div></div>