Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit feb746e

Browse files
Willi BraunOpenModelica-Hudson
authored andcommitted
[SC] remove the replacement of the DIV operator by a call
- added thow execption to the optimization, since ipopt seems to be abel to handle it Belonging to [master]: - #2379 - OpenModelica/OpenModelica-testsuite#927
1 parent de3a487 commit feb746e

File tree

4 files changed

+33
-296
lines changed

4 files changed

+33
-296
lines changed

Compiler/SimCode/SimCodeUtil.mo

Lines changed: 0 additions & 259 deletions
Original file line numberDiff line numberDiff line change
@@ -449,21 +449,6 @@ algorithm
449449
zeroCrossings := updateZeroCrossEqnIndex(zeroCrossings, eqBackendSimCodeMapping, BackendDAEUtil.equationArraySizeBDAE(dlow));
450450
if debug then execStat("simCode: update zero crossing index"); end if;
451451

452-
// replace div operator with div operator with check of Division by zero
453-
allEquations := List.map(allEquations, addDivExpErrorMsgtoSimEqSystem);
454-
odeEquations := List.mapList(odeEquations, addDivExpErrorMsgtoSimEqSystem);
455-
algebraicEquations := List.mapList(algebraicEquations, addDivExpErrorMsgtoSimEqSystem);
456-
startValueEquations := List.map(startValueEquations, addDivExpErrorMsgtoSimEqSystem);
457-
nominalValueEquations := List.map(nominalValueEquations, addDivExpErrorMsgtoSimEqSystem);
458-
minValueEquations := List.map(minValueEquations, addDivExpErrorMsgtoSimEqSystem);
459-
maxValueEquations := List.map(maxValueEquations, addDivExpErrorMsgtoSimEqSystem);
460-
parameterEquations := List.map(parameterEquations, addDivExpErrorMsgtoSimEqSystem);
461-
removedEquations := List.map(removedEquations, addDivExpErrorMsgtoSimEqSystem);
462-
initialEquations := List.map(initialEquations, addDivExpErrorMsgtoSimEqSystem);
463-
initialEquations_lambda0 := List.map(initialEquations_lambda0, addDivExpErrorMsgtoSimEqSystem);
464-
removedInitialEquations := List.map(removedInitialEquations, addDivExpErrorMsgtoSimEqSystem);
465-
if debug then execStat("simCode: addDivExpErrorMsgtoSimEqSystem"); end if;
466-
467452
// collect all LinearSystem and NonlinearSystem algebraic system in modelInfo and update
468453
// the corresponding index (indexNonLinear, indexLinear) in SES_NONLINEAR and SES_LINEAR
469454
// Also collect all jacobians
@@ -771,9 +756,6 @@ algorithm
771756

772757
(ouniqueEqIndex, removedEquations) := BackendEquation.traverseEquationArray(syst.removedEqs, traversedlowEqToSimEqSystem, (ouniqueEqIndex, {}));
773758

774-
equations := List.map(equations, addDivExpErrorMsgtoSimEqSystem);
775-
removedEquations := List.map(removedEquations, addDivExpErrorMsgtoSimEqSystem);
776-
777759
prevClockedVars := {};
778760
isPrevVar := arrayCreate(BackendVariable.varsSize(syst.orderedVars), false);
779761

@@ -8521,247 +8503,6 @@ algorithm
85218503
(_, outExpLst) := Expression.traverseExpList(inExps, inFn, {});
85228504
end getMatchingExpsList;
85238505

