[petsc-users] Using /src/ksp/ksp/example/tutorial/ex29.c to solve Poisson Equation Twice

Barry Smith bsmith at mcs.anl.gov
Sun Oct 2 15:56:16 CDT 2011


On Oct 2, 2011, at 12:04 PM, Alan Wei wrote:

> Dear all,
>     I hope you're having a nice weekend. I'm still using this program to solve Poisson Equations. After several discussions before, I know how to use it in general. However, I met a problem when I want to use it twice to solve a same Poisson Equations with two different RHS.(same boundary conditions)
> 1) after I've done my first computation of a Poisson equation, I use DMMGSetKSP() again setting up another (*rhs) . 
>     However, I found that this DMMGSetKSP does not call the function that makes the new (*rhs), i.e. ComputeNewRHS(). 
> 2) In the first tempt to solve the Poisson equation with old RHS, DMMGSetKSP called the function making the old (*rhs). If I comment out the first DMMGSetKSP(), which creates the old (*rhs), then this DMMGSetKSP, which create the new (*rhs), can call the function making the new (*rhs)
> 2) I read the manual of "DMMGSetKSP" saying For linear problems may be called more than once, reevaluates the matrices if it is called more than once. Call DMMGSolve() directly several times to solve with the same matrix but different right hand sides. Does this mean that I do not need to call DMMGSetKSP if I need to solve the same Poisson equation with another RHS? If so, how can I pass my new RHS to dmmg?

    With the DMMG interface you provide a __function__ to compute the right hand side, if you want to solve with several right hand sides you just have the rhs function compute a different right hand side each time it is called corresponding to the right hand sides you want to compute

    By the way the DMMG is being deprecated and will not be in the next PETSc release so we recommend moving away from it and just using the KSP linear solver interface (see the manual page for KSPSetDM() and several examples that us KSPSetDM() in the src/ksp/ksp/examples/tutorials directory.

   Barry

> 
> thanks in advance, 
> Alan
> 



More information about the petsc-users mailing list