[petsc-users] How to create a mapping of global to local indices?

Smith, Barry F. bsmith at mcs.anl.gov
Thu Jul 4 10:45:32 CDT 2019


  You do not use the AO when adding values to the matrices or vectors. You use the AO to change the numbering inside your mesh data structure. Your mesh data structure then has contiguous number of degrees of freedom per process just like the Mat and Vec need so you use these values directly to put values into the matrix/vectors. For example after applying the AO your cell (triangular for simplicity) may have vertices  0, 22, 88 you would form the element stiffness can call MatSetValues(A,3,{0,22,38},3,{0,22,38},values, ADD_VALUES).

   Barry


> On Jul 4, 2019, at 8:34 AM, Dongyu Liu - CITG <D.Liu-4 at tudelft.nl> wrote:
> 
> Thanks, Smith. I understand the functionalities of the AOCreate, AOApplicationToPetsc(), they can be used to basicially convert old global indices to new indices. But my next question will be how can they cooperate with the sparse matrix? As I understand, these objects behave kind of like maps, but I don't know how to pass this information when I create the global stiffness matrix or add value to the global stiffness matrix. 
> 
> Best,
> Dongyu
> From: Smith, Barry F. <bsmith at mcs.anl.gov>
> Sent: Wednesday, July 3, 2019 9:02:21 PM
> To: Matthew Knepley
> Cc: Dongyu Liu - CITG; petsc-users at mcs.anl.gov
> Subject: Re: [petsc-users] How to create a mapping of global to local indices?
>  
> 
>   Note that number ingof vertices/nodes whatever is just an arbitrary label; no one is better or more fundamental than another. In your code's interaction with PETSc vectors and matrices you must use the contiguous numbering, in your mesh management code you can do whatever you want.
> 
> There are routines  AOCreate(), AOApplicationToPetsc() etc that you can, if you choose, use to renumber the vertices/nodes in your mesh data structure to match those used by PETSc vectors/matrices.
> 
> 
>   Barry
> 
> 
> > On Jul 3, 2019, at 12:55 PM, Matthew Knepley via petsc-users <petsc-users at mcs.anl.gov> wrote:
> > 
> > On Wed, Jul 3, 2019 at 9:07 AM Dongyu Liu - CITG via petsc-users <petsc-users at mcs.anl.gov> wrote:
> > Thank you, Mark. My question is if I have some node indices like [0, 1, 3, 8, 9] handled by the current processor, is that necessary to renumber these indices to something like 0 to 4?
> > 
> > Yes.
> >  
> > or is there any alternative?
> > 
> > No.
> > 
> >   Thanks,
> > 
> >     Matt 
> > 
> > 
> > Dongyu
> > 
> > From: Mark Adams <mfadams at lbl.gov>
> > Sent: Wednesday, July 3, 2019 3:54:49 PM
> > To: Dongyu Liu - CITG
> > Cc: petsc-users at mcs.anl.gov
> > Subject: Re: [petsc-users] How to create a mapping of global to local indices?
> >  
> > PETSc matrices and vectors are created with a local size n or global size N and PETSC_DECIDE instead of n. The global PETSc indices are ordered from 0 to n_0 - 1 where n_0 is the number of equations on process 0. This numbering continues for all processes. 
> > 
> > You can use:
> > PetscErrorCode MatGetOwnershipRange(Mat mat,PetscInt *m,PetscInt *n)
> > To see what your local global indices are (rows m to n-1 are on this process and so its the local indices are 0 to (n-m-1)).
> > 
> > Mark
> > 
> > 
> > On Wed, Jul 3, 2019 at 9:11 AM Dongyu Liu - CITG via petsc-users <petsc-users at mcs.anl.gov> wrote:
> > Hi,
> > 
> > 
> > 
> > I am running a FEM program using PETSc. In the beginning,  the mesh is partitioned in gmsh, and we read the partitioned mesh using our own reader.
> > 
> > 
> > 
> > Now my question is: How can I get a global to local indices mapping? and do I need to renumber the indices after I read the partitioned mesh?
> > 
> > 
> > 
> > From my understanding, the rows handled by each processor should be consecutive, but the indices of nodes which I directly read from a gmsh file are not. Is this an issue?
> > 
> > 
> > 
> > Best,
> > 
> > 
> > 
> > Dongyu
> > 
> > 
> > 
> > 
> > 
> > -- 
> > 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
> > 
> > https://www.cse.buffalo.edu/~knepley/



More information about the petsc-users mailing list