8524-
protected function addDivExpErrorMsgtoExp "author: Frenkel TUD 2010-02
8525-
Adds the error msg to Expression.Div."
8526-
input DAE.Exp inExp;
8527-
input DAE.ElementSource inSource;
8528-
output DAE.Exp outExp;
8529-
algorithm
8530-
false := Expression.traverseCrefsFromExp(inExp, traversingXLOCExpFinder, false);
8531-
(outExp, _) := Expression.traverseExpBottomUp(inExp, traversingDivExpFinder, inSource);
8532-
end addDivExpErrorMsgtoExp;
8533-
8534-
protected function traversingXLOCExpFinder "author: Frenkel TUD 2010-02"
8535-
input DAE.ComponentRef inCref;
8536-
input Boolean inB;
8537-
output Boolean outB;
8538-
algorithm
8539-
outB := match inCref
8540-
case DAE.CREF_IDENT(ident="xloc", identType=DAE.T_ARRAY(dims={DAE.DIM_UNKNOWN()}))
8541-
then true;
8542-
8543-
else inB;
8544-
end match;
8545-
end traversingXLOCExpFinder;
8546-
8547-
protected function traversingDivExpFinder "author: Frenkel TUD 2010-02"
8548-
input DAE.Exp inExp;
8549-
input DAE.ElementSource inSource;
8550-
output DAE.Exp outExp;
8551-
output DAE.ElementSource outSource;
8552-
algorithm
8553-
(outExp,outSource) := matchcontinue (inExp,inSource)
8554-
local
8555-
DAE.Exp e, e1, e2;
8556-
DAE.Type ty;
8557-
String se;
8558-
DAE.ElementSource source;
8559-
case (e as DAE.BINARY(operator = DAE.DIV(_), exp2 = e2), source)
8560-
equation
8561-
true = Expression.isConst(e2);
8562-
false = Expression.isZero(e2);
8563-
then (e, source);
8564-
8565-
case (DAE.BINARY(exp1 = e1, operator = DAE.DIV(ty), exp2 = e2), source)
8566-
then (DAE.CALL(Absyn.IDENT("DIVISION"), {e1, e2}, DAE.CALL_ATTR(ty, false, true, false, false, DAE.NO_INLINE(), DAE.NO_TAIL())), source);
8567-
8568-
case (e as DAE.BINARY(operator = DAE.DIV_ARRAY_SCALAR(_), exp2 = e2), source)
8569-
equation
8570-
true = Expression.isConst(e2);
8571-
false = Expression.isZero(e2);
8572-
then (e, source);
8573-
case (DAE.BINARY(exp1 = e1, operator = DAE.DIV_ARRAY_SCALAR(ty), exp2 = e2), source)
8574-
then (DAE.CALL(Absyn.IDENT("DIVISION_ARRAY_SCALAR"), {e1, e2}, DAE.CALL_ATTR(ty, false, true, false, false, DAE.NO_INLINE(), DAE.NO_TAIL())), source);
8575-
8576-
case (e as DAE.BINARY(operator = DAE.DIV_SCALAR_ARRAY(_), exp2 = e2), source)
8577-
equation
8578-
true = Expression.isConst(e2);
8579-
false = Expression.isZero(e2);
8580-
then (e, source);
8581-
case (DAE.BINARY(exp1 = e1, operator = DAE.DIV_SCALAR_ARRAY(ty), exp2 = e2), source)
8582-
then (DAE.CALL(Absyn.IDENT("DIVISION_SCALAR_ARRAY"), {e1, e2}, DAE.CALL_ATTR(ty, false, true, false, false, DAE.NO_INLINE(), DAE.NO_TAIL())), source);
8583-
else (inExp,inSource);
8584-
end matchcontinue;
8585-
end traversingDivExpFinder;
8586-
8587-
protected function addDivExpErrorMsgtosimJac
8588-
input tuple<Integer, Integer, SimCode.SimEqSystem> inJac;
8589-
output tuple<Integer, Integer, SimCode.SimEqSystem> outJac;
8590-
protected
8591-
Integer a, b;
8592-
SimCode.SimEqSystem ses, ses_;
8593-
algorithm
8594-
((a, b, ses)) := inJac;
8595-
ses_ := addDivExpErrorMsgtoSimEqSystem(ses);
8596-
outJac := if referenceEq(ses, ses_) then inJac else (a, b, ses_);
8597-
end addDivExpErrorMsgtosimJac;
8598-
8599-
protected function addDivExpErrorMsgtosymJac "helper for addDivExpErrorMsgtoSimEqSystem."
8600-
input Option<SimCode.JacobianMatrix> inJac;
8601-
output Option<SimCode.JacobianMatrix> outJac = inJac;
8602-
algorithm
8603-
outJac := match inJac
8604-
local
8605-
list<SimCode.SimEqSystem> eqns;
8606-
SimCode.JacobianColumn jacColumn;
8607-
SimCode.JacobianMatrix tmpJac;
8608-
case SOME(tmpJac as SimCode.JAC_MATRIX(columns={jacColumn as SimCode.JAC_COLUMN()}))
8609-
equation
8610-
jacColumn.columnEqns = List.map(jacColumn.columnEqns, addDivExpErrorMsgtoSimEqSystem);
8611-
tmpJac.columns = {jacColumn};
8612-
then
8613-
SOME(tmpJac);
8614-
else
8615-
outJac;
8616-
end match;
8617-
end addDivExpErrorMsgtosymJac;
8618-
8619-
protected function addDivExpErrorMsgtoSimEqSystem "Traverses all subexpressions of an expression of an equation."
8620-
input SimCode.SimEqSystem inSES;
8621-
output SimCode.SimEqSystem outSES;
8622-
algorithm
8623-
outSES:=
8624-
matchcontinue (inSES)
8625-
local
8626-
DAE.Exp e,left, e_;
8627-
DAE.ComponentRef cr;
8628-
Boolean partOfMixed,partOfMixed1;
8629-
list<SimCodeVar.SimVar> vars,vars1;
8630-
list<DAE.Exp> elst, elst1;
8631-
list<tuple<Integer, Integer, SimCode.SimEqSystem>> simJac, simJac1;
8632-
Integer index, index1, indexSys, indexSys1, nUnknowns, nUnknowns1;
8633-
list<DAE.ComponentRef> crefs, crefs1;
8634-
SimCode.SimEqSystem cont, cont1, elseWhenEq, elseWhen;
8635-
list<SimCode.SimEqSystem> discEqs, discEqs1;
8636-
list<DAE.ComponentRef> conditions;
8637-
Boolean initialCall;
8638-
DAE.ElementSource source;
8639-
Option<SimCode.JacobianMatrix> symJac, symJac1;
8640-
list<DAE.ElementSource> sources,sources1;
8641-
Boolean homotopySupport, homotopySupport1;
8642-
Boolean mixedSystem, mixedSystem1, tornSystem, tornSystem1;
8643-
list<BackendDAE.WhenOperator> whenStmtLst, whenOps;
8644-
BackendDAE.WhenOperator whenOpNew;
8645-
Option<SimCode.SimEqSystem> oelsewe;
8646-
BackendDAE.Constraints cons;
8647-
BackendDAE.EquationAttributes eqAttr;
8648-
8649-
case SimCode.SES_RESIDUAL(index= index, exp = e, source = source, eqAttr=eqAttr)
8650-
equation
8651-
e = addDivExpErrorMsgtoExp(e, source);
8652-
then
8653-
SimCode.SES_RESIDUAL(index, e, source, eqAttr);
8654-
8655-
case SimCode.SES_SIMPLE_ASSIGN(index= index, cref = cr, exp = e, source = source, eqAttr=eqAttr)
8656-
equation
8657-
e_ = addDivExpErrorMsgtoExp(e, source);
8658-
then
8659-
if referenceEq(e,e_) then inSES else SimCode.SES_SIMPLE_ASSIGN(index, cr, e_, source, eqAttr);
8660-
8661-
case SimCode.SES_SIMPLE_ASSIGN_CONSTRAINTS(index= index, cref = cr, exp = e, source = source, cons = cons, eqAttr=eqAttr)
8662-
equation
8663-
e_ = addDivExpErrorMsgtoExp(e, source);
8664-
then
8665-
if referenceEq(e,e_) then inSES else SimCode.SES_SIMPLE_ASSIGN_CONSTRAINTS(index, cr, e_, source, cons, eqAttr);
8666-
8667-
case SimCode.SES_ARRAY_CALL_ASSIGN(index = index, lhs = left, exp = e, source = source, eqAttr=eqAttr)
8668-
equation
8669-
e = addDivExpErrorMsgtoExp(e, source);
8670-
then
8671-
SimCode.SES_ARRAY_CALL_ASSIGN(index, left, e, source, eqAttr);
8672-
/*
8673-
case (SimCode.SES_ALGORITHM(), inDlowMode)
8674-
equation
8675-
e = addDivExpErrorMsgtoExp(e, (source, inDlowMode));
8676-
then
8677-
SimCode.SES_ALGORITHM();
8678-
*/
8679-
8680-
// no dynamic tearing
8681-
case SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(index, partOfMixed, tornSystem, vars, elst, simJac, discEqs, symJac, sources, indexSys, nUnknowns), NONE(), eqAttr=eqAttr)
8682-
equation
8683-
simJac1 = List.map(simJac, addDivExpErrorMsgtosimJac);
8684-
symJac = addDivExpErrorMsgtosymJac(symJac);
8685-
elst1 = List.map1(elst, addDivExpErrorMsgtoExp, DAE.emptyElementSource);
8686-
discEqs1 = List.map(discEqs, addDivExpErrorMsgtoSimEqSystem);
8687-
then
8688-
SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(index, partOfMixed, tornSystem, vars, elst1, simJac1, discEqs1, symJac, sources, indexSys, nUnknowns), NONE(), eqAttr);
8689-
8690-
case SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(index=index, eqs=discEqs, crefs=crefs, indexNonLinearSystem=indexSys, nUnknowns=nUnknowns, jacobianMatrix=symJac, homotopySupport=homotopySupport, mixedSystem=mixedSystem, tornSystem=tornSystem), NONE(), eqAttr=eqAttr)
8691-
equation
8692-
discEqs = List.map(discEqs, addDivExpErrorMsgtoSimEqSystem);
8693-
symJac = addDivExpErrorMsgtosymJac(symJac);
8694-
then
8695-
SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(index, discEqs, crefs, indexSys, nUnknowns, symJac, homotopySupport, mixedSystem, tornSystem), NONE(), eqAttr);
8696-
8697-
// dynamic tearing
8698-
case SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(index, partOfMixed, tornSystem, vars, elst, simJac, discEqs, symJac, sources, indexSys, nUnknowns), SOME(SimCode.LINEARSYSTEM(index1, partOfMixed1, tornSystem1, vars1, elst1, simJac1, discEqs1, symJac1, sources1, indexSys1, nUnknowns1)), eqAttr=eqAttr)
8699-
equation
8700-
simJac = List.map(simJac, addDivExpErrorMsgtosimJac);
8701-
symJac = addDivExpErrorMsgtosymJac(symJac);
8702-
elst = List.map1(elst, addDivExpErrorMsgtoExp, DAE.emptyElementSource);
8703-
discEqs = List.map(discEqs, addDivExpErrorMsgtoSimEqSystem);
8704-
simJac1 = List.map(simJac1, addDivExpErrorMsgtosimJac);
8705-
symJac1 = addDivExpErrorMsgtosymJac(symJac1);
8706-
elst1 = List.map1(elst1, addDivExpErrorMsgtoExp, DAE.emptyElementSource);
8707-
discEqs1 = List.map(discEqs1, addDivExpErrorMsgtoSimEqSystem);
8708-
then
8709-
SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(index, partOfMixed, tornSystem, vars, elst, simJac, discEqs, symJac, sources, indexSys, nUnknowns), SOME(SimCode.LINEARSYSTEM(index1, partOfMixed1, tornSystem1, vars1, elst1, simJac1, discEqs1, symJac1, sources1, indexSys1, nUnknowns1)), eqAttr);
8710-
8711-
case SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(index=index, eqs=discEqs, crefs=crefs, indexNonLinearSystem=indexSys, nUnknowns=nUnknowns, jacobianMatrix=symJac, homotopySupport=homotopySupport, mixedSystem=mixedSystem, tornSystem=tornSystem), SOME(SimCode.NONLINEARSYSTEM(index=index1, eqs=discEqs1, crefs=crefs1, indexNonLinearSystem=indexSys1, nUnknowns=nUnknowns1, jacobianMatrix=symJac1, homotopySupport=homotopySupport1, mixedSystem=mixedSystem1, tornSystem=tornSystem1)), eqAttr=eqAttr)
8712-
equation
8713-
discEqs = List.map(discEqs, addDivExpErrorMsgtoSimEqSystem);
8714-
symJac = addDivExpErrorMsgtosymJac(symJac);
8715-
discEqs1 = List.map(discEqs1, addDivExpErrorMsgtoSimEqSystem);
8716-
symJac1 = addDivExpErrorMsgtosymJac(symJac1);
8717-
then
8718-
SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(index, discEqs, crefs, indexSys, nUnknowns, symJac, homotopySupport, mixedSystem, tornSystem), SOME(SimCode.NONLINEARSYSTEM(index1, discEqs1, crefs1, indexSys1, nUnknowns1, symJac1, homotopySupport1, mixedSystem1, tornSystem1)), eqAttr);
8719-
8720-
case SimCode.SES_MIXED(index, cont, vars, discEqs, indexSys, eqAttr=eqAttr)
8721-
equation
8722-
cont1 = addDivExpErrorMsgtoSimEqSystem(cont);
8723-
discEqs1 = List.map(discEqs, addDivExpErrorMsgtoSimEqSystem);
8724-
then
8725-
SimCode.SES_MIXED(index, cont1, vars, discEqs1, indexSys, eqAttr);
8726-
8727-
case SimCode.SES_WHEN(index=index, conditions=conditions, initialCall=initialCall, whenStmtLst=whenStmtLst, elseWhen=oelsewe, source=source, eqAttr=eqAttr)
8728-
algorithm
8729-
whenOps := {};
8730-
for whenOp in whenStmtLst loop
8731-
whenOpNew := match whenOp
8732-
case BackendDAE.ASSIGN(left, e, source) then BackendDAE.ASSIGN(left, addDivExpErrorMsgtoExp(e, source), source);
8733-
else whenOp;
8734-
end match;
8735-
whenOps := whenOpNew::whenOps;
8736-
end for;
8737-
if isSome(oelsewe) then
8738-
SOME(elseWhen) := oelsewe;
8739-
elseWhenEq := addDivExpErrorMsgtoSimEqSystem(elseWhen);
8740-
oelsewe := SOME(elseWhenEq);
8741-
else
8742-
oelsewe := NONE();
8743-
end if;
8744-
then
8745-
SimCode.SES_WHEN(index, conditions, initialCall, whenOps, oelsewe, source, eqAttr);
8746-
else inSES;
8747-
end matchcontinue;
8748-
end addDivExpErrorMsgtoSimEqSystem;
8749-
8750-
protected function addDivExpErrorMsgtoSimEqSystemTuple
8751-
input tuple<SimCode.SimEqSystem,Integer> inSES;
8752-
output tuple<SimCode.SimEqSystem, Integer> outSES;
8753-
8754-
protected
8755-
Integer sccIdx;
8756-
SimCode.SimEqSystem eqSyst;
8757-
8758-
algorithm
8759-
(eqSyst,sccIdx) := inSES;
8760-
eqSyst := addDivExpErrorMsgtoSimEqSystem(eqSyst);
8761-
outSES := (eqSyst,sccIdx);
8762-
8763-
end addDivExpErrorMsgtoSimEqSystemTuple;
8764-
87658506
protected function extractVarUnit "author: asodja, 2010-03-11
87668507
Extract variable's unit and displayUnit as strings from
87678508
DAE.VariablesAttributes structures."

