Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #10223 > unrolled thread

Button operation that indicates start and finish of simulation

Started byHugh Goyder <h.g.d.goyder@cranfield.ac.uk>
First post2012-05-27 08:41 +0000
Last post2012-05-28 09:13 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Button operation that indicates start and finish of simulation Hugh Goyder <h.g.d.goyder@cranfield.ac.uk> - 2012-05-27 08:41 +0000
    Re: Button operation that indicates start and finish of simulation A Retey <awnl@gmx-topmail.de> - 2012-05-28 09:13 +0000

#10223 — Button operation that indicates start and finish of simulation

FromHugh Goyder <h.g.d.goyder@cranfield.ac.uk>
Date2012-05-27 08:41 +0000
SubjectButton operation that indicates start and finish of simulation
Message-ID<jpspc2$hc5$1@smc.vnet.net>
In a notebook with many dynamic modules I have a long simulation which I start with a button.  I would like to give an indication that the simulation is starting and also when it is finished. Below, in a toy example,  I attempt to use a simple message and also an EvaluationMonitor. Both only give results when the simulation is finished. What don't I understand and how do I fix this? Many thanks.

ClearAll[LongSimulation]
LongSimulation[] :=
 TimeConstrained[NDSolve[{Derivative[2][x][t] + x[t] == 0,
         x[0] == 1, Derivative[1][x][0] == 0}, x, {t, 0, 100000*Pi},
       MaxSteps -> Infinity, Method -> {"Projection", "Invariants" ->
             {x[t]^2 + Derivative[1][x][t]^2}},
   EvaluationMonitor :> k++], 3]

k=0;

DynamicModule[{message = " "},
   Column[{Button["Start Simulation", message = "Starting Simulation";
          LongSimulation[]; message = "Simulation Finished"],
   Dynamic[message],
       Dynamic[k]}]]

[toc] | [next] | [standalone]


#10237

FromA Retey <awnl@gmx-topmail.de>
Date2012-05-28 09:13 +0000
Message-ID<jpvfj0$q6t$1@smc.vnet.net>
In reply to#10223
Am 27.05.2012 10:41, schrieb Hugh Goyder:
> In a notebook with many dynamic modules I have a long simulation which I start with a button.  I would like to give an indication that the simulation is starting and also when it is finished. Below, in a toy example,  I attempt to use a simple message and also an EvaluationMonitor. Both only give results when the simulation is finished. What don't I understand and how do I fix this? Many thanks.
>
> ClearAll[LongSimulation]
> LongSimulation[] :=
>   TimeConstrained[NDSolve[{Derivative[2][x][t] + x[t] == 0,
>           x[0] == 1, Derivative[1][x][0] == 0}, x, {t, 0, 100000*Pi},
>         MaxSteps ->  Infinity, Method ->  {"Projection", "Invariants" ->
>               {x[t]^2 + Derivative[1][x][t]^2}},
>     EvaluationMonitor :>  k++], 3]
>
> k=0;
>
> DynamicModule[{message = " "},
>     Column[{Button["Start Simulation", message = "Starting Simulation";
>            LongSimulation[]; message = "Simulation Finished"],
>     Dynamic[message],
>         Dynamic[k]}]]
>
This should work:

DynamicModule[{message = " "},
  Column[{
    Button["Start Simulation",
     message = "Starting Simulation";
     k = 0;
     LongSimulation[];
     message = "Simulation Finished",
     Method -> "Queued"
     ],
    Dynamic[message, TrackedSymbols :> {message}],
    Dynamic[k]
    }]]

there are other possibilities with which you should also be able to 
achieve what you want, but setting Method->"Queued" is a good idea 
anyway: if LongSimulation runs longer than about 5 sec. it will be 
aborted with the default method "Preemptive". For reasons not entirely 
clear to me that helps also to make the Dynamic[k] update as expected. 
For even more reasons not clear to me that still doesn't help with the 
update of Dynamic[message]. But giving the TrackedSymbols explicitly 
does help there, at least on my Mathematica 8.0.4 on Windows 7. That the 
latter is necessary I would consider a bug. The problem with Dynamic[k] 
I don't exactly understand but it looks like somehow the evaluation 
through the preemptive link does block the updates of the Dynamics. I'm 
not sure whether this is by design or a bug.

hth,

albert

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web