Great! that works. Now my problem is with DASetUniformCoordinates or DASetCoordinates. Do they exist in petsc4py? I can't see them when I do a dir(da).
Thanks, Blaise On Jul 30, 2010, at 9:10 PM, Lisandro Dalcin wrote: > On 30 July 2010 21:13, Blaise Bourdin <bourdin at lsu.edu> wrote: >> Hi, >> >> Is PetscViewerSetFormat implemented in petsc4py (I am using petsc-3.1-p3 and >> petsc4py-1.1)? > > Viewer.setFormat() is certainly available. > >> I am trying to save a DA and Vec in vtk format, but can't figure out the >> python equivalent to >> PetscViewerSetFormat(VTKViewer,PETSC_VIEWER_ASCII_VTK). >> > > However, it seems I missed to add Viewer.Format.ASCII_VTK. As a > workaround, you could do: > > viewer.setFormat(11) # "11" is the corresponding enum value from petscviewer.h > > Alternatively, you could monkeypatch like below at the beginning of your code: > > from petsc4py import PETSc > PETSc.Viewer.Format.ASCII_VTK = 11 > > >> My C code would be >> ierr = PetscViewerCreate(PETSC_COMM_WORLD,&VTKViewer);CHKERRQ(ierr); >> ierr = PetscViewerSetType(VTKViewer,PETSC_VIEWER_ASCII);CHKERRQ(ierr); >> ierr = PetscViewerFileSetName(VTKViewer,filename);CHKERRQ(ierr); >> ierr = PetscViewerSetFormat(VTKViewer,PETSC_VIEWER_ASCII_VTK);CHKERRQ(ierr); >> >> ierr = DAView(da,VTKViewer);CHKERRQ(ierr); >> ierr = VecView(U,VTKViewer);CHKERRQ(ierr); >> >> What would be the python equivalent? >> > > vtkviewer = PETSc.Viewer().create(PETSc.COMM_WORLD) > vtkviewer.setType('ascii') # or pass PETSc.Viewer.Type.ASCII > vtkviewer.setFileName(filename) > vtkviewer.setFromat(PETSc.Viewer.Format.ASCII_VTK) # of course, > requires previous hack. > > > However, this way is simpler: > > vtkviewer = PETSc.Viewer().createASCII( > filename, format=PETSc.Viewer.Format.ASCII_VTK, > comm= PETSc.COMM_WORLD) > > > PS: I'll add the missing format enumerate ASAP to petsc4py-dev, > branch release-1-1. I'm near to make a micro release with a bunch of > fixes, I?m just waiting for Cython 0.13 to be released. > > -- > Lisandro Dalcin > --------------- > CIMEC (INTEC/CONICET-UNL) > Predio CONICET-Santa Fe > Colectora RN 168 Km 472, Paraje El Pozo > Tel: +54-342-4511594 (ext 1011) > Tel/Fax: +54-342-4511169 -- Department of Mathematics and Center for Computation & Technology Louisiana State University, Baton Rouge, LA 70803, USA Tel. +1 (225) 578 1612, Fax +1 (225) 578 4276 http://www.math.lsu.edu/~bourdin