@@ -447,22 +447,11 @@ algorithm
447447 case (compelem::{},_,(_,v)::{},_,_,_,_,false )
448448 then BackendDAE . SINGLEEQUATION (compelem,v);
449449
450- case (comp,eqn_lst,var_varindx_lst,syst as BackendDAE . EQSYSTEM (orderedVars= _,orderedEqs= _),shared ,ass1,ass2,false )
451- equation
452- var_lst = List . map(var_varindx_lst,Util . tuple21);
453- true = BackendVariable . hasDiscreteVar(var_lst);
454- true = BackendVariable . hasContinousVar(var_lst);
455- varindxs = List . map(var_varindx_lst,Util . tuple22);
456- (cont_eqn,cont_var,_,_,indxcont_eqn,indxcont_var,indxdisc_eqn,indxdisc_var) = splitMixedEquations(eqn_lst, comp, var_lst, varindxs);
457- var_varindx_lst_cond = List . threadTuple(cont_var,indxcont_var);
458- sc = analyseStrongComponentBlock(indxcont_eqn,cont_eqn,var_varindx_lst_cond,syst,shared ,ass1,ass2,true );
459- then
460- BackendDAE . MIXEDEQUATIONSYSTEM (sc,indxdisc_eqn,indxdisc_var);
461-
462450 case (comp,eqn_lst,var_varindx_lst,syst as BackendDAE . EQSYSTEM (orderedVars= _,orderedEqs= _),shared ,_,_,_)
463451 equation
464452 var_lst = List . map(var_varindx_lst,Util . tuple21);
465- false = BackendVariable . hasDiscreteVar(var_lst);
453+ // false = BackendVariable.hasDiscreteVar(var_lst); //lochel: mixed systems and non-linear systems are treated the same
454+ true = BackendVariable . hasContinousVar(var_lst); // lochel: pure discrete equation systems are not supported
466455 varindxs = List . map(var_varindx_lst,Util . tuple22);
467456 eqn_lst1 = replaceDerOpInEquationList(eqn_lst);
468457 // States are solved for der(x) not x.
@@ -667,16 +656,6 @@ algorithm
667656 var = BackendVariable . getVarAt(vars, v);
668657 then
669658 ({eqn}, {var }, e);
670- case (BackendDAE . MIXEDEQUATIONSYSTEM (condSystem= comp, disc_eqns= elst, disc_vars= vlst), eqns, vars)
671- equation
672- eqnlst1 = BackendEquation . getEqns(elst, eqns);
673- varlst1 = List . map1r(vlst, BackendVariable . getVarAt, vars);
674- e = List . first(elst);
675- (eqnlst, varlst, _) = getEquationAndSolvedVar(comp, eqns, vars);
676- eqnlst = listAppend(eqnlst, eqnlst1);
677- varlst = listAppend(varlst, varlst1);
678- then
679- (eqnlst, varlst, e);
680659 case (BackendDAE . EQUATIONSYSTEM (eqns= elst, vars= vlst), eqns, vars)
681660 equation
682661 eqnlst = BackendEquation . getEqns(elst, eqns);
@@ -788,13 +767,6 @@ algorithm
788767 case (BackendDAE . SINGLEEQUATION (eqn= e,var = v))
789768 then
790769 ({e},{v});
791- case BackendDAE . MIXEDEQUATIONSYSTEM (condSystem= comp,disc_eqns= elst,disc_vars= vlst)
792- equation
793- (elst1,vlst1) = getEquationAndSolvedVarIndxes(comp);
794- elst = listAppend(elst1,elst);
795- vlst = listAppend(vlst1,vlst);
796- then
797- (elst,vlst);
798770 case BackendDAE . EQUATIONSYSTEM (eqns= elst,vars= vlst)
799771 then
800772 (elst,vlst);
@@ -830,183 +802,6 @@ algorithm
830802 end matchcontinue;
831803end getEquationAndSolvedVarIndxes;
832804
833- protected function splitMixedEquations "author: PA
834-
835- Splits the equation of a mixed equation system into its continuous and
836- discrete parts.
837-
838- Even though the matching algorithm might say that a discrete variable is solved in a specific equation
839- (when part of a mixed system) this is not always correct. It might be impossible to solve the discrete
840- variable from that equation, for instance solving v from equation x = v < 0; This happens for e.g. the Gear model.
841- Instead, to split the equations and variables the following scheme is used:
842-
843- 1. Split the variables into continuous and discrete.
844- 2. For each discrete variable v, select among the equations where it is present
845- for an equation v = expr. (This could be done
846- by looking at incidence matrix but for now we look through all equations. This is sufficiently
847- efficient for small systems of mixed equations < 100)
848- 3. The equations not selected in step 2 are continuous equations.
849- "
850- input list< BackendDAE . Equation > eqnLst;
851- input list< Integer > indxEqnLst;
852- input list< BackendDAE . Var > varLst;
853- input list< Integer > indxVarLst;
854- output list< BackendDAE . Equation > contEqnLst;
855- output list< BackendDAE . Var > contVarLst;
856- output list< BackendDAE . Equation > discEqnLst;
857- output list< BackendDAE . Var > discVarLst;
858- output list< Integer > indxcontEqnLst;
859- output list< Integer > indxcontVarLst;
860- output list< Integer > indxdiscEqnLst;
861- output list< Integer > indxdiscVarLst;
862- algorithm
863- (contEqnLst, contVarLst, discEqnLst, discVarLst, indxcontEqnLst, indxcontVarLst, indxdiscEqnLst, indxdiscVarLst) := matchcontinue (eqnLst, indxEqnLst, varLst, indxVarLst)
864- local
865- list< tuple< BackendDAE . Equation , Integer >> eqnindxlst;
866-
867- case (_, _, _, _) equation
868- (discVarLst, contVarLst, indxdiscVarLst, indxcontVarLst) = splitVars(varLst, indxVarLst, BackendVariable . isVarDiscrete, {}, {}, {}, {});
869- eqnindxlst = List . map1(discVarLst, findDiscreteEquation, (eqnLst, indxEqnLst));
870- discEqnLst = List . map(eqnindxlst, Util . tuple21);
871- indxdiscEqnLst = List . map(eqnindxlst, Util . tuple22);
872- contEqnLst = List . setDifferenceOnTrue(eqnLst, discEqnLst, BackendEquation . equationEqual);
873- indxcontEqnLst = List . setDifferenceOnTrue(indxEqnLst, indxdiscEqnLst, intEq);
874- then (contEqnLst, contVarLst, discEqnLst, discVarLst, indxcontEqnLst, indxcontVarLst, indxdiscEqnLst, indxdiscVarLst);
875-
876- case (_, _, _, _) equation
877- Error . addInternalError(BackendDump . varListString(varLst, "involved variables" ));
878- Error . addInternalError(BackendDump . equationListString(eqnLst, "involved equations" ));
879- then fail();
880- end matchcontinue;
881- end splitMixedEquations;
882-
883- protected function splitVars "
884- Helper function to splitMixedEquations."
885- input list< Type_a > inList;
886- input list< Type_b > inListb;
887- input PredicateFunc inFunc;
888- input list< Type_a > inTrueList;
889- input list< Type_a > inFalseList;
890- input list< Type_b > inTrueListb;
891- input list< Type_b > inFalseListb;
892- output list< Type_a > outTrueList;
893- output list< Type_a > outFalseList;
894- output list< Type_b > outTrueListb;
895- output list< Type_b > outFalseListb;
896-
897- replaceable type Type_a subtypeof Any ;
898- replaceable type Type_b subtypeof Any ;
899-
900- partial function PredicateFunc
901- input Type_a inElement;
902- output Boolean outResult;
903- end PredicateFunc ;
904- algorithm
905- (outTrueList, outFalseList,outTrueListb, outFalseListb) := match(inList, inListb, inFunc, inTrueList, inFalseList, inTrueListb, inFalseListb)
906- local
907- Type_a e;
908- Type_b eb;
909- list< Type_a > rest_e, tl, fl;
910- list< Type_b > rest_eb, tlb, flb;
911- Boolean pred;
912-
913- case ({}, {}, _, tl, fl, tlb, flb)
914- then (listReverse(tl), listReverse(fl),listReverse(tlb), listReverse(flb));
915-
916- case (e :: rest_e,eb :: rest_eb, _, tl, fl, tlb, flb) equation
917- pred = inFunc(e);
918- (tl, fl,tlb, flb) = splitVars1(e, rest_e,eb, rest_eb, pred, inFunc, tl, fl, tlb, flb);
919- then (tl, fl,tlb, flb);
920- end match;
921- end splitVars;
922-
923- protected function splitVars1 "
924- Helper function to splitVars."
925- input Type_a inHead;
926- input list< Type_a > inRest;
927- input Type_b inHeadb;
928- input list< Type_b > inRestb;
929- input Boolean inPred;
930- input PredicateFunc inFunc;
931- input list< Type_a > inTrueList;
932- input list< Type_a > inFalseList;
933- input list< Type_b > inTrueListb;
934- input list< Type_b > inFalseListb;
935- output list< Type_a > outTrueList;
936- output list< Type_a > outFalseList;
937- output list< Type_b > outTrueListb;
938- output list< Type_b > outFalseListb;
939-
940- replaceable type Type_a subtypeof Any ;
941- replaceable type Type_b subtypeof Any ;
942-
943- partial function PredicateFunc
944- input Type_a inElement;
945- output Boolean outResult;
946- end PredicateFunc ;
947- algorithm
948- (outTrueList, outFalseList,outTrueListb, outFalseListb) := match(inHead, inRest,inHeadb, inRestb, inPred, inFunc, inTrueList, inFalseList,inTrueListb, inFalseListb)
949- local
950- list< Type_a > tl, fl;
951- list< Type_b > tlb, flb;
952-
953- case (_, _, _, _, true , _, tl, fl, tlb, flb) equation
954- tl = inHead :: tl;
955- tlb = inHeadb :: tlb;
956- (tl, fl, tlb, flb) = splitVars(inRest, inRestb, inFunc, tl, fl, tlb, flb);
957- then (tl, fl, tlb, flb);
958-
959- case (_, _, _, _, false , _, tl, fl, tlb, flb) equation
960- fl = inHead :: fl;
961- flb = inHeadb :: flb;
962- (tl, fl, tlb, flb) = splitVars(inRest, inRestb, inFunc, tl, fl, tlb, flb);
963- then (tl, fl, tlb, flb);
964- end match;
965- end splitVars1;
966-
967- protected function findDiscreteEquation "help function to splitMixedEquations, finds the discrete equation
968- on the form v = expr for solving variable v"
969- input BackendDAE . Var v;
970- input tuple< list< BackendDAE . Equation > , list< Integer >> eqnIndxLst;
971- output tuple< BackendDAE . Equation , Integer > eqnindx;
972- algorithm
973- eqnindx := matchcontinue(v, eqnIndxLst)
974- local
975- DAE . ComponentRef cr1, cr;
976- DAE . Exp e2;
977- Integer i;
978- BackendDAE . Equation eqn;
979- list< Integer > ilst;
980- list< BackendDAE . Equation > eqnLst;
981- String errstr;
982-
983- case (_, (((eqn as BackendDAE . EQUATION (exp= DAE . CREF (componentRef= cr), scalar= _))::_), i::_)) equation
984- cr1= BackendVariable . varCref(v);
985- true = ComponentReference . crefEqualNoStringCompare(cr1, cr);
986- then ((eqn, i));
987-
988- case (_, (((eqn as BackendDAE . EQUATION (exp= _, scalar= DAE . CREF (componentRef= cr)))::_), i::_)) equation
989- cr1= BackendVariable . varCref(v);
990- true = ComponentReference . crefEqualNoStringCompare(cr1, cr);
991- then ((eqn, i));
992-
993- case (_, (_::eqnLst, _::ilst)) equation
994- ((eqn, i)) = findDiscreteEquation(v, (eqnLst, ilst));
995- then ((eqn, i));
996-
997- else equation
998- Error . addMessage(Error . INTERNAL_ERROR , {"./Compiler/BackEnd/BackendDAETransform.mo: function findDiscreteEquation failed
999- Your model contains a mixed system involving algorithms or other complex-equations.
1000- Sorry. Currently are supported only mixed system involving simple equations and boolean variables.
1001- Try to break the loop by using the pre operator." });
1002- true = Flags . isSet(Flags . FAILTRACE );
1003- Debug . trace("findDiscreteEquation failed, searching for variables: " );
1004- errstr = ComponentReference . printComponentRefStr(BackendVariable . varCref(v));
1005- Debug . traceln(errstr);
1006- then fail();
1007- end matchcontinue;
1008- end findDiscreteEquation;
1009-
1010805public function tarjanAlgorithm "author: PA
1011806
1012807 This is the second part of the BLT sorting. It takes the variable
0 commit comments