Browse Source

added commented examples and code from the paper.

Cláudio Gomes 4 years ago
parent
commit
9559548198

+ 45 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/power_window_case_study/loop.sa

@@ -0,0 +1,45 @@
+module Loop_SA
+
+semantic adaptation reactive mealy LoopSA adaptedFMU
+at "./path/to/LoopSA.fmu"
+
+	for inner fmu WindowSA window_sa
+		at "./path/to/WindowSA.fmu"
+		with input ports displacement (rad), speed (rad/s), reaction_force (N)
+		with output ports disp (m), tau (N.m)
+	
+	for inner fmu Obstacle obstacle
+		at "./path/to/Obstacle.fmu"
+		with input ports disp (m)
+		with output ports reaction_force (m)
+	
+	with window_sa.disp -> obstacle.disp
+	with obstacle.reaction_force -> window_sa.reaction_force
+
+output ports tau
+
+param 	MAXITER := 10, 
+		REL_TOL := 1e-05, 
+		ABS_TOL := 1e-05;
+
+ctrl var prev_disp := 0.0;
+control {
+	for (var iter in 0 .. MAXITER) {
+		save_state(obstacle);
+		save_state(window_sa);
+		obstacle.disp := prev_disp;
+		do_step(obstacle,t,H);
+		do_step(window_sa,t,H);
+		
+		if (is_close(prev_disp, window_sa.disp, REL_TOL, ABS_TOL)) {
+			break;
+		} else {
+			prev_disp := window_sa.disp;
+			rollback(obstacle);
+			rollback(window_sa);
+		}
+	}
+	return H;
+}
+
+

+ 3 - 63
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/power_window_case_study/window_sa.BASE.sa

@@ -3,77 +3,17 @@ module Window_SA
 semantic adaptation reactive mealy WindowSA windowSA
 at "./path/to/WindowSA.fmu"
 
-/*
-Reactive means that the unit expects the following treatment:
-Supose the external master is at time t, and that there is an FMU f providing inputs to windowsa.
-Then,
-f.doStep(t, H) // f goes from t->t+H 
-u := f.getValues(...)
-windowsa.setValues(u) // Input provided from the future (t+H)
-windowsa.doStep(t, H) // windowsa goes from t->t+H
-v := windowsa.getValues(...)
-
-Delayed unit means that the unit expects the following treatment:
-Supose the external master is at time t, and that there is an FMU f providing inputs to windowsa.
-Then,
-pu := f.getValues(...)
-f.doStep(t, H) // f goes from t->t+H 
-windowsa.setValues(pu) // Input provided at the time t
-windowsa.doStep(t, H) // windowsa goes from t->t+H and does not need input at time (t+H)
-v := windowsa.getValues(...)
-
-
-Mealy unit means the following:
-windowsa.setValues(v1)  // values set at time t
-o1 = windowsa.getValues() // values set at time t
-assert v2 <> v1 // Assumption
-windowsa.setValues(v2)  // values set at time t
-o2 = windowsa.getValues() // values set at time t
-It is probably the case that o1 <> o2
-
-Moore unit means the following:
-windowsa.setValues(v1)  // values set at time t
-o1 = windowsa.getValues() // values set at time t
-assert v2 <> v1 // Assumption
-windowsa.setValues(v2)  // values set at time t
-o2 = windowsa.getValues() // values set at time t
-It must be the case that o1 == o2
-In other words, the output at time t, only depends on the state at time t.
-*/
-
-	
-	/*
-	The definition for the wrapped FMU is now done here.
-	This is because, for adaptations that wrap multiple FMUs as well as other adaptations, the connection information cannot be fully completed in the senario description (see the window_obstacle.sa example).
-	*/
 	for inner fmu Window window
 		at "./path/to/WindowSA.fmu"
 		with input ports displacement (rad), speed (rad/s), reaction_force (N)
 		with output ports height (cm), reaction_torque (N.m)
 
-/*
-No need to have input ports declared for this model.
-Every input port of the original FMU will be automatically assumed to be an input port of the adapted FMU.
-
-If there is an input port window.p which is dangling, but is not declared here, then an input port windowsa.p will be created in the adapted FMU, and we will have that window.p -> windowsa.p.
-*/
-
-/*
-Declares two output ports, and specified how height is mapped to disp.
-Here, the units need to be specified, so that the conversion can take place.
-The units of disp can be either obtained from the scenario, or specified explicitly here.
-*/
 output ports disp (m)  <- height, tau
-/*
-There are alternative ways that this can be interpreted:
-disp  := arbitrary_function(height) * 100 or arbitrary_function(height * 100) (they are not necessarily equal)
-We pick the first one, so what we have is this:
-aux_var := arbitrary_function(height);
-disp := aux_var*100; // This part never has to be coded.
-*/
 
 out rules {
 	true -> {} --> {
 		tau := -reaction_force;
 	};
-}
+}
+
+

+ 4 - 21
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/power_window_case_study/window_sa_canonical.BASE.sa

@@ -8,11 +8,6 @@ at "./path/to/WindowSA.fmu"
 		with input ports displacement (rad), speed (rad/s), reaction_force (N)
 		with output ports height (m), reaction_torque (N.m)
 
-/*
-In the original version, no input ports where declared, so all dangling inputs of the original fmus are bound to the input ports of the adapted FMU.
-In the canonical version, the input and output ports are all declared explicitly, and their bindings are implemented in the in/out rules.
-*/
-
 input ports 	reaction_force,
 				displacement,
 				speed
@@ -20,9 +15,8 @@ input ports 	reaction_force,
 output ports	disp,
 				tau
 
-
 control {
-	do_step(window, t, H); // includes update_in rules and update_out (update-in rules do not update state)
+	do_step(window, t, H);
 	return H;
 }
 
@@ -32,19 +26,9 @@ in var 	stored_windowsa_reaction_force := 0.0,
 
 in rules {
 	true -> {
-		/*
-		is_set checks whether the input value is given in the setValues call of the adapted FMU.
-		Notice that in the canonical version, all ports are prefixed.
-		*/
-		if (is_set(windowSA.reaction_force)){
-			stored_windowsa_reaction_force := windowSA.reaction_force;
-		}
-		if (is_set(windowSA.displacement)){
-			stored_windowsa_displacement := windowSA.displacement;			
-		}
-		if (is_set(windowSA.speed)){
-			stored_windowsa_speed := windowSA.speed;
-		}
+		stored_windowsa_reaction_force := windowSA.reaction_force;
+		stored_windowsa_displacement := windowSA.displacement;			
+		stored_windowsa_speed := windowSA.speed;
 	} --> {
 		window.reaction_force := stored_windowsa_reaction_force;
 		window.displacement := stored_windowsa_displacement; 
@@ -64,4 +48,3 @@ out rules {
 		windowSA.disp := stored_window_height / 100;
 	};
 }
-

+ 67 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/power_window_case_study/window_sa_canonical_commented.BASE.sa

@@ -0,0 +1,67 @@
+module Window_SA
+
+semantic adaptation reactive mealy WindowSA windowSA
+at "./path/to/WindowSA.fmu"
+
+	for inner fmu Window window
+		at "./path/to/Window.fmu"
+		with input ports displacement (rad), speed (rad/s), reaction_force (N)
+		with output ports height (m), reaction_torque (N.m)
+
+/*
+In the original version, no input ports where declared, so all dangling inputs of the original fmus are bound to the input ports of the adapted FMU.
+In the canonical version, the input and output ports are all declared explicitly, and their bindings are implemented in the in/out rules.
+*/
+
+input ports 	reaction_force,
+				displacement,
+				speed
+
+output ports	disp,
+				tau
+
+
+control {
+	do_step(window, t, H); // includes update_in rules and update_out (update-in rules do not update state)
+	return H;
+}
+
+in var 	stored_windowsa_reaction_force := 0.0, 
+		stored_windowsa_displacement := 0.0, 
+		stored_windowsa_speed := 0.0;
+
+in rules {
+	true -> {
+		/*
+		is_set checks whether the input value is given in the setValues call of the adapted FMU.
+		Notice that in the canonical version, all ports are prefixed.
+		*/
+		if (is_set(windowSA.reaction_force)){
+			stored_windowsa_reaction_force := windowSA.reaction_force;
+		}
+		if (is_set(windowSA.displacement)){
+			stored_windowsa_displacement := windowSA.displacement;			
+		}
+		if (is_set(windowSA.speed)){
+			stored_windowsa_speed := windowSA.speed;
+		}
+	} --> {
+		window.reaction_force := stored_windowsa_reaction_force;
+		window.displacement := stored_windowsa_displacement; 
+		window.speed := stored_windowsa_speed;
+	};
+}
+
+out var stored_window_reaction_torque := 0,
+		stored_window_height := 0;
+		
+out rules {
+	true -> {
+		stored_window_reaction_torque := window.reaction_torque;
+		stored_window_height := window.height;
+	} --> {
+		windowSA.tau := - stored_window_reaction_torque;
+		windowSA.disp := stored_window_height / 100;
+	};
+}
+

+ 79 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/power_window_case_study/window_sa_commented.BASE.sa

@@ -0,0 +1,79 @@
+module Window_SA
+
+semantic adaptation reactive mealy WindowSA windowSA
+at "./path/to/WindowSA.fmu"
+
+/*
+Reactive means that the unit expects the following treatment:
+Supose the external master is at time t, and that there is an FMU f providing inputs to windowsa.
+Then,
+f.doStep(t, H) // f goes from t->t+H 
+u := f.getValues(...)
+windowsa.setValues(u) // Input provided from the future (t+H)
+windowsa.doStep(t, H) // windowsa goes from t->t+H
+v := windowsa.getValues(...)
+
+Delayed unit means that the unit expects the following treatment:
+Supose the external master is at time t, and that there is an FMU f providing inputs to windowsa.
+Then,
+pu := f.getValues(...)
+f.doStep(t, H) // f goes from t->t+H 
+windowsa.setValues(pu) // Input provided at the time t
+windowsa.doStep(t, H) // windowsa goes from t->t+H and does not need input at time (t+H)
+v := windowsa.getValues(...)
+
+
+Mealy unit means the following:
+windowsa.setValues(v1)  // values set at time t
+o1 = windowsa.getValues() // values set at time t
+assert v2 <> v1 // Assumption
+windowsa.setValues(v2)  // values set at time t
+o2 = windowsa.getValues() // values set at time t
+It is probably the case that o1 <> o2
+
+Moore unit means the following:
+windowsa.setValues(v1)  // values set at time t
+o1 = windowsa.getValues() // values set at time t
+assert v2 <> v1 // Assumption
+windowsa.setValues(v2)  // values set at time t
+o2 = windowsa.getValues() // values set at time t
+It must be the case that o1 == o2
+In other words, the output at time t, only depends on the state at time t.
+*/
+
+	
+	/*
+	The definition for the wrapped FMU is now done here.
+	This is because, for adaptations that wrap multiple FMUs as well as other adaptations, the connection information cannot be fully completed in the senario description (see the window_obstacle.sa example).
+	*/
+	for inner fmu Window window
+		at "./path/to/WindowSA.fmu"
+		with input ports displacement (rad), speed (rad/s), reaction_force (N)
+		with output ports height (cm), reaction_torque (N.m)
+
+/*
+No need to have input ports declared for this model.
+Every input port of the original FMU will be automatically assumed to be an input port of the adapted FMU.
+
+If there is an input port window.p which is dangling, but is not declared here, then an input port windowsa.p will be created in the adapted FMU, and we will have that window.p -> windowsa.p.
+*/
+
+/*
+Declares two output ports, and specified how height is mapped to disp.
+Here, the units need to be specified, so that the conversion can take place.
+The units of disp can be either obtained from the scenario, or specified explicitly here.
+*/
+output ports disp (m)  <- height, tau
+/*
+There are alternative ways that this can be interpreted:
+disp  := arbitrary_function(height) * 100 or arbitrary_function(height * 100) (they are not necessarily equal)
+We pick the first one, so what we have is this:
+aux_var := arbitrary_function(height);
+disp := aux_var*100; // This part never has to be coded.
+*/
+
+out rules {
+	true -> {} --> {
+		tau := -reaction_force;
+	};
+}