Question: Matrix with parameter, re-assemble?

Issue #93 resolved
Former user created an issue

I'm trying to work a bit with the heat.py example in the demo folder. If I want to add a variable time-step size dt, do I need to instantiate a new ode object each time this parameter changes (and go through the whole bunch of setup routines again) or can I somehow set this parameter and then simply call ts.solve(x) again?

More generally, if an operator (linear or non-linear) defining my system to solve depends on a parameter (like I - dt*F), what steps do I need to do in order to be able to call the solve-routine again when the parameter changes?

Note: I'm just starting to use PETSc and petsc4py, so this may be a stupid question..

Comments (10)

  1. Lisandro Dalcin

    You should try with repeated calls to ts.SetMaxTime(), ts.setTimeStep(), TS.solve(). This way you can solve in "batches" with different (but constant within each batch) timesteps (and of course you can change other problem parameters). Of course, at the beginning you should use ts.setExactFinalTime(ts.ExactFinalTime.MATCHSTEP).

  2. Robert Speck

    Great, thanks! Still, what if I want to write my own time-stepping routine, where I'd need to modify the operator myself?

    To give you some background: I'm about to hook petsc4py to my parallel-in-time code pySDC. There is a solve_system routine in my code, which passes the current time-step size to the solver. I want to avoid having to restart the whole PETSc machinery from scratch each time.. is this possible?

  3. Lisandro Dalcin

    So, basically, you want to solve the problem your way, one step at a time, setting a possibly different time step size for each step, but still use PETSc's TS solver? Is that correct?

  4. Robert Speck

    Uh, I see what you mean. No, sorry, that's not what I want: I want to use PETSc datatypes and linear/non-linear solvers as one possible backbone for my own Python time-stepping library.

    Referring to the ODE example in this question was probably not a good idea, sorry for that. I could ask the same question for the Poisson examples: what if my matrix depends on some parameter (just a scaling factor)? Do I have to restart the whole machinery when the parameter changes (assembly, linear solver setup etc.) or can I reuse things?

  5. Robert Speck

    Take the simplest (yet stupid) case: I have my own implicit Euler written in Python and I now want to use PETSc's datatypes and solvers (MG, Newton, whatnot) for my examples. But the time-step changes every now and then, so I cannot pre-assemble everything once and for all (or I don't want to). I know the right-hand side F of my ODE, so in each step I want to solve I - dt*F. What do I need to rerun before I can use the solver, what can I reuse?

  6. Lisandro Dalcin
    # init
    ts.setMaxSteps(0)
    ts.setExactFinalTime(ts.ExactFinalTime.MATCHSTEP)
    
    # step
    ts.setMaxSteps(ts.getMaxSteps() + 1)
    ts.setTimeStep(dt)
    ts.solve(x)
    
  7. Lisandro Dalcin

    BTW, this issue tracker is intended to report issues, not general questions or help. A more appropriate place with much more visibility and chances of getting good advice is the petsc-users mailing list.

  8. Robert Speck

    OK, I did not know whether this was also for petsc4py. Will move to there, then. Thanks so far!

  9. Log in to comment