Simple Counter

Top  Previous  Next

How long did the vegetation period last? How many days did the maximum temperature exceed 30°? How many days did a plant suffer drought stress?

 

If the modules don't provide this information, there is no need to drill out the modules to implement a counter as a SimVariable.

 

Counting with Default Management

 

The DefaultManagement now provides methods to implement counters. The management tag takes an additional attribute mode=""

 

         MAX: if true, existing and new value compared

       MIN: if true, existing and new value compared

       RESET: if true sets the default value, else nothing

       SET: if true sets the value, else nothing

       ITE (Default): if true sets the value, false sets the default

       SUM: if true adds the value to the previous sim variable value

 

With the mode SUM you can create a counter. E.g. Starting a counter with a value of 10 and incrementing it, when the MODEL_DOY is between 30 and 300

 

       <action rule="${_MODEL_DOY_} &gt; 30 &amp; ${_MODEL_DOY_} &lt; 300">

        <mgm id="ManagementCounter" datatype="INT" default="10" mode="SUM">3</mgm>

       </action>

 

For resetting it, you have to write an expression as the value of the sum action. E.g. reset the counter above on DOY 90.

 

       <action rule="${_MODEL_DOY_} &gt; 30 &amp; ${_MODEL_DOY_} &lt; 300">

        <mgm id="ManagementCounter" datatype="INT" default="10" mode="SUM">!EXP:ITE(${_MODEL_DOY_}=90,-${Defaultmanagent.ManagementCounter}+10,3)!</mgm>

       </action>

 

Notice: The example above is not yet tested

 

Simple Resettable Counter

 

You can use an instance of SimpleCounter module (maybe together with DefaultManagement or Simcomponents) to perform the counting.

 

The counter is controlled by a daily input variable iDoCount. Every day where iDoCount is true, the counter is incremented. When the input iReset is true, then the counter is reset to it's initial value before the counting is possibly performed. The counter can be customized with the constants cStartValue (default value 0) and cIncrement (default value 1).

 

Main output is Counter which holds the actual value. There is also the NumberOfResets available, as well as the TotalCount (i.e. the number of times the counter was incremented, ignoring any resets).

 

In this example we count the number of days where temperature exceeds 35°. DefaultManagment defines two boolean variables IsHotDay and IsFirstJanuary which will turn true when the corresponding rule holds. The variables are supplied to the SimpleCounter.

 

       <simcomponent id="DefaultManagement" class="net.simplace.simulation.model.DefaultManagement">

               <action rule="${weather.MaxTemperature &gt; 35">

                       <mgm id="IsHotDay" datatype="BOOLEAN" default="false">true</mgm>

               </action>

               <action rule="${_MODEL_DOY_} = 1">

                       <mgm id="IsFirstJanuary" datatype="BOOLEAN" default="false">true</mgm>

               </action>

       </simcomponent>

       <simcomponent id="HotDayCounter" class="net.simplace.client.simulation.lap.util.SimpleCounter">

               <input id="cIncrement" datatype="INT">1</input>

               <input id="cStartValue" datatype="INT">0</input>

               <input id="iDoCount" source="DefaultManagement.IsHotDay"/>

               <input id="iReset" source="DefaultManagement.IsFirstJanuary"/>

       </simcomponent>

 

You can use multiple instances of SimpleCounter in your solution as long as you give them a different id. For example you could include in the DefaultManagment a check whether LintulWaterStress.TRANRF is below 1 and use it in a second SimpleCounter named CountWaterstressDay.