[Date Index]
[Thread Index]
[Author Index]
When to use FinishDynamic[] in Manipulate?
*To*: mathgroup at smc.vnet.net
*Subject*: [mg125288] When to use FinishDynamic[] in Manipulate?
*From*: "Nasser M. Abbasi" <nma at 12000.org>
*Date*: Sun, 4 Mar 2012 04:36:36 -0500 (EST)
*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com
*Reply-to*: nma at 12000.org
Looking at
http://reference.wolfram.com/mathematica/ref/FinishDynamic.html
It describes what FinishDynamic[] does, but does not really
tell someone when to use it or not to use it.
I am asking because sometimes my Manipulate stops updating
a dynamic in the control area of when I run a simulation and
sometimes it does not stop updating it.
So it is a chance if it will stop updating or not. But for longer
runs, it seems to stop updating at one point.
But when I added FinishDynamic[] in the Manipulate expression,
I never had a case so far where it stopped updating the dynamic.
I'll show the general layout of the Manipulate I use. It is
very simple, as I use one controlled variable
(I just typed this on the fly here, not Mathematica code,
just to illustrate the logic, that is all)
------------------------------
Manipulate[
my_control_variable;
result = do_some_processing[];
counter = counter + 1; (*Dynamic[counter] below should now update!*)
If not_finished_simulation
my_control_variable++ (*to force refresh on this expression*)
end;
FinishDynamic[];
result, (*display simulation step result*)
(*----- control variables area -------*)
many_control_variables_and_slides_here,
Button["start",my_control_variable++],
Dynamic[counter], (*This is the dynamic that stops updating sometimes*)
TrackedSymbols :>{my_controlled_variable},
SynchronousUpdating -> False,
ContinuousAction -> False,
SynchronousInitialization -> True
]
-------------------------------
So, when I hit a Button, my_controlled_variable is
touched and this kicks in the simulation loop. The
loop runs until completion.
The controlled_variable is updated at the end of each step
on its own so that the Manpulate expression is revaluated
again. This allows the simulation to run as fast as it
can.
Sometimes I see the Dynamic[counter] stops updating
on the screen, even though the actual loop is still running,
and the counter is being incremented. I know that since
I print it and I see it is being updated.
It is only that the display of the Dynamic[counter]
is not updating.
The main display of the manipulate is updating fine. i.e.
in the above, the 'result' is updating on the screen and
is changing.
So, it is only the Dynamic located in the control
variable area that _sometimes_ stops updating on
the screen. And this happens at different times
or not at all. Which makes it hard to debug.
btw, I tried Refresh also on the above counter, as in
Dynamic[Refresh[counter,UpdateInterval->...]]
different values, Infinity, etc.. that did NOT help
in the stopping of the update on the screen.
Only FinishDynamic[] seems to finally solved this
problem for me.
Question: Any ideas what might cause this? I am now adding
FinishDynamic[] to be safe.
Question: When should one NOT use FinishDynamic[]? It
seems then one should use it all the time, just to
be safe. Does using FinishDynamic[] cause a problem
somewhere else? So far, I do not see a problem, other than
an occasional pause in the simulation, but no hangs. I assume
these pauses, very short, is due to the system waiting
to finish updating. But at least this is better than
the Dynamic not updating at all.
thanks,
--Nasser
Prev by Date:
**Re: Can I solve this system of nonlinear equations?**
Next by Date:
**Re: Can I solve this system of nonlinear equations?**
Previous by thread:
**Re: When to use FinishDynamic[] in Manipulate?**
Next by thread:
**much power to mathematica**
| |