On Sun, Jun 9, 2013 at 7:58 PM, John Assael <[email protected]> wrote:
> Dear Jonathan,
> How are you? Your help was very valuable to me!
> I am running a different model this time and I am using sort of a trial
> and error to simulate the real experiment and find the values that make a
> perfect fit to the experimental results.
>
> The problem is that the first 2 seconds of the simulation are the same
> each time, as due to the mesh geometry are not affected by the different
> parameters I use each time.
>
> Is there a way to save the process until that stage, saving me a lot of
> extra time from each run?
>
> FiPy has no built in way to save the state of a simulation and restart
with a single command or two. You will need to explicitly save out the
arrays for each of the variables and then reassign the values when the
simulation is restarted. There are lots of ways to save arrays, the
simplest is to use "np.savetxt" and "np.loadtxt" to get started. You can
also use "fipy.dump" and "fipy.load" to pickle the variables directly.
PyTables is also a possibility for more sophisticated data across multiple
time steps in one file with quick access.
For the actually reading and writing, one way is to have two different
setups. One setup reads in whatever the latest variable values are from the
saved files while the other reinitializes. Something like this
mesh = ...
if restart:
timestep = np.loadtxt('timestep.txt')
var0array = np.loadtxt('var0.txt')
var1array = np.loadtxt('var1.txt')
else:
timestep = 0
var0array = np.zeros(...)
var1array = np.zeros(...)
var0 = fp.CellVariable(mesh=mesh, value=var0array)
...
while timestep < timesteps
np.savetxt('timestep.txt', np.array((timestep,)))
np.savetxt('var0.txt', var0.value)
np.savetxt('var1.txt', var1.value)
## solve equations
>
> Finally, the timeStep = 2e-4 works perfect but its too slow, is there a
> better way to increase the time step, for example gradually?
>
The time step is entirely under your control you can increase it based on
elapsed time or something more sophisticated such as the number of steps to
convergence, but FiPy doesn't have any build in stepper schemes.
--
Daniel Wheeler
_______________________________________________
fipy mailing list
[email protected]
http://www.ctcms.nist.gov/fipy
[ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]