usnistgov / fipy

FiPy is a Finite Volume PDE solver written in Python
http://pages.nist.gov/fipy/en/latest
Other
506 stars 148 forks source link

Question about 'viewer.plot()' and 'input()' in example tri2Dinput.py #947

Open CalebDmArcher opened 1 year ago

CalebDmArcher commented 1 year ago

The example code contains the following two lines viewer.plot() input("finished")

If comment out input("finished"), the plot will pop out and automatically close. If keep input("finished"), the plot stays but the plot window crashes (not responding).

Can anyone help me with this issue to keep the plot window open and not crash? Can you also explain what exactly this 'input' function does? (The source code is too complex for me to understand.)

guyer commented 1 year ago

The purpose of the input() is to display the string as a prompt and wait for keyboard input, i.e., hit return or enter. We use it to pause the program so you can see the plot.

As to the crash or non-response, please tell us what example you're talking about.

CalebDmArcher commented 1 year ago

Thank you for your fast response. I was trying /examples/diffusion/steadyState/mesh1D/tri2Dinput.py and /examples/diffusion/steadyState/mesh20x20/tri2Dinput.py. Both of them have viewer. plot() and input("finished"). I tried the code by using PyCharm and the terminal. Both cases have the 'not responding' issue. I also tried to debug by placing a pause point at the line of viewer. plot(). The plot works fine (it shows up and not crashing). However, if continue running (running input("finished")), the text 'finished' will be printed in the console, and the plot window freeze with showing not responding.

(Usually, I used plt.show() to keep the plot window open and not crashing. Not sure how to do a similar thing with 'viewer'.) notres

guyer commented 1 year ago

And if you press return?

Have you run examples/diffusion/mesh1D.py? That's where we expect people to start.

CalebDmArcher commented 1 year ago

And if you press return?

Have you run examples/diffusion/mesh1D.py? That's where we expect people to start.

If I press return, the program terminates (plot window closes) with 'Process finished with exit code 0'.

I haven't tired examples/diffusion/mesh1D.py yet. Thank you for sharing this resource.

guyer commented 1 year ago

If I press return, the program terminates (plot window closes) with 'Process finished with exit code 0'.

That's as expected