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

Application Lifecycle Management

Search In Project

Search inClear

Tags:  not added yet

Feedback

Data flowing through multiple instances of a component execution chain.

Concept

Often with agroenvironmetal models, the output from a component in the execution chain in the previous time step provides the input to another component in the execution chain during the next time step. More generally, output from a component feeds back to an earlier component in the execution chain until a convergence is reached completing execution.

Implementation

In this example there are two components in a feedback loop, bouncing 'fb' back and forth until it reaches convergence (greater than 10). The variable 'fb' is declared @In and @Out in both components. Note there can be an indirect feedback, data flowing through multiple components until it comes back.

'Comp1' consumes the 'initial' parameter and assigns it to 'fb', which is decremented, the value printed out with preceding string, and sent as 'fb' output. While not done, 'Comp1' consumes 'fb' from another component and acts on it as previously described. 'Comp1' sets done when 'fb' exceeds 10 after preceding decrement.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
package ex11;

import oms3.annotations.*;

public class Comp1 {

    @In public double initial;

    @In @Out public Double fb;

    @Out public boolean done;

    @Execute
    public void execute() {
        if (fb == null) {
            fb = initial;
        }
        fb = fb - 0.1;
        done = fb < 10;
        System.out.println("Comp1: " + fb);
    }
}

'Comp2' consumes 'fb' from 'Comp1', increments it, prints out the value with preceding string, and sends as 'fb' output.

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

import oms3.annotations.*;

public class Comp2 {

    @In @Out public Double fb;

    @Execute
    public void execute() {
        fb = fb + 1;
        System.out.println("Comp2: " + fb);
    }
}

The simulation file connects 'Comp1' and 'Comp2' with a forward connect and feedback connect, from 'Comp1' to 'Comp2' and from 'Comp2' to 'Comp1'. The simulation iterates as long as 'fb' does not exceed 10 after its preceding decrement in 'Comp1'.

 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
import static oms3.SimBuilder.instance as OMS3

OMS3.sim {
  model (while:'c1.done') {
    parameter {
          // pass in the coordinated as native integer to the 
          // first component. 
          'c1.initial'  1.1
       }

       components {
          'c1' 'ex11.Comp1'
          'c2' 'ex11.Comp2'
       }

       connect {
            // forward connectivity
            'c1.fb' 'c2.fb'
       }

       feedback {
            // feedback connectivity
            'c2.fb' 'c1.fb'
       }
   }
}