Skip to content

Commit

Permalink
- Implemented support for uncertainty computations
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@11000 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Leonardo Laguna committed Feb 2, 2012
1 parent 0ddc057 commit c32f655
Show file tree
Hide file tree
Showing 23 changed files with 1,777 additions and 106 deletions.
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendDAECreate.mo
Expand Up @@ -2182,7 +2182,7 @@ algorithm
cref_ = ComponentReference.makeCrefIdent("$dummy",DAE.T_REAL_DEFAULT,{});
vars_1 = BackendVariable.addVar(BackendDAE.VAR(cref_, BackendDAE.STATE(),DAE.BIDIR(),DAE.T_REAL_DEFAULT,NONE(),NONE(),{},-1,
DAE.emptyElementSource,
SOME(DAE.VAR_ATTR_REAL(NONE(),NONE(),NONE(),(NONE(),NONE()),NONE(),SOME(DAE.BCONST(true)),NONE(),NONE(),NONE(),NONE(),NONE())),
SOME(DAE.VAR_ATTR_REAL(NONE(),NONE(),NONE(),(NONE(),NONE()),NONE(),SOME(DAE.BCONST(true)),NONE(),NONE(),NONE(),NONE(),NONE(),NONE())),
NONE(),DAE.NON_CONNECTOR(),DAE.NON_STREAM()), vars);
exp = Expression.crefExp(cref_);
then
Expand Down
7 changes: 6 additions & 1 deletion Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -897,6 +897,7 @@ algorithm
var = BackendVariable.getVarAt(vars,intAbs(i));
// no State
false = BackendVariable.isStateorStateDerVar(var);
false = BackendVariable.varHasUncertainValueRefine(var);
// try to solve the equation
pos_1 = pos-1;
eqn = BackendDAEUtil.equationNth(eqns,pos_1);
Expand All @@ -918,6 +919,7 @@ algorithm
var = BackendVariable.getVarAt(vars,intAbs(i));
// no State
false = BackendVariable.isStateorStateDerVar(var);
false = BackendVariable.varHasUncertainValueRefine(var);
// try to solve the equation
pos_1 = pos-1;
eqn = BackendDAEUtil.equationNth(eqns,pos_1);
Expand All @@ -936,6 +938,8 @@ algorithm
// a = der(b)
case ({i,j},length,pos,syst as BackendDAE.EQSYSTEM(orderedVars=vars,orderedEqs=eqns),shared,mvars,mavars)
equation
var = BackendVariable.getVarAt(vars,intAbs(i));
false = BackendVariable.varHasUncertainValueRefine(var);
pos_1 = pos-1;
eqn = BackendDAEUtil.equationNth(eqns,pos_1);
(cr,_,es,_,negate) = BackendEquation.derivativeEquation(eqn);
Expand Down Expand Up @@ -1091,6 +1095,7 @@ algorithm
BackendVariable.isVarKindVariable(kind) "cr1 not constant";
false = BackendVariable.isVarOnTopLevelAndOutput(var);
false = BackendVariable.isVarOnTopLevelAndInput(var);
false = BackendVariable.varHasUncertainValueRefine(var);
then
();
end match;
Expand Down Expand Up @@ -3611,7 +3616,7 @@ algorithm
cr = BackendVariable.varCref(var);
crt = ComponentReference.prependStringCref("tearingresidual_",cr);
vars_1 = BackendVariable.addVar(BackendDAE.VAR(crt, BackendDAE.VARIABLE(),DAE.BIDIR(),DAE.T_REAL_DEFAULT,NONE(),NONE(),{},-1,DAE.emptyElementSource,
SOME(DAE.VAR_ATTR_REAL(NONE(),NONE(),NONE(),(NONE(),NONE()),NONE(),SOME(DAE.BCONST(true)),NONE(),NONE(),NONE(),NONE(),NONE())),
SOME(DAE.VAR_ATTR_REAL(NONE(),NONE(),NONE(),(NONE(),NONE()),NONE(),SOME(DAE.BCONST(true)),NONE(),NONE(),NONE(),NONE(),NONE(),NONE())),
NONE(),DAE.NON_CONNECTOR(),DAE.NON_STREAM()), ordvars);
// replace in residual equation orgvar with Tearing Var
BackendDAE.EQUATION(eqn,scalar,source) = BackendDAEUtil.equationNth(eqns,residualeqn-1);
Expand Down
17 changes: 9 additions & 8 deletions Compiler/BackEnd/BackendDAETransform.mo
Expand Up @@ -1502,7 +1502,7 @@ algorithm
end matchcontinue;
end findDiscreteEquation;

