store old values FiPy

269 views Asked by At

I'm trying to solve some differential equations using FiPy in Python and as a newbie, I still have some problems. What I do is the following: I define a cell variable, I solve an equation for this variable and I update it. I want to store its values after each time iteration. Here is an example:

a = CellVariable(mesh,name='a', value=0., hasOld=True) 
# eq is an equation involving 'a'
# define an array to store the values of 'a' after solving 'eq'
a_tt = []
for t in range(10):
      eq.sweep(dt=0.01)
      a.updateOld() 
      a_tt.append(a)

I realize my mistake - the values in 'a_tt' are updated every time I update 'a', so I have at the end an array with all the same elements. What shoud I alternatively do to avoid this?

1

There are 1 answers

0
jeguyer On

I think a_tt.append(a.copy()) might work.

Otherwise, the method used in the sweeps part of http://www.ctcms.nist.gov/fipy/examples/diffusion/generated/examples.diffusion.mesh1D.html should work. Something like:

a_tt.append(CellVariable(mesh=m, value=a.value))