Browse Source

fixed bugs in canonical generation: step size should have an explicit type, and ctrl rules block of single inner fmu should not use min.

Claudio Gomes 5 years ago
parent
commit
760b2913dc

+ 18 - 8
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.canonical/src/be/uantwerpen/ansymo/semanticadaptation/cg/canonical/SemanticAdaptationCanonicalGenerator.xtend

@@ -411,19 +411,28 @@ class SemanticAdaptationCanonicalGenerator {
 			throw new Exception("Does not make sense. At least one inner FMU is expected.")
 		}
 		
-		val minExpression = SemanticAdaptationFactory.eINSTANCE.createMin()
+		var Expression returnExpression = null
 		
-		Log.println("Creating min(...) expression with the following arguments:")
-		
-		for(varDecl : stepVariables){
+		if (stepVariables.size == 1){
 			val varRef = SemanticAdaptationFactory.eINSTANCE.createVariable()
-			varRef.ref = varDecl
-			minExpression.args.add(varRef)
-			Log.println(varDecl.name)
+			varRef.ref = stepVariables.first
+			returnExpression = varRef
+			Log.println("Single inner fmu: return " + stepVariables.first.name)
+		} else {
+			Log.println("Creating min(...) expression with the following arguments:")
+			
+			val minExpression = SemanticAdaptationFactory.eINSTANCE.createMin()
+			for(varDecl : stepVariables){
+				val varRef = SemanticAdaptationFactory.eINSTANCE.createVariable()
+				varRef.ref = varDecl
+				minExpression.args.add(varRef)
+				Log.println(varDecl.name)
+			}
+			returnExpression = minExpression
 		}
 		
 		rule.returnstatement = SemanticAdaptationFactory.eINSTANCE.createReturnStatement()
-		rule.returnstatement.expr = minExpression
+		rule.returnstatement.expr = returnExpression
 		
 		Log.pop("appendReturnCosimStep")
 	}
@@ -441,6 +450,7 @@ class SemanticAdaptationCanonicalGenerator {
 		val step_var = SemanticAdaptationFactory.eINSTANCE.createSingleVarDeclaration()		
 		step_var.name = "H_" + fmu.name
 		step_var.expr = doStep
+		step_var.type = "Real"
 		
 		val step_decl = SemanticAdaptationFactory.eINSTANCE.createDeclaration()
 		step_decl.declarations.add(step_var)

+ 6 - 16
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/CppGenerator.xtend

@@ -163,6 +163,7 @@ class CppGenerator {
 			var inVars = if(inRuleBlock !== null) compileRuleBlockVars(inRuleBlock.globalInVars, params);
 			var outVars = if(outRuleBlock !== null) compileRuleBlockVars(outRuleBlock.globalOutVars, params);
 			val crtlVars = if(crtlRuleBlock !== null) compileRuleBlockVars(crtlRuleBlock.globalCtrlVars, params);
+			
 			/*
 			 * Support for source dependency: output ports tau <- loop_sa.tau
 			 * Only carried out for outVars.
@@ -231,23 +232,12 @@ class CppGenerator {
 
 				// Compile the Control Rules. These might use the out vars, so pass these along.
 				val crtlRules = if(adap.control !== null) adap.control else null;
-	  
-																						 
-				val crtlRuleResult = compileControlRuleBlock(crtlRules, adapClassName, adapInteralRefName,
 																						 
-				  
-				  
-			
-							
-					mappedScalarVariables, SASVs, params, if(inVars !== null) inVars.value else null,
-											 
-					if(outVars !== null) outVars.value else null, if(crtlVars !== null) crtlVars.value else null);
-				 
-					  
-													 
-													  
-	 
-	 
+				val crtlRuleResult = compileControlRuleBlock(crtlRules, adapClassName, adapInteralRefName, 
+																mappedScalarVariables, SASVs, params, 
+																if(inVars !== null) inVars.value else null,
+											 					if(outVars !== null) outVars.value else null, 
+											 					if(crtlVars !== null) crtlVars.value else null);
 
 				/*
 				 * Compile the constructor, destructor and initialize functions

+ 0 - 4
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/FmuGenerator.xtend

@@ -166,10 +166,6 @@ class FmuGenerator {
 				if (status != fmi2OK)
 					return status;
 		
-				status = g_adaptation->flushAllEnabledOutRules();
-				if (status != fmi2OK)
-					return status;
-		
 				for (int i = 0; i < nvr; i++)
 				{
 					value[i] = ((*g_adaptation).*getter)(vr[i]);