@@ -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, {});
85228504end 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-
87658506protected function extractVarUnit "author: asodja, 2010-03-11
87668507 Extract variable's unit and displayUnit as strings from
87678508 DAE.VariablesAttributes structures."
0 commit comments