Skip to content

Commit

Permalink
Fix whether value is changeable in OMEdit (OpenModelica#12294)
Browse files Browse the repository at this point in the history
  • Loading branch information
phannebohm committed Apr 23, 2024
1 parent a63bb10 commit d8bc442
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/BackEnd/BackendVariable.mo
Expand Up @@ -2053,7 +2053,7 @@ end isFinalVar;

public function isFinalOrProtectedVar
input BackendDAE.Var inVar;
output Boolean b = DAEUtil.getFinalAttr(inVar.values) or isProtectedVar(inVar);
output Boolean b = isFinalVar(inVar) or isProtectedVar(inVar);
end isFinalOrProtectedVar;

public function getVariableAttributes "Returns the DAE.VariableAttributes of a variable."
Expand Down
2 changes: 2 additions & 0 deletions OMCompiler/Compiler/NSimCode/NSimVar.mo
Expand Up @@ -459,6 +459,8 @@ public
else (start, false, Causality.LOCAL);

// ToDo: more cases!

// FIXME: variables that are fixed and are not CALCULATED should have isValueChangeable=true
end match;
end parseBinding;

Expand Down
22 changes: 11 additions & 11 deletions OMCompiler/Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -9991,19 +9991,13 @@ algorithm
(minValue, maxValue) = getMinMaxValues(dlowVar);
initVal = getStartValue(dlowVar);
nomVal = getNominalValue(dlowVar);
// checkInitVal(initVal, source);
isFixed = BackendVariable.varFixed(dlowVar);
type_ = tp;
isDiscrete = BackendVariable.isVarDiscrete(dlowVar);
arrayCref = ComponentReference.getArrayCref(cr);
aliasvar = getAliasVar(dlowVar, optAliasVars);
numArrayElement = List.map(inst_dims, ExpressionDump.dimensionIntString);
// print("name: " + ComponentReference.printComponentRefStr(cr) + "indx: " + intString(indx) + "\n");
// check if the variable has changeable value
// parameter which has final = true or evaluate annotation are not changeable
isValueChangeable = ((not BackendVariable.hasVarEvaluateAnnotationTrueOrFinalOrProtected(dlowVar)
and (BackendVariable.varHasConstantBindExp(dlowVar) or not BackendVariable.varHasBindExp(dlowVar))))
and isFixed;
isValueChangeable = isChangeable(dlowVar);
caus = getCausality(dlowVar, vars, isValueChangeable);
variability = SimCodeVar.FIXED(); // PARAMETERS()
initial_ = setInitialAttribute(dlowVar, variability, caus, isFixed, iterationVars, aliasvar, vars);
Expand Down Expand Up @@ -10036,14 +10030,13 @@ algorithm
(minValue, maxValue) = getMinMaxValues(dlowVar);
initVal = getStartValue(dlowVar);
nomVal = getNominalValue(dlowVar);
// checkInitVal(initVal, source);
isFixed = BackendVariable.varFixed(dlowVar);
type_ = tp;
isDiscrete = BackendVariable.isVarDiscrete(dlowVar);
arrayCref = ComponentReference.getArrayCref(cr);
aliasvar = getAliasVar(dlowVar, optAliasVars);
numArrayElement = List.map(inst_dims, ExpressionDump.dimensionIntString);
isValueChangeable = BackendVariable.varHasConstantStartExp(dlowVar);
isValueChangeable = isChangeable(dlowVar);
caus = getCausality(dlowVar, vars, isValueChangeable);
variability = SimCodeVar.CONTINUOUS(); // state() should be CONTINUOUS
initial_ = setInitialAttribute(dlowVar, variability, caus, isFixed, iterationVars, aliasvar, vars);
Expand Down Expand Up @@ -10077,14 +10070,14 @@ algorithm
(minValue, maxValue) = getMinMaxValues(dlowVar);
initVal = getStartValue(dlowVar);
nomVal = getNominalValue(dlowVar);
// checkInitVal(initVal, source);
isFixed = BackendVariable.varFixed(dlowVar);
type_ = tp;
isDiscrete = BackendVariable.isVarDiscrete(dlowVar);
arrayCref = ComponentReference.getArrayCref(cr);
aliasvar = getAliasVar(dlowVar, optAliasVars);
numArrayElement = List.map(inst_dims, ExpressionDump.dimensionIntString);
isValueChangeable = match dir case DAE.INPUT() then true; else false; end match;
isValueChangeable = match dir case DAE.INPUT() then true; else isChangeable(dlowVar);
end match;
caus = getCausality(dlowVar, vars, isValueChangeable);
variability = getVariabilityAttribute(dlowVar);
initial_ = setInitialAttribute(dlowVar, variability, caus, isFixed, iterationVars, aliasvar, vars);
Expand All @@ -10095,6 +10088,13 @@ algorithm
end match;
end dlowvarToSimvar;

protected function isChangeable
input BackendDAE.Var dlowVar;
output Boolean isValueChangeable = BackendVariable.varFixed(dlowVar)
and not BackendVariable.hasVarEvaluateAnnotationTrueOrFinalOrProtected(dlowVar)
and (BackendVariable.varHasConstantBindExp(dlowVar) or not BackendVariable.varHasBindExp(dlowVar));
end isChangeable;

protected function getCausality
input BackendDAE.Var dlowVar;
input BackendDAE.Variables inVars;
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditLIB/Plotting/VariablesWidget.cpp
Expand Up @@ -1197,7 +1197,7 @@ void VariablesTreeModel::getVariableInformation(ModelicaMatReader *pMatReader, Q
QHash<QString, QString> hash = mScalarVariablesHash.value(variableToFind);
if (hash.value("name").compare(variableToFind) == 0) {
*type = hash.value("type");
*changeAble = (hash.value("isValueChangeable").compare(QStringLiteral("true")) == 0) ? true : false;
*changeAble = hash.value("isValueChangeable").compare(QStringLiteral("true")) == 0;
*variability = hash.value("variability");
if (*changeAble) {
*value = hash.value("start");
Expand Down
Expand Up @@ -60,7 +60,7 @@ readFile("Bug5673.xml"); getErrorString();
// name = \"b\"
// valueReference = \"1000\"
// variability = \"continuous\" isDiscrete = \"false\"
// causality = \"local\" isValueChangeable = \"false\"
// causality = \"local\" isValueChangeable = \"true\"
// alias = \"noAlias\"
// classIndex = \"0\" classType = \"rAlg\"
// isProtected = \"false\" hideResult = \"\" initNonlinear = \"false\"
Expand Down

0 comments on commit d8bc442

Please sign in to comment.