[petsc-users] non-homogenous Dirichlet bc using MatZeroRowsColumns
Barry Smith
bsmith at petsc.dev
Thu Apr 13 13:12:48 CDT 2023
This is a good question.
MatZeroRowsColumns() removes the rows and columns from the matrix and (optionally) updates the right hand side (and inserts values in the prescribed solution locations). Thus repeated calls cannot continue to update the right hand side vector; since the needed matrix values are gone.
The way I solve problems where the boundary solution depends on time is by replacing that term by differentiating that equation; and do not use MatZeroRowsColumns(). So let w be the solution at some grid point on the boundary and w(t) = f(t) then I write w'(t) = f'(t) and then code the f'(t) as the right hand side for that grid point. If f(t)= c is a constant then f'(t) is zero and I just code zero as the right hand side for that point and use the initial condition w(0) = c.
There may be better ways to do this.
Barry
> On Apr 13, 2023, at 9:40 AM, Karthikeyan Chockalingam - STFC UKRI via petsc-users <petsc-users at mcs.anl.gov> wrote:
>
> Hi,
>
> I am trying to solve the below parabolic system for a constant time interval dt
>
> (M + dt * K) x = M * x^(old)
>
> Where,
> M – Mass matrix
> K – Stiffness matrix
> A = M + dt * K (remains constant)
>
> I apply the boundary condition using MatZeroRowsColumns. For homogenous boundary conditions, I notice that the A matrix remains unmodified from one-time step to the next.
>
> For the non-homogenous boundary condition, I supply ‘x’ with the prescribed boundary value and pass it to MatZeroRowsColumns as follows
>
> MatZeroRowsColumnsIS(A, is, 1, x, b);
>
> After the linear solve, I find that A is modified. So I have to reassemble A again for every time step. Is it MatZeroRowsColumns or the solve itself that modifies A and why?
>
> Kind regards,
> Karthik.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20230413/8a40deb2/attachment.html>
More information about the petsc-users
mailing list