You are not logged in. Click here to log in.

Application Lifecycle Management

Search In Project

Search inClear

Tags:  not added yet

Time Iteration

Many agro-environmental models compute biophysical state for each of the specified steps through time during the simulation period.

Concept

The 'TimeControl' component iterates through time. It consumes four parameters, allowing most regular time steps. 'TimeControl' outputs the time, which is consumed by the 'TimeConsumerComponent'. The OMS simulation controls when iteration is complete.

Implementation

'TimeControl' consumes parameters for calendar state and end dates, the type of calendar to use, and amount to increment during iteration. The component's method increments and outputs a current time.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package ex06;

import java.util.Calendar;
import oms3.annotations.*;

/**
 * Time control
 * 
 * @author od
 */
public class TimeControl {

    @In public Calendar start;
    @In public Calendar end;
    @In public int calfield;
    @In public int amount;

    @Out public Calendar current;

    // flag for controlling the iteration
    @Out public boolean done;

    @Execute
    public void execute() {
        if (current == null) {
            current = (Calendar) start.clone();
        } else {
            current.add(calfield, amount);
        }
        done = current.before(end);
    }
}

'TimeConsumerComponent' consumes the current time from 'TimeControl' and prints it out in the specified Java Calendar format.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
package ex06;

import java.util.Calendar;
import oms3.annotations.*;

public class TimeConsumerComponent {

    @In public Calendar current;

    @Execute
    public void execute() {
        System.out.println(current.getTime());
    }
}

In the OMS simulation, the two model components are connected, and the four parameters instantiated.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import static oms3.SimBuilder.instance as OMS3

OMS3.sim {
    model(while:"c.done") {
       parameter {
          // specified as Calendar object, not really nice looking, but possibe
          'c.start'       new java.util.GregorianCalendar(2001, 9, 1)

          // ISO Data get's converted into the same GregorianCalendar object,
          // same thing as above, but looks nicer.
          'c.end'         '2001-10-10'

          // static Calendar field constants
          'c.calfield'    java.util.Calendar.DAY_OF_YEAR

          // the number of units to increase
          'c.amount'      1
       }

       components {
          'c' 'ex06.TimeControl'
          'c1' 'ex06.TimeConsumerComponent'
       }

       connect {
         // pass current time to 'c1'
         'c.current'  'c1.current'
       }
    }
}