Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question
1

BCVTB: Fire a script at midnight only?

asked 2016-06-27 17:16:25 -0600

updated 2016-06-27 17:22:17 -0600

I'm trying to launch an external script to run at midnight of each day during my E+ simulation.

In pseudo code I'd do something like:

if simulation_timestep % (24*timestep_per_hour) == 0:
    // call my script

I'm facing two isues:

I wasn't sure how to do a modulo operation in BCVTB, I thought the UnaryMathFunction would do, but there's no modulo under it, so I've used Remainder, which for positive values such as mine is exactly the same. Problem is, I'm getting this error:

java.lang.ClassCastException: ptolemy.data.IntToken cannot be cast to ptolemy.data.DoubleToken
at ptolemy.actor.lib.Remainder.fire(Remainder.java:113)
at ptolemy.actor.AtomicActor.iterate(AtomicActor.java:497)
at ptolemy.actor.sched.StaticSchedulingDirector.fire(StaticSchedulingDirector.java:216)
at ptolemy.domains.sdf.kernel.SDFDirector.fire(SDFDirector.java:500)
at ptolemy.actor.CompositeActor.fire(CompositeActor.java:454)
at ptolemy.actor.Manager.iterate(Manager.java:841)
at ptolemy.actor.Manager.execute(Manager.java:367)
at ptolemy.actor.Manager.run(Manager.java:1252)

Bigger problem, I cannot seem to figure out how to trigger an event at the specific timestep I want. I've tried using a a Const, my timestep and a Logic > Equal box in conjuncton with a Boolean Switch, trying to create a dummy csv file only at timestep = 320. Problem is, it does output at 320, but also for all the following timesteps.

I tried using a Boolean Select, but got a type error too.

Here is an example of what I've tried. The remainder portion fails, I have to delete it and replace it by the "Const 320" in order to try the boolean switch.

bad tries

How can I trigger an event every day at the same time in the BCVTB?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2016-06-27 18:19:17 -0600

I constructed a simple system model which might address your concern.

The model has a DiscreteClock and a LineWriter. You can find the Clock in Actors/Sources/TimedSources. The clock fires (produces an output) every 86400 seconds. At every tick, it causes the LineWriter to write its output to a file (ClockOutput.txt) which must be on your file system.

Although the system model runs from 0 to 172800s with a period of 900 seconds, you can see that ClockOutput.txt has only three entries. Is that what you would like to achieve?

Notes:

  • The model is at C:\fakepath\model.png.
  • Please rename the model from model.png to model.xml so you can run it.
  • Do not forget to specify the path to the output file (ClockOutput.txt) so the model can find it.
edit flag offensive delete link more

Comments

Thanks, that's really helpful! That's almost what I want. In the end I want to trigger a SystemCommand at a given timestep. How do I connect your discrete clock to trigger events?

It got messy with my example above, but if you're curious, I'm really doing something along the line of load forecasting and determining the optional operation of an electrical battery, which I want to do at midnight of each day, and I want to avoid launching the SystemCommand at all cost the rest of the time: just the fact of calling python to do nothing slows down the simulation a ton

Julien Marrec's avatar Julien Marrec  ( 2016-06-28 00:24:27 -0600 )edit

If you right click on the SystemCommand actor, and go to Customize -> Ports, you will see that you can add inputs ports. If you connect these ports to your trigger signal, then the SystemCommand will fire when data are available at this port. Note that all inputs ports need to be connected for the SystemCommand to fire.

Thierry Nouidui's avatar Thierry Nouidui  ( 2016-06-28 09:09:52 -0600 )edit

Furthermore, rather than writing and reading csv, you could also print the output that you want to use in downstream actors in your Python script. If you use print in your Python script, then the printed output will be available at the output port of the SystemCommand actor. Note that this output is a string which could be post process for further use. Take a look at the BCVTB radiance40 example. You can in this example open the String2Double composite actor to see how strings have been parsed there.

Thierry Nouidui's avatar Thierry Nouidui  ( 2016-06-28 09:16:22 -0600 )edit

Thanks Thierry. I'm getting an "Actor is not ready to fire" when I do that? any clues?

Julien Marrec's avatar Julien Marrec  ( 2016-06-28 10:09:23 -0600 )edit

How many inputs do you have? Are they all connected? In the SDF domain, an actor will fire only if all its inputs are connected and available...

Thierry Nouidui's avatar Thierry Nouidui  ( 2016-06-28 11:11:51 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Training Workshops

Careers

Question Tools

1 follower

Stats

Asked: 2016-06-27 17:16:25 -0600

Seen: 304 times

Last updated: Jun 27 '16