store old values FiPy

…衆ロ難τιáo~ 提交于 2019-12-08 07:10:38

问题


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:


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))


来源:https://stackoverflow.com/questions/30827942/store-old-values-fipy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!