diff --git a/Compiler/BackEnd/BackendVariable.mo b/Compiler/BackEnd/BackendVariable.mo index 3a3b517d172..2d42c131526 100644 --- a/Compiler/BackEnd/BackendVariable.mo +++ b/Compiler/BackEnd/BackendVariable.mo @@ -2048,6 +2048,17 @@ algorithm end match; end getVarDirection; +public function getVarNominalValue " + Returns the DAE.NominalValue or default value of a variable." + input BackendDAE.Var InVar; + output DAE.Exp nom; +algorithm + nom := match(InVar) + local Option attr; + case(BackendDAE.VAR(values = attr)) then DAEUtil.getNominalAttr(attr); + end match; +end varNominalValueFail; + public function isVarOnTopLevelAndOutput "and has the DAE.VarDirection = OUTPUT The check for top-model is done by spliting the name at \'.\' and diff --git a/Compiler/BackEnd/DynamicOptimization.mo b/Compiler/BackEnd/DynamicOptimization.mo index cd3f11bcb55..8b20e55ae61 100644 --- a/Compiler/BackEnd/DynamicOptimization.mo +++ b/Compiler/BackEnd/DynamicOptimization.mo @@ -252,19 +252,23 @@ output Option mayer; algorithm mayer := match(InVarlst, Inmayer) local list varlst; BackendDAE.Var v; - DAE.Exp e, e2, e3; Option opte; DAE.ComponentRef cr; + DAE.Exp e, e2, e3, nom; Option opte; DAE.ComponentRef cr; case({},NONE()) then NONE(); case({},opte as SOME(e)) then opte; case(v::varlst, SOME(e)) equation + nom = BackendVariable.getVarNominalValue(v); cr = BackendVariable.varCref(v); e2 = DAE.CREF(cr, DAE.T_REAL_DEFAULT); + e2 = Expression.expDiv(e2, nom); e3 = Expression.expAdd(e,e2); opte = SOME(e3); then findMayerTerm2(varlst, opte); case(v::varlst, NONE()) equation + nom = BackendVariable.getVarNominalValue(v); cr = BackendVariable.varCref(v); e2 = DAE.CREF(cr, DAE.T_REAL_DEFAULT); + e2 = Expression.expDiv(e2, nom); opte = SOME(e2); then findMayerTerm2(varlst, opte); else then NONE();