On Sep 17, 2013, at 8:35 PM, Roc Wang <[email protected]> wrote:

> Hello,
> 
>     I am trying to solve a linear problem by using KSPSolve and DM. In the 
> example  /src/ksp/ksp/examples/tutorials/ex45.c, the Matrix and the RHS 
> vector are computed by calling  KSPSetComputeRHS and  KSPSetComputeOperators 
> in which functions ComputeRHS() and ComputeMatrix() are called and the matrix 
> is assembled in ComputeMatrix().   
> 
>     Since the linear system is solved in an iteration, it will save time to 
> reuse the matrix assembled in ComputeMatrix().  That is the ComputeMatrix() 
> is called only once, but ComputeRHS() is called in each iteration.

   What do you need mean by an "iteration" here? Do you mean one iteration of a 
KSP solvers, of which several are needed to produce the approximate solution or 
something else? 

   The ComputeRHS() function is only called ONCE for each KSPSolve (even though 
KSP may take several iterations to solve the linear system).

   The ComputeMatrix() function is actually only called ONCE period, unless you 
call KSPSetComputeOperators() again, even if you call KSPSolve() several times 
it uses the same matrix until you call KSPSetComputerOperators() again.

>  Can anyone tell me what should I do to keep the assembled matrix?
> 
>      I am thinking not to use  KSPSetComputeOperators for assembling the 
> matrix, but use DMCreateMatrix() alternatively. Am I right?

   That is a completely orthogonal issue; DMCreateMatrix() only gives you an 
empty sparse matrix with the right nonzero structure for the mesh associated 
with DM. You still need to compute its entries yourself, possibly in a 
ComputeMatrix function you write.

   Barry

> 
>      Any hits would be appreciated very much. Thanks alot.
> 
>  

Reply via email to