User Tools

Site Tools


time_event

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
time_event [2020/10/12 14:56]
erik [Working with simulation time]
time_event [2023/03/02 12:39] (current)
dmytroh [See also]
Line 3: Line 3:
 Time event is an [[events|event block]] which lets the user specify time points when actions should be performed by simulation blocks. They have a big performance benefit over [[discrete event|discrete events]] in that the event time can be predetermined before the simulation starts. Time event is an [[events|event block]] which lets the user specify time points when actions should be performed by simulation blocks. They have a big performance benefit over [[discrete event|discrete events]] in that the event time can be predetermined before the simulation starts.
  
-In order to allow end-users to be able to input event time data(for instance in [[Ecolego Player]])), the time points used by a [[time event]] are taken from [[parameter|parameters]], [[lookup table|lookup tables]], [[time point|time points]] and [[time series|time series']]. This means that the user selects one, or more, blocks for the time event. The event block will search the block for time points that in turn will cause the event to be sent. +In order to allow end-users to be able to input event time data(for instance in [[Ecolego Player]])), the time points used by a [[time event]] are taken from [[parameter|parameters]], [[lookup table|lookup tables]], [[time point|time points]] and [[time_series_page|time series]]. This means that the user selects one, or more, blocks for the time event. The event block will search the block for time points that in turn will cause the event to be sent. 
  
 Depending on the type of block(s) selected, the user can model different kinds of behaviour; working with dates resp. working with simulation time, periodic vs. single instances.  Depending on the type of block(s) selected, the user can model different kinds of behaviour; working with dates resp. working with simulation time, periodic vs. single instances. 
Line 9: Line 9:
 ====Working with simulation time==== ====Working with simulation time====
  
-Simulation time boundaries are set in the [[simulation settings window]]. The start time is typically 0, and end time is typically a value indicating the number of time units to run the simulation. +Simulation time boundaries are set in the [[simulation settings]] window. The **start time** is typically 0, and **end time** typically indicates the number of time units to run the simulation. 
  
-When you want an event to trigger depending on the value of the [[time]] variable, you use either [[parameter]] or [[lookup table]] blocks. +When you want an event to trigger depending on the value of the //time// variable, you use either [[parameter]] or [[lookup table]] blocks. 
  
 ^Type^Description^ ^Type^Description^
 |Single|In order to set a single time point for when the event triggers, use a [[parameter]] which contains the target value of the time variable. For instance, if the simulation time is set to go from 0 to 100 days, and the parameter has the value 20, simulation will pause after 20 days and all actions related to the event will trigger| |Single|In order to set a single time point for when the event triggers, use a [[parameter]] which contains the target value of the time variable. For instance, if the simulation time is set to go from 0 to 100 days, and the parameter has the value 20, simulation will pause after 20 days and all actions related to the event will trigger|
 |Multiple|Multiple time points can be specified either by selecting several parameters, or by using a [[lookup table]]. In the latter case, the time event block will fire for every time point discovered in the lookup table.| |Multiple|Multiple time points can be specified either by selecting several parameters, or by using a [[lookup table]]. In the latter case, the time event block will fire for every time point discovered in the lookup table.|
 +|Periodic|For an event to be fired at certain intervals, use a lookup table which has been marked as **cyclic**. The period will be determined by the first and the last time point in the lookup table. For instance, a lookup table with the values (10,40,60) gives the period 50 time units. The event will thus fire at t=10, t=40, t=60, t=90, t=110, t=140 etc. |
    
- 
- 
 ====Working with dates====   ====Working with dates====  
  
 +The end user specifies the simulation start date in the [[simulation settings]] window. The end date is either derived from the duration of the simulation (the end time-the start time), or given by the user. When working with dates Ecolego converts the simulation time to a calendar date. This means that leap years are taken into account.   
  
 +For dates there are more options than when working with simulation time. You would use either [[time point]] or [[time_series_page|time series]] blocks. The **mode** of the block (date, year, day of year etc.) will influence the behaviour of the event time block.  
  
 +^Type^Periodic^Description^
 +|Date|No|Use a [[time point]] block in **date** mode|
 +|Multiple dates|No|Use a [[time_series_page|time series]] block in **date** mode. An event will be sent for every date in the block.|
 +|Year|No|Use a [[time point]] block in **year** mode|
 +|Multiple years|No|Use a [[time_series_page|time series]] block in **year** mode. An event will be sent for every year in the block.|
 +|Monthly|Yes|Use a [[time point]] block in **month** mode. Events are fired yearly at the 1st of the month specified in the block.|
 +|Multiple months|Yes|Use a [[time_series_page|time series]] block in **month** mode. Events are fired yearly at the 1st of each month specified in the block.|
 +|Day of year|Yes|Use a [[time point]] block in **day of year** mode. Events are fired yearly at the day and month specified in the block.|
 +|Day of year|Yes|Use a [[time_series_page|time series]] block in **day of year** mode. Events are fired yearly at each day and month specified in the block.|
 +|Day of month|Yes|Use a [[time point]] block in **day of month** mode. Events are fired every month at the day  specified in the block. **Note:** events are only fired if the day is valid for the month. For example, if the day 29 is specified, an event will only fire for months with 29 days or more - non-leap year Februaries are ignored.|
 +|Day of month|Yes|Use a [[time_series_page|time series]] block in **day of month** mode. Events are fired yearly at each day and month specified in the block.|
 +|Weekly|Yes|Use a [[time point]] block in **day** mode. Events are fired weekly at the day specified in the block.|
 +|Weekly|Yes|Use a [[time_series_page|time series]] block in **day** mode. Events are fired weekly at the days specified in the block.|
 +|Daily|Yes|Use a [[time point]] block in **hour** mode. Events are fired daily at the hour specified in the block.|
 +|Daily|Yes|Use a [[time_series_page|time series]] block in **hour** mode. Events are fired daily at the hours specified in the block.|
 +|Hourly|Yes|Use a [[time point]] block in **minute** mode. Events are fired hourly at the minute specified in the block.|
 +|Hourly|Yes|Use a [[time_series_page|time series]] block in **minute** mode. Events are fired hourly at the minutes specified in the block.|
 +|Once every minute|Yes|Use a [[time point]] block in **seconds** mode. Events are fired at the seconds specified in the block.|
 +|Several times each minute|Yes|Use a [[time_series_page|time series]] block in **seconds** mode. Events are fired at each second specified in the block.|
  
 +For examples, check out the [[Tutorial - Time events]]. 
  
-Discrete events are used by various blocks in order to trig an action. The [[Snapshot|snapshot]] block uses a discrete event in order to trigger the snapshot, the [[Transfer|transfer]] block can specify a discrete transfer by referencing a discrete event.+===== Linking time event blocks to actions =====
  
-The discrete event can also be used to notify the ODE solver that something drastic has happened in the model and that the solver needs to reduce the current time_stepA typical case is for models that contain [[Expression_syntax|conditions]]. In a model with a condition such as (time>t_leakage), where t_leakage is a parameter indicating when a container starts to leak, it is important that the solver includes this time point when the simulation is run.+As with [[discrete event|discrete events]], several blocks can take advantage of eventsRead more [[events#Reacting to events|here]].
  
-The block has a right hand side expression and a left hand side expression. The event is triggered when these are equal. Whenever a time step is taken by the solver, the solver will see if the difference of the two expressions has changed sign since the last time step. If so, the solver will try to backtrace to the time point when they are equal. After, the solver will restart with a time step given in [[Simulation_Settings|simulation settings]] as the //initial time step//. +===== Creating a time event =====
- +
-===== Creating a discrete event =====+
  
 From the [[Projects_window|Projects window]] From the [[Projects_window|Projects window]]
  
-  * Expand the Project to which you wish to add the discrete event by clicking the + symbol next to it. Right-click on ‘Blocks’, or a [[Sub-system|sub-system]] in ‘Blocks’, and select **Discrete event** from the pop-up menu.+  * Expand the Project to which you wish to add the time event by clicking the + symbol next to it. Right-click on ‘Blocks’, or a [[Sub-system|sub-system]] in ‘Blocks’, and select **Time event** from the pop-up menu.
  
 From the [[Matrix_window|Matrix window]] From the [[Matrix_window|Matrix window]]
  
-  * Right click an empty diagonal cell of the matrix and select **Discrete event** from the the pop-up menu.+  * Right click an empty diagonal cell of the matrix and select **Time event** from the the pop-up menu.
  
 From the [[Blocks_window|Blocks window]] From the [[Blocks_window|Blocks window]]
  
-  * Place the mouse cursor over the table and right-click on it. Select **New | Discrete event** from the pop-up menu, //or// +  * Place the mouse cursor over the table and right-click on it. Select **New | Time event** from the pop-up menu, //or// 
-  * In the title bar, select **Discrete event** from the **Type** drop-down list and click on the {{:New24.png|New}} button.+  * In the title bar, select **Time event** from the **Type** drop-down list and click on the {{:New24.png|New}} button.
  
-===== Editing a discrete event =====+===== Editing a time event =====
  
 |Note|Most block properties can be edited directly in the [[Blocks_window|blocks window]].| |Note|Most block properties can be edited directly in the [[Blocks_window|blocks window]].|
Line 65: Line 83:
 ==== Values ==== ==== Values ====
  
-|Note|When entering an expression, you can also enter names of objects that are not yet created and let Ecolego use [[Automatic_object_creation|automatic object creation]] to define them.| +This page lets you select which objects to read time points from. This page lists all [[parameter]][[lookup table]], [[time point]] and [[time_series_page|time series]] blocks of the model. Below the list are controls that allow you to search for blocks and selecting a sub-system. **Note** by default the list shows only blocks from the same sub-system as the event. 
- +
-This page lets you specify the condition for the event. It is important that the terms are put on the correct sides. The left hand side should approach the right hand side. +
- +
-For the example given in the introduction, the left hand side would be “time” and the right hand side would be “t_leakage” because time will approach t_leakage from below. +
- +
-Another example would be when a discrete event is used to assert that the quantity of a [[Compartment|compartment]] does not decrease below a certain limit. In a [[Transfer|transfer]]the following expression is written: (Comp1>limit) · TC, where limit is the lower boundary for the compartment. In this case, Comp1 will approach limit from above, so the terms should be shifted in the discrete event: the left hand term is limit and the right hand side is Comp1.+
  
 **Dimension** - You can specify the dimension of the block by using the **Type** drop down list. Depending on the dimension the index drop down lists are activated. See [[Editing_values|editing values]] for more information. **Dimension** - You can specify the dimension of the block by using the **Type** drop down list. Depending on the dimension the index drop down lists are activated. See [[Editing_values|editing values]] for more information.
- 
-**Data** 
- 
-  * **//Indices//** - For blocks that are non-scalar, the first columns will specify indices from the [[Index_list|index lists]]. This allows you to specify different expressions for different indices. 
-  * **First expression** - The left hand side. 
-  * **Direction** - The expected direction of the event. If the left hand side is expected to exceed the right hand side when the event occurs, use **>>**. In the opposite case, use **<<**. If the event should be triggered for both cases, use **BOTH**. 
-  * **Second expression** - The right hand side. 
-  * **Information** - By using the [[Table_control_button|Table control button]] you can display more columns that will help you document your model. 
- 
-===== Cyclic events ===== 
- 
-For recurring events, you do not need to create several discrete event blocks. By using a trick, it is possible to make an event trigger several times. A typical case is when an event should be triggered every year, month or day. 
- 
-During the simulation an event is triggered when the //sign// of the //difference// of the left hand side expression and the right hand side expression changes between two time points. In other words; for every time step taken, ''%%sign(leftexpression-rightexpression)%%'' will be checked. As explained in the introduction, when the sign changes the solver will backtrace to a time point when the two sides are equal. 
- 
-In the following example we will create an event that is trigged every month of the year. The simulation time unit is years. We need to construct expressions so that the left hand side is equal to the right hand side 12 times every year. 
- 
-One way to achieve this is to compare the two expressions ''%%time/12%%'' with ''%%round(time/12)%%''. The table below shows the value of the two over two years: 
- 
-^Time^time/12^round(time/12)^time/12-round(time/12)^ 
-|0,0 |0,0    |0,0           |**0,0**               | 
-|1,0 |0,1    |0,0           |0,                  | 
-|2,0 |0,2    |0,0           |0,                  | 
-|6,0 |0,5    |1,0           |-0,                 | 
-|12,0|1,   |1,0           |**0,0**               | 
-|13,0|1,   |1,0           |0,                  | 
-|18,0|1,   |2,0           |-0,                 | 
-|24,0|2,   |2,0           |**0,0**               | 
-|40,0|3,   |3,0           |0,                  | 
-|45,0|3,   |4,0           |-0,                 | 
- 
-{{:CyclicEvent.png|CyclicEvent.png}} 
  
 ===== See also ===== ===== See also =====
Line 112: Line 92:
   * The [[Blocks_window|Blocks window]]   * The [[Blocks_window|Blocks window]]
   * The [[Matrix_window|Matrix window]]   * The [[Matrix_window|Matrix window]]
-  * The [[Recorder|recorder]] block 
   * [[Expression_syntax|Expression syntax]]   * [[Expression_syntax|Expression syntax]]
  
time_event.1602507398.txt.gz · Last modified: 2020/10/12 14:56 by erik