Browse Source

Added an fmu and fixed minor code gen issues

Casper Thule 4 years ago
parent
commit
e7e475f4ea

BIN
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window/Window.fmu


BIN
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window/Window.fmu.bu


+ 8 - 21
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window/correct/modelDescription.xml

@@ -1,36 +1,23 @@
-<?xml version="1.0" encoding="UTF-8"?><fmiModelDescription fmiVersion="2.0" guid="124d182d-3cfe-4fa6-bb9e-97e1bbb40fb4" modelName="WindowSA" variableNamingConvention="flat">
+<?xml version="1.0" encoding="UTF-8"?><fmiModelDescription fmiVersion="2.0" guid="ea92ae6c-f37d-482c-b875-ca0ac374128b" modelName="WindowSA" variableNamingConvention="flat">
     <ModelVariables>
-        <ScalarVariable causality="output" name="disp" valueReference="0" variability="continuous">
+        <ScalarVariable causality="input" name="reaction_force" valueReference="0" variability="continuous">
             <Real/>
         </ScalarVariable>
         <ScalarVariable causality="input" name="displacement" valueReference="1" variability="continuous">
-            <Real start="0.0"/>
-        </ScalarVariable>
-        <ScalarVariable causality="output" name="friction" valueReference="2" variability="continuous">
             <Real/>
         </ScalarVariable>
-        <ScalarVariable causality="input" name="reaction_force" valueReference="3" variability="continuous">
-            <Real start="0.0"/>
-        </ScalarVariable>
-        <ScalarVariable causality="input" name="speed" valueReference="4" variability="continuous">
-            <Real start="0.0"/>
-        </ScalarVariable>
-        <ScalarVariable causality="output" name="tau" valueReference="5" variability="continuous">
+        <ScalarVariable causality="input" name="speed" valueReference="2" variability="continuous">
             <Real/>
         </ScalarVariable>
-        <ScalarVariable causality="local" name="v" valueReference="6" variability="continuous">
+        <ScalarVariable causality="output" name="disp" valueReference="3" variability="continuous">
             <Real/>
         </ScalarVariable>
-        <ScalarVariable causality="parameter" name="b" valueReference="7" variability="fixed">
-            <Real start="10.0"/>
-        </ScalarVariable>
-        <ScalarVariable causality="parameter" name="r" valueReference="8" variability="fixed">
-            <Real start="0.11"/>
+        <ScalarVariable causality="output" name="tau" valueReference="4" variability="continuous">
+            <Real/>
         </ScalarVariable>
     </ModelVariables>
     <Outputs>
-        <Unknown index="1"/>
-        <Unknown index="3"/>
-        <Unknown index="6"/>
+        <Unknown index="4"/>
+        <Unknown index="5"/>
     </Outputs>
 </fmiModelDescription>

+ 54 - 51
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window/correct/windowSA.cpp

@@ -1,27 +1,34 @@
-#include "windowSA.h"
+#include "WindowSA.h"
 
 namespace adaptation 
 {
-	WindowSA::WindowSA(shared_ptr<string> resourceLocation) : SemanticAdaptation(createInputRules(),createOutputRules())
+	WindowSA::WindowSA(shared_ptr<string> resourceLocation, const fmi2CallbackFunctions* functions) : 
+		SemanticAdaptation(resourceLocation, createInputRules(),createOutputRules(), functions)
 	{
-		stored_window_reaction_torque = 0.0;
-		stored_window_height = 0.0;
-		
+		this->stored_window_reaction_torque = 0.0;
+		this->stored_window_height = 0.0;
 		this->stored_windowsa_reaction_force = 0.0;
 		this->stored_windowsa_displacement = 0.0;
 		this->stored_windowsa_speed = 0.0;
 		
-		this->displacement = 0.0;
-		this->reaction_force = 0.0;
-		this->speed = 0.0;
-		this->b = 10.0;
-		this->r = 0.11;
-		
 		const char* path = Fmu::combinePath(resourceLocation, make_shared<string>("Window.fmu"))->c_str();
 		auto windowFmu = make_shared<fmi2::Fmu>(path);
 		windowFmu->initialize();
-		this->window = windowFmu->instantiate("Window",fmi2CoSimulation, "{29e3eae4-7ed5-4ccc-a0e7-7d8198e20bc0}", true, true, make_shared<Callback>()); 
+		this->window = windowFmu->instantiate("window",fmi2CoSimulation, "{efb4a002-4c0c-487b-8816-c0311d2f04d9}", true, true, make_shared<Callback>()); 
+	}
+	
+	void WindowSA::initialize()
+	{
+		const char* path = Fmu::combinePath(resourceLocation, make_shared<string>("Window.fmu"))->c_str();
+		auto windowFmu = make_shared<fmi2::Fmu>(*path);
+		windowFmu->initialize();
+		this->window = windowFmu->instantiate("window",fmi2CoSimulation, "{efb4a002-4c0c-487b-8816-c0311d2f04d9}", true, true, shared_from_this());
+		
+		if(this->window->component == NULL)
+			this->lastErrorState = fmi2Fatal;
+		this->instances->push_back(this->window);
 	}
+	
 	WindowSA::~WindowSA()
 	{
 	}
@@ -31,19 +38,15 @@ namespace adaptation
 		return this;
 	}
 	
