<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<div style="16px" text-align="left">I am sorry for the bad formatting of my createFromDAG function. I attach this function, and I hope it will be easier to read.<br></div><div style="16px" text-align="left"><br></div><div style="16px" text-align="left">Mar 19, 2019, 12:46 PM by finnkochinski@keemail.me:<br></div><blockquote class="tutanota_quote" style="border-left: 1px solid #93A3B8; padding-left: 10px; margin-left: 5px;"><div style="16px">Thanks Matt,<br></div><div style="16px">I tried your suggestions to implement DMPlexCreateFromDAG in petsc4py:<br></div><ol><br></ol><p>1. In <code>petsc4py/src/PETSc/petscdmplex.pxi</code> I uncommented:<br></p><pre><code class=""> <span class="">int</span> <span class="">DMMPlexCreateFromDAG</span>(<span class="">PetscDM</span>,<span class="">PetscInt</span>,<span class="">const_PetscInt</span>[],<span class="">const_PetscInt</span>[],
<span class="">const_PetscInt</span>[],<span class="">const_PetscInt</span>[],<span class="">const_PetscScalar</span>[])</code><br></pre><p>2. In <code>petsc4py/src/PETSc/DMPlex.pyx</code> I added:<br></p><pre><code class=""> <span class="">def</span> <span class="">createFromDAG</span>(<span class="">self</span>, <span class="">depth</span>, <span class="">numPoints</span>, <span class="">coneSize</span>, <span class="">cones</span>, <span class="">coneOrientations</span>, <span class="">vertexCoords</span>):
<span class="">cdef</span> <span class="">PetscInt</span> <span class="">cdepth</span> <span class="">=</span> <span class="">asInt</span>(<span class="">depth</span>)
<span class="">cdef</span> <span class="">const</span> <span class="">PetscInt</span> <span class="">*</span><span class="">cnumPoints</span> <span class="">=</span> <span class="">NULL</span>
<span class="">cdef</span> <span class="">const</span> <span class="">PetscInt</span> <span class="">*</span><span class="">cconeSize</span> <span class="">=</span> <span class="">NULL</span>
<span class="">cdef</span> <span class="">const</span> <span class="">PetscInt</span> <span class="">*</span><span class="">ccones</span> <span class="">=</span> <span class="">NULL</span>
<span class="">cdef</span> <span class="">const</span> <span class="">PetscInt</span> <span class="">*</span><span class="">cconeOrientations</span> <span class="">=</span> <span class="">NULL</span>
<span class="">cdef</span> <span class="">const</span> <span class="">PetscScalar</span> <span class="">*</span><span class="">cvertexCoords</span> <span class="">=</span> <span class="">NULL</span>
<span class="">cnumPoints</span> <span class="">=</span> <span class=""><</span><span class="">const</span> <span class="">PetscInt</span> <span class="">*</span><span class="">></span> <span class="">PyArray_DATA</span>(<span class="">numPoints</span>)
<span class="">cconeSize</span> <span class="">=</span> <span class=""><</span><span class="">const</span> <span class="">PetscInt</span> <span class="">*</span><span class="">></span> <span class="">PyArray_DATA</span>(<span class="">coneSize</span>)
<span class="">ccones</span> <span class="">=</span> <span class=""><</span><span class="">const</span> <span class="">PetscInt</span> <span class="">*</span><span class="">></span> <span class="">PyArray_DATA</span>(<span class="">cones</span>)
<span class="">cconeOrientations</span> <span class="">=</span> <span class=""><</span><span class="">const</span> <span class="">PetscInt</span> <span class="">*</span><span class="">></span> <span class="">PyArray_DATA</span>(<span class="">coneOrientations</span>)
<span class="">cvertexCoords</span> <span class="">=</span> <span class=""><</span><span class="">const</span> <span class="">PetscScalar</span> <span class="">*</span><span class="">></span> <span class="">PyArray_DATA</span>(<span class="">vertexCoords</span>)
<span class="">CHKERR</span>( <span class="">DMPlexCreateFromDAG</span>(<span class="">self</span>.<span class="">dm</span>, <span class="">cdepth</span>, <span class="">cnumPoints</span>, <span class="">cconeSize</span>, <span class="">ccones</span>,
<span class="">cconeOrientations</span>, <span class="">cvertexCoords</span>) )
<span class="">return</span> <span class="">self</span></code><br></pre><div style="16px">I am testing this function using this snippet (following <a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/DMPLEX/DMPlexCreateFromDAG.html" rel="noopener noreferrer" target="_blank">https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/DMPLEX/DMPlexCreateFromDAG.html</a>):<br></div><div style="16px"><br></div><div style="16px">import petsc4py<br></div><div style="16px">import numpy as np<br></div><div style="16px">import sys<br></div><div style="16px">petsc4py.init(sys.argv)<br></div><div style="16px">from petsc4py import PETSc<br></div><div style="16px"><br></div><div style="16px">dm=PETSc.DMPlex().create()<br></div><div style="16px">dm.setType(PETSc.DM.Type.PLEX)<br></div><div style="16px"><br></div><div style="16px">numPoints=np.array([4,2])<br></div><div style="16px">coneSize=np.array([3,3,0,0,0,0])<br></div><div style="16px">cones=np.array([2,3,4, 3,5,4])<br></div><div style="16px">coneOrientations=np.array([0,0,0, 0,0,0])<br></div><div style="16px">vertexCoords=np.array([-1,0, 0,-1, 0,1, 1,0])<br></div><div style="16px">depth=1<br></div><div style="16px">dm.createFromDAG(depth,numPoints,coneSize,cones,coneOrientations,vertexCoords)<br></div><div style="16px"><br></div><div style="16px">It fails with output:<br></div><div style="16px"><br></div><div style="16px">Traceback (most recent call last):<br></div><div style="16px"> File "test.py", line 16, in <module><br></div><div style="16px"> dm.createFromDAG(depth,numPoints,coneSize,cones,coneOrientations,vertexCoords)<br></div><div style="16px"> File "PETSc/DMPlex.pyx", line 64, in petsc4py.PETSc.DMPlex.createFromDAG<br></div><div style="16px">petsc4py.PETSc.Error: error code 63<br></div><div style="16px">[0] DMPlexCreateFromDAG() line 1669 in /build/petsc-vurd6G/petsc-3.7.7+dfsg1/src/dm/impls/plex/plexcreate.c<br></div><div style="16px">[0] DMPlexSetCone() line 1066 in /build/petsc-vurd6G/petsc-3.7.7+dfsg1/src/dm/impls/plex/plex.c<br></div><div style="16px">[0] Argument out of range<br></div><div style="16px">[0] Cone point 4 is not in the valid range [0, 4)<br></div><div style="16px"><br></div><div style="16px">Someone can spot the problem in my python wrapping attempts?<br></div><div style="16px">I assume my test.py snippet should be fine. At least, the equivalent C-snippet runs without problems:<br></div><div style="16px"><br></div><div style="16px">#include <petscdmplex.h><br></div><div style="16px">int main(int argc,char **argv){<br></div><div style="16px"> PetscInitialize(&argc, &argv, NULL, NULL);<br></div><div style="16px"> DM dm;<br></div><div style="16px"> int dim=2;<br></div><div style="16px"> DMPlexCreate(PETSC_COMM_WORLD,&dm);<br></div><div style="16px"> DMSetType(dm, DMPLEX);<br></div><div style="16px"> DMSetDimension(dm,dim);<br></div><div style="16px"> int depth=1;<br></div><div style="16px"> int numPoints[]={4,2};<br></div><div style="16px"> int coneSize[]={3,3,0,0,0,0};<br></div><div style="16px"> int cones[]={2, 3, 4, 3, 5, 4};<br></div><div style="16px"> int coneOrientations[]={0,0,0, 0,0,0};<br></div><div style="16px"> double vertexCoords[]={-1,0, 0,-1, 0,1, 1,0};<br></div><div style="16px"> DMPlexCreateFromDAG(dm, depth, numPoints, coneSize, cones, coneOrientations,vertexCoords);<br></div><div style="16px"> PetscFinalize();<br></div><div style="16px">}<br></div><div style="16px"><br></div><div style="16px">regards<br></div><div style="16px">Chris<br></div><div style="16px"><br></div><div style="16px">Mar 8, 2019, 6:38 PM by <a rel="noopener noreferrer" target="_blank" href="mailto:knepley@gmail.com">knepley@gmail.com</a>:<br></div><blockquote class="tutanota_quote" style="border-left: 1px solid #93A3B8; padding-left: 10px; margin-left: 5px;"><div dir="ltr"><div dir="ltr">On Fri, Mar 8, 2019 at 11:02 AM Chris Finn via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" rel="noopener noreferrer" target="_blank">petsc-users@mcs.anl.gov</a>> wrote:<br></div><div class=""><blockquote class="" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div>Dear petsc4py experts,<br></div><div>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?<br></div></div></blockquote><div><br></div><div>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<br></div><div>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.<br></div><div><br></div><div> Thanks,<br></div><div><br></div><div> Matt<br></div><div> <br></div><blockquote class="" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div>Then, if it was just lack of time that prevented these functions from being available in petsc4py but if it could be done easily:<br></div><div>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?<br></div><div><br></div><div>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?<br></div><div><br></div><div>regards<br></div><div>Chris<br></div><div><br></div><div>-- <br></div><div>Securely sent with Tutanota. Get your own encrypted, ad-free mailbox: <br></div><div><a href="https://tutanota.com" target="_blank" rel="noopener noreferrer">https://tutanota.com</a><br></div></div></blockquote></div><div style="16px"><br></div><div><br></div><div style="16px">-- <br></div><div dir="ltr" class=""><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div style="16px">What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br></div><div style="16px">-- Norbert Wiener<br></div></div><div><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank" rel="noopener noreferrer">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div></blockquote><div style="16px"><br></div></blockquote><div style="16px" text-align="left"><br></div> </body>
</html>