Skip to content

Commit

Permalink
- code simplifications and more debug output
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@24634 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
lochel committed Feb 19, 2015
1 parent c87d049 commit 7135184
Showing 1 changed file with 23 additions and 34 deletions.
57 changes: 23 additions & 34 deletions Compiler/BackEnd/Initialization.mo
Expand Up @@ -200,7 +200,7 @@ algorithm
end if;

// now let's solve the system!
(initdae, _) := BackendDAEUtil.mapEqSystemAndFold(initdae, solveInitialSystemEqSystem, dae);
initdae := BackendDAEUtil.mapEqSystem(initdae, solveInitialSystemEqSystem);

// transform and optimize DAE
pastOptModules := BackendDAEUtil.getPostOptModules(SOME({"constantLinearSystem", /* here we need a special case and remove only alias and constant (no variables of the system) variables "removeSimpleEquations", */ "tearingSystem","calculateStrongComponentJacobians", "solveSimpleEquations"}));
Expand Down Expand Up @@ -276,44 +276,33 @@ protected function solveInitialSystemEqSystem "author: lochel
This is a helper function of solveInitialSystem and solves the generated system."
input BackendDAE.EqSystem isyst;
input BackendDAE.Shared inShared;
input BackendDAE.BackendDAE inDAE;
output BackendDAE.EqSystem osyst;
output BackendDAE.EqSystem osyst := isyst;
output BackendDAE.Shared outShared := inShared "unused";
output BackendDAE.BackendDAE outDAE := inDAE "unused";
protected
Integer nVars, nEqns;
algorithm
osyst := matchcontinue(isyst)
local
Integer nVars, nEqns;
nEqns := BackendDAEUtil.systemSize(isyst);
nVars := BackendVariable.varsSize(BackendVariable.daeVars(isyst));

// over-determined system: nEqns > nVars
case (_) equation
nVars = BackendVariable.varsSize(BackendVariable.daeVars(isyst));
nEqns = BackendDAEUtil.systemSize(isyst);
true = intGt(nEqns, nVars);
// over-determined system: nEqns > nVars
if intGt(nEqns, nVars) then
if Flags.isSet(Flags.INITIALIZATION) then
Error.addCompilerWarning("It was not possible to solve the over-determined initial system (" + intString(nEqns) + " equations and " + intString(nVars) + " variables)");
BackendDump.dumpEqSystem(isyst, "It was not possible to solve the over-determined initial system (" + intString(nEqns) + " equations and " + intString(nVars) + " variables)");
end if;

if Flags.isSet(Flags.INITIALIZATION) then
Error.addCompilerWarning("It was not possible to solve the over-determined initial system (" + intString(nEqns) + " equations and " + intString(nVars) + " variables)");
end if;
then fail();
fail();
end if;

// determined system: nEqns = nVars
case (_) equation
nVars = BackendVariable.varsSize(BackendVariable.daeVars(isyst));
nEqns = BackendDAEUtil.systemSize(isyst);
true = intEq(nEqns, nVars);
then (isyst);

// under-determined system: nEqns < nVars
case (_) equation
nVars = BackendVariable.varsSize(BackendVariable.daeVars(isyst));
nEqns = BackendDAEUtil.systemSize(isyst);
true = intLt(nEqns, nVars);

if Flags.isSet(Flags.INITIALIZATION) then
Error.addCompilerWarning("It was not possible to solve the under-determined initial system (" + intString(nEqns) + " equations and " + intString(nVars) + " variables)");
end if;
then fail();
end matchcontinue;
// under-determined system: nEqns < nVars
if intLt(nEqns, nVars) then
if Flags.isSet(Flags.INITIALIZATION) then
Error.addCompilerWarning("It was not possible to solve the under-determined initial system (" + intString(nEqns) + " equations and " + intString(nVars) + " variables)");
BackendDump.dumpEqSystem(isyst, "It was not possible to solve the under-determined initial system (" + intString(nEqns) + " equations and " + intString(nVars) + " variables)");
end if;

fail();
end if;
end solveInitialSystemEqSystem;

// =============================================================================
Expand Down

0 comments on commit 7135184

Please sign in to comment.