[petsc-users] Re-zero sparse matrix and MatZeroEntries

Barry Smith bsmith at mcs.anl.gov
Fri Feb 18 08:04:13 CST 2011


On Feb 18, 2011, at 5:57 AM, Matthew Knepley wrote:

> On Fri, Feb 18, 2011 at 5:20 AM, TAY wee-beng <zonexo at gmail.com> wrote:
> Hi,
> 
> I am trying to solve the Navier Stokes momentum equation of a moving body.
> 
> For most points (a), I will be using the north/south/east/west locations to form the equation.
> 
> However, for some points (b), due to the moving body, I will be using some interpolation schemes. At different time step, the interpolation template will be different for these points. Hence, I will use different neighboring points to form the equation.
> 
> Moreover, points (a) can change to points (b) and vice versa.
> 
> I wonder if I can use MatZeroEntries to re-zero the whole sparse matrix. But in the manual, it states that "For sparse matrices this routine retains the old nonzero structure. ". However for my case, the template is different at different time step.
> 
> Hence what is the most efficient procedure?
> 
> There is no efficiently, updateable data structure in PETSc, since this would be much lower performance for general use.
> 
> I suggest using a matrix-free application of your full operator, and a fixed sparsity operator for your preconditioner. Alternatively,
> you can rebuild the matrix structure at each step, which might be the best option depending on how much work you do in each solve.

   Here Matt means simply create a new Mat each time the nonzero structure will change and properly preallocate it each time. The additional cost of the new creation is at most a few percent of a run and the code is easier to maintain.

   Barry

> 
>    Matt
>  
> -- 
> Yours sincerely,
> 
> TAY wee-beng
> 
> 
> 
> 
> -- 
> 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



More information about the petsc-users mailing list