Thanks! that's what I was looking for. Your example is more or less what I had in mind.
I will try to implement it and see how it goes.

Adrian.

On Mon, May 6, 2013 at 4:47 PM, Adrian Jacobo <[email protected] <mailto:[email protected]>> wrote:

   Hi,

      Is there a simple way to implement an adaptive time step in Fipy?


You can pass any time step you like to "sweep" or "solve". "dt" is just a float. Just calculate a new "dt" at every time step based on whatever criteria limits the time step. There are no specific time stepping schemes in FiPy. We have abandoned all attempts at formalizing the outer iteration loop (non-linear iterations) and time stepping since every problem seems to require some form of customization and Python is so high level anyway. It just seems easier to create the necessary loops by hand for every now problem.


      More specifically, is there a way that, when calling the solve
   function store the time advanced fields in temporary variables?


Just make sure the CellVariables that are solved for have an old value ("hasOld=True"). Then the CellVariables can be reset if the time step is too large and the convergence criteria is not met.

   , so that
   the evolution can be recalculated using a different time step (and then
   comparing the time advance variables for the two different time steps to
   decide whether the time step can be incremented)


In that case you will need to define backup CellVariables (or arrays would work just as well) for each of the dependent variables (var and varAlternative). Compare var with varAlternative and set var to have varAlternative's value if varAlternative is better. Then carry on. Something like:

  otherVars = [v.copy() for v in vars]
   while timeElapsed < totalTime:
       for v, otherV in zip(vars, otherVars):
            v.updateOld()
            otherV.setValue(v.value)
            otherV.old.setValue(v.old.value)
       dt, otherDt = calculateDts(args)
       for vs, actualDt in zip([vars, otherVars], [dt, otherDt]):
           for e, v in zip(eqns, vs):
                e.solve(v, dt=actualDt)

       if otherIsBetter(vars, otherVars, args):
           for v, otherV in zip(vars, otherVars):
                v.setValue(otherV.value)
           timeElapsed += otherDt
       else:
           timeElapsed += dt


There is no magic in FiPy for this sort of thing. It is just basic Python with loops, conditionals and resetting values. Hope the above helps.

--
Daniel Wheeler


_______________________________________________
fipy mailing list
[email protected]
http://www.ctcms.nist.gov/fipy
  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]

Reply via email to