Help with TS.computeRHSFunctionLinear

Issue #11 closed
Kim Usi created an issue

Hello,

I am trying to make a linear version of the heat.py example in the demos. I have added this to the code:

ts.setProblemType(0) 
ts.setType(ts.Type.RK)

ts.setRHSFunction(ts.computeRHSFunctionLinear, ode.gvec)

#ts.setIFunction(ode.evalFunction, ode.gvec)
#ts.setIJacobian(ode.evalJacobian, ode.mat)

And I get the follow error:

Traceback (most recent call last):
  File "heat_rk.py", line 129, in <module>
    ts.solve(x)
  File "TS.pyx", line 537, in petsc4py.PETSc.TS.solve (src/petsc4py.PETSc.c:137505)
  File "petscts.pxi", line 203, in petsc4py.PETSc.TS_RHSFunction (src/petsc4py.PETSc.c:28655)
  File "TS.pyx", line 167, in petsc4py.PETSc.TS.computeRHSFunctionLinear (src/petsc4py.PETSc.c:131167)
TypeError: computeRHSFunctionLinear() takes exactly 3 positional arguments (4 given)

I have also tried using a function like this (very similar to the original evalFunction):

    def evalFunction2(self, ts, t, x, f):
        self.g2l.scatter(x, self.lvec, PETSc.InsertMode.INSERT) # lvec is a work vector
        h = self.h
        with self.lvec as u:
            f.setArray(-2*u[1:-1]/h + u[:-2]/h + u[2:]/h) # Scale equation by volume element
ts.setRHSFunction(ode.evalFunction2, ode.gvec)

This runs, but it gives the following (several of the "Very small steps" line):

Very small steps: 0.000000
Very small steps: 0.000000
Very small steps: 0.000000
steps 100 (0 rejected, 0 SNES fails), nonlinear its 0, linear its 0
/home/kim/anaconda/lib/python2.7/site-packages/matplotlib/axes.py:4747: UserWarning: No labeled objects found. Use label='...' kwarg on individual plots.
  warnings.warn("No labeled objects found. "

I'm not really sure how this works, any help is appreciated.

Thanks, Kim

Comments (2)

  1. Lisandro Dalcin

    Use it this way:

    ts.setRHSFunction(TS.computeRHSFunctionLinear, ode.gvec)
    

    that is, you need an unbound method, as PETSc is going to pass the TS instance as the first argument to the callback.

    About evalFunction2(), I'm not sure what's going on.

  2. Log in to comment