Browse Source

window_sa now propagates inputs to internal FMU, and gets its outputs, as any reactive SA should do. However, internal FMU does not perform computation accordingly.

Cláudio Gomes 7 years ago
parent
commit
9c9494e655

+ 20 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmus/FMI_Window_sa/FMI_Window_sa.c

@@ -84,6 +84,11 @@ fmi2Status fmi2SetReal(fmi2Component fc, const fmi2ValueReference vr[], size_t n
 	int isset[NUMBER_OF_REALS];
 	memset(isset, 0, sizeof(int)*NUMBER_OF_REALS);
 
+	printf("%s: setReal with vr: \n", comp->instanceName);
+	for (int i = 0; i < nvr; ++i) {
+		printf("vr[%d] = %d \n", i, vr[i]);
+	}
+
 	for (i = 0; i < nvr; i++)
 	{
 		comp->r[vr[i]] = value[i];
@@ -106,6 +111,21 @@ fmi2Status fmi2SetReal(fmi2Component fc, const fmi2ValueReference vr[], size_t n
 			comp->stored_windowsa_displacement = comp->r[_in_displacement];
 		}
 		/* If mealy do update_in and recursive call */
+
+		fmi2ValueReference vr_toWindow[3] = {3,4,0};
+		fmi2Real values[3];
+		values[0] = comp->stored_windowsa_reaction_force;
+		values[1] = comp->stored_windowsa_speed;
+		values[2] = comp->stored_windowsa_displacement;
+
+		comp->fmu[0].setReal(comp->c_fmu[0],vr_toWindow, 3, &values[0]);
+
+		fmi2ValueReference vr_fromWindow[2] = {5,2};
+		fmi2Real out_values[2];
+		comp->fmu[0].getReal(comp->c_fmu[0],vr_fromWindow, 2, &out_values[0]);
+		comp->stored_window_reaction_torque = out_values[0];
+		comp->stored_window_height = out_values[1];
+
 	}
 	//out_condition_executed := empty map
 	memset(comp->out_conditions_executed,0,sizeof(fmi2Boolean)*_NR_OF_OUT_CONDITIONS);

+ 4 - 3
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmus/FMI_loop_sa/FMI_loop_sa.c

@@ -21,7 +21,7 @@ Template for a  FMU
 
 #define MAX 100000
 
-#define NUMBER_OF_REALS 3
+#define NUMBER_OF_REALS 4
 #define NUMBER_OF_STRINGS 0
 #define NUMBER_OF_BOOLEANS 0
 #define NUMBER_OF_INTEGERS 0
@@ -33,7 +33,7 @@ Template for a  FMU
 #define _out_tau 0
 #define _in_speed 1
 #define _in_displacement 2
-
+#define _out_window_height 3
 
 #define _window_sa 0
 #define _obstacle 1
@@ -344,7 +344,7 @@ static fmi2Status DoInnerStep(fmi2Component fc, int index, fmi2Real currentCommP
 		toWindowSA[2] = fi->r[_in_speed];
 		printf("to window speed = %f\n", fi->r[_in_speed]);
 		fflush(stdout);
-		fi->fmu[_window_sa].setReal(fi->c_fmu[_window_sa], vr_to_window_sa, 3, &toWindowSA[0]);
+		fi->fmu[_window_sa].setReal(fi->c_fmu[_window_sa], vr_to_window_sa, 3, &toWindowSA[0]); // remember: this runs the new inputs by the internal FMU window.
 		fi->fmu[_window_sa].getReal(fi->c_fmu[_window_sa], vr_from_window, 2, &fromWindow[0]);
 
 		converged = is_close(fi->prev_disp, fromWindow[1], REL_TOL, ABS_TOL);
@@ -373,6 +373,7 @@ static fmi2Status DoInnerStep(fmi2Component fc, int index, fmi2Real currentCommP
 
 	if(1){
 		fi->r[_out_tau] = fromWindow[0];
+		fi->r[_out_window_height] = fromWindow[1];
 	}
 
 	return status;

+ 6 - 5
SemanticAdaptationForFMI/Experiments/power_window_case_study/fmus/FMI_loop_sa/test.c

@@ -49,8 +49,8 @@ int main(void) {
     	return -1;
     }
 
-    fmi2ValueReference vr_out_loop_sa[1] = {0};
-    fmi2Real r_out_loop_sa[1];
+    fmi2ValueReference vr_out_loop_sa[2] = {0,3};
+    fmi2Real r_out_loop_sa[2];
     fmi2ValueReference vr_toLoop[2] = {1,2}; // speed, displacement
 	fmi2Real toLoop[2];
 
@@ -67,13 +67,14 @@ int main(void) {
 		}
     	fmi2Flag = fmu_loop_sa.doStep(c_loop_sa, currentTime, STEP_SIZE, fmi2True);
     	fflush(stdout);
-    	if (fmu_loop_sa.getReal(c_loop_sa, vr_out_loop_sa, 1, &r_out_loop_sa[0]) != fmi2OK){
+    	if (fmu_loop_sa.getReal(c_loop_sa, vr_out_loop_sa, 2, &r_out_loop_sa[0]) != fmi2OK){
     		return 1;
 		}
 
-    	printf("%f,%f\n",
+    	printf("%f,%f,%f\n",
 						currentTime,
-						r_out_loop_sa[0]
+						r_out_loop_sa[0],
+						r_out_loop_sa[1]
 						);
 
     	currentTime += STEP_SIZE;