|
@@ -3,8 +3,8 @@ code AdaptedFMU:
|
|
|
/*
|
|
|
These maps will keep track of which rules execute and which don't
|
|
|
*/
|
|
|
- var out_condition_executed = empty map
|
|
|
var in_condition_executed = empty map
|
|
|
+ var out_condition_executed = empty map
|
|
|
|
|
|
var fmu1 //FMU fmu1 ref
|
|
|
var fmu2 //FMU fmu2 ref
|
|
@@ -22,13 +22,17 @@ code AdaptedFMU:
|
|
|
...
|
|
|
|
|
|
// in vars
|
|
|
- var cv1 = init_cv1
|
|
|
+ var iv1 = init_iv1
|
|
|
...
|
|
|
|
|
|
// out vars
|
|
|
var ov1 = init_ov1
|
|
|
...
|
|
|
|
|
|
+ // control vars
|
|
|
+ var cv1 = init_cv1
|
|
|
+ ...
|
|
|
+
|
|
|
function instantiate()
|
|
|
fmu1.instantiate()
|
|
|
...
|
|
@@ -36,7 +40,7 @@ code AdaptedFMU:
|
|
|
end function
|
|
|
|
|
|
function setup_experiment(t,...)
|
|
|
- window.setup_experiment(t,...)
|
|
|
+ fmu1.setup_experiment(t,...)
|
|
|
time_last_fmu1 = t
|
|
|
...
|
|
|
return
|
|
@@ -54,11 +58,15 @@ code AdaptedFMU:
|
|
|
return
|
|
|
end function
|
|
|
|
|
|
- function setValues(ports, values)
|
|
|
+ function fmi2SetValues(ports, values)
|
|
|
/*
|
|
|
Evaluates each condition (and sa_in rule) in order.
|
|
|
*/
|
|
|
|
|
|
+ /*
|
|
|
+ TODO: First eval all conditions, and only then run the blocks.
|
|
|
+ */
|
|
|
+
|
|
|
if (in_condition_1) then
|
|
|
in_condition_executed[IN_COND_1] = true
|
|
|
<sa_in_1>
|
|
@@ -69,7 +77,7 @@ code AdaptedFMU:
|
|
|
*/
|
|
|
var h = 0
|
|
|
var dt = 0
|
|
|
- <update_sa_in_1>
|
|
|
+ <update_in_1>
|
|
|
}
|
|
|
<end if>
|
|
|
end if
|
|
@@ -78,22 +86,7 @@ code AdaptedFMU:
|
|
|
out_condition_executed := empty map // force output computation.
|
|
|
end function
|
|
|
|
|
|
- function doStep(t, H)
|
|
|
-
|
|
|
- /*
|
|
|
- A new doStep means that a new set of conditions will be triggered.
|
|
|
- */
|
|
|
- out_condition_executed = empty map
|
|
|
-
|
|
|
- /*
|
|
|
- Calculate the elapsed time since the last transition
|
|
|
- */
|
|
|
- var elapsed_fmu1 = t - time_last_fmu1
|
|
|
- ...
|
|
|
- var e = min(elapsed_fmu1, ...)
|
|
|
-
|
|
|
- <control_block_part_1>
|
|
|
-
|
|
|
+ function do_inner_step(fmu, t, inner_t, h)
|
|
|
/*
|
|
|
Evaluate each update_in block of the rules that were successfully evaluated before the doStep was called.
|
|
|
This is because the window.doStep will be called immediately afterward.
|
|
@@ -113,11 +106,14 @@ code AdaptedFMU:
|
|
|
<update_in_2>
|
|
|
end if
|
|
|
...
|
|
|
- do_step(fmu1, inner_t, h)
|
|
|
+ fmi2DoStep(fmu1, inner_t, h)
|
|
|
/*
|
|
|
Executes the update_out blocks.
|
|
|
These always execute after a doStep is called on an internal FMU.
|
|
|
*/
|
|
|
+ /*
|
|
|
+ TODO: First eval all conditions, and only then run the blocks.
|
|
|
+ */
|
|
|
if (<out_condition_1>) then
|
|
|
out_condition_executed[OUT_COND_1] = true
|
|
|
var h = h
|
|
@@ -125,12 +121,37 @@ code AdaptedFMU:
|
|
|
<update_out_1>
|
|
|
end if
|
|
|
...
|
|
|
+ end function
|
|
|
+
|
|
|
+ function fmi2DoStep(t, H)
|
|
|
+
|
|
|
+ /*
|
|
|
+ A new doStep means that a new set of conditions will be triggered.
|
|
|
+ */
|
|
|
+ out_condition_executed = empty map
|
|
|
+
|
|
|
+ /*
|
|
|
+ Calculate the elapsed time since the last transition
|
|
|
+ */
|
|
|
+ var elapsed_fmu1 = t - time_last_fmu1
|
|
|
+ ...
|
|
|
+ var e = min(elapsed_fmu1, ...)
|
|
|
+
|
|
|
+ <control_block_part_1>
|
|
|
+
|
|
|
+ do_inner_step(fmu1, t, inner_t, h);
|
|
|
+
|
|
|
+ <control_block_part_2>
|
|
|
|
|
|
in_condition_executed = empty map;
|
|
|
|
|
|
end function
|
|
|
|
|
|
- function getValues(ports)
|
|
|
+ function fmi2GetValues(ports)
|
|
|
+ var values = empty map;
|
|
|
+ /*
|
|
|
+ TODO: First eval all conditions, and only then run the blocks.
|
|
|
+ */
|
|
|
if out_condition_executed == empty map then
|
|
|
// This can happen since the adapted unit is a mealy machine
|
|
|
// So execute the update_out blocks
|
|
@@ -148,4 +169,6 @@ code AdaptedFMU:
|
|
|
<sa_out_1>
|
|
|
end if
|
|
|
...
|
|
|
+
|
|
|
+ return values;
|
|
|
end function
|