Question: Matrix with parameter, re-assemble?
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)
-
-
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 usets.setExactFinalTime(ts.ExactFinalTime.MATCHSTEP)
. -
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? -
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?
-
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?
-
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?
-
# init ts.setMaxSteps(0) ts.setExactFinalTime(ts.ExactFinalTime.MATCHSTEP)
# step ts.setMaxSteps(ts.getMaxSteps() + 1) ts.setTimeStep(dt) ts.solve(x)
-
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.
-
OK, I did not know whether this was also for petsc4py. Will move to there, then. Thanks so far!
-
- changed status to resolved
- Log in to comment
Sorry, did not intend to post this anonymously.