Ok, thanks to all for the help. I figured out how to save the data for each time step using both methods, an array and using the TSV-Viewer. Just for clarity I wound up switching over to the NumPy array, and using the append function from there. Also, I think the code needed to be:
phis = []
for step in range(steps):
eq.solve(var=phi,dt=timeStepDuration)
phis=phis.append(phi)
I’m not sure if the NumPy array was the fix here or if it is that alteration. The NumPy version of that works though. 

Here is my code with output for each t-step as a file, in case it will help anyone. 
#examples.diffusion.mesh20x20
from fipy import *
from numpy import *
nx=20
ny=nx
dx=1.
dy=dx
L=dx*nx
mesh=Grid2D(dx=dx,dy=dy,nx=nx,ny=ny)
phi=CellVariable(name="solution variable",mesh=mesh,value=0.)
D=1
eq=TransientTerm()==DiffusionTerm(coeff=D)
valueTopLeft=0.
valueBottomRight=1.
X,Y=mesh.faceCenters
facesTopLeft=((mesh.facesLeft&(Y>L/2))|(mesh.facesTop&(X<L/2)))
facesBottomRight=((mesh.facesRight&(Y<L/2))|(mesh.facesBottom&(X>L/2)))
phi.constrain(valueTopLeft,facesTopLeft)
phi.constrain(valueBottomRight,facesBottomRight)
timeStepDuration=10*0.9*dx**2/(2*D)
steps=10
phis=array([])
for step in range(steps):
    eq.solve(var=phi,dt=timeStepDuration)
    TSVViewer(vars=(phi)).plot(filename="myTSV"+str(step)+".tsv")
  
On Nov 17, 2014, at 5:41 PM, Guyer, Jonathan E. Dr. <jonathan.gu...@nist.gov> wrote:

When you write

phis = []
for step in range(steps):
eq.solve(var=phi,dt=timeStepDuration)
phis.append(phi)

you end up with a list of [phi, phi, phi, ..., phi]. You're not appending the *values* of phi, you're appending the object phi itself and all it holds is its final value. hasOld=True allows it to hold its final value and one value before that, but that's still not helpful here.

At a minimum, you would need to change the last line to

phis.append(phi.value)

but I don't recommend this approach. The FiPy TSVViewer doesn't know anything about such a list, so you can't use that to export the data. You could make something work with numpy.savetxt, but for any practical problem, the phis list would quickly overrun memory.

L.Bryce's recommendation to output a set of files, each named by the time step is the better approach. Yes, you need to change the name of the file at each iteration; the filename argument to TSVViewer.plot() is provided by you.



On Nov 17, 2014, at 2:21 PM, Kyle Briton Lawlor <klawlor...@gmail.com> wrote:

Ok, I understand that FiPy only holds just one previous time step in its memory. But I find this even without the hasOld=True flag set. So I am confused with why you mention that flag.

I assume that the file names would be changed for each iteration of the solve() loop, and of course using the tsvViewer(). So the output would be a whole bunch of TSV files with the data from each time-step present.

Furthermore, another thing one could do is create an empty array.
Say, phis=[]
Within the solve loop, below the solve() line within that loop, one could say:
phis.append(phi)

Then one could look to export the data with the TSV function. So basically both ways are equivalent.

However, when I do this all of the entries of the array phis, and the final solution phi. And this does not make sense to me.

Does anyone have any advice on how to better handle exporting data for each time-step?

Kyle.

On Nov 14, 2014, at 7:17 AM, L.Bryce Whitson Jr. <lwhits...@gmail.com> wrote:

FiPy only keeps one old time step in memory at a time and only if you have the hasOld=True flag set on the variable. The only way I know to do what you want is to create a set of files named by the time step where each one contains one set of formatted data.

On Fri, Nov 14, 2014, 2:05 AM Kyle Briton Lawlor <klawlor...@gmail.com> wrote:
Hi all,

I have been slamming my head on the wall trying to figure out how to access the data from each time step in the 2D-diffusion example.

I’ve tried defining an array:
phis=[]

Then solving with:
for step in range(steps):
eq.solve(var=phi,dt=timeStepDuration)
phis.append(phi)

The result of this though is just an array full of the final solution. I tried putting the append before solving, in the loop, but there is no difference. However, when I use "print phi” where the append function is, it prints out the distinct solutions for each time-step. I would ideally like to write out one tsv-file with all the data, to visualize elsewhere.

Any help will be greatly appreciated!
Still, looking for more clues in my first email.

Thanks,
Kyle


On Nov 13, 2014, at 10:08 PM, Kyle Briton Lawlor <klawlor...@gmail.com> wrote:

Thanks for the response.

I am using MacPorts.
How do I install that package? I can’t find it by itself on MacPorts.

Kyle.

On Nov 13, 2014, at 9:37 PM, L.Bryce Whitson Jr. <lwhits...@gmail.com> wrote:

Kyle,

It looks like you are missing the installation of the tvtk package that FiPy utilizes. Are you using the Enthought Python distribution or MacPorts? Either way, you should be able to find that package and install it. Once that is done, I think everything will work. This is just my initial thoughts though.

- - - - - - - - - - - - - - - - -
L.Bryce Whitson Jr.
lwhits...@gmail.com

On Thu, Nov 13, 2014 at 8:30 PM, Kyle Briton Lawlor <klawlor...@gmail.com> wrote:
Hi all,

I am a graduate student beginning to work with FiPy. I am running into some issues with getting the program and its dependencies configured properly. I am not sure if this is the right place to ask these types of questions, let me know if there is somewhere else I could go to find answers. So I will keep things short and I admit I am relatively new to programming, so I have probably done some silly things here.

I am using a Mac OS X 10.9.5. I have installed FiPy via MacPorts (py27-fipy).
When I run test I get the following output:
“Ran 352 tests in 28.032s … Failed (failures=8)… Skipped 83 dockets examples because ‘tvtk’ package cannot be imported”

I worked through the 1D-Diffusion example. I had no troubles compiling anything there (including the Viewer()).

So I am now trying to work through the 2D-Diffusion in a square.
When it comes to viewing I am getting the following error:
"Import Error: Failed to import a viewer: [“matplotlib: ufunc ‘isfinite’ not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ‘’safe’’, ‘gist: __call__() takes at least 2 arguments (1 given)’,’gnu plot: __call__() takes at least 2 arguments(1 given)’, ‘mayavi: No module named enthought.tvtk.api’]”

My line of code for the viewing segment is:
if __name__=='__main__':
 viewer=Viewer(vars=phi,datamin=0.,datamax=1.)
 viewer.plot()
(resulting in the above error.)

I am sure there is at least one dumb thing I am doing here. Any pointers or help will be much appreciated. I hope there is a simple solution. I can explain more of what I tried to do to fix this, but I’ll wait to hear back.

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

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


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

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


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

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

Reply via email to