Dear all
In my problem, I know the ghost vertices in each partition since I have
used metis to partition my unstructured grid. I want to get a vector ul
with ghosts, from a global vector ug.
I will use ul to assemble my non-linear rhs vector.
Is the following approach optimal for this purpose ?
PetscInt nvar; // number of variables at each vertex
PetscInt nvl; // number of local vertices in this partition
PetscInt nvg; // number of ghost vertices for this partition
PetscInt *vghost; // global index of ghost vertices for this partition
PetscReal **u; // size u[nvl+nvg][nvar]
Vec ul; // vector with ghosts
Vec ug; // global vector without ghosts
VecCreate(PETSC_COMM_WORLD, &ug);
VecSetSizes(ug, nvar*nvl, PETSC_DECIDE);
VecSetFromOptions(ug);
VecCreateGhostBlockWithArray(PETSC_COMM_WORLD, nvar, nvar*nvl,
PETSC_DECIDE, nvg, vghost,
&u, ul);
// Following would be inside RHSFunction
double **array;
VecGetArray2d(ug, nvl, nvar, 0, 0, &array);
for(unsigned int i=0; i<nvl; ++i)
for(unsigned int j=0; j<nvar; ++j)
u[i][j] = array[i][j];
VecRestoreArray2d(ug, nvl, nvar, 0, 0, &array);
// Fill ghost values
VecGhostUpdateBegin(ul, INSERT_VALUES, SCATTER_FORWARD);
VecGhostUpdateEnd (ul, INSERT_VALUES, SCATTER_FORWARD);
// now use u[][] to compute local part of rhs vector
Thanks
praveen