[petsc-users] better way of setting dirichlet boundary conditions

Matthew Knepley knepley at gmail.com
Tue Aug 20 08:06:00 CDT 2013


On Tue, Aug 20, 2013 at 7:19 AM, Bishesh Khanal <bisheshkh at gmail.com> wrote:

> Hi all,
> In solving problems such as laplacian/poisson equations with dirichlet
> boundary conditions with finite difference methods, I set explicity the
> required values to the diagonal of the boundary rows of the system matrix,
> and the corresponding rhs vector.
> i.e.  typically my matrix building loop would be like:
>
> e.g. in 2d problems, using DMDA:
>
> FOR (i=0 to xn-1, j = 0 to yn-1)
>      set row.i = i, row. j = j
>      IF (i = 0 or xn-1) or (j = 0 or yn-1)
>             set diagonal value of matrix A to 1 in current row.
>      ELSE
>             normal interior points: set the values accordingly
>      ENDIF
> ENDFOR
>
> Is there another preferred method instead of doing this ? I saw functions
> such as MatZeroRows()
> when following the answer in the FAQ regarding this at:
> http://www.mcs.anl.gov/petsc/documentation/faq.html#redistribute
>
> but I did not understand what it is trying to say in the last sentence of
> the answer "An alternative approach is ... into the load"
>

Since those values are fixed, you do not really have to solve for them. You
can eliminate them from your
system entirely. Imagine you take the matrix you produce, plug in the
values to X, act with the part of the
matrix  that hits them A_ID X, and move that to the RHS, then eliminate the
row for Dirichlet values.

   Matt

Thanks,
> Bishesh
>



-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20130820/8c4c7b60/attachment.html>


More information about the petsc-users mailing list