[petsc-users] FD Dirichlet boundary conditions with ghosted DMDA

Barry Smith bsmith at mcs.anl.gov
Wed Mar 18 21:48:11 CDT 2015


  Use either the results for DMDAGetGhostCorners() or DMDAGetCorners() to determine if the first or last node is local. This extends trivially to 2 and 3d. See for example src/ksp/ksp/examples/tutorials/ex34.c ComputeMatrix() if (i==0 || j==0 || k==0 || i==mx-1 || j==my-1 || k==mz-1) { etc

  Barry

> On Mar 18, 2015, at 9:06 PM, Adrian Croucher <a.croucher at auckland.ac.nz> wrote:
> 
> hi,
> 
> I'm setting up a simple 1-D finite difference test problem with Dirichlet boundary conditions at each end, using DMDA.
> 
> I used DMDACreate1d() with the DM_BOUNDARY_GHOSTED option, and set the global array dimension to be the total number of nodes (including boundary nodes) minus 2- so the boundary nodes aren't included in the mesh.
> 
> When I'm evaluating the differential equation on this mesh, I use DMGetLocalVector() and DMGlobalToLocalBegin/End() to scatter to my ghosted vector, then DMDAVecGetArray() to get an array on the local vector.
> 
> When I want to apply the BCs at each end, I call DMDAGetGhostCorners() to find the indices of the ghost points.  I can now plug the required boundary values into my array.
> 
> At present, if I'm running on multiple processors, I'm just checking if rank=0 or rank=size-1 to make sure the BCs only get applied at the actual ends of the mesh, and not at the ends of the internal partitions as well.
> 
> This works, but is there a better way to do it? It seems potentially unreliable- as it assumes rank 0 is always the left hand end and rank size-1 always the right-hand end. Also it won't really work in 2D or 3D.
> 
> Thanks!
> 
> - Adrian
> 
> -- 
> Dr Adrian Croucher
> Senior Research Fellow
> Department of Engineering Science
> University of Auckland, New Zealand
> email: a.croucher at auckland.ac.nz
> tel: +64 (0)9 923 84611
> 



More information about the petsc-users mailing list