[petsc-users] [petsc4py] a problem with computeRHSFunctionLinear interface?

Francesco Caimmi francesco.caimmi at polimi.it
Sun Aug 21 05:01:29 CDT 2016


Dear Lisandro,

many thanks for your answer

On Thursday 18 August 2016 10:20:59 Lisandro Dalcin wrote:
> Dear Francesco, sorry for the late answer, I missed your email.
> 
> You have to do it this way:
> 
>         ts.setRHSFunction(PETSc.TS.computeRHSFunctionLinear)
>         ts.setRHSJacobian(PETSc.TS.computeRHSJacobianConstant, J=A, P=A)

Ok, now that works!
> 
> I.e, you have to set unbound methods, not instance methods as you did
> in your original code. Additionally, do not pass "args" nor "kargs".
This makes sense to me, although they are passed in the original source code I 
was  translating.

I will also take the chance to ask a related question: in the original C code, 
lines 213 -214 read
    ierr = TSGetSNES(ts,&snes);CHKERRQ(ierr);
    ierr=SNESSetJacobian(snes,NULL,NULL,SNESComputeJacobianDefault,NULL);CHKERRQ(ierr);

How do I translate the last line in Python? I was not able to find the 
equivalent of SNESComputeJacobianDefault.

Thanks,
Francesco
> 
> On 11 August 2016 at 10:36, Francesco Caimmi <francesco.caimmi at polimi.it> 
wrote:
> > Dear all,
> > 
> > I was trying to reproduce /ts/examples/tutorials/ex4.c in python to learn
> > how to use TS solvers; the example uses the function
> > TSComputeRHSFunctionLinear. However I get an error when running my code
> > (attached in case you want to look at it), when I call ts.solve.
> > 
> > Here is the trace:
> > [fcaimmi at Wotan 2645] > ./ts_ex4.py
> > Solving a linear TS problem, number of processors =  1
> > Timestep  0 : time = 0.0  2-norm error = 1.14956855594e-08  max norm error
> > = 0> 
> > Traceback (most recent call last):
> >   File "./ts_ex4.py", line 473, in <module>
> >   
> >     main(m = m, debug = debug)
> >   
> >   File "./ts_ex4.py", line 340, in main
> >   
> >     ts.solve(u)
> >   
> >   File "PETSc/TS.pyx", line 568, in petsc4py.PETSc.TS.solve
> > 
> > (src/petsc4py.PETSc.c:188927)
> > 
> >   File "PETSc/petscts.pxi", line 221, in petsc4py.PETSc.TS_RHSFunction
> > 
> > (src/petsc4py.PETSc.c:35490)
> > 
> >   File "PETSc/TS.pyx", line 189, in
> >   petsc4py.PETSc.TS.computeRHSFunctionLinear> 
> > (src/petsc4py.PETSc.c:181611)
> > TypeError: computeRHSFunctionLinear() takes exactly 3 positional arguments
> > (5 given)
> > 
> > I cannot understand if there is a problem with my code or if the problem
> > is in computeRHSFunctionLinear interface.
> > 
> >  I checked https://bitbucket.org/petsc/petsc4py/ and the interface to
> > 
> > computeRHSFunctionLinear  has three arguments, however I am not that much
> > into petsc4py to tell how it gets called.
> > 
> > I am on Petsc Release Version 3.7.3
> > 
> > Thank you for your time.
> > 
> > Best,
> > --
> > Francesco Caimmi
> > 
> > Laboratorio di Ingegneria dei Polimeri
> > http://www.chem.polimi.it/polyenglab/
> > 
> > Politecnico di Milano - Dipartimento di Chimica,
> > Materiali e Ingegneria Chimica “Giulio Natta”
> > 
> > P.zza Leonardo da Vinci, 32
> > I-20133 Milano
> > Tel. +39.02.2399.4711
> > Fax +39.02.7063.8173
> > 
> > francesco.caimmi at polimi.it
> > Skype: fmglcaimmi (please arrange meetings by e-mail)



More information about the petsc-users mailing list