protected function strongConnectMain "function: strongConnectMain
public function strongConnectMain "function: strongConnectMain
author: PA

Helper function to strong_components
Expand Down Expand Up @@ -2568,6 +2568,7 @@ algorithm
Option<Boolean> finalPrefix;
BackendDAE.EquationArray eqns,eqns_1;
BackendDAE.StateOrder so,so1;
Option<DAE.Uncertainty> unc;

case ((DAE.CALL(path = Absyn.IDENT(name = "der"),expLst = {DAE.CALL(path = Absyn.IDENT(name = "der"),expLst = {DAE.CREF(componentRef = cr)})}),(vars,eqns,so,ilst)))
equation
Expand All @@ -2576,36 +2577,36 @@ algorithm
//dummyder = ComponentReference.crefPrefixDer(cr);
dummyder = ComponentReference.makeCrefQual("$_DER",DAE.T_REAL_DEFAULT,{},cr);
(eqns_1,so1) = addDummyStateEqn(vars,eqns,cr,dummyder,so);
vars_1 = BackendVariable.addVar(BackendDAE.VAR(dummyder, BackendDAE.STATE(), a, b, NONE(), NONE(), lstSubs, 0, source, SOME(DAE.VAR_ATTR_REAL(NONE(),NONE(),NONE(),(NONE(),NONE()),NONE(),NONE(),NONE(),SOME(DAE.NEVER()),NONE(),NONE(),NONE())), comment, flowPrefix, streamPrefix), vars);
vars_1 = BackendVariable.addVar(BackendDAE.VAR(dummyder, BackendDAE.STATE(), a, b, NONE(), NONE(), lstSubs, 0, source, SOME(DAE.VAR_ATTR_REAL(NONE(),NONE(),NONE(),(NONE(),NONE()),NONE(),NONE(),NONE(),SOME(DAE.NEVER()),NONE(),NONE(),NONE(),NONE())), comment, flowPrefix, streamPrefix), vars);
e = Expression.makeCrefExp(dummyder,DAE.T_REAL_DEFAULT);
i = BackendVariable.varsSize(vars_1);
then
((DAE.CALL(Absyn.IDENT("der"),{e},DAE.callAttrBuiltinReal), (vars_1,eqns_1,so1,i::ilst)));

case ((e as DAE.CALL(path = Absyn.IDENT(name = "der"),expLst = {DAE.CREF(componentRef = cr)}),(vars,eqns,so,ilst)))
equation
((BackendDAE.VAR(_,BackendDAE.DUMMY_DER(),a,b,c,d,lstSubs,g,source,SOME(DAE.VAR_ATTR_REAL(quantity,unit,displayUnit,min,initial_,fixed,nominal,_,equationBound,isProtected,finalPrefix)),comment,flowPrefix,streamPrefix) :: _),i::_) = BackendVariable.getVar(cr, vars) "der(v) v is alg var => der_v" ;
vars_1 = BackendVariable.addVar(BackendDAE.VAR(cr,BackendDAE.STATE(),a,b,c,d,lstSubs,g,source,SOME(DAE.VAR_ATTR_REAL(quantity,unit,displayUnit,min,initial_,fixed,nominal,SOME(DAE.NEVER()),equationBound,isProtected,finalPrefix)),comment,flowPrefix,streamPrefix), vars);
((BackendDAE.VAR(_,BackendDAE.DUMMY_DER(),a,b,c,d,lstSubs,g,source,SOME(DAE.VAR_ATTR_REAL(quantity,unit,displayUnit,min,initial_,fixed,nominal,_,unc,equationBound,isProtected,finalPrefix)),comment,flowPrefix,streamPrefix) :: _),i::_) = BackendVariable.getVar(cr, vars) "der(v) v is alg var => der_v" ;
vars_1 = BackendVariable.addVar(BackendDAE.VAR(cr,BackendDAE.STATE(),a,b,c,d,lstSubs,g,source,SOME(DAE.VAR_ATTR_REAL(quantity,unit,displayUnit,min,initial_,fixed,nominal,SOME(DAE.NEVER()),unc,equationBound,isProtected,finalPrefix)),comment,flowPrefix,streamPrefix), vars);
then
((e, (vars_1,eqns,so,i::ilst)));
case ((e as DAE.CALL(path = Absyn.IDENT(name = "der"),expLst = {DAE.CREF(componentRef = cr)}),(vars,eqns,so,ilst)))
equation
((BackendDAE.VAR(_,BackendDAE.DUMMY_DER(),a,b,c,d,lstSubs,g,source,NONE(),comment,flowPrefix,streamPrefix) :: _),i::_) = BackendVariable.getVar(cr, vars) "der(v) v is alg var => der_v" ;
vars_1 = BackendVariable.addVar(BackendDAE.VAR(cr,BackendDAE.STATE(),a,b,c,d,lstSubs,g,source,SOME(DAE.VAR_ATTR_REAL(NONE(),NONE(),NONE(),(NONE(),NONE()),NONE(),NONE(),NONE(),SOME(DAE.NEVER()),NONE(),NONE(),NONE())),comment,flowPrefix,streamPrefix), vars);
vars_1 = BackendVariable.addVar(BackendDAE.VAR(cr,BackendDAE.STATE(),a,b,c,d,lstSubs,g,source,SOME(DAE.VAR_ATTR_REAL(NONE(),NONE(),NONE(),(NONE(),NONE()),NONE(),NONE(),NONE(),SOME(DAE.NEVER()),NONE(),NONE(),NONE(),NONE())),comment,flowPrefix,streamPrefix), vars);
then
((e, (vars_1,eqns,so,i::ilst)));

case ((e as DAE.CALL(path = Absyn.IDENT(name = "der"),expLst = {DAE.CREF(componentRef = cr)}),(vars,eqns,so,ilst)))
equation
((BackendDAE.VAR(_,BackendDAE.VARIABLE(),a,b,c,d,lstSubs,g,source,SOME(DAE.VAR_ATTR_REAL(quantity,unit,displayUnit,min,initial_,fixed,nominal,_,equationBound,isProtected,finalPrefix)),comment,flowPrefix,streamPrefix) :: _),i::_) = BackendVariable.getVar(cr, vars) "der(v) v is alg var => der_v" ;
vars_1 = BackendVariable.addVar(BackendDAE.VAR(cr,BackendDAE.STATE(),a,b,c,d,lstSubs,g,source,SOME(DAE.VAR_ATTR_REAL(quantity,unit,displayUnit,min,initial_,fixed,nominal,SOME(DAE.NEVER()),equationBound,isProtected,finalPrefix)),comment,flowPrefix,streamPrefix), vars);
((BackendDAE.VAR(_,BackendDAE.VARIABLE(),a,b,c,d,lstSubs,g,source,SOME(DAE.VAR_ATTR_REAL(quantity,unit,displayUnit,min,initial_,fixed,nominal,_,unc,equationBound,isProtected,finalPrefix)),comment,flowPrefix,streamPrefix) :: _),i::_) = BackendVariable.getVar(cr, vars) "der(v) v is alg var => der_v" ;
vars_1 = BackendVariable.addVar(BackendDAE.VAR(cr,BackendDAE.STATE(),a,b,c,d,lstSubs,g,source,SOME(DAE.VAR_ATTR_REAL(quantity,unit,displayUnit,min,initial_,fixed,nominal,SOME(DAE.NEVER()),unc,equationBound,isProtected,finalPrefix)),comment,flowPrefix,streamPrefix), vars);
then
((e, (vars_1,eqns,so,i::ilst)));

case ((e as DAE.CALL(path = Absyn.IDENT(name = "der"),expLst = {DAE.CREF(componentRef = cr)}),(vars,eqns,so,ilst)))
equation
((BackendDAE.VAR(_,BackendDAE.VARIABLE(),a,b,c,d,lstSubs,g,source,NONE(),comment,flowPrefix,streamPrefix) :: _),i::_) = BackendVariable.getVar(cr, vars) "der(v) v is alg var => der_v" ;
vars_1 = BackendVariable.addVar(BackendDAE.VAR(cr,BackendDAE.STATE(),a,b,c,d,lstSubs,g,source,SOME(DAE.VAR_ATTR_REAL(NONE(),NONE(),NONE(),(NONE(),NONE()),NONE(),NONE(),NONE(),SOME(DAE.NEVER()),NONE(),NONE(),NONE())),comment,flowPrefix,streamPrefix), vars);
vars_1 = BackendVariable.addVar(BackendDAE.VAR(cr,BackendDAE.STATE(),a,b,c,d,lstSubs,g,source,SOME(DAE.VAR_ATTR_REAL(NONE(),NONE(),NONE(),(NONE(),NONE()),NONE(),NONE(),NONE(),SOME(DAE.NEVER()),NONE(),NONE(),NONE(),NONE())),comment,flowPrefix,streamPrefix), vars);
then
((e, (vars_1,eqns,so,i::ilst)));

Expand Down
28 changes: 23 additions & 5 deletions Compiler/BackEnd/BackendVariable.mo
Expand Up @@ -181,7 +181,7 @@ algorithm
streamPrefix = streamPrefix),fixed)
then
BackendDAE.VAR(a,b,c,DAE.T_REAL_DEFAULT,e,f,g,i,source,
SOME(DAE.VAR_ATTR_REAL(NONE(),NONE(),NONE(),(NONE(),NONE()),NONE(),SOME(DAE.BCONST(fixed)),NONE(),NONE(),NONE(),NONE(),NONE())),
SOME(DAE.VAR_ATTR_REAL(NONE(),NONE(),NONE(),(NONE(),NONE()),NONE(),SOME(DAE.BCONST(fixed)),NONE(),NONE(),NONE(),NONE(),NONE(),NONE())),
s,t,streamPrefix);

case (BackendDAE.VAR(varName = a,
Expand All @@ -199,7 +199,7 @@ algorithm
streamPrefix = streamPrefix),fixed)
then
BackendDAE.VAR(a,b,c,DAE.T_REAL_DEFAULT,e,f,g,i,source,
SOME(DAE.VAR_ATTR_INT(NONE(),(NONE(),NONE()),NONE(),SOME(DAE.BCONST(fixed)),NONE(),NONE(),NONE())),
SOME(DAE.VAR_ATTR_INT(NONE(),(NONE(),NONE()),NONE(),SOME(DAE.BCONST(fixed)),NONE(),NONE(),NONE(),NONE())),
s,t,streamPrefix);

case (BackendDAE.VAR(varName = a,
Expand Down Expand Up @@ -334,7 +334,7 @@ algorithm
streamPrefix = streamPrefix),inExp)
then
BackendDAE.VAR(a,b,c,DAE.T_REAL_DEFAULT,e,f,g,i,source,
SOME(DAE.VAR_ATTR_REAL(NONE(),NONE(),NONE(),(NONE(),NONE()),SOME(inExp),NONE(),NONE(),NONE(),NONE(),NONE(),NONE())),
SOME(DAE.VAR_ATTR_REAL(NONE(),NONE(),NONE(),(NONE(),NONE()),SOME(inExp),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE())),
s,t,streamPrefix);

case (BackendDAE.VAR(varName = a,
Expand All @@ -352,7 +352,7 @@ algorithm
streamPrefix = streamPrefix),inExp)
then
BackendDAE.VAR(a,b,c,DAE.T_REAL_DEFAULT,e,f,g,i,source,
SOME(DAE.VAR_ATTR_INT(NONE(),(NONE(),NONE()),SOME(inExp),NONE(),NONE(),NONE(),NONE())),
SOME(DAE.VAR_ATTR_INT(NONE(),(NONE(),NONE()),SOME(inExp),NONE(),NONE(),NONE(),NONE(),NONE())),
s,t,streamPrefix);

