[petsc-users] DMCreateMatrix error with Composite (no getlocaltoglobalmapping)

Mark Adams mfadams at lbl.gov
Wed Aug 6 17:31:20 CDT 2014


Jed, it looks like DM_DA creates its l2gmap in Setup, but DM_Shell does
not.  This seems to be causing errors when DM_Shell is used in DM_Composit
and I make a matrix.

I'm thinking I could add this construction to DM_Shell.  DM_Shell does not
have a Setup method (like DM_DA) but I could create function and set it
in DMShellCreate, like PetscErrorCode  DMShellCreate(MPI_Comm comm,DM *dm)
{
  PetscErrorCode ierr;

  PetscFunctionBegin;
  PetscValidPointer(dm,2);
  ierr = DMCreate(comm,dm);CHKERRQ(ierr);
  ierr = DMSetType(*dm,DMSHELL);CHKERRQ(ierr);
  ierr = DMSetUp(*dm);CHKERRQ(ierr);
  dm->ops->getlocaltoglobalmapping = DMGetLocalToGlobalMapping_Shell
  PetscFunctionReturn(0);
}

Does this seem like a reasonable approach?





On Wed, Aug 6, 2014 at 2:49 PM, Mark Adams <mfadams at lbl.gov> wrote:

> Now that I look at DMShellSetLocalToGlobal, I see that it sets the
> begin/end functions.  But these are already set.
>
> It looks like DMShell's SetType must set something for dm->ops->getlocaltoglobalmapping
> for DMShell to be usable to get a matrix from a Composite DM.
>
>
> On Wed, Aug 6, 2014 at 2:34 PM, Mark Adams <mfadams at lbl.gov> wrote:
>
>> It looks like DMShellCreate does not set dm->ops->getlocaltoglobalmapping,
>> which is needed for DMCreateMatrix with a composite DM.  I do set a
>> global and local vector and a matrix.  It looks like I could call DMShellSetLocalToGlobal.
>>  Should I be doing this?  Seems low level and the kind of thing this using
>> the DM was supposed to avoid
>>
>> This seems like it is simply a copy of a local vector to to local part of
>> a global vector.
>>
>> Mark
>>
>>
>>
>> On Wed, Aug 6, 2014 at 12:23 PM, Mark Adams <mfadams at lbl.gov> wrote:
>>
>>> adding a subject ...
>>>
>>>
>>> On Wed, Aug 6, 2014 at 12:00 PM, Mark Adams <mfadams at lbl.gov> wrote:
>>>
>>>> I am moving my code to have the DM create the matrix and am hitting
>>>> this error in DMGetLocalToGlobalMapping:
>>>>
>>>> if (!dm->ops->getlocaltoglobalmapping)
>>>> SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"DM can not create
>>>> LocalToGlobalMapping");
>>>>
>>>> This happens when I create the matrix like this:
>>>>
>>>>   call DMCompositeCreate(comm,solver%da,ierr)
>>>>   call DMSetOptionsPrefix(solver%da,'fsa_',ierr)
>>>>   call DMCompositeAddDM(solver%da,solver%daphi,ierr)
>>>>   call DMCompositeAddDM(solver%da,solver%dalam,ierr)
>>>>   call DMSetFromOptions(solver%da,ierr)
>>>>   call DMCreateMatrix(solver%da,solver%KKTmat,ierr)
>>>>
>>>> I am using DMShell and create them like so:
>>>>
>>>>   ! phi DM
>>>>   call VecCreate(comm,x1Vec,ierr)
>>>>   call VecSetSizes(x1Vec,N1loc,N1Glob,ierr)
>>>>    call VecSetFromOptions(x1Vec,ierr)
>>>>
>>>>   call DMShellCreate(comm,solver%daphi,ierr)
>>>>   call DMShellSetGlobalVector(solver%daphi,x1Vec,ierr)
>>>>   call DMShellSetMatrix(solver%daphi,solver%A0Mat,ierr)
>>>>   call VecDestroy(x1Vec,ierr)
>>>>   call DMSetOptionsPrefix(solver%daphi,'phi_',ierr)
>>>>   call DMSetFromOptions(solver%daphi,ierr)
>>>>
>>>>   call VecCreate(PETSC_COMM_SELF,x1Vecloc,ierr)
>>>>   call VecSetSizes(x1Vecloc,N1loc,N1loc,ierr)
>>>>   call VecSetFromOptions(x1Vecloc,ierr)
>>>>   call DMShellSetLocalVector(solver%daphi,x1Vecloc,ierr)
>>>>   call VecDestroy(x1Vecloc,ierr)
>>>>
>>>> All the examples that I see use DMDAs.  I am able to create a global
>>>> vector with this DM.
>>>>
>>>> Any ideas?
>>>>
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20140806/029e8b32/attachment-0001.html>


More information about the petsc-users mailing list