-	double  WindowSA::getFmiValueReal(fmi2ValueReference id)
+	double WindowSA::getFmiValueReal(fmi2ValueReference id)
 	{
 		switch (id)
 		{
-			case WINDOWDISP:
+			case WINDOWSADISP:
 			{
 				return this->disp;
 			}
-			case WINDOWFRICTION:
-			{
-				return this->friction;
-			}
-			case WINDOWTAU:
+			case WINDOWSATAU:
 			{
 				return this->tau;
 			}
@@ -55,17 +58,17 @@ namespace adaptation
 		
 	}
 	
-	string  WindowSA::getFmiValueString(fmi2ValueReference id)
+	string WindowSA::getFmiValueString(fmi2ValueReference id)
 	{
 		return "";
 	}
 	
-	int  WindowSA::getFmiValueInteger(fmi2ValueReference id)
+	int WindowSA::getFmiValueInteger(fmi2ValueReference id)
 	{
 		return 0;
 	}
 	
-	bool  WindowSA::getFmiValueBoolean(fmi2ValueReference id)
+	bool WindowSA::getFmiValueBoolean(fmi2ValueReference id)
 	{
 		return false;
 	}
@@ -74,19 +77,19 @@ namespace adaptation
 	{
 		switch (id)	
 			{
-				case WINDOWDISPLACEMENT:
+				case WINDOWSAREACTION_FORCE:
 				{
-					this->displacement = value;
-					this->isSetdisplacement = true;
+					this->reaction_force = value;
+					this->isSetreaction_force = true;
 					break;
 				}
-				case WINDOWREACTION_FORCE:
+				case WINDOWSADISPLACEMENT:
 				{
-					this->reaction_force = value;
-					this->isSetreaction_force = true;
+					this->displacement = value;
+					this->isSetdisplacement = true;
 					break;
 				}
-				case WINDOWSPEED:
+				case WINDOWSASPEED:
 				{
 					this->speed = value;
 					this->isSetspeed = true;
@@ -145,29 +148,29 @@ namespace adaptation
 	}
 	shared_ptr<list<Rule<WindowSA>>> WindowSA::createInputRules()
 	{
-		auto list = make_shared<list<Rule<WindowSA>>>()
+		auto list = make_shared<std::list<Rule<WindowSA>>>();
 		
 		list->push_back(
 			(Rule<WindowSA>){
-				&WindowSA::in_rule_condition1();,
-				&WindowSA::in_rule_body1();
-				&WindowSA::in_rule_flush1();
+				&WindowSA::in_rule_condition1(),
+				&WindowSA::in_rule_body1(),
+				&WindowSA::in_rule_flush1()
 			});
 		
 		
 		list->push_back(
 			(Rule<WindowSA>){
-				&WindowSA::in_rule_condition2();,
-				&WindowSA::in_rule_body2();
-				&WindowSA::in_rule_flush2();
+				&WindowSA::in_rule_condition2(),
+				&WindowSA::in_rule_body2(),
+				&WindowSA::in_rule_flush2()
 			});
 		
 		
 		list->push_back(
 			(Rule<WindowSA>){
-				&WindowSA::in_rule_condition3();,
-				&WindowSA::in_rule_body3();
-				&WindowSA::in_rule_flush3();
+				&WindowSA::in_rule_condition3(),
+				&WindowSA::in_rule_body3(),
+				&WindowSA::in_rule_flush3()
 			});
 		
 		
@@ -176,46 +179,46 @@ namespace adaptation
 	}
 	
 	
-	void windowSA::executeInternalControlFlow(double h, double dt)
+	void WindowSA::executeInternalControlFlow(double h, double dt)
 	{
-		this->doStep(window,h,dt);
+		this->do_step(window,h,dt);
 	}
 	
 	bool WindowSA::out_rule_condition1(){
 		return true;
 	}
 	void WindowSA::out_rule_body1(){
-		this->stored_window_reaction_torque = getValueReal(window,WINDOWTAU);
+		this->stored_window_reaction_torque = getValueDouble(window,WINDOWREACTION_TORQUE);
 	}
 	void WindowSA::out_rule_flush1(){
-		this->tau = -this->stored_window_reaction_torque;
+		this->tau = this->stored_window_reaction_torque;
 	}
 	bool WindowSA::out_rule_condition2(){
 		return true;
 	}
 	void WindowSA::out_rule_body2(){
-		this->stored_window_height = getValueReal(window,WINDOWDISP);
+		this->stored_window_height = getValueDouble(window,WINDOWHEIGHT);
 	}
 	void WindowSA::out_rule_flush2(){
 		this->disp = this->stored_window_height * 100;
 	}
 	shared_ptr<list<Rule<WindowSA>>> WindowSA::createOutputRules()
 	{
-		auto list = make_shared<list<Rule<WindowSA>>>()
+		auto list = make_shared<std::list<Rule<WindowSA>>>();
 		
 		list->push_back(
 			(Rule<WindowSA>){
-				&WindowSA::out_rule_condition1();,
-				&WindowSA::out_rule_body1();
-				&WindowSA::out_rule_flush1();
+				&WindowSA::out_rule_condition1(),
+				&WindowSA::out_rule_body1(),
+				&WindowSA::out_rule_flush1()
 			});
 		
 		
 		list->push_back(
 			(Rule<WindowSA>){
-				&WindowSA::out_rule_condition2();,
-				&WindowSA::out_rule_body2();
-				&WindowSA::out_rule_flush2();
+				&WindowSA::out_rule_condition2(),
+				&WindowSA::out_rule_body2(),
+				&WindowSA::out_rule_flush2()
 			});
 		
 		

+ 87 - 67
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window/correct/windowSA.h

@@ -1,72 +1,92 @@
-#include "SemanticAdaptation.h"
-#include <memory>
-#include "Fmu.h"
 
-using namespace std;
-using namespace fmi2;
+	#ifndef SRC_WINDOWSA_H
+	#define SRC_WINDOWSA_H
 
-namespace adaptation
-{
-
-	class WindowSA : public SemanticAdaptation<WindowSA>{
-		public:
-			WindowSA(shared_ptr<string> resourceLocation);
-			virtual ~WindowSA();
-			
-			void setFmiValue(fmi2ValueReference id, int value);
-			void setFmiValue(fmi2ValueReference id, bool value);
-			void setFmiValue(fmi2ValueReference id, double value);
+	#include "SemanticAdaptation.h"
+	#include <memory>
+	#include "Fmu.h"
+	
+	using namespace std;
+	using namespace fmi2;
+	
+	namespace adaptation
+	{
 		
-			int getFmiValueInteger(fmi2ValueReference id);
-			bool getFmiValueBoolean(fmi2ValueReference id);
-			double getFmiValueDouble(fmi2ValueReference id);
-		private:
-			
-			WindowSA* getRuleThis();
-			
-			/*in rules*/
-			bool in_rule_condition1();
-			void in_rule_body1();
-			void in_rule_flush1();
-			bool in_rule_condition2();
-			void in_rule_body2();
-			void in_rule_flush2();
-			bool in_rule_condition3();
-			void in_rule_body3();
-			void in_rule_flush3();
-			shared_ptr<list<Rule<WindowSA>>> createInputRules();
-			
-			/*out rules*/
-			bool out_rule_condition1();
-			void out_rule_body1();
-			void out_rule_flush1();
-			bool out_rule_condition2();
-			void out_rule_body2();
-			void out_rule_flush2();
-			shared_ptr<list<Rule<WindowSA>>> createOutputRules();
-			
-			void executeInternalControlFlow(double h, double dt);
-			
-			shared_ptr<FmuComponent> window;
-			
-			double disp;
-			double displacement;
-			bool isSetdisplacement;
-			double friction;
-			double reaction_force;
-			bool isSetreaction_force;
-			double speed;
-			bool isSetspeed;
-			double tau;
-			double v;
-			double b;
-			double r;
-			
-			double stored_window_reaction_torque;
-			double stored_window_height;
+		#define WINDOWDISPLACEMENT 0
+		#define WINDOWFRICTION 1
+		#define WINDOWHEIGHT 2
+		#define WINDOWREACTION_FORCE 3
+		#define WINDOWREACTION_TORQUE 4
+		#define WINDOWSPEED 5
+		#define WINDOWV 6
+		#define WINDOWB 7
+		#define WINDOWR 8
+		
+		#define WINDOWSAREACTION_FORCE 0
+		#define WINDOWSADISPLACEMENT 1
+		#define WINDOWSASPEED 2
+		#define WINDOWSADISP 3
+		#define WINDOWSATAU 4
+	
+		class WindowSA : public SemanticAdaptation<WindowSA>, public enable_shared_from_this<WindowSA>
+		{
+			public:
+				WindowSA(shared_ptr<string> resourceLocation, const fmi2CallbackFunctions* functions);
+				void initialize();
+				virtual ~WindowSA();
+				
+				void setFmiValue(fmi2ValueReference id, int value);
+				void setFmiValue(fmi2ValueReference id, bool value);
+				void setFmiValue(fmi2ValueReference id, double value);
+				void setFmiValue(fmi2ValueReference id, string value);
 			
-			double stored_windowsa_reaction_force;
-			double stored_windowsa_displacement;
-			double stored_windowsa_speed;
+				int getFmiValueInteger(fmi2ValueReference id);
+				bool getFmiValueBoolean(fmi2ValueReference id);
+				double getFmiValueReal(fmi2ValueReference id);
+				string getFmiValueString(fmi2ValueReference id);
+				
+			private:
+				
+				WindowSA* getRuleThis();
+				
+				/*in rules*/
+				bool in_rule_condition1();
+				void in_rule_body1();
+				void in_rule_flush1();
+				bool in_rule_condition2();
+				void in_rule_body2();
+				void in_rule_flush2();
+				bool in_rule_condition3();
+				void in_rule_body3();
+				void in_rule_flush3();
+				shared_ptr<list<Rule<WindowSA>>> createInputRules();;
+				
+				/*out rules*/
+				bool out_rule_condition1();
+				void out_rule_body1();
+				void out_rule_flush1();
+				bool out_rule_condition2();
+				void out_rule_body2();
+				void out_rule_flush2();
+				shared_ptr<list<Rule<WindowSA>>> createOutputRules();;
+				
+				void executeInternalControlFlow(double h, double dt);;
+				
+				shared_ptr<FmuComponent> window;
+				
+				double reaction_force;
+				bool isSetreaction_force;
+				double displacement;
+				bool isSetdisplacement;
+				double speed;
+				bool isSetspeed;
+				double disp;
+				double tau;
+				
+				double stored_window_reaction_torque;
+				double stored_window_height;
+				double stored_windowsa_reaction_force;
+				double stored_windowsa_displacement;
+				double stored_windowsa_speed;
+		};
 	}
-}

+ 0 - 30
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window/modelDescription.xml

@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<fmiModelDescription fmiVersion="2.0" modelName="SingleWatertank" guid="{cfc65592-9ece-4563-9705-1581b6e7071c}" generationTool="20-sim" numberOfEventIndicators="0" copyright="Controllab Products B.V." license="-">
-<CoSimulation modelIdentifier="SingleWatertank" needsExecutionTool="false" canHandleVariableCommunicationStepSize="true" canInterpolateInputs="false" maxOutputDerivativeOrder="0" canRunAsynchronuously="false" canBeInstantiatedOnlyOncePerProcess="true" canNotUseMemoryManagementFunctions="true" canGetAndSetFMUstate="false" canSerializeFMUstate="false" providesDirectionalDerivative="false" />
-
-<ModelVariables>
-<ScalarVariable name="reaction_force" valueReference="1" variability="continuous" causality="input">
-<Real start="0.0" />
-</ScalarVariable>
-<ScalarVariable name="displacement" valueReference="2" variability="continuous" causality="input">
-<Real start="0.0" />
-</ScalarVariable>
-<ScalarVariable name="speed" valueReference="3" variability="continuous" causality="input">
-<Real start="0.0" />
-</ScalarVariable>
-
-<ScalarVariable name="disp" valueReference="4" variability="continuous" causality="output">
-<Real />
-</ScalarVariable>
-<ScalarVariable name="tau" valueReference="5" variability="continuous" causality="output">
-<Real />
-</ScalarVariable>
-
-</ModelVariables>
-<ModelStructure>
-<Outputs>
-<Unknown index="4" />
-<Unknown index="5" />
-</Outputs>
-</ModelStructure>
-</fmiModelDescription>

+ 11 - 9
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/CppGenerator.xtend

@@ -294,6 +294,8 @@ class CppGenerator extends SemanticAdaptationGenerator {
 						«ENDFOR»
 				};
 			}
+			
+			#endif
 		''';
 	}
 
@@ -309,16 +311,11 @@ class CppGenerator extends SemanticAdaptationGenerator {
 				«FOR v : globalVariables.entrySet»
 					this->«(v.key)» = «v.value.value»;
 				«ENDFOR»
-				
-				const char* path = Fmu::combinePath(resourceLocation, make_shared<string>("«fmuTypeName».fmu"))->c_str();
-				auto «fmuName»Fmu = make_shared<fmi2::Fmu>(path);
-				«fmuName»Fmu->initialize();
-				this->«fmuName» = «fmuName»Fmu->instantiate("«fmuName»",fmi2CoSimulation, "«guid»", true, true, make_shared<Callback>()); 
 			}
 			
 			void «adapClassName»::initialize()
 			{
-				const char* path = Fmu::combinePath(resourceLocation, make_shared<string>("«fmuTypeName».fmu"))->c_str();
+				auto path = Fmu::combinePath(resourceLocation, make_shared<string>("«fmuTypeName».fmu"));
 				auto «fmuName»Fmu = make_shared<fmi2::Fmu>(*path);
 				«fmuName»Fmu->initialize();
 				this->«fmuName» = «fmuName»Fmu->instantiate("«fmuName»",fmi2CoSimulation, "«guid»", true, true, shared_from_this());
@@ -452,6 +449,11 @@ class CppGenerator extends SemanticAdaptationGenerator {
 	def String SplitAtSpaceAndRemoveFirst(String content) {
 		content.substring(content.indexOf(" ") + 1, content.length);
 	}
+	
+	def String removeEmptyArgumentParenthesis(String content)
+	{
+		return	content.substring(0,content.length-2);
+	}
 
 	/*
 	 * Compiles the source file functions <in/out>_rule_<condition, body, flush>.
@@ -480,9 +482,9 @@ class CppGenerator extends SemanticAdaptationGenerator {
 					'''
 						list->push_back(
 							(Rule<«adaptationClassName»>){
-								&«adaptationClassName»::«visitor.functionSignatures.get(i).SplitAtSpaceAndRemoveFirst»,
-								&«adaptationClassName»::«visitor.functionSignatures.get(i+1).SplitAtSpaceAndRemoveFirst»,
-								&«adaptationClassName»::«visitor.functionSignatures.get(i+2).SplitAtSpaceAndRemoveFirst»
+								&«adaptationClassName»::«visitor.functionSignatures.get(i).SplitAtSpaceAndRemoveFirst.removeEmptyArgumentParenthesis»,
+								&«adaptationClassName»::«visitor.functionSignatures.get(i+1).SplitAtSpaceAndRemoveFirst.removeEmptyArgumentParenthesis»,
+								&«adaptationClassName»::«visitor.functionSignatures.get(i+2).SplitAtSpaceAndRemoveFirst.removeEmptyArgumentParenthesis»
 							});
 						
 					''');