# Who understands the malfunction of the attached simulation?

Posted 25 days ago
342 Views
|
8 Replies
|
5 Total Likes
|
 The malfunction is described explicitly in the leading comment of the attached notebook file. I'm stuck and barely need help from the community. Attachments:
8 Replies
Sort By:
Posted 25 days ago
 The following snippet If[freeze, run = False, (* code that produces Graphics *)] will, of course, return False and not a graphics when freeze happens to be True
Posted 24 days ago
 You are so right! Thank you.
Posted 24 days ago
 Unfortunately I sent a wrong attachment which showed the silly structure for which Ilian's argument applied. The true problem, however, is in the new attachment. Here the If[freeze, run = False, … ] is the first part of a compound expression in the following parts of which the graphics generation and display should take place. Actually it does take place and displays Null. Attachments:
Posted 24 days ago
 It seems that you have If[run,...] without an "else" clause. So, when run is False, the result is Null. Also, it is not clear to me why you need the freeze control variable? Doesn't the run control achieve the same effect? But, I also don't fully know what you are trying to do to create a "snapshot". Based on the code, it looks like you want to start/stop the simulation while maintaining the instantaneous state of the Graphics.
Posted 24 days ago
 In the attached code If is always used as introducing a statement and not to produce a return value. The Wolfram Documentation on If has an example of that usage. "Snapshots" are a preformed way in Wolfram Demonstrations to document results (e.g. graphics) created by running a Manipulate with a particular setting of the control variables. Since many of my contributions to the Wolfram Demonstrations project are freely running simulations (of a basic structure similar to the one in the attachment) I don't get a final state (end of evaluation) for free but try to create it by 'freezing'. In the freezed state I copy and paste the output cell of Manipulate to the snapshot area of the Demonstration. If I would simply uncheck the run button one could 'reanimate' the snapshot result and change the graphics so that it would no longer show what was intended to be shown. Since the mechanism worked so far in many demonstrations I'm rather surprised that it goes wrong in my simple present example.
Posted 24 days ago
 Ok, I should have noticed this before, but the condition If[initialized,Graphics...] doesn't have an else clause. The documentation shows in the 3rd bullet under the Details section that Details If[condition,t] gives Null if condition evaluates to False. When I run your code, clicking on freeze causes that statement to evaluate to Null. Somehow, initialized is getting set to False. I believe I verified this by inserting Echo[initialized] as the else clause. For me, clicking freeze causes that statement to print False in the Messages window.I noticed you have Dynamic nested inside Manipulate. Could be some race condition associated with that? I don't have an clear cut explanation, but if I get time I'll take another look. Possibly, this could be done without need of the nested Dynamic since Manipulate handles that use case very well. Just a thought.
 Thank you, David, for your considerations. I think your suggestion that Manipulate alone should work (without DynamicModule and Dynamic) brings us close to understanding the situation. I attach a version of the simulation that realizes your suggestion. It runs and 'freeze' works as it should. There is a serious problem however: after minutes of running in stops with an internal error (that I already reported to the link they give). During run a yellow dot at the right lower corner of the Mathematica icon on the task bar shines up and the cell bar of the output cell flickers. So probably something goes wrong with the Kernel to Frontend communication. Similar un-understood phenomena made me once playing with Dynamic in addition to Manipulate and finally led to an empirically stable behavior as in SimulationDemoXe.nb (with un-understood reaction to freeze, though). Do you have an idea what the problem with SimulationDemoYa.nb could be? Attachments:
 Just found a stable working version by re-introducing Dynamic. See attachment. You set afloat the ship of my thoughts with your remarks. Thank you for that, David. Attachments: