Browse Source

new version of algorithm and new test of window_sa

Cláudio Gomes 8 years ago
parent
commit
79d8fc302b

+ 24 - 35
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/examples/algorithm.txt

@@ -4,24 +4,20 @@ code AdaptedFMU:
 	var out_condition_executed;
 	var out_condition_executed;
 	
 	
 	function instantiate()
 	function instantiate()
-		// We are abstracting away the instances. This needs to be changed to accomodate for that.
-		for each fmu in original_fmus do
-			fmu.instantiate()
-		end for
+		fmu1.instantiate()
+		...
 		return
 		return
 	end function
 	end function
 	
 	
 	function enter_init() 
 	function enter_init() 
-		for each fmu in original_fmus do
-			fmu.enter_init()
-		end for
+		fmu1.enter_init()
+		...
 		return
 		return
 	end function
 	end function
 	
 	
 	function exit_init() 
 	function exit_init() 
-		for each fmu in original_fmus do
-			fmu.exit_init()
-		end for
+		fmu1.exit_init()
+		...
 		return
 		return
 	end function
 	end function
 	
 	
@@ -30,51 +26,44 @@ code AdaptedFMU:
 		if (in_condition_1) then
 		if (in_condition_1) then
 			in_condition_executed[cond1] = true
 			in_condition_executed[cond1] = true
 			sa_in_1
 			sa_in_1
-			update_in_1
-		end if
-		if (in_condition_2) then
-			in_condition_executed[cond2] = true
-			sa_in_2
-			update_in_2
+			<if AdaptedFMU is mealy then>	
+				update_sa_in_1
+			<end if>
 		end if
 		end if
 		...
 		...
+		
+		out_condition_executed := empty map // force output computation.
 	end function
 	end function
 	
 	
 	function doStep(t, H)
 	function doStep(t, H)
 		
 		
 		control_block // or generic algorithm cosim step
 		control_block // or generic algorithm cosim step
-		/* In the midst of the control block code,
+		/* 
+		In the midst of the control block code,
 		before any setValues is called on an inner FMU,
 		before any setValues is called on an inner FMU,
 		the following code will be injected:
 		the following code will be injected:
 			if in_condition_executed[cond1] then
 			if in_condition_executed[cond1] then
 				update_in_1
 				update_in_1
 			end if
 			end if
-			if in_condition_executed[cond2] then
-				update_in_2
-			end if
 			...
 			...
 		*/
 		*/
 		
 		
-		out_condition_executed = empty map
-		if (out_condition_1) then
-			out_condition_executed[cond1] = true
-			update_out_1
-			sa_out_1
-		end if
-		if (out_condition_2) then
-			out_condition_executed[cond2] = true
-			update_out_2
-			sa_out_2
-		end if
-		...
+		out_condition_executed := empty map // force output computation.
+		
 	end function
 	end function
 	
 	
 	function getValues(ports)
 	function getValues(ports)
+		
+		if out_condition_executed == empty map then
+			if (out_condition_1) then
+				out_condition_executed[cond1] = true
+				update_out_1
+			end if
+			...
+		end if
+		
 		if out_condition_executed[cond1] then
 		if out_condition_executed[cond1] then
 			sa_out_1
 			sa_out_1
 		end if
 		end if
-		if out_condition_executed[cond2] then
-			sa_out_2
-		end if
 		...
 		...
 	end function
 	end function

+ 1 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/examples/window_sa.BASE.sa

@@ -2,7 +2,7 @@ import PowerWindowModel
 
 
 module Window_SA
 module Window_SA
 
 
-semantic adaptation window_sa
+semantic adaptation mealy reactive window_sa
 
 
 for fmu window
 for fmu window
 
 

+ 91 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/examples/window_sa.BASE_generated_algorithm.txt

@@ -0,0 +1,91 @@
+code window_sa:
+	
+	var in_condition_executed;
+	var out_condition_executed;
+	
+	var window; //FMU window ref
+	
+	var time_last_window;
+	
+	var stored_windowsa_reaction_force,
+		stored_windowsa_displacement,
+		stored_windowsa_speed;
+	
+	var stored_window_reaction_torque,
+		stored_window_height;
+	
+	function instantiate()
+		window.instantiate()
+		return
+	end function
+	
+	function enter_init() 
+		window.enter_init()
+		return
+	end function
+	
+	function exit_init() 
+		window.exit_init()
+		return
+	end function
+	
+	function setValues(ports, values) 		
+		in_condition_executed = empty map
+		if (true) then
+			in_condition_executed[cond1] = true
+			
+			stored_windowsa_reaction_force = values["reaction_force"]
+			stored_windowsa_displacement = values["displacement"]
+			stored_windowsa_speed = values["speed"]
+			
+			// window_sa is mealy
+			{ // new scope
+				var t := 0
+				var h := 0
+				var dt := 0
+				window.setValues("reaction_force", stored_windowsa_reaction_force)
+				window.setValues("displacement", stored_windowsa_displacement)
+				window.setValues("speed", stored_windowsa_speed)
+			}
+			
+		end if
+		
+		out_condition_executed := empty map // force output computation.
+	end function
+	
+	function doStep(t, H)
+		
+		var e := t - time_last_window;
+		{ // new scope
+			var t := t
+			var h := H
+			var dt := 0
+			window.setValues("reaction_force", stored_reaction_force)
+			window.setValues("displacement", stored_displacement)
+			window.setValues("speed", stored_speed)
+		}
+		window.doStep(t, H);
+		time_last_window := t;
+		
+		out_condition_executed := empty map
+		
+	end function
+	
+	function getValues(ports)
+		var values = empty map
+		
+		if out_condition_executed == empty map then
+			if true then
+				stored_window_reaction_torque = window.getValues("reaction_torque")
+				stored_window_height = window.getValues("height")
+				out_condition_executed[cond1] := true
+			end if
+		end if
+		
+		if out_condition_executed[cond1] then
+			values["tau"] := - stored_window_reaction_torque
+			values["disp"] := stored_window_height * 100
+		end if
+		
+		return values
+	end function

+ 53 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/examples/window_sa_canonical.BASE.sa

@@ -0,0 +1,53 @@
+import PowerWindowModel
+
+module Window_SA
+
+semantic adaptation mealy reactive window_sa
+
+for fmu window
+
+input ports 	reaction_force,
+				displacement,
+				speed;
+
+output ports	disp;
+				tau;
+				
+in var 	stored_windowsa_reaction_force,
+		stored_windowsa_displacement,
+		stored_windowsa_speed;
+		
+in rules {
+	true -> {
+		stored_windowsa_reaction_force := window_sa.reaction_force;
+		stored_windowsa_displacement := window_sa.displacement;
+		stored_windowsa_speed := window_sa.speed;
+	} --> {
+		window.reaction_force := stored_windowsa_reaction_force; 
+		window.displacement := stored_windowsa_displacement; 
+		window.speed := stored_windowsa_speed;
+	};
+}
+
+control var time_last_window := 0
+
+control rules {
+	var e := t - time_last_window;
+	invoke_update_in(t=t, h=H, dt=0);
+	window.doStep(t, H);
+	time_last_window := t;
+	invoke_update_out(t=t, h=H, dt=0);
+}
+
+out var stored_window_reaction_torque,
+		stored_window_height;
+
+out rules {
+	true -> {
+		stored_window_reaction_torque := window.reaction_torque;
+		stored_window_height := window.height;
+	} --> { 
+		window_sa.tau := - stored_window_reaction_torque;
+		window_sa.disp := stored_window_height * 100;
+	};
+}