Claudio Gomes 7 лет назад
Родитель
Сommit
9fcc520591

+ 1 - 0
HintCO/model/Candidates.xcore

@@ -297,6 +297,7 @@ class PowerBondAdaptation extends UnitAdaptation {
 	refers PortInstance effort
 	refers PortInstance flow
 	refers OutputPortInstance pOut
+	refers InputPortInstance pIn
 	op PowerBondAdaptation getDual() {
 		var PowerBondAdaptation res = null
 		if (effort instanceof InputPortInstance && flow instanceof OutputPortInstance){

+ 30 - 2
HintCO/src-gen/ua/ansymo/hintco/HintcoPackage.java

@@ -2533,6 +2533,15 @@ public interface HintcoPackage extends EPackage {
 	 */
 	int POWER_BOND_ADAPTATION__POUT = UNIT_ADAPTATION_FEATURE_COUNT + 2;
 
+	/**
+	 * The feature id for the '<em><b>PIn</b></em>' reference.
+	 * <!-- begin-user-doc -->
+	 * <!-- end-user-doc -->
+	 * @generated
+	 * @ordered
+	 */
+	int POWER_BOND_ADAPTATION__PIN = UNIT_ADAPTATION_FEATURE_COUNT + 3;
+
 	/**
 	 * The feature id for the '<em><b>Name</b></em>' attribute.
 	 * <!-- begin-user-doc -->
@@ -2540,7 +2549,7 @@ public interface HintcoPackage extends EPackage {
 	 * @generated
 	 * @ordered
 	 */
-	int POWER_BOND_ADAPTATION__NAME = UNIT_ADAPTATION_FEATURE_COUNT + 3;
+	int POWER_BOND_ADAPTATION__NAME = UNIT_ADAPTATION_FEATURE_COUNT + 4;
 
 	/**
 	 * The number of structural features of the '<em>Power Bond Adaptation</em>' class.
@@ -2549,7 +2558,7 @@ public interface HintcoPackage extends EPackage {
 	 * @generated
 	 * @ordered
 	 */
-	int POWER_BOND_ADAPTATION_FEATURE_COUNT = UNIT_ADAPTATION_FEATURE_COUNT + 4;
+	int POWER_BOND_ADAPTATION_FEATURE_COUNT = UNIT_ADAPTATION_FEATURE_COUNT + 5;
 
 	/**
 	 * The operation id for the '<em>Adapted</em>' operation.
@@ -3702,6 +3711,17 @@ public interface HintcoPackage extends EPackage {
 	 */
 	EReference getPowerBondAdaptation_POut();
 
+	/**
+	 * Returns the meta object for the reference '{@link ua.ansymo.hintco.PowerBondAdaptation#getPIn <em>PIn</em>}'.
+	 * <!-- begin-user-doc -->
+	 * <!-- end-user-doc -->
+	 * @return the meta object for the reference '<em>PIn</em>'.
+	 * @see ua.ansymo.hintco.PowerBondAdaptation#getPIn()
+	 * @see #getPowerBondAdaptation()
+	 * @generated
+	 */
+	EReference getPowerBondAdaptation_PIn();
+
 	/**
 	 * Returns the meta object for the attribute '{@link ua.ansymo.hintco.PowerBondAdaptation#getName <em>Name</em>}'.
 	 * <!-- begin-user-doc -->
@@ -4546,6 +4566,14 @@ public interface HintcoPackage extends EPackage {
 		 */
 		EReference POWER_BOND_ADAPTATION__POUT = eINSTANCE.getPowerBondAdaptation_POut();
 
+		/**
+		 * The meta object literal for the '<em><b>PIn</b></em>' reference feature.
+		 * <!-- begin-user-doc -->
+		 * <!-- end-user-doc -->
+		 * @generated
+		 */
+		EReference POWER_BOND_ADAPTATION__PIN = eINSTANCE.getPowerBondAdaptation_PIn();
+
 		/**
 		 * The meta object literal for the '<em><b>Name</b></em>' attribute feature.
 		 * <!-- begin-user-doc -->

+ 27 - 0
HintCO/src-gen/ua/ansymo/hintco/PowerBondAdaptation.java

@@ -15,6 +15,7 @@ package ua.ansymo.hintco;
  *   <li>{@link ua.ansymo.hintco.PowerBondAdaptation#getEffort <em>Effort</em>}</li>
  *   <li>{@link ua.ansymo.hintco.PowerBondAdaptation#getFlow <em>Flow</em>}</li>
  *   <li>{@link ua.ansymo.hintco.PowerBondAdaptation#getPOut <em>POut</em>}</li>
+ *   <li>{@link ua.ansymo.hintco.PowerBondAdaptation#getPIn <em>PIn</em>}</li>
  *   <li>{@link ua.ansymo.hintco.PowerBondAdaptation#getName <em>Name</em>}</li>
  * </ul>
  *
@@ -101,6 +102,32 @@ public interface PowerBondAdaptation extends UnitAdaptation {
 	 */
 	void setPOut(OutputPortInstance value);
 
+	/**
+	 * Returns the value of the '<em><b>PIn</b></em>' reference.
+	 * <!-- begin-user-doc -->
+	 * <p>
+	 * If the meaning of the '<em>PIn</em>' reference isn't clear,
+	 * there really should be more of a description here...
+	 * </p>
+	 * <!-- end-user-doc -->
+	 * @return the value of the '<em>PIn</em>' reference.
+	 * @see #setPIn(InputPortInstance)
+	 * @see ua.ansymo.hintco.HintcoPackage#getPowerBondAdaptation_PIn()
+	 * @model
+	 * @generated
+	 */
+	InputPortInstance getPIn();
+
+	/**
+	 * Sets the value of the '{@link ua.ansymo.hintco.PowerBondAdaptation#getPIn <em>PIn</em>}' reference.
+	 * <!-- begin-user-doc -->
+	 * <!-- end-user-doc -->
+	 * @param value the new value of the '<em>PIn</em>' reference.
+	 * @see #getPIn()
+	 * @generated
+	 */
+	void setPIn(InputPortInstance value);
+
 	/**
 	 * Returns the value of the '<em><b>Name</b></em>' attribute.
 	 * <!-- begin-user-doc -->

+ 12 - 1
HintCO/src-gen/ua/ansymo/hintco/impl/HintcoPackageImpl.java

@@ -1100,13 +1100,22 @@ public class HintcoPackageImpl extends EPackageImpl implements HintcoPackage {
 		return (EReference)powerBondAdaptationEClass.getEStructuralFeatures().get(2);
 	}
 
+	/**
+	 * <!-- begin-user-doc -->
+	 * <!-- end-user-doc -->
+	 * @generated
+	 */
+	public EReference getPowerBondAdaptation_PIn() {
+		return (EReference)powerBondAdaptationEClass.getEStructuralFeatures().get(3);
+	}
+
 	/**
 	 * <!-- begin-user-doc -->
 	 * <!-- end-user-doc -->
 	 * @generated
 	 */
 	public EAttribute getPowerBondAdaptation_Name() {
-		return (EAttribute)powerBondAdaptationEClass.getEStructuralFeatures().get(3);
+		return (EAttribute)powerBondAdaptationEClass.getEStructuralFeatures().get(4);
 	}
 
 	/**
@@ -1303,6 +1312,7 @@ public class HintcoPackageImpl extends EPackageImpl implements HintcoPackage {
 		createEReference(powerBondAdaptationEClass, POWER_BOND_ADAPTATION__EFFORT);
 		createEReference(powerBondAdaptationEClass, POWER_BOND_ADAPTATION__FLOW);
 		createEReference(powerBondAdaptationEClass, POWER_BOND_ADAPTATION__POUT);
+		createEReference(powerBondAdaptationEClass, POWER_BOND_ADAPTATION__PIN);
 		createEAttribute(powerBondAdaptationEClass, POWER_BOND_ADAPTATION__NAME);
 		createEOperation(powerBondAdaptationEClass, POWER_BOND_ADAPTATION___GET_DUAL);
 
@@ -1510,6 +1520,7 @@ public class HintcoPackageImpl extends EPackageImpl implements HintcoPackage {
 		initEReference(getPowerBondAdaptation_Effort(), this.getPortInstance(), null, "effort", null, 0, 1, PowerBondAdaptation.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
 		initEReference(getPowerBondAdaptation_Flow(), this.getPortInstance(), null, "flow", null, 0, 1, PowerBondAdaptation.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
 		initEReference(getPowerBondAdaptation_POut(), this.getOutputPortInstance(), null, "pOut", null, 0, 1, PowerBondAdaptation.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
+		initEReference(getPowerBondAdaptation_PIn(), this.getInputPortInstance(), null, "pIn", null, 0, 1, PowerBondAdaptation.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
 		initEAttribute(getPowerBondAdaptation_Name(), theEcorePackage.getEString(), "name", null, 0, 1, PowerBondAdaptation.class, IS_TRANSIENT, IS_VOLATILE, !IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, IS_DERIVED, IS_ORDERED);
 
 		initEOperation(getPowerBondAdaptation__GetDual(), this.getPowerBondAdaptation(), "getDual", 0, 1, !IS_UNIQUE, IS_ORDERED);

+ 60 - 0
HintCO/src-gen/ua/ansymo/hintco/impl/PowerBondAdaptationImpl.java

@@ -38,6 +38,7 @@ import ua.ansymo.hintco.UnitInstance;
  *   <li>{@link ua.ansymo.hintco.impl.PowerBondAdaptationImpl#getEffort <em>Effort</em>}</li>
  *   <li>{@link ua.ansymo.hintco.impl.PowerBondAdaptationImpl#getFlow <em>Flow</em>}</li>
  *   <li>{@link ua.ansymo.hintco.impl.PowerBondAdaptationImpl#getPOut <em>POut</em>}</li>
+ *   <li>{@link ua.ansymo.hintco.impl.PowerBondAdaptationImpl#getPIn <em>PIn</em>}</li>
  *   <li>{@link ua.ansymo.hintco.impl.PowerBondAdaptationImpl#getName <em>Name</em>}</li>
  * </ul>
  *
@@ -74,6 +75,16 @@ public class PowerBondAdaptationImpl extends UnitAdaptationImpl implements Power
 	 */
 	protected OutputPortInstance pOut;
 
+	/**
+	 * The cached value of the '{@link #getPIn() <em>PIn</em>}' reference.
+	 * <!-- begin-user-doc -->
+	 * <!-- end-user-doc -->
+	 * @see #getPIn()
+	 * @generated
+	 * @ordered
+	 */
+	protected InputPortInstance pIn;
+
 	/**
 	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
 	 * <!-- begin-user-doc -->
@@ -217,6 +228,44 @@ public class PowerBondAdaptationImpl extends UnitAdaptationImpl implements Power
 			eNotify(new ENotificationImpl(this, Notification.SET, HintcoPackage.POWER_BOND_ADAPTATION__POUT, oldPOut, pOut));
 	}
 
+	/**
+	 * <!-- begin-user-doc -->
+	 * <!-- end-user-doc -->
+	 * @generated
+	 */
+	public InputPortInstance getPIn() {
+		if (pIn != null && pIn.eIsProxy()) {
+			InternalEObject oldPIn = (InternalEObject)pIn;
+			pIn = (InputPortInstance)eResolveProxy(oldPIn);
+			if (pIn != oldPIn) {
+				if (eNotificationRequired())
+					eNotify(new ENotificationImpl(this, Notification.RESOLVE, HintcoPackage.POWER_BOND_ADAPTATION__PIN, oldPIn, pIn));
+			}
+		}
+		return pIn;
+	}
+
+	/**
+	 * <!-- begin-user-doc -->
+	 * <!-- end-user-doc -->
+	 * @generated
+	 */
+	public InputPortInstance basicGetPIn() {
+		return pIn;
+	}
+
+	/**
+	 * <!-- begin-user-doc -->
+	 * <!-- end-user-doc -->
+	 * @generated
+	 */
+	public void setPIn(InputPortInstance newPIn) {
+		InputPortInstance oldPIn = pIn;
+		pIn = newPIn;
+		if (eNotificationRequired())
+			eNotify(new ENotificationImpl(this, Notification.SET, HintcoPackage.POWER_BOND_ADAPTATION__PIN, oldPIn, pIn));
+	}
+
 	/**
 	 * <!-- begin-user-doc -->
 	 * <!-- end-user-doc -->
@@ -318,6 +367,9 @@ public class PowerBondAdaptationImpl extends UnitAdaptationImpl implements Power
 			case HintcoPackage.POWER_BOND_ADAPTATION__POUT:
 				if (resolve) return getPOut();
 				return basicGetPOut();
+			case HintcoPackage.POWER_BOND_ADAPTATION__PIN:
+				if (resolve) return getPIn();
+				return basicGetPIn();
 			case HintcoPackage.POWER_BOND_ADAPTATION__NAME:
 				return getName();
 		}
@@ -341,6 +393,9 @@ public class PowerBondAdaptationImpl extends UnitAdaptationImpl implements Power
 			case HintcoPackage.POWER_BOND_ADAPTATION__POUT:
 				setPOut((OutputPortInstance)newValue);
 				return;
+			case HintcoPackage.POWER_BOND_ADAPTATION__PIN:
+				setPIn((InputPortInstance)newValue);
+				return;
 		}
 		super.eSet(featureID, newValue);
 	}
@@ -362,6 +417,9 @@ public class PowerBondAdaptationImpl extends UnitAdaptationImpl implements Power
 			case HintcoPackage.POWER_BOND_ADAPTATION__POUT:
 				setPOut((OutputPortInstance)null);
 				return;
+			case HintcoPackage.POWER_BOND_ADAPTATION__PIN:
+				setPIn((InputPortInstance)null);
+				return;
 		}
 		super.eUnset(featureID);
 	}
@@ -380,6 +438,8 @@ public class PowerBondAdaptationImpl extends UnitAdaptationImpl implements Power
 				return flow != null;
 			case HintcoPackage.POWER_BOND_ADAPTATION__POUT:
 				return pOut != null;
+			case HintcoPackage.POWER_BOND_ADAPTATION__PIN:
+				return pIn != null;
 			case HintcoPackage.POWER_BOND_ADAPTATION__NAME:
 				return NAME_EDEFAULT == null ? getName() != null : !NAME_EDEFAULT.equals(getName());
 		}

+ 2 - 2
HintCO/src/ua/ansymo/hintco/AdaptedFMUInstance.xtend

@@ -66,8 +66,8 @@ class AdaptedFMUInstance extends FmuInstance {
 				// Create new adapted output for the pOut port
 				adaptedOutPorts.put(adaptation.POut.identifier, new PowerOutAdaptedPort(adaptation, powerTermStorage, this))
 				
-				// Create adapted input for the pIn port. Not used for now.
-				// addInAdaptation(adaptation.PIn.identifier, new StoreAdaptedPort())
+				// Create adapted input for the pIn port.
+				addInAdaptation(adaptation.PIn.identifier, new StoreAdaptedPort())
 				
 			}
 		}

+ 18 - 1
HintCO/src/ua/ansymo/hintco/CandidatesGenerator.xtend

@@ -48,7 +48,7 @@ class CandidatesGenerator {
 		val adaptations = cs.eAllContents.filter(PowerBondAdaptation).toList
 		
 		for (pbAdaptation : adaptations){
-//			Assert.isTrue(pbAdaptation.PIn === null )
+			Assert.isTrue(pbAdaptation.PIn === null )
 			Assert.isTrue(pbAdaptation.POut === null)
 			val adaptedUnit = pbAdaptation.adapted as CosimUnitInstance
 			
@@ -62,8 +62,25 @@ class CandidatesGenerator {
 				adaptedUnit.ports.add(pOutPort)
 				pbAdaptation.POut = pOutPort
 			}
+			
+			// Create powerIn declaration
+			{
+				val pInId = pbAdaptation.effort.identifier + "_" + pbAdaptation.flow.identifier + "_pIn"
+				Assert.isTrue(!adaptedUnit.ports.exists[p | p.identifier == pInId])
+				
+				val pInPort = f.createInputPortInstance
+				pInPort.identifier = pInId	
+				adaptedUnit.ports.add(pInPort)
+				pbAdaptation.PIn = pInPort
+			}
 		}
 		
+		// Connect the power out with the power Ins
+		for (pbAdaptation : adaptations){
+			if (pbAdaptation.POut.valueTo.empty){
+				pbAdaptation.POut.valueTo.add(pbAdaptation.dual.PIn)
+			}
+		}
 	}
 	
 	def createVariantTree(Candidates cs){

+ 5 - 1
HintCO/src/ua/ansymo/hintco/PowerOutAdaptedPort.xtend

@@ -9,6 +9,7 @@ class PowerOutAdaptedPort implements IAdaptedOutputPort {
 	var protected AdaptedFMUInstance fmu
 	var protected PowerBondAdaptation adaptation;
 	var protected StoreAdaptedPort powerTermStorage;
+	double externalPowerTerm;
 	
 	new(PowerBondAdaptation a, StoreAdaptedPort s, AdaptedFMUInstance f) {
 		fmu = f
@@ -23,10 +24,13 @@ class PowerOutAdaptedPort implements IAdaptedOutputPort {
 			Assert.isTrue(adaptation.flow instanceof OutputPortInstance)
 			interPowerTerm = fmu.getInnerReal(adaptation.flow.identifier)
 		}
+		// Record the external power term now, as this is the value that the inner fmu got in its step.
+		// If this value were obtained in the getReal operation, it might have been updated already, which makes it wrong.
+		externalPowerTerm = powerTermStorage.storedVal
 	}
 	
 	override getReal() {
-		interPowerTerm*powerTermStorage.storedVal
+		interPowerTerm*externalPowerTerm
 	}
 	
 	override startStep() {

+ 3 - 3
HintCO/test/ua/ansymo/hintco/test/CandidatesGeneratorTest.xtend

@@ -281,13 +281,13 @@ class CandidatesGeneratorTest {
 			[ns, vId, constraints, cs | ])
 		generator.processAdaptations(src)
 		
-//		val plant = findIded("EMAPlantNoLoad_FixedEuler_1Em6", src) as CosimUnitInstance
+		val plant = findIded("EMAPlantNoLoad_FixedEuler_1Em6", src) as CosimUnitInstance
 		val sensor = findIded("LoadNSensor_FixedEuler_1Em6", src) as CosimUnitInstance	
 		
 		assertTrue((sensor.adaptation as PowerBondAdaptation).POut !== null)
 		
-//		val pIn = (plant.adaptation as PowerBondAdaptation).PIn
-//		assertTrue(pIn.valueFrom == (sensor.adaptation as PowerBondAdaptation).POut)
+		val pIn = (plant.adaptation as PowerBondAdaptation).PIn
+		assertTrue(pIn.valueFrom == (sensor.adaptation as PowerBondAdaptation).POut)
 		
 		generator.createVariantTree(src)
 		generator.generateVariants(src, 1)

+ 2 - 2
HintCO/test/ua/ansymo/hintco/test/CosimRunnerTest.xtend

@@ -228,8 +228,8 @@ class CosimRunnerTest {
 	@Test
 	@Ignore // Because it only works on windows.
 	def void executeCosimulationTestDoubleLoopPowerBond(){
-		System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "debug")
-		System.setProperty("org.slf4j.simpleLogger.logFile", "powerbond.log")
+		//System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "debug")
+		//System.setProperty("org.slf4j.simpleLogger.logFile", "powerbond.log")
 		val resultsDirPath = "results-gen/cosimTestDLoopPBond"
 		val loader = new ModelStorage()
 		val runner = new CosimRunner(new OutputProcessor(resultsDirPath), new FmuLoader)