case (BackendDAE.VAR(varName = a,
Expand Down Expand Up @@ -638,7 +638,7 @@ algorithm
outReal := matchcontinue (inVar)
local
Real nominal;
case (BackendDAE.VAR(values = SOME(DAE.VAR_ATTR_REAL(_,_,_,_,_,_,SOME(DAE.RCONST(nominal)),_,_,_,_)))) then nominal;
case (BackendDAE.VAR(values = SOME(DAE.VAR_ATTR_REAL(_,_,_,_,_,_,SOME(DAE.RCONST(nominal)),_,_,_,_,_)))) then nominal;
end matchcontinue;
end varNominal;

Expand Down Expand Up @@ -706,6 +706,24 @@ algorithm
end matchcontinue;
end isNonStateVar;

public function varHasUncertainValueRefine
"
author: Daniel Hedberg, 2011-01
modified by: Leonardo Laguna, 2012-01
Returns true if the specified variable has the attribute uncertain and the
value of it is Uncertainty.refine, false otherwise.
"
input BackendDAE.Var var;
output Boolean b;
algorithm
b := matchcontinue (var)
case (BackendDAE.VAR(values = SOME(DAE.VAR_ATTR_REAL(uncertainOption = SOME(DAE.REFINE))))) then true;
case (BackendDAE.VAR(values = SOME(DAE.VAR_ATTR_INT(uncertainOption = SOME(DAE.REFINE))))) then true;
case (_) then false;
end matchcontinue;
end varHasUncertainValueRefine;

protected function failIfNonState
"Fails if the given variable kind is state."
input BackendDAE.Var inVar;
Expand Down
16 changes: 8 additions & 8 deletions Compiler/BackEnd/SimCode.mo
Expand Up @@ -298,7 +298,7 @@ uniontype SimVar
DAE.ElementSource source;
Causality causality;
Option<Integer> variable_index;
list <String> numArrayElement;
list<String> numArrayElement;

end SIMVAR;
end SimVar;
Expand Down Expand Up @@ -6958,7 +6958,7 @@ algorithm
DAE.ComponentRef arrayCref;
DAE.ElementSource source;
Option<Integer> variable_index;
list <String> numArrayElement;
list<String> numArrayElement;
case (SIMVAR(name, kind, comment, unit, displayUnit, index, minVal, maxVal, initVal, nomVal, isFixed, type_, isDiscrete, NONE(),_, source,_,NONE(),numArrayElement))
equation
name = ComponentReference.crefPrefixDer(name);
Expand Down Expand Up @@ -7248,7 +7248,7 @@ algorithm
DAE.ElementSource source;
Causality causality;
Option<Integer> variable_index;
list <String> numArrayElement;
list<String> numArrayElement;
Integer index;

case ({},_) then {};
Expand Down Expand Up @@ -7358,7 +7358,7 @@ algorithm
Absyn.Info info;
Causality causality;
Option<Integer> variable_index;
list <String> numArrayElement;
list<String> numArrayElement;
case (SIMVAR(name, kind, comment, unit, displayUnit, index, minVal, maxVal, initVal, nomVal, isFixed, type_, isDiscrete, arrayCref, aliasvar, source, causality,NONE(),numArrayElement), initCrefs)
equation
(_ :: _) = List.select1(initCrefs, ComponentReference.crefEqualNoStringCompare, name);
Expand Down Expand Up @@ -11455,7 +11455,7 @@ algorithm (outSimVar):= matchcontinue(stateVars,dae_low)
DAE.ElementSource source;
Causality causality;
Option<Integer> variable_index;
list <String> numArrayElement;
list<String> numArrayElement;
BackendDAE.EqSystems eqsystems;
case(SIMVAR(name=name,varKind=varKind,comment=comment,unit=unit,displayUnit=displayUnit,index=index,minValue=minValue,maxValue=maxValue,initialValue=initialValue,nominalValue=nominalValue,isFixed=isFixed,type_=type_,isDiscrete=isDiscrete,arrayCref=arrayCref,aliasvar=aliasvar,source=source,causality=causality,variable_index=variable_index,numArrayElement=numArrayElement),dae_low as BackendDAE.DAE(eqs=eqsystems))
equation
Expand Down Expand Up @@ -11528,7 +11528,7 @@ algorithm
Causality causality;
Option<Integer> variable_index;
list<SimVar> rest,indexed_vector;
list <String> numArrayElement;
list<String> numArrayElement;
case({},_) then {};
case(SIMVAR(name=name,varKind=varKind,comment=comment,unit=unit,displayUnit=displayUnit,minValue=minValue,maxValue=maxValue,initialValue=initialValue,nominalValue=nominalValue,isFixed=isFixed,type_=type_,isDiscrete=isDiscrete,arrayCref=arrayCref,aliasvar=aliasvar,source=source,causality=causality,variable_index=variable_index,numArrayElement=numArrayElement) :: rest,index)
equation
Expand Down Expand Up @@ -11644,7 +11644,7 @@ algorithm
Option<Integer> variable_index;
DAE.ComponentRef cr_1;
String name_str,id_str;
list <String> numArrayElement;
list<String> numArrayElement;
Integer i;
/*case(SIMVAR(name,varKind,comment,unit,displayUnit,0,initialValue,nominalValue,isFixed,type_,isDiscrete,arrayCref,aliasvar,source,causality,variable_index,numArrayElement))
equation
Expand Down Expand Up @@ -11718,7 +11718,7 @@ algorithm
Option <Integer> variable_index;
Integer variable_index1;
SimVar v,newvar1;
list <String> numArrayElement;
list<String> numArrayElement;

case((v as SIMVAR(name,varKind,comment,unit,displayUnit,index,minValue,maxValue,initialValue,nominalValue,isFixed,type_,isDiscrete,arrayCref,aliasvar,source,causality,variable_index,numArrayElement)),SIMVAR(name1,_,_,_,_,index1,_,_,_,_,_,_,_,_,_,_,_,SOME(variable_index1),_)::_)
equation
Expand Down

0 comments on commit c32f655

Please sign in to comment.