Compiler/Template/CodegenCFunctions.tpl

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4899,13 +4899,21 @@ case BINARY(__) then
48994899
else '<%e1%> - (<%e2%>)'
49004900
case MUL(__) then '(<%e1%>) * (<%e2%>)'
49014901
case DIV(ty = ty) then
4902-
let tvar = tempDecl(expTypeModelica(ty),&varDecls)
4903-
let &preExp += '<%tvar%> = <%e2%>;<%\n%>'
4904-
let &preExp +=
4905-
if acceptMetaModelicaGrammar()
4906-
then 'if (<%tvar%> == 0) {<%generateThrow()%>;}<%\n%>'
4907-
else 'if (<%tvar%> == 0) {throwStreamPrint(threadData, "Division by zero %s", "<%Util.escapeModelicaStringToCString(ExpressionDumpTpl.dumpExp(exp,"\""))%>");}<%\n%>'
4908-
'(<%e1%>) / <%tvar%>'
4902+
(match context
4903+
case FUNCTION_CONTEXT(__)
4904+
case PARALLEL_FUNCTION_CONTEXT(__) then
4905+
let tvar = tempDecl(expTypeModelica(ty),&varDecls)
4906+
let &preExp += '<%tvar%> = <%e2%>;<%\n%>'
4907+
let &preExp += if acceptMetaModelicaGrammar() then 'if (<%tvar%> == 0) {<%generateThrow()%>;}<%\n%>'
4908+
'(<%e1%>) / <%tvar%>'
4909+
case SIMULATION_CONTEXT() then
4910+
let e2str = Util.escapeModelicaStringToCString(ExpressionDumpTpl.dumpExp(exp2,"\""))
4911+
'DIVISION_SIM(<%e1%>,<%e2%>,"<%e2str%>",equationIndexes)'
4912+
else
4913+
let e2str = Util.escapeModelicaStringToCString(ExpressionDumpTpl.dumpExp(exp2,"\""))
4914+
'DIVISION(<%e1%>,<%e2%>,"<%e2str%>")'
4915+
)
4916+
49094917
case POW(__) then
49104918
if isHalf(exp2) then
49114919
let tmp = tempDecl(expTypeFromExpModelica(exp1),&varDecls)
@@ -5054,7 +5062,15 @@ case BINARY(__) then
50545062
let type = match ty case T_ARRAY(ty=T_INTEGER(__)) then "integer_array"
50555063
case T_ARRAY(ty=T_ENUMERATION(__)) then "integer_array"
50565064
else "real_array"
5057-
'div_alloc_<%type%>_scalar(<%e1%>, <%e2%>)'
5065+
let e2str = Util.escapeModelicaStringToCString(ExpressionDumpTpl.dumpExp(exp2,"\""))
5066+
(match context
5067+
case FUNCTION_CONTEXT(__)
5068+
case PARALLEL_FUNCTION_CONTEXT(__) then
5069+
'div_alloc_<%type%>_scalar(<%e1%>, <%e2%>)'
5070+
else
5071+
'division_alloc_<%type%>_scalar(threadData,<%e1%>,<%e2%>,"<%e2str%>")'
5072+
)
5073+
50585074
case DIV_SCALAR_ARRAY(__) then
50595075
let type = match ty case T_ARRAY(ty = T_INTEGER(__)) then "integer_array"
50605076
case T_ARRAY(ty = T_ENUMERATION(__)) then "integer_array"
@@ -5501,33 +5517,6 @@ template daeExpCall(Exp call, Context context, Text &preExp, Text &varDecls, Tex
55015517
let var2 = daeExp(e2, context, &preExp, &varDecls, &auxFunction)
55025518
var2
55035519

5504-
case CALL(path=IDENT(name="DIVISION"),
5505-
expLst={e1, e2}) then
5506-
let var1 = daeExp(e1, context, &preExp, &varDecls, &auxFunction)
5507-
let var2 = daeExp(e2, context, &preExp, &varDecls, &auxFunction)
5508-
let var3 = Util.escapeModelicaStringToCString(ExpressionDumpTpl.dumpExp(e2,"\""))
5509-
(match context
5510-
case FUNCTION_CONTEXT(__)
5511-
case PARALLEL_FUNCTION_CONTEXT(__) then
5512-
'DIVISION(<%var1%>,<%var2%>,"<%var3%>")'
5513-
else
5514-
'DIVISION_SIM(<%var1%>,<%var2%>,"<%var3%>",equationIndexes)'
5515-
)
5516-
5517-
case CALL(attr=CALL_ATTR(ty=ty),
5518-
path=IDENT(name="DIVISION_ARRAY_SCALAR"),
5519-
expLst={e1, e2}) then
5520-
let type = match ty case T_ARRAY(ty=T_INTEGER(__)) then "integer_array"
5521-
case T_ARRAY(ty=T_ENUMERATION(__)) then "integer_array"
5522-
else "real_array"
5523-
let var1 = daeExp(e1, context, &preExp, &varDecls, &auxFunction)
5524-
let var2 = daeExp(e2, context, &preExp, &varDecls, &auxFunction)
5525-
let var3 = Util.escapeModelicaStringToCString(ExpressionDumpTpl.dumpExp(e2,"\""))
5526-
'division_alloc_<%type%>_scalar(threadData,<%var1%>,<%var2%>,"<%var3%>")'
5527-
5528-
case exp as CALL(attr=CALL_ATTR(ty=ty), path=IDENT(name="DIVISION_ARRAY_SCALAR")) then
5529-
error(sourceInfo(),'Code generation does not support <%ExpressionDumpTpl.dumpExp(exp,"\"")%>')
5530-
55315520
case CALL(path=IDENT(name="der"), expLst={arg as CREF(__)}) then
55325521
cref(crefPrefixDer(arg.componentRef))
55335522
case CALL(path=IDENT(name="der"), expLst={exp}) then

SimulationRuntime/c/optimization/optimizer_main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ int runOptimizer(DATA* data, threadData_t *threadData, SOLVER_INFO* solverInfo){
4444
OptData *optData, optData_;
4545

4646
solverInfo->solverData = &optData_;
47+
data->simulationInfo->noThrowDivZero = 1;
4748

4849
pickUpModelData(data, threadData, solverInfo);
4950
optData = (OptData*) solverInfo->solverData;

SimulationRuntime/c/util/division.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,14 @@ static inline modelica_real __OMC_DIV_SIM(threadData_t *threadData, const modeli
6262
else
6363
res = a / division_error_equation_time(threadData, a, b, msg, equationIndexes, time_, noThrowDivZero);
6464

65-
if(!valid_number(res))
66-
throwStreamPrintWithEquationIndexes(threadData, equationIndexes, "division leads to inf or nan at time %g, (a=%g) / (b=%g), where divisor b is: %s", time_, a, b, msg);
65+
if(!valid_number(res)){
66+
if(noThrowDivZero) {
67+
warningStreamPrintWithEquationIndexes(LOG_UTIL, 0, equationIndexes, "division leads to inf or nan at time %g, (a=%g) / (b=%g), where divisor b is: %s", time_, a, b, msg);
68+
}
69+
else {
70+
throwStreamPrintWithEquationIndexes(threadData, equationIndexes, "division leads to inf or nan at time %g, (a=%g) / (b=%g), where divisor b is: %s", time_, a, b, msg);
71+
}
72+
}
6773
return res;
6874
}
6975

0 commit comments

Comments
 (0)