It is often useful to be able to use current simulation time in your model: for example, you may want to incorporate a gradual increase in some external variable such as temperature. For this purpose, a special function called *time* is provided in Simile.

The *time* function has a value equal to the number of time units that has elapsed since the start of the simulation (which is assigned a time of zero). To help avoid any confusion, please note that it has nothing to do with the real-world time that elapses as the model runs. How long a simulation takes to run depends on how complex it is and how fast your computer is, amongst other factors, but none of these influences the *time* function. If you run a simulation for 100 time units, then the *time* function will increase from zero to 100 during the simulation. This may take 20 seconds of your time or it may take 20 minutes, depending as I say, on the model’s complexity and the speed of your computer.

You can use the *time* function in constructing expressions in Simile’s equation language. This gives enormous flexibility in constructing expressions. Perhaps the two most common uses are in drawing sketch graphs to illustrate how some external influence changes through time, and in constructing cycles, such as the repetition of the seasons year after year.

Page type:

Many environmental factors vary on a daily or an annual basis: e.g. temperature, radiation, evapotranspiration. It is desirable to be able to capture this if you want to capture the effect of the factor on the behaviour of your modelled system, and if the time-scale is appropriate.

Let’s assume that your time unit is the month (i.e. all your rates are expressed per month, and that simulation time is shown in month).

The function *fmod* is used to calculate remainders when doing division. For example, dividing 28 by 12, gives two with a remainder of four. This gives us a mathematical means to create a cycle. Dividing the *time* function by 12 and looking only at the remainder will give a series of numbers from zero to 11 in sequence again and again. We can use these as the month number (0=January, 1=February, 2=March and so on).

To return to the example used in illustrating the sketch graph, rainfall patterns repeat year after year. So we can modify the expression used in the equation for the sketch graph to use the *fmod* function as well as the *time* function. This looks like this: “graph(fmod(time(),12))”

In fact there are now easier ways to get data into a Simile model and have it repeat after a certain period of time. The sketch graph dialogue includes a pulldown menu with the caption "Out of range:" which gives a series of options for how to pick a value when the input value is outside the range covered by the graph. The options are:

**Truncate,**which means return the value at the nearest side of the graph,**Extrapolate,**which means extend the last (or first) section of the sketch graph in a straight line to the required datapoint, or**Wraparound,**which means that the range of values given by the graph repeats after the given input range to cover any input value.

Using the **Wraparound** option has the same effect as placing an "fmod()" function around the expression supplied to the graph function.

Page type:

We can combine the use of the time function with the sketched graph. This is very useful when you have a historical record for some external factor, e.g. rainfall or temperature: the graph you sketch is a copy of the historical record.

For example, to use a sketch of how rainfall varies throughout the year in your model, you first create a variable called “rainfall”. Double-click on this variable to set its properties, and click on the “Graph” button. This opens the sketch pad window.

Enter the range on the X-axis, from a minimum of zero to a maximum of 12 which corresponds to one year, if the time unit is one month.(in general, the maximum value on the X-axis will correspond to the length of time you want the simulation to run for) Enter the range of the Y-axis from, for example, zero to 30, depending on how rainy your locality is.

Sketch a curve with perhaps two well-defined peaks, to enable you to see the response clearly when you run the model. Use the on-line help if you're unsure of how to draw the curve.

Click “OK” and return to the equation dialogue box. You’ll notice that the function name *graph( )* has been entered in the equation. To complete the expression, use the *time( )* function as its argument. The expression should read “graph(time())”.

Page type: