Skip to content

Commit

Permalink
add some exeption handling for torn linear systems
Browse files Browse the repository at this point in the history
  • Loading branch information
Willi Braun authored and OpenModelica-Hudson committed May 25, 2016
1 parent 087bdd2 commit 59c64ac
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Compiler/BackEnd/SymbolicJacobian.mo
Expand Up @@ -3466,6 +3466,16 @@ algorithm

end jacobianConstant;

public function isJacobianGeneric
input BackendDAE.Jacobian inJac;
output Boolean result;
algorithm
result := match(inJac)
case BackendDAE.GENERIC_JACOBIAN() then true;
else false;
end match;
end isJacobianGeneric;

protected function varsNotInRelations
input output DAE.Exp exp;
output Boolean cont;
Expand Down
7 changes: 6 additions & 1 deletion Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -3119,7 +3119,6 @@ algorithm
then (equations_, equations_, uniqueEqIndex, tempvars, tmpEqSccMapping, tmpBackendMapping);

// TORNSYSTEM

case (BackendDAE.EQSYSTEM(orderedVars=vars, orderedEqs=eqns), _, BackendDAE.TORNSYSTEM(strictTearingSet, casualTearingSet, linear=b, mixedSystem=mixedSystem))
equation
if Flags.isSet(Flags.GRAPHML) then
Expand Down Expand Up @@ -3404,6 +3403,12 @@ algorithm
// CASE: linear
case(true, BackendDAE.EQSYSTEM(orderedVars=vars, orderedEqs=eqns), BackendDAE.SHARED(knownVars=kv)) equation
BackendDAE.TEARINGSET(tearingvars=tearingVars, residualequations=residualEqns, innerEquations=innerEquations, jac=inJacobian) = strictTearingSet;

if not SymbolicJacobian.isJacobianGeneric(inJacobian) then
Error.addMessage(Error.NO_JACONIAN_TORNLINEAR_SYSTEM, {});
fail();
end if;

// get tearing vars
tvars = List.map1r(tearingVars, BackendVariable.getVarAt, vars);
tvars = List.map(tvars, BackendVariable.transformXToXd);
Expand Down
3 changes: 3 additions & 0 deletions Compiler/Util/Error.mo
Expand Up @@ -702,6 +702,9 @@ public constant Message SCANNER_ERROR_LIMIT = MESSAGE(287, SYNTAX(), ERROR(),
Util.gettext("Additional syntax errors were suppressed."));
public constant Message INVALID_TIME_SCOPE = MESSAGE(288, TRANSLATION(), ERROR(),
Util.gettext("Built-in variable 'time' may only be used in a model or block."));
public constant Message NO_JACONIAN_TORNLINEAR_SYSTEM = MESSAGE(289, SYMBOLIC(), ERROR(),
Util.gettext("A torn linear system has no symbolic jacobian and currently there are no means to solve that numerically. Please compile with the module \"calculateStrongComponentJacobians\" to provide symbolic jacobians for torn linear systems."));

public constant Message UNBOUND_PARAMETER_WITH_START_VALUE_WARNING = MESSAGE(499, TRANSLATION(), WARNING(),
Util.gettext("Parameter %s has no value, and is fixed during initialization (fixed=true), using available start value (start=%s) as default value."));
public constant Message UNBOUND_PARAMETER_WARNING = MESSAGE(500, TRANSLATION(), WARNING(),
Expand Down
1 change: 1 addition & 0 deletions SimulationRuntime/c/simulation/solver/linearSystem.c
Expand Up @@ -103,6 +103,7 @@ int initializeLinearSystems(DATA *data, threadData_t *threadData)
if(linsys[i].initialAnalyticalJacobian(data, threadData))
{
linsys[i].jacobianIndex = -1;
throwStreamPrint(threadData, "Failed to initialize the jacobian for torn linear system %d.", (int)linsys[i].equationIndex);
}
nnz = data->simulationInfo->analyticJacobians[linsys[i].jacobianIndex].sparsePattern.numberOfNoneZeros;
linsys[i].nnz = nnz;
Expand Down

0 comments on commit 59c64ac

Please sign in to comment.