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

Matthew Knepley knepley at gmail.com
Wed Aug 21 06:57:24 CDT 2013


On Wed, Aug 21, 2013 at 4:59 AM, Bishesh Khanal <bisheshkh at gmail.com> wrote:

>
>
>
> On Tue, Aug 20, 2013 at 3:06 PM, Matthew Knepley <knepley at gmail.com>wrote:
>
>> 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.
>>
>
> Now I understand the concept, thanks! So how do I efficiently do this with
> petsc functions when I am using DMDA which contains the boundary points
> too? Conceptually the steps would be the following, I think, but which
> petsc functions would enable me to do this efficiently, for example,
> without explicitly creating the new matrix A1 in the following and instead
> informing KSP about it ?
> 1) First create the big system matrix (from DM da) including the identity
> rows for Dirichlet points and corresponding rhs, Lets say Ax = b.
> 2) Initialize x with zero, then set the desired Dirichlet values on
> corresponding boundary points of x.
> 3) Create a new matrix, A1 with zeros everywhere except the row,col
> positions corresponding to Dirchlet points where put -1.
> 4) Get b1 by multiplying A1 with x.
> 5) Update rhs with b = b + b1.
> 6) Now update A by removing its rows and columns that correspond to the
> Dirichlet points, and remove corresponding rows of b and x.
> 7) Solve Ax=b
>

This is generally not a good thing to do with FD.

   Matt


>>    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
>>
>
>


-- 
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/20130821/7f315d12/attachment.html>


More information about the petsc-users mailing list