Skip to content

Commit

Permalink
add modifier uncertainty.propagate (#9692)
Browse files Browse the repository at this point in the history
* allow parameters to tag as uncertainty.refine and treat as variable of interest

* add modifier uncertainty.propagate for unmeasured variable of interest

* expected output
  • Loading branch information
arun3688 committed Nov 11, 2022
1 parent 4923608 commit df98762
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 9 deletions.
1 change: 1 addition & 0 deletions OMCompiler/Compiler/BackEnd/BackendDump.mo
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/BackEnd/DataReconciliation.mo
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions OMCompiler/Compiler/FFrontEnd/FBuiltin.mo
Expand Up @@ -202,6 +202,8 @@ protected constant list<SCode.Element> 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(),
Expand Down
1 change: 1 addition & 0 deletions OMCompiler/Compiler/FrontEnd/DAE.mo
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions OMCompiler/Compiler/FrontEnd/DAEDump.mo
Expand Up @@ -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;

Expand Down
11 changes: 7 additions & 4 deletions OMCompiler/Compiler/FrontEnd/InstBinding.mo
Expand Up @@ -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 =
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFBackendExtension.mo
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFBuiltin.mo
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFConvertDAE.mo
Expand Up @@ -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());
Expand Down
3 changes: 2 additions & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFModelicaBuiltin.mo
Expand Up @@ -40,7 +40,8 @@ type StateSelect = enumeration(
type Uncertainty = enumeration(
given,
sought,
refine
refine,
propagate
) annotation(__OpenModelica_builtin = true);

partial class Clock
Expand Down
1 change: 1 addition & 0 deletions OMCompiler/Compiler/Template/AbsynToJuliaTV.mo
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions OMCompiler/Compiler/Template/DAEDumpTV.mo
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions OMCompiler/Compiler/Template/DAEDumpTpl.tpl
Expand Up @@ -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> distribution)
Expand Down
2 changes: 1 addition & 1 deletion testsuite/flattening/modelica/scodeinst/Clock2.mo
Expand Up @@ -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...
Expand Down

0 comments on commit df98762

Please sign in to comment.