From df98762a3eaf183ff89ca312dfb84e3dce10d99b Mon Sep 17 00:00:00 2001 From: arun3688 Date: Fri, 11 Nov 2022 19:28:11 +0100 Subject: [PATCH] add modifier uncertainty.propagate (#9692) * allow parameters to tag as uncertainty.refine and treat as variable of interest * add modifier uncertainty.propagate for unmeasured variable of interest * expected output --- OMCompiler/Compiler/BackEnd/BackendDump.mo | 1 + OMCompiler/Compiler/BackEnd/DataReconciliation.mo | 2 +- OMCompiler/Compiler/FFrontEnd/FBuiltin.mo | 2 ++ OMCompiler/Compiler/FrontEnd/DAE.mo | 1 + OMCompiler/Compiler/FrontEnd/DAEDump.mo | 1 + OMCompiler/Compiler/FrontEnd/InstBinding.mo | 11 +++++++---- OMCompiler/Compiler/NFFrontEnd/NFBackendExtension.mo | 2 +- OMCompiler/Compiler/NFFrontEnd/NFBuiltin.mo | 2 +- OMCompiler/Compiler/NFFrontEnd/NFConvertDAE.mo | 1 + OMCompiler/Compiler/NFFrontEnd/NFModelicaBuiltin.mo | 3 ++- OMCompiler/Compiler/Template/AbsynToJuliaTV.mo | 1 + OMCompiler/Compiler/Template/DAEDumpTV.mo | 1 + OMCompiler/Compiler/Template/DAEDumpTpl.tpl | 1 + testsuite/flattening/modelica/scodeinst/Clock2.mo | 2 +- 14 files changed, 22 insertions(+), 9 deletions(-) diff --git a/OMCompiler/Compiler/BackEnd/BackendDump.mo b/OMCompiler/Compiler/BackEnd/BackendDump.mo index 5901e98a627..e953ffeaa4c 100644 --- a/OMCompiler/Compiler/BackEnd/BackendDump.mo +++ b/OMCompiler/Compiler/BackEnd/BackendDump.mo @@ -2820,6 +2820,7 @@ algorithm case(SOME(DAE.GIVEN())) then "uncertain=Uncertainty.given"; case(SOME(DAE.SOUGHT())) then "uncertain=Uncertainty.sought"; case(SOME(DAE.REFINE())) then "uncertain=Uncertainty.refine"; + case(SOME(DAE.PROPAGATE())) then "uncertain=Uncertainty.propagate"; end match; end optUncertainty; diff --git a/OMCompiler/Compiler/BackEnd/DataReconciliation.mo b/OMCompiler/Compiler/BackEnd/DataReconciliation.mo index 48a26ee7762..4db06912b9c 100644 --- a/OMCompiler/Compiler/BackEnd/DataReconciliation.mo +++ b/OMCompiler/Compiler/BackEnd/DataReconciliation.mo @@ -1569,7 +1569,7 @@ protected algorithm for var in BackendVariable.varList(shared.globalKnownVars) loop // check for param Vars, as we are only interested in causality = calculatedParameters - if BackendVariable.isRealParam(var) and BackendVariable.hasOpenModelicaBoundaryConditionAnnotation(var) then + if BackendVariable.isRealParam(var) and (BackendVariable.hasOpenModelicaBoundaryConditionAnnotation(var) or BackendVariable.varHasUncertainValueRefine(var)) then //print("\n knownsVars :" + anyString(var.bindExp)); lhs := BackendVariable.varExp(var); rhs := BackendVariable.varBindExpStartValueNoFail(var); diff --git a/OMCompiler/Compiler/FFrontEnd/FBuiltin.mo b/OMCompiler/Compiler/FFrontEnd/FBuiltin.mo index e036288012e..94688eabb17 100644 --- a/OMCompiler/Compiler/FFrontEnd/FBuiltin.mo +++ b/OMCompiler/Compiler/FFrontEnd/FBuiltin.mo @@ -202,6 +202,8 @@ protected constant list uncertaintyComps = { SCode.COMPONENT("sought",commonPrefixes, attrConst,Absyn.TPATH(Absyn.IDENT("EnumType"),NONE()),SCode.NOMOD(),SCode.noComment,NONE(),AbsynUtil.dummyInfo), SCode.COMPONENT("refine",commonPrefixes, + attrConst,Absyn.TPATH(Absyn.IDENT("EnumType"),NONE()),SCode.NOMOD(),SCode.noComment,NONE(),AbsynUtil.dummyInfo), + SCode.COMPONENT("propagate",commonPrefixes, attrConst,Absyn.TPATH(Absyn.IDENT("EnumType"),NONE()),SCode.NOMOD(),SCode.noComment,NONE(),AbsynUtil.dummyInfo)} "The Uncertainty enumeration" ; protected constant SCode.Element stateSelectType = SCode.CLASS("StateSelect",commonPrefixes,SCode.NOT_ENCAPSULATED(),SCode.NOT_PARTIAL(),SCode.R_ENUMERATION(), diff --git a/OMCompiler/Compiler/FrontEnd/DAE.mo b/OMCompiler/Compiler/FrontEnd/DAE.mo index b9c6e1ccef5..5b37b544832 100644 --- a/OMCompiler/Compiler/FrontEnd/DAE.mo +++ b/OMCompiler/Compiler/FrontEnd/DAE.mo @@ -565,6 +565,7 @@ public uniontype Uncertainty record GIVEN end GIVEN; record SOUGHT end SOUGHT; record REFINE end REFINE; + record PROPAGATE end PROPAGATE; end Uncertainty; public uniontype Distribution diff --git a/OMCompiler/Compiler/FrontEnd/DAEDump.mo b/OMCompiler/Compiler/FrontEnd/DAEDump.mo index 74f88a3f271..1d6a8ec04a5 100644 --- a/OMCompiler/Compiler/FrontEnd/DAEDump.mo +++ b/OMCompiler/Compiler/FrontEnd/DAEDump.mo @@ -524,6 +524,7 @@ algorithm case DAE.GIVEN() then "Uncertainty.given"; case DAE.SOUGHT() then "Uncertainty.sought"; case DAE.REFINE() then "Uncertainty.refine"; + case DAE.PROPAGATE() then "Uncertainty.propagate"; end match; end dumpUncertaintyStr; diff --git a/OMCompiler/Compiler/FrontEnd/InstBinding.mo b/OMCompiler/Compiler/FrontEnd/InstBinding.mo index 9ce6d0a7a54..d035354b771 100644 --- a/OMCompiler/Compiler/FrontEnd/InstBinding.mo +++ b/OMCompiler/Compiler/FrontEnd/InstBinding.mo @@ -87,14 +87,16 @@ public constant DAE.Type stateSelectType = },{}); public constant DAE.Type uncertaintyType = - DAE.T_ENUMERATION(NONE(),Absyn.IDENT(""),{"given","sought","refine"}, + DAE.T_ENUMERATION(NONE(),Absyn.IDENT(""),{"given","sought","refine","propagate"}, { DAE.TYPES_VAR("given",DAE.dummyAttrParam, - DAE.T_ENUMERATION(SOME(1),Absyn.IDENT(""),{"given","sought","refine"},{},{}),DAE.UNBOUND(),false,NONE()), + DAE.T_ENUMERATION(SOME(1),Absyn.IDENT(""),{"given","sought","refine","propagate"},{},{}),DAE.UNBOUND(),false,NONE()), DAE.TYPES_VAR("sought",DAE.dummyAttrParam, - DAE.T_ENUMERATION(SOME(2),Absyn.IDENT(""),{"given","sought","refine"},{},{}),DAE.UNBOUND(),false,NONE()), + DAE.T_ENUMERATION(SOME(2),Absyn.IDENT(""),{"given","sought","refine","propagate"},{},{}),DAE.UNBOUND(),false,NONE()), DAE.TYPES_VAR("refine",DAE.dummyAttrParam, - DAE.T_ENUMERATION(SOME(3),Absyn.IDENT(""),{"given","sought","refine"},{},{}),DAE.UNBOUND(),false,NONE()) + DAE.T_ENUMERATION(SOME(3),Absyn.IDENT(""),{"given","sought","refine","propagate"},{},{}),DAE.UNBOUND(),false,NONE()), + DAE.TYPES_VAR("propagate",DAE.dummyAttrParam, + DAE.T_ENUMERATION(SOME(4),Absyn.IDENT(""),{"given","sought","refine","propagate"},{},{}),DAE.UNBOUND(),false,NONE()) },{}); public constant DAE.Type distributionType = @@ -504,6 +506,7 @@ algorithm case (SOME(DAE.ENUM_LITERAL(name = Absyn.QUALIFIED(name = "Uncertainty", path = Absyn.IDENT("given"))))) then SOME(DAE.GIVEN()); case (SOME(DAE.ENUM_LITERAL(name = Absyn.QUALIFIED(name = "Uncertainty", path = Absyn.IDENT("sought"))))) then SOME(DAE.SOUGHT()); case (SOME(DAE.ENUM_LITERAL(name = Absyn.QUALIFIED(name = "Uncertainty", path = Absyn.IDENT("refine"))))) then SOME(DAE.REFINE()); + case (SOME(DAE.ENUM_LITERAL(name = Absyn.QUALIFIED(name = "Uncertainty", path = Absyn.IDENT("propagate"))))) then SOME(DAE.PROPAGATE()); else NONE(); end match; end getUncertainFromExpOption; diff --git a/OMCompiler/Compiler/NFFrontEnd/NFBackendExtension.mo b/OMCompiler/Compiler/NFFrontEnd/NFBackendExtension.mo index ecf7db6d654..1fc478fd938 100644 --- a/OMCompiler/Compiler/NFFrontEnd/NFBackendExtension.mo +++ b/OMCompiler/Compiler/NFFrontEnd/NFBackendExtension.mo @@ -1145,7 +1145,7 @@ public type StateSelect = enumeration(NEVER, AVOID, DEFAULT, PREFER, ALWAYS); type TearingSelect = enumeration(NEVER, AVOID, DEFAULT, PREFER, ALWAYS); - type Uncertainty = enumeration(GIVEN, SOUGHT, REFINE); + type Uncertainty = enumeration(GIVEN, SOUGHT, REFINE, PROPAGATE); uniontype Distribution record DISTRIBUTION diff --git a/OMCompiler/Compiler/NFFrontEnd/NFBuiltin.mo b/OMCompiler/Compiler/NFFrontEnd/NFBuiltin.mo index 6231db5461e..1e72d4f4744 100644 --- a/OMCompiler/Compiler/NFFrontEnd/NFBuiltin.mo +++ b/OMCompiler/Compiler/NFFrontEnd/NFBuiltin.mo @@ -355,7 +355,7 @@ constant Expression ASSERTIONLEVEL_ERROR = Expression.ENUM_LITERAL( ASSERTIONLEVEL_TYPE, "error", 2); constant Type UNCERTAINTY_TYPE = Type.ENUMERATION( - Absyn.IDENT("Uncertainty"), {"given", "sought", "refine"}); + Absyn.IDENT("Uncertainty"), {"given", "sought", "refine", "propagate"}); // Lookup tree for Clock. Generated by makeBuiltinLookupTree. constant LookupTree.Tree CLOCK_LOOKUP_TREE = LookupTree.Tree.NODE( diff --git a/OMCompiler/Compiler/NFFrontEnd/NFConvertDAE.mo b/OMCompiler/Compiler/NFFrontEnd/NFConvertDAE.mo index d80de3298bb..9941e912914 100644 --- a/OMCompiler/Compiler/NFFrontEnd/NFConvertDAE.mo +++ b/OMCompiler/Compiler/NFFrontEnd/NFConvertDAE.mo @@ -525,6 +525,7 @@ algorithm case "given" then DAE.Uncertainty.GIVEN(); case "sought" then DAE.Uncertainty.SOUGHT(); case "refine" then DAE.Uncertainty.REFINE(); + case "propagate" then DAE.Uncertainty.PROPAGATE(); else algorithm Error.assertion(false, getInstanceName() + " got unknown Uncertainty literal " + name, sourceInfo()); diff --git a/OMCompiler/Compiler/NFFrontEnd/NFModelicaBuiltin.mo b/OMCompiler/Compiler/NFFrontEnd/NFModelicaBuiltin.mo index 6fb6342db4f..eae24ebce2d 100644 --- a/OMCompiler/Compiler/NFFrontEnd/NFModelicaBuiltin.mo +++ b/OMCompiler/Compiler/NFFrontEnd/NFModelicaBuiltin.mo @@ -40,7 +40,8 @@ type StateSelect = enumeration( type Uncertainty = enumeration( given, sought, - refine + refine, + propagate ) annotation(__OpenModelica_builtin = true); partial class Clock diff --git a/OMCompiler/Compiler/Template/AbsynToJuliaTV.mo b/OMCompiler/Compiler/Template/AbsynToJuliaTV.mo index a94a17fb0db..169489cd95b 100644 --- a/OMCompiler/Compiler/Template/AbsynToJuliaTV.mo +++ b/OMCompiler/Compiler/Template/AbsynToJuliaTV.mo @@ -1889,6 +1889,7 @@ package DAE record GIVEN end GIVEN; record SOUGHT end SOUGHT; record REFINE end REFINE; + record PROPAGATE end PROPAGATE; end Uncertainty; uniontype Distribution diff --git a/OMCompiler/Compiler/Template/DAEDumpTV.mo b/OMCompiler/Compiler/Template/DAEDumpTV.mo index 9f80cefa4c0..22dd1b69763 100644 --- a/OMCompiler/Compiler/Template/DAEDumpTV.mo +++ b/OMCompiler/Compiler/Template/DAEDumpTV.mo @@ -873,6 +873,7 @@ package DAE record GIVEN end GIVEN; record SOUGHT end SOUGHT; record REFINE end REFINE; + record PROPAGATE end PROPAGATE; end Uncertainty; uniontype Distribution diff --git a/OMCompiler/Compiler/Template/DAEDumpTpl.tpl b/OMCompiler/Compiler/Template/DAEDumpTpl.tpl index bc42bcec7db..73f3876242b 100644 --- a/OMCompiler/Compiler/Template/DAEDumpTpl.tpl +++ b/OMCompiler/Compiler/Template/DAEDumpTpl.tpl @@ -525,6 +525,7 @@ match uncertainty case GIVEN(__) then 'Uncertainty.given' case SOUGHT(__) then 'Uncertainty.sought' case REFINE(__) then 'Uncertainty.refine' + case PROPAGATE(__) then 'Uncertainty.propagate' end dumpUncertainty; template dumpDistributionAttrOpt(Option distribution) diff --git a/testsuite/flattening/modelica/scodeinst/Clock2.mo b/testsuite/flattening/modelica/scodeinst/Clock2.mo index b6112bebf0f..c3aa7054c4e 100644 --- a/testsuite/flattening/modelica/scodeinst/Clock2.mo +++ b/testsuite/flattening/modelica/scodeinst/Clock2.mo @@ -14,7 +14,7 @@ end Clock2; // Result: // Error processing file: Clock2.mo -// [lib/omc/NFModelicaBuiltin.mo:46:1-48:10:writable] Notification: From here: +// [lib/omc/NFModelicaBuiltin.mo:47:1-49:10:writable] Notification: From here: // [flattening/modelica/scodeinst/Clock2.mo:7:1-9:10:writable] Error: An element with name Clock is already declared in this scope. // // # Error encountered! Exiting...