[petsc-users] [petsc4py] DMPlexCreateFromDAG and other missing functions

finnkochinski at keemail.me finnkochinski at keemail.me
Tue Mar 19 07:54:11 CDT 2019


I am sorry for the bad formatting of my createFromDAG function. I attach this function, and I hope it will be easier to read.

Mar 19, 2019, 12:46 PM by finnkochinski at keemail.me:

> Thanks Matt,
> I tried your suggestions to implement DMPlexCreateFromDAG in petsc4py:
>
>
> 1. In > petsc4py/src/PETSc/petscdmplex.pxi>  I uncommented:
>
>     > int>  > DMMPlexCreateFromDAG> (> PetscDM> ,> PetscInt> ,> const_PetscInt> [],> const_PetscInt> [],                             > const_PetscInt> [],> const_PetscInt> [],> const_PetscScalar> [])
>
> 2. In > petsc4py/src/PETSc/DMPlex.pyx>  I added:
>
>   > def>  > createFromDAG> (> self> , > depth> , > numPoints> , > coneSize> , > cones> , > coneOrientations> , > vertexCoords> ):        > cdef>  > PetscInt>   > cdepth>  > =>  > asInt> (> depth> )        > cdef>  > const>  > PetscInt>  > *> cnumPoints>  > =>  > NULL>         > cdef>  > const>  > PetscInt>  > *> cconeSize>  > =>  > NULL>         > cdef>  > const>  > PetscInt>  > *> ccones>  > =>  > NULL>         > cdef>  > const>  > PetscInt>  > *> cconeOrientations>  > =>  > NULL>         > cdef>  > const>  > PetscScalar>  > *> cvertexCoords>  > =>  > NULL>         > cnumPoints>  > =>  > <> const>  > PetscInt>  > *> >>      > PyArray_DATA> (> numPoints> )        > cconeSize>  > =>  > <> const>  > PetscInt>  > *> >>      > PyArray_DATA> (> coneSize> )        > ccones>  > =>  > <> const>  > PetscInt>  > *> >>      > PyArray_DATA> (> cones> )        > cconeOrientations>  > =>  > <> const>  > PetscInt>  > *> >>      > PyArray_DATA> (> coneOrientations> )        > cvertexCoords>  > =>  > <> const>  > PetscScalar>  > *> >>      > PyArray_DATA> (> vertexCoords> )        > CHKERR> ( > DMPlexCreateFromDAG> (> self> .> dm> , > cdepth> , > cnumPoints> , > cconeSize> , > ccones> ,         > cconeOrientations> , > cvertexCoords> ) )        > return>  > self
> I am testing this function using this snippet (following > https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/DMPLEX/DMPlexCreateFromDAG.html <https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/DMPLEX/DMPlexCreateFromDAG.html>> ):
>
> import petsc4py
> import numpy as np
> import sys
> petsc4py.init(sys.argv)
> from petsc4py import PETSc
>
> dm=PETSc.DMPlex().create()
> dm.setType(PETSc.DM.Type.PLEX)
>
> numPoints=np.array([4,2])
> coneSize=np.array([3,3,0,0,0,0])
> cones=np.array([2,3,4, 3,5,4])
> coneOrientations=np.array([0,0,0, 0,0,0])
> vertexCoords=np.array([-1,0, 0,-1, 0,1, 1,0])
> depth=1
> dm.createFromDAG(depth,numPoints,coneSize,cones,coneOrientations,vertexCoords)
>
> It fails with output:
>
> Traceback (most recent call last):
>   File "test.py", line 16, in <module>
>     dm.createFromDAG(depth,numPoints,coneSize,cones,coneOrientations,vertexCoords)
>   File "PETSc/DMPlex.pyx", line 64, in petsc4py.PETSc.DMPlex.createFromDAG
> petsc4py.PETSc.Error: error code 63
> [0] DMPlexCreateFromDAG() line 1669 in /build/petsc-vurd6G/petsc-3.7.7+dfsg1/src/dm/impls/plex/plexcreate.c
> [0] DMPlexSetCone() line 1066 in /build/petsc-vurd6G/petsc-3.7.7+dfsg1/src/dm/impls/plex/plex.c
> [0] Argument out of range
> [0] Cone point 4 is not in the valid range [0, 4)
>
> Someone can spot the problem in my python wrapping attempts?
> I assume my test.py snippet should be fine. At least, the equivalent C-snippet runs without problems:
>
> #include <petscdmplex.h>
> int main(int argc,char **argv){
>   PetscInitialize(&argc, &argv, NULL, NULL);
>   DM	dm;
>   int dim=2;
>   DMPlexCreate(PETSC_COMM_WORLD,&dm);
>   DMSetType(dm, DMPLEX);
>   DMSetDimension(dm,dim);
>   int depth=1;
>   int numPoints[]={4,2};
>   int coneSize[]={3,3,0,0,0,0};
>   int cones[]={2, 3, 4,  3, 5, 4};
>   int coneOrientations[]={0,0,0, 0,0,0};
>   double vertexCoords[]={-1,0, 0,-1, 0,1, 1,0};
>   DMPlexCreateFromDAG(dm, depth, numPoints, coneSize, cones, coneOrientations,vertexCoords);
>   PetscFinalize();
> }
>
> regards
> Chris
>
> Mar 8, 2019, 6:38 PM by > knepley at gmail.com <mailto:knepley at gmail.com>> :
>
>> On Fri, Mar 8, 2019 at 11:02 AM Chris Finn via petsc-users <>> petsc-users at mcs.anl.gov <mailto:petsc-users at mcs.anl.gov>>> > wrote:
>>
>>> Dear petsc4py experts,
>>> I'd like to ask why several PETSc functions are not wrapped in petsc4py. I'd need to use DMPlexCreateFromDAG from python. Could you explain with this function as an example why there is no python wrapper available? Do I have to expect severe difficulties when I try this myself - impossible data structures, memory management or something else?
>>>
>>
>> Lisandro is the expert, but I will try answering. The main problem is just time. There is no documentation for contributing, but what I do
>> is copy a function that is pretty much like the one I want. So I think DMPlexCreateFromCellList() is wrapped, and it looks almost the same.
>>
>>   Thanks,
>>
>>     Matt
>>  
>>
>>> Then, if it was just lack of time that prevented these functions from being available in petsc4py but if it could be done easily:
>>> Is the wrapping process of petsc4py documented somewhere? Or do I have to browse the sources to get an understanding? Do you use swig, clif, boost.python or something else?
>>>
>>> Is it possible to write another (small) python extension for the missing functions independent from petsc4py that allows me to pass PETSc structures back and forth between the two? Or is it necessary to have /one/ complete wrapper, because interoperability is not possible otherwise?
>>>
>>> regards
>>> Chris
>>>
>>> -- 
>>> Securely sent with Tutanota. Get your own encrypted, ad-free mailbox: 
>>> https://tutanota.com <https://tutanota.com>
>>>
>>
>>
>> -- 
>> 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/ <http://www.cse.buffalo.edu/~knepley/>
>>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20190319/995f3019/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dmplexnew.pyx
Type: application/octet-stream
Size: 883 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20190319/995f3019/attachment-0001.obj>


More information about the petsc-users mailing list