Skip to content

Commit

Permalink
- new unit check module (flag +newUnitChecking, disabled by default)
Browse files Browse the repository at this point in the history
  - for all variables unspecified units get calculated if possible 
  - inconsistent equations get reported in a user friendly way 
- new debug/dump flags for unit check module: dumpUnits, dumpEqInUC, dumpEqUCStruct
- add some examples for testing


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@22530 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
lochel committed Oct 1, 2014
1 parent 5179589 commit 7502ca1
Show file tree
Hide file tree
Showing 9 changed files with 2,446 additions and 8 deletions.
1 change: 1 addition & 0 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -6472,6 +6472,7 @@ algorithm
end match;
end expandAlgorithmStmts;


// =============================================================================
// section for preOptModule >>encapsulateWhenConditions<<
//
Expand Down
6 changes: 4 additions & 2 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -97,6 +97,7 @@ protected import System;
protected import SynchronousFeatures;
protected import Tearing;
protected import Types;
protected import UnitCheck;
protected import Values;

protected
Expand Down Expand Up @@ -9098,8 +9099,9 @@ algorithm
(BackendDAEOptimize.simplifyIfEquations, "simplifyIfEquations", false),
(BackendDAEOptimize.replaceEdgeChange, "replaceEdgeChange", false),
(BackendDAEOptimize.residualForm, "residualForm", false),
(ResolveLoops.resolveLoops, "resolveLoops", false),
(EvaluateFunctions.evalFunctions, "evalFunc", false)
(ResolveLoops.resolveLoops, "resolveLoops",false),
(EvaluateFunctions.evalFunctions, "evalFunc",false),
(UnitCheck.unitChecking, "unitChecking", true)
};
strPreOptModules := getPreOptModulesString();
strPreOptModules := Util.getOptionOrDefault(ostrPreOptModules,strPreOptModules);
Expand Down
8 changes: 4 additions & 4 deletions Compiler/BackEnd/BackendDump.mo
Expand Up @@ -2673,18 +2673,18 @@ algorithm
outString :=
match (inAttr)
local
Option<DAE.Exp> min,max,start,fixed,nominal;
Option<DAE.Exp> min,max,start,fixed,nominal,unit;
Option<Boolean> isProtected,finalPrefix;
Option<DAE.Distribution> dist;
Option<DAE.StateSelect> stateSelectOption;
Option<DAE.Uncertainty> uncertainopt;
String str;
case NONE() then "";
case SOME(DAE.VAR_ATTR_REAL(min=NONE(),max=NONE(),start=NONE(),fixed=NONE(),nominal=NONE(),stateSelectOption=NONE(),isProtected=NONE(),finalPrefix=NONE(),distributionOption=NONE(),uncertainOption=NONE()))
case SOME(DAE.VAR_ATTR_REAL(min=NONE(),max=NONE(),start=NONE(),unit=NONE(),fixed=NONE(),nominal=NONE(),stateSelectOption=NONE(),isProtected=NONE(),finalPrefix=NONE(),distributionOption=NONE(),uncertainOption=NONE()))
then "";
case SOME(DAE.VAR_ATTR_REAL(min=min,max=max,start=start,fixed=fixed,nominal=nominal,stateSelectOption=stateSelectOption,isProtected=isProtected,finalPrefix=finalPrefix,distributionOption=dist,uncertainOption=uncertainopt))
case SOME(DAE.VAR_ATTR_REAL(min=min,max=max,start=start,unit=unit,fixed=fixed,nominal=nominal,stateSelectOption=stateSelectOption,isProtected=isProtected,finalPrefix=finalPrefix,distributionOption=dist,uncertainOption=uncertainopt))
equation
str = optExpressionString(min,"min") +& optExpressionString(max,"max") +& optExpressionString(start,"start") +& optExpressionString(fixed,"fixed")
str = optExpressionString(min,"min") +& optExpressionString(max,"max") +& optExpressionString(start,"start") +& optExpressionString(unit,"unit") +& optExpressionString(fixed,"fixed")
+& optExpressionString(nominal,"nominal") +& optStateSelectionString(stateSelectOption) +& optBooleanString(isProtected,"protected")
+& optBooleanString(finalPrefix,"final") +& optDistributionString(dist) +& optUncertainty(uncertainopt);
then str;
Expand Down
57 changes: 57 additions & 0 deletions Compiler/BackEnd/BackendVariable.mo
Expand Up @@ -838,6 +838,63 @@ algorithm
end match;
end setVarMinMax;

public function setUnit "author: jhagemann
Sets the unit attribute of a variable."
input BackendDAE.Var inVar;
input DAE.Exp inUnit;
output BackendDAE.Var outVar;
algorithm
outVar := match (inVar,inUnit)
local
DAE.ComponentRef a;
BackendDAE.VarKind b;
DAE.VarDirection c;
DAE.VarParallelism prl;
BackendDAE.Type d;
Option<DAE.Exp> e,min,max;
Option<Values.Value> f;
list<DAE.Dimension> g;
DAE.ElementSource source;
DAE.VariableAttributes attr;
Option<DAE.VariableAttributes> oattr1;
Option<SCode.Comment> s;
DAE.ConnectorType ct;

case (BackendDAE.VAR(varName = a,
varKind = b,
varDirection = c,
varParallelism = prl,
varType = d,
bindExp = e,
bindValue = f,
arryDim = g,
source = source,
values = NONE(),
comment = s,
connectorType = ct), _)
equation
attr = getVariableAttributefromType(d);
oattr1 = DAEUtil.setUnitAttr(SOME(attr),inUnit);
then BackendDAE.VAR(a,b,c,prl,d,e,f,g,source,oattr1,s,ct);

case (BackendDAE.VAR(varName = a,
varKind = b,
varDirection = c,
varParallelism = prl,
varType = d,
bindExp = e,
bindValue = f,
arryDim = g,
source = source,
values = SOME(attr),
comment = s,
connectorType = ct), _)
equation
oattr1 = DAEUtil.setUnitAttr(SOME(attr),inUnit);
then BackendDAE.VAR(a,b,c,prl,d,e,f,g,source,oattr1,s,ct);
end match;
end setUnit;

public function varNominalValue
"author: Frenkel TUD"
input BackendDAE.Var inVar;
Expand Down

0 comments on commit 7502ca1

Please sign in to comment.