[petsc-users] How to create and assemble matrices for DA vectors??
Satish Balay
balay at mcs.anl.gov
Thu Apr 7 18:32:47 CDT 2011
On Fri, 8 Apr 2011, Алексей Рязанов wrote:
> Hello.
>
> When I create vectors using
>
> VecCreate(PETSC_COMM_WORLD,&u);
> VecSetSizes(u,PETSC_DECIDE, VecSize);
> VecSetFromOptions(u);
> VecDuplicate(u,&b);
>
> and matrix using
>
> MatCreate(PETSC_COMM_WORLD,&A);
> MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,VecSize,VecSize);
> MatSetFromOptions(A);
>
> PETSc distributes their elements in a proper identical way among processors,
> so I can use procedures like
>
> MatMult(A,u,b);
>
> and
> KSPSolve(ksp,b,x);
> Ofcourse after matrix assembling and initialization of KSP and PC
>
> KSPCreate(PETSC_COMM_WORLD,&ksp);
> KSPSetOperators(ksp,A,A,DIFFERENT_NONZERO_PATTERN);
>
> And thats great and works amazingly!
>
>
>
>
> But now I've created DA vectors "u" and "b" and assembled them through the
> natural grid indexing.
>
> And I need to solve the same SLE Au=b, where A is a Laplacian.
>
> How should I create and assemble the A matrix according to my DA vector to
> use the same functionality?
Create u,b with DAGetGlobalVector() and A with DAGetMatrix() and they
will match the DA. For eg: check: src/snes/examples/tutorials/ex5.c
[or some of the examples in src/dm/da/examples]
Satish
>
> Thank you!
>
> Alexey Ryazanov
> ______________________________________
> Nuclear Safety Institute of Russian Academy of Sciences
> <http://www.ibrae.ac.ru/>
>
More information about the petsc-users
mailing list