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

Adrian Croucher a.croucher at auckland.ac.nz
Wed Mar 18 21:06:12 CDT 2015


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