Hi,
I'm trying to get DMPlex to solve and display with Dirichlet boundary conditions.
My global and local solution vectors are of different sizes. The length difference is the number of nodes read from the nodeset read in the exodus file.
I am able to project the initial solution/boundary data that I want with with VecSetValuesSection. The initial condition looks ok with the global solution
in the viewer. However, I seem to be losing the dirichlet boundary data on the solve ? I'm trying to use the suggested global to local scattering on the output.
{
Vec localX;
PetscSection section;
PetscInt vStart, vEnd, v ;
DMGetLocalVector(dm, &localX);
DMGetDefaultSection(dm, §ion);
DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd);
for (v = vStart; v < vEnd; ++v) {
PetscScalar bcData = 101.0;
VecSetValuesSection(localX, section, v, &bcData , INSERT_BC_VALUES);
}
DMRestoreLocalVector(dm, &localX);
DMLocalToGlobalBegin(dm, localX, INSERT_VALUES, u);
DMLocalToGlobalEnd(dm, localX, INSERT_VALUES, u);
PetscViewer viewer;
char vtkfilename[PETSC_MAX_PATH_LEN] = "initialcondition.vtk";
ierr = PetscViewerVTKOpen(PETSC_COMM_WORLD,vtkfilename,FILE_MODE_WRITE,&viewer);CHKERRQ(ierr);
ierr = VecView(u,viewer);CHKERRQ(ierr);
ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr)
}
.
.
ierr = SNESSolve(snes, NULL, u);CHKERRQ(ierr);
.
.
if (write_output) {
PetscViewer viewer;
const char *name;
Vec lv;
DMGetLocalVector(dm, &lv);
ierr = PetscObjectGetName((PetscObject) u,&name);CHKERRQ(ierr);
ierr = PetscObjectSetName((PetscObject) lv, name);CHKERRQ(ierr);
ierr = DMGlobalToLocalBegin(dm, u, INSERT_VALUES, lv);CHKERRQ(ierr);
ierr = DMGlobalToLocalEnd(dm, u, INSERT_VALUES, lv);CHKERRQ(ierr);
char vtkfilename[PETSC_MAX_PATH_LEN] = "solution.vtk";
ierr = PetscViewerVTKOpen(PETSC_COMM_WORLD,vtkfilename,FILE_MODE_WRITE,&viewer);CHKERRQ(ierr);
ierr = VecView(lv,viewer);CHKERRQ(ierr);
ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
ierr = DMRestoreLocalVector(dm, &lv);CHKERRQ(ierr);
}