Skip to content

Commit

Permalink
Update the fixed attribute in the initialization DAE (#611)
Browse files Browse the repository at this point in the history
  • Loading branch information
arun3688 authored and lochel committed Dec 3, 2019
1 parent d7cc1e9 commit e7ab1da
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 29 deletions.
29 changes: 25 additions & 4 deletions OMCompiler/Compiler/BackEnd/Initialization.mo
Expand Up @@ -1210,7 +1210,7 @@ protected function fixInitialSystem "author: lochel
input DoubleEnded.MutableList<BackendDAE.Equation> removedEqns;
protected
BackendDAE.EquationArray eqns2;
list<BackendDAE.Var> dumpVars2;
list<BackendDAE.Var> dumpVars2 = {};
list<BackendDAE.Equation> removedEqns2;
Integer nVars, nEqns, nInitEqs, nAddEqs, nAddVars;
list<Integer> stateIndices, range, initEqsIndices, redundantEqns;
Expand Down Expand Up @@ -1304,9 +1304,15 @@ algorithm
initVarList := List.map1r(range, BackendVariable.getVarAt, inEqSystem.orderedVars);
(eqns2, dumpVars2) := addStartValueEquations(initVarList, eqns2, {});
//BackendDump.dumpEquationArray(eqns2, "remaining equations");
//BackendDump.dumpVarList(dumpVars2,"Check fixed attribute in vars");
DoubleEnded.push_list_back(dumpVars, dumpVars2);
end if;
outEqSystem := BackendDAEUtil.setEqSystEqs(inEqSystem, eqns2);

// update fixed attribute
(outEqSystem.orderedVars, _) := BackendVariable.traverseBackendDAEVarsWithUpdate(outEqSystem.orderedVars, updateFixedAttribute, BackendVariable.listVar(dumpVars2));
(outShared.globalKnownVars, _) := BackendVariable.traverseBackendDAEVarsWithUpdate(outShared.globalKnownVars, updateFixedAttribute, BackendVariable.listVar(dumpVars2));

//print("index-" + intString(index) + " ende\n");
//execStat("fixInitialSystem (initialization) [nEqns: " + intString(nEqns) + ", nAddEqs: " + intString(nAddEqs) + ", nAddVars: " + intString(nAddVars) + "]");
return;
Expand All @@ -1319,6 +1325,21 @@ algorithm
fail();
end fixInitialSystem;

protected function updateFixedAttribute
"function which updates the fixed attribute of a variable"
input BackendDAE.Var inVar;
input BackendDAE.Variables inArg;
output BackendDAE.Var outVar = inVar;
output BackendDAE.Variables outArg = inArg;
protected
DAE.ComponentRef cr;
algorithm
cr := BackendVariable.varCref(inVar);
if BackendVariable.containsCref(cr, inArg) then
outVar := BackendVariable.setVarFixed(outVar, true);
end if;
end updateFixedAttribute;

protected function fixUnderDeterminedSystem "author: lochel"
input BackendDAE.IncidenceMatrix inM;
input list<Integer> inInitVarIndices;
Expand Down Expand Up @@ -1419,13 +1440,13 @@ algorithm
dumpVar := BackendVariable.copyVarNewName(cref, var);
// crStr = BackendDump.varString(dumpVar);
// fcall(Flags.INITIALIZATION, Error.addCompilerWarning, " " + crStr);

dumpVar := BackendVariable.setVarFixed(dumpVar, true);
outDumpVars := dumpVar::outDumpVars;
else
// crStr = BackendDump.varString(var);
// fcall(Flags.INITIALIZATION, Error.addCompilerWarning, " " + crStr);

outDumpVars := var::outDumpVars;
dumpVar := BackendVariable.setVarFixed(var, true);
outDumpVars := dumpVar::outDumpVars;
end if;
end for;
end addStartValueEquations;
Expand Down
12 changes: 6 additions & 6 deletions testsuite/openmodelica/debugDumps/optdaedump.mos
Expand Up @@ -1161,7 +1161,7 @@ buildModel(testOptdaedump); getErrorString();
// ========================================
// 1: iC:VARIABLE() type: Real
// 2: $DER.iL:VARIABLE() type: Real
// 3: iL:VARIABLE() type: Real
// 3: iL:VARIABLE(fixed = true ) type: Real
// 4: i2:VARIABLE() type: Real
// 5: i1:VARIABLE() type: Real
// 6: i0:VARIABLE() type: Real
Expand Down Expand Up @@ -1261,7 +1261,7 @@ buildModel(testOptdaedump); getErrorString();
// ========================================
// 1: iC:VARIABLE() type: Real
// 2: $DER.iL:VARIABLE() type: Real
// 3: iL:VARIABLE() type: Real
// 3: iL:VARIABLE(fixed = true ) type: Real
// 4: i2:VARIABLE() type: Real
// 5: i1:VARIABLE() type: Real
// 6: i0:VARIABLE() type: Real
Expand Down Expand Up @@ -1363,7 +1363,7 @@ buildModel(testOptdaedump); getErrorString();
// ========================================
// 1: iC:VARIABLE() type: Real
// 2: $DER.iL:VARIABLE() type: Real
// 3: iL:VARIABLE() type: Real
// 3: iL:VARIABLE(fixed = true ) type: Real
// 4: i2:VARIABLE() type: Real
// 5: i1:VARIABLE() type: Real
// 6: i0:VARIABLE() type: Real
Expand Down Expand Up @@ -2082,7 +2082,7 @@ buildModel(testOptdaedump); getErrorString();
// ========================================
// 1: iC:VARIABLE() type: Real
// 2: $DER.iL:VARIABLE() type: Real
// 3: iL:VARIABLE() type: Real
// 3: iL:VARIABLE(fixed = true ) type: Real
// 4: i2:VARIABLE() type: Real
// 5: i1:VARIABLE() type: Real
// 6: i0:VARIABLE() type: Real
Expand Down Expand Up @@ -2184,7 +2184,7 @@ buildModel(testOptdaedump); getErrorString();
// ========================================
// 1: iC:VARIABLE() type: Real
// 2: $DER.iL:VARIABLE() type: Real
// 3: iL:VARIABLE() type: Real
// 3: iL:VARIABLE(fixed = true ) type: Real
// 4: i2:VARIABLE() type: Real
// 5: i1:VARIABLE() type: Real
// 6: i0:VARIABLE() type: Real
Expand Down Expand Up @@ -2286,7 +2286,7 @@ buildModel(testOptdaedump); getErrorString();
// ========================================
// 1: iC:VARIABLE() type: Real
// 2: $DER.iL:VARIABLE() type: Real
// 3: iL:VARIABLE() type: Real
// 3: iL:VARIABLE(fixed = true ) type: Real
// 4: i2:VARIABLE() type: Real
// 5: i1:VARIABLE() type: Real
// 6: i0:VARIABLE() type: Real
Expand Down
Expand Up @@ -91,7 +91,7 @@ val(x4,1.0);
// "
// end SimulationResult;
// "Warning: Assuming fixed start value for the following 1 variables:
// x:VARIABLE() type: Real
// x:VARIABLE(fixed = true ) type: Real
// "
// record SimulationResult
// resultFile = "Alg5_res.mat",
Expand All @@ -101,8 +101,8 @@ val(x4,1.0);
// "
// end SimulationResult;
// "Warning: Assuming fixed start value for the following 2 variables:
// x2:VARIABLE() type: Real
// x1:VARIABLE() type: Real
// x2:VARIABLE(fixed = true ) type: Real
// x1:VARIABLE(fixed = true ) type: Real
// "
// 0.0
// 0.1224090895290663
Expand Down
Expand Up @@ -24,7 +24,7 @@ simulate(OverdeterminedInitialization.Fluid.DynamicPipeInitialValues); getErrorS
// end SimulationResult;
// "Warning: The model contains alias variables with conflicting start and/or nominal values. It is recommended to resolve the conflicts, because otherwise the system could be hard to solve. To print the conflicting alias sets and the chosen candidates please use -d=aliasConflicts.
// Warning: Assuming fixed start value for the following 1 variables:
// m_flow_initial:DISCRETE(unit = "kg/s" fixed = false ) type: Real
// m_flow_initial:DISCRETE(unit = "kg/s" fixed = true ) type: Real
// Warning: The initial conditions are over specified. The following 1 initial equations are redundant, so they are removed from the initialization sytem:
// pipe.mediums[1].p = 10000000.0.
// "
Expand Down
Expand Up @@ -18,7 +18,7 @@ buildModel(OverdeterminedInitialization.Fluid.DynamicPipeLumpedPressureInitializ
// {"OverdeterminedInitialization.Fluid.DynamicPipeLumpedPressureInitialization","OverdeterminedInitialization.Fluid.DynamicPipeLumpedPressureInitialization_init.xml"}
// "Warning: The model contains alias variables with conflicting start and/or nominal values. It is recommended to resolve the conflicts, because otherwise the system could be hard to solve. To print the conflicting alias sets and the chosen candidates please use -d=aliasConflicts.
// Warning: Assuming fixed start value for the following 1 variables:
// m_flow_initial:DISCRETE(unit = "kg/s" fixed = false ) type: Real
// m_flow_initial:DISCRETE(unit = "kg/s" fixed = true ) type: Real
// Warning: The initial conditions are over specified. The following 4 initial equations are redundant, so they are removed from the initialization sytem:
// $DER.pipe.mediums[2].p = 0.0
// $DER.pipe.mediums[3].p = 0.0
Expand Down
10 changes: 5 additions & 5 deletions testsuite/simulation/modelica/initialization/autoFixed.mos
Expand Up @@ -88,8 +88,8 @@ res := readSimulationResult("initializationTests.autoFixed.test6_res.mat", {time
// "
// end SimulationResult;
// "Warning: Assuming fixed start value for the following 2 variables:
// b:VARIABLE(start = 2.0 ) "comment b" type: Real
// a:DISCRETE(start = 1.0 fixed = false ) "comment a" type: Real
// b:VARIABLE(start = 2.0 fixed = true ) "comment b" type: Real
// a:DISCRETE(start = 1.0 fixed = true ) "comment a" type: Real
// "
// {{0.0,0.0},{1.0,1.0},{2.0,2.0}}
// ""
Expand All @@ -101,7 +101,7 @@ res := readSimulationResult("initializationTests.autoFixed.test6_res.mat", {time
// "
// end SimulationResult;
// "Warning: Assuming fixed start value for the following 1 variables:
// b:VARIABLE(start = 2.0 ) "comment b" type: Real
// b:VARIABLE(start = 2.0 fixed = true ) "comment b" type: Real
// "
// {{0.0,0.0},{1.0,1.0},{2.0,2.0}}
// ""
Expand All @@ -113,7 +113,7 @@ res := readSimulationResult("initializationTests.autoFixed.test6_res.mat", {time
// "
// end SimulationResult;
// "Warning: Assuming fixed start value for the following 1 variables:
// a:DISCRETE(start = 1.0 fixed = false ) "comment a" type: Real
// a:DISCRETE(start = 1.0 fixed = true ) "comment a" type: Real
// "
// {{0.0,0.0},{1.0,1.0},{2.0,2.0}}
// ""
Expand All @@ -125,7 +125,7 @@ res := readSimulationResult("initializationTests.autoFixed.test6_res.mat", {time
// "
// end SimulationResult;
// "Warning: Assuming fixed start value for the following 1 variables:
// b:VARIABLE(start = 2.0 ) "comment b" type: Real
// b:VARIABLE(start = 2.0 fixed = true ) "comment b" type: Real
// "
// record SimulationResult
// resultFile = "initializationTests.autoFixed.test5_res.mat",
Expand Down
Expand Up @@ -37,8 +37,8 @@ res := OpenModelica.Scripting.readSimulationResult("initializationTests.underdet
// "
// end SimulationResult;
// "Warning: Assuming fixed start value for the following 2 variables:
// x:VARIABLE() type: Real
// y:VARIABLE() type: Real
// x:VARIABLE(fixed = true ) type: Real
// y:VARIABLE(fixed = true ) type: Real
// "
// {{0.0,0.0},{0.0,0.0},{0.0,0.0}}
// ""
Expand Down
Expand Up @@ -39,7 +39,7 @@ res := OpenModelica.Scripting.readSimulationResult("initializationTests.underdet
// "
// end SimulationResult;
// "Warning: Assuming fixed start value for the following 1 variables:
// y:VARIABLE() type: Real
// y:VARIABLE(fixed = true ) type: Real
// "
// {{0.0,0.0},{1.0,1.0},{0.0,0.0}}
// ""
Expand Down
Expand Up @@ -37,7 +37,7 @@ res := OpenModelica.Scripting.readSimulationResult("initializationTests.underdet
// "
// end SimulationResult;
// "Warning: Assuming fixed start value for the following 1 variables:
// x:DISCRETE(start = 1.0 fixed = false ) type: Real
// x:DISCRETE(start = 1.0 fixed = true ) type: Real
// "
// {{0.0,0.0},{1.0,1.0}}
// ""
Expand Down
Expand Up @@ -33,7 +33,7 @@ res := OpenModelica.Scripting.readSimulationResult("initializationTests.underdet
// "
// end SimulationResult;
// "Warning: Assuming fixed start value for the following 1 variables:
// p:VARIABLE(start = 1.0 fixed = false ) type: Real
// p:VARIABLE(start = 1.0 fixed = true ) type: Real
// "
// {{0.0,0.0},{1.0,1.0}}
// ""
Expand Down
Expand Up @@ -54,8 +54,8 @@ res := OpenModelica.Scripting.readSimulationResult("initializationTests.underdet
// "
// end SimulationResult;
// "Warning: Assuming fixed start value for the following 2 variables:
// y:VARIABLE(start = -4.0 ) type: Real
// x:VARIABLE(start = -3.0 ) type: Real
// y:VARIABLE(start = -4.0 fixed = true ) type: Real
// x:VARIABLE(start = -3.0 fixed = true ) type: Real
// "
// {{0.0,0.0},{-3.0,-3.0},{1.0,1.0},{-3.0,-3.0},{-4.0,-4.0}}
// ""
Expand Down
Expand Up @@ -40,7 +40,7 @@ val(y, {0.0,0.25,0.5,0.75,1.0});
//
// Nonlinear iteration variables with default zero start attribute in NLSJac0. (1)
// ========================================
// 1: x2:VARIABLE() type: Real
// 1: x2:VARIABLE() type: Real
//
// Info: Only non-linear iteration variables in non-linear eqation systems require start values. All other start values have no influence on convergence and are ignored. Use "-d=dumpLoops" to show all loops. In OMEdit Tools->Options->Simulation->OMCFlags, in OMNotebook call setCommandLineOptions("-d=dumpLoops")
//
Expand All @@ -52,7 +52,7 @@ val(y, {0.0,0.25,0.5,0.75,1.0});
// "
// end SimulationResult;
// "Warning: Assuming fixed start value for the following 1 variables:
// y:VARIABLE() type: Real
// y:VARIABLE(fixed = true ) type: Real
// "
// {-1.572302755514847,-1.618421380238098,-1.738059371463845,-1.818945608412304,-1.907039392827518}
// {0.7861513777574233,0.7500029985869119,0.6996133736697597,0.609294856314359,0.4995556640036673}
Expand Down

0 comments on commit e7ab1da

Please sign in to comment.