[petsc-users] How to create and assemble matrices for DA vectors??

Jed Brown jed at 59A2.org
Sat Apr 16 15:47:19 CDT 2011


On Sat, Apr 16, 2011 at 22:26, Алексей Рязанов <ram at ibrae.ac.ru> wrote:

> 1. Please tell me, what's the principal difference between procedures
> DAGetGlobalVector and DACreateGlobalVector? I cant catch it from man pages.
>

Use DACreateGlobalVector() if you ownership of the vector, you call
VecDestroy() when you are done with it.

Use DAGetGlobalVector() to let the DA manage the lifetime of the vector,
call DARestoreGlobalVector() when you are done with it. The DA does not
actually destroy the vector, it keeps it around and just gives it back next
time you call DAGetGlobalVector(). This is usually what you want for "work"
vectors.


>
> 2. As I can read from DAGetMatrix man page, this procedure:
>
> Creates a matrix with the correct parallel layout and nonzero structure
> required for computing the Jacobian on a function defined using the stencil
> set in the
>  DA
>
> Notes: This properly preallocates the number of nonzeros in the sparse
> matrix so you do not need to do it yourself.
>
> By default it also sets the nonzero structure and puts in the zero entries.
> To prevent setting the nonzero pattern call DASetMatPreallocateOnly<http://../DA/DASetMatPreallocateOnly.html#DASetMatPreallocateOnly>
> ()
>
> So I use DASetMatPreallocateOnly.
>

Why would you want to do that?


> But I dont need a Jacobian. I need a matrix of my linear system
>

But that _is_ the Jacobian of the residual function (f(x) = A*x - b for
linear problems). This language is used frequently in PETSc.


> with its original number of nonzeros per row and its original nonzero
> pattern.
>

What do you mean by "original"?

You are setting values that have not been preallocated, perhaps because the
stencil you defined for the DA is different from the one you are using
during assembly.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110416/7ec57153/attachment.htm>


More information about the petsc-users mailing list