Changeset e91dba5 in OpenModelica


Ignore:
Timestamp:
2021-01-21T10:58:57+01:00 (3 years ago)
Author:
Karim Abdelhak <karim.abdelhak@…>
Parents:
03da1b5
Message:

[BE, SimCode] update nonlinear jacobian handling

  • [BE] add case for f1() = f2() where f1 and f2 return records as residual

    tmp1 = f1();
    tmp2 = f2();
    tmp1.attribute - tmp2.attribute = 0; for all attributes in tmp1 and tmp2

  • [BE] make structure more clear and create subfunctions for functionalities that are applied multiple times
  • [SimCode] create dataRecon jacobian before modelInfo so that the created tempVars can be put inside modelInfo
File:
1 edited

Legend:

Unmodified
Added
Removed
  • OMCompiler/Compiler/SimCode/SimCodeUtil.mo

    rbace85d1 re91dba5  
    472472    if debug then execStat("simCode: createStateSets"); end if;
    473473
     474    // Generate jacobian code for DataReconciliation
     475    if Util.isSome(shared.dataReconciliationData) then //KAB1
     476      BackendDAE.DATA_RECON(dataReconJac,setcVars,datareconinputvars) := Util.getOption(shared.dataReconciliationData);
     477      (SOME(dataReconSimJac), uniqueEqIndex, tempvars) := createSymbolicSimulationJacobian(dataReconJac, uniqueEqIndex, tempvars);
     478    end if;
     479
    474480    // create model info
    475481    modelInfo := createModelInfo(inClassName, program, dlow, inInitDAE, functions, {}, numStateSets, inFileDir, listLength(clockedSysts), tempvars);
     
    510516    // the corresponding index (indexNonLinear, indexLinear) in SES_NONLINEAR and SES_LINEAR
    511517    // Also collect all jacobians
     518
    512519    SymbolicJacsNLS := {};
    513520    (initialEquations, modelInfo, SymbolicJacsTemp) := addAlgebraicLoopsModelInfo(initialEquations, modelInfo);
     
    524531    SymbolicJacsNLS := listAppend(SymbolicJacsTemp, SymbolicJacsNLS);
    525532
    526     // Generate jacobian code for DataReconciliation
    527533    if Util.isSome(shared.dataReconciliationData) then
    528       BackendDAE.DATA_RECON(dataReconJac,setcVars,datareconinputvars) := Util.getOption(shared.dataReconciliationData);
    529       (SOME(dataReconSimJac), uniqueEqIndex, tempvars) := createSymbolicSimulationJacobian(dataReconJac, uniqueEqIndex, tempvars);
    530534      (SymbolicJacsdatarecon, modelInfo, SymbolicJacsTemp) := addAlgebraicLoopsModelInfoSymJacs({dataReconSimJac}, modelInfo);
    531535      SymbolicJacsNLS := listAppend(SymbolicJacsTemp, SymbolicJacsNLS);
    532       //SymbolicJacsNLS := dataReconSimJac::SymbolicJacsNLS;
    533536    end if;
    534537
     
    24452448  (equations_, ouniqueEqIndex, otempvars) := matchcontinue (inExp, inExp1)
    24462449    local
    2447       DAE.ComponentRef cr, crtmp;
     2450      DAE.ComponentRef cr, cr1, crtmp;
    24482451      list<DAE.ComponentRef> crlst;
    24492452      list<list<DAE.ComponentRef>> crlstlst;
    24502453      DAE.Exp e1, e2, e1_1, e2_1, etmp;
    2451       DAE.Statement stms;
    2452       DAE.Type tp;
    2453       list<DAE.Exp> expl, crexplst, lhsExpLstRes, rhsExpLstRes, lhsExpLstAss, rhsExpLstAss;
     2454      DAE.Statement stms, stms1;
     2455      DAE.Type tp, tp1;
     2456      list<DAE.Exp> expl, crexplst, crexplst1, lhsExpLstRes, rhsExpLstRes, lhsExpLstAss, rhsExpLstAss;
    24542457      list<DAE.Var> varLst;
    24552458      list<DAE.Exp> e1lst, e2lst;
    2456       SimCode.SimEqSystem simeqn_complex;
     2459      SimCode.SimEqSystem simeqn_complex, simeqn_complex1;
    24572460      list<SimCode.SimEqSystem> eqSystlst, eqSystlst_simpAss;
    24582461      list<tuple<DAE.Exp, DAE.Exp>> exptl;
    24592462      Integer uniqueEqIndex;
    2460       Absyn.Path path, rpath;
    2461       String ident, s, s1, s2;
     2463      Absyn.Path path, path1, rpath;
     2464      String ident, ident1, s, s1, s2;
    24622465      list<SimCodeVar.SimVar> tempvars;
     2466      DAE.CallAttributes ca, ca1;
    24632467
    24642468    /* casts */
    2465     case (DAE.CAST(_, e1), _) equation
    2466       (equations_, ouniqueEqIndex, otempvars) = createNonlinearResidualEquationsComplex(e1, inExp1, source, eqAttr, iuniqueEqIndex, itempvars);
    2467     then (equations_, ouniqueEqIndex, otempvars);
     2469    case (DAE.CAST(_, e1), _)
     2470    then createNonlinearResidualEquationsComplex(e1, inExp1, source, eqAttr, iuniqueEqIndex, itempvars);
    24682471
    24692472    /* casts */
    2470     case (_, DAE.CAST(_, e2)) equation
    2471       (equations_, ouniqueEqIndex, otempvars) = createNonlinearResidualEquationsComplex(inExp, e2, source, eqAttr, iuniqueEqIndex, itempvars);
    2472     then (equations_, ouniqueEqIndex, otempvars);
     2473    case (_, DAE.CAST(_, e2))
     2474    then createNonlinearResidualEquationsComplex(inExp, e2, source, eqAttr, iuniqueEqIndex, itempvars);
    24732475
    24742476    /* a = f() */
    2475     case (DAE.CREF(componentRef=cr), _) equation
    2476       // ((e1_1, _)) = Expression.extendArrExp((inExp, false));
    2477       (e2_1, _) = Expression.extendArrExp(inExp1, false);
    2478       // true = ComponentReference.crefEqualNoStringCompare(cr, cr2);
    2479       (tp as DAE.T_COMPLEX(varLst=varLst, complexClassType=ClassInf.RECORD(path)))  = Expression.typeof(inExp);
    2480       // tmp
    2481       ident = AbsynUtil.pathStringUnquoteReplaceDot(path, "_");
    2482       crtmp = ComponentReference.makeCrefIdent("$TMP_" + ident + intString(iuniqueEqIndex), tp, {});
    2483       tempvars = createTempVars(varLst, crtmp, itempvars);
    2484       // 0 = a - tmp
    2485       e1lst = List.map1(varLst, Expression.generateCrefsExpFromExpVar, cr);
    2486       e2lst = List.map1(varLst, Expression.generateCrefsExpFromExpVar, crtmp);
    2487       exptl = List.zip(e1lst, e2lst);
    2488       (eqSystlst, uniqueEqIndex) = List.map2Fold(exptl, makeSES_RESIDUAL1, source, eqAttr, iuniqueEqIndex);
    2489       // tmp = f(x, y)
    2490       etmp = Expression.crefExp(crtmp);
    2491       stms = DAE.STMT_ASSIGN(tp, etmp, e2_1, source);
    2492       eqSystlst = SimCode.SES_ALGORITHM(uniqueEqIndex, {stms}, eqAttr)::eqSystlst;
    2493     then (eqSystlst, uniqueEqIndex+1, tempvars);
     2477    case (DAE.CREF(componentRef=cr), _)
     2478    then createNonlinearResidualEquationsComplexCref(inExp, inExp1, cr, source, eqAttr, iuniqueEqIndex, itempvars);
    24942479
    24952480    /* f() = a */
    2496     case (_, DAE.CREF(componentRef=cr)) equation
    2497       // true = ComponentReference.crefEqualNoStringCompare(cr, cr2);
    2498       (e1_1, _) = Expression.extendArrExp(inExp, false);
    2499       // ((e2_1, _)) = Expression.extendArrExp((inExp1, false));
    2500       (tp as DAE.T_COMPLEX(varLst=varLst, complexClassType=ClassInf.RECORD(path)))  = Expression.typeof(inExp1);
    2501       // tmp
    2502       ident = AbsynUtil.pathStringUnquoteReplaceDot(path, "_");
    2503       crtmp = ComponentReference.makeCrefIdent("$TMP_" + ident + intString(iuniqueEqIndex), tp, {});
    2504       tempvars = createTempVars(varLst, crtmp, itempvars);
    2505       // 0 = a - tmp
    2506       e1lst = List.map1(varLst, Expression.generateCrefsExpFromExpVar, cr);
    2507       e2lst = List.map1(varLst, Expression.generateCrefsExpFromExpVar, crtmp);
    2508       exptl = List.zip(e1lst, e2lst);
    2509       (eqSystlst, uniqueEqIndex) = List.map2Fold(exptl, makeSES_RESIDUAL1, source, eqAttr, iuniqueEqIndex);
    2510       // tmp = f(x, y)
    2511       etmp = Expression.crefExp(crtmp);
    2512       stms = DAE.STMT_ASSIGN(tp, etmp, e1_1, source);
    2513       eqSystlst = SimCode.SES_ALGORITHM(uniqueEqIndex, {stms}, eqAttr)::eqSystlst;
    2514     then (eqSystlst, uniqueEqIndex+1, tempvars);
     2481    case (_, DAE.CREF(componentRef=cr))
     2482    then createNonlinearResidualEquationsComplexCref(inExp1, inExp, cr, source, eqAttr, iuniqueEqIndex, itempvars);
    25152483
    25162484    /* Record() = f() */
    2517     case (DAE.CALL(path=path, expLst=e2lst, attr=DAE.CALL_ATTR(ty= tp as DAE.T_COMPLEX(varLst=varLst, complexClassType=ClassInf.RECORD(rpath)))), _) equation
    2518       true = AbsynUtil.pathEqual(path, rpath);
    2519       (e2_1, _) = Expression.extendArrExp(inExp1, false);
    2520       // true = ComponentReference.crefEqualNoStringCompare(cr, cr2);
    2521       // tmp = f()
    2522       ident = AbsynUtil.pathStringUnquoteReplaceDot(path, "_");
    2523       cr = ComponentReference.makeCrefIdent("$TMP_" + ident + intString(iuniqueEqIndex), tp, {});
    2524       e1_1 = Expression.crefToExp(cr);
    2525       stms = DAE.STMT_ASSIGN(tp, e1_1, e2_1, source);
    2526       simeqn_complex = SimCode.SES_ALGORITHM(iuniqueEqIndex, {stms}, eqAttr);
    2527       uniqueEqIndex = iuniqueEqIndex + 1;
    2528 
    2529       // Record()-tmp = 0
    2530       /* Expand the tmp record and any arrays */
    2531       e1lst = Expression.expandExpression(e1_1, expandRecord = true);
    2532       /* Expand the varLst. Each var might be an array or record. */
    2533       e2lst = List.mapFlat(e2lst, function Expression.expandExpression(expandRecord = true));
    2534       /* pair each of the expanded expressions to coressponding one*/
    2535       exptl = List.zip(e1lst, e2lst);
    2536       /* Create residual equations for each pair*/
    2537       (eqSystlst, uniqueEqIndex) = List.map2Fold(exptl, makeSES_RESIDUAL1, source, eqAttr, uniqueEqIndex);
    2538       eqSystlst = simeqn_complex::eqSystlst;
    2539 
    2540       tempvars = createTempVars(varLst, cr, itempvars);
    2541     then (eqSystlst, uniqueEqIndex, tempvars);
     2485    case (DAE.CALL(expLst=e2lst, attr=DAE.CALL_ATTR(ty= tp as DAE.T_COMPLEX(varLst=varLst, complexClassType=ClassInf.RECORD(rpath)))), DAE.CALL(path=path))
     2486      guard(AbsynUtil.pathEqual(path, rpath))
     2487    then createNonlinearResidualEquationsComplexRecord(inExp, inExp1, source, eqAttr, path, tp, e2lst, varLst, iuniqueEqIndex, itempvars);
    25422488
    25432489    /* f() = Record() */
    2544     case (_, DAE.CALL(path=path, expLst=e2lst, attr=DAE.CALL_ATTR(ty=tp as DAE.T_COMPLEX(varLst=varLst, complexClassType=ClassInf.RECORD(rpath))))) equation
    2545       true = AbsynUtil.pathEqual(path, rpath);
    2546       (e1_1, _) = Expression.extendArrExp(inExp1, false);
    2547       // true = ComponentReference.crefEqualNoStringCompare(cr, cr2);
    2548       // tmp = f()
    2549       ident = AbsynUtil.pathStringUnquoteReplaceDot(path, "_");
    2550       cr = ComponentReference.makeCrefIdent("$TMP_" + ident + intString(iuniqueEqIndex), tp, {});
    2551       e2_1 = Expression.crefExp(cr);
    2552       stms = DAE.STMT_ASSIGN(tp, e2_1, e1_1, source);
    2553       simeqn_complex = SimCode.SES_ALGORITHM(iuniqueEqIndex, {stms}, eqAttr);
    2554       uniqueEqIndex = iuniqueEqIndex + 1;
    2555       // Record()-tmp = 0
    2556       e1lst = List.map1(varLst, Expression.generateCrefsExpFromExpVar, cr);
    2557       exptl = List.zip(e1lst, e2lst);
    2558       (eqSystlst, uniqueEqIndex) = List.map2Fold(exptl, makeSES_RESIDUAL1, source, eqAttr, uniqueEqIndex);
    2559       eqSystlst = simeqn_complex::eqSystlst;
    2560       tempvars = createTempVars(varLst, cr, itempvars);
    2561     then (eqSystlst, uniqueEqIndex, tempvars);
     2490    case (DAE.CALL(path=path), DAE.CALL(expLst=e2lst, attr=DAE.CALL_ATTR(ty= tp as DAE.T_COMPLEX(varLst=varLst, complexClassType=ClassInf.RECORD(rpath)))))
     2491      guard(AbsynUtil.pathEqual(path, rpath))
     2492    then createNonlinearResidualEquationsComplexRecord(inExp1, inExp, source, eqAttr, path, tp, e2lst, varLst, iuniqueEqIndex, itempvars);
    25622493
    25632494    /* Tuple() = f()  */
     
    25962527    then (eqSystlst, uniqueEqIndex, tempvars);
    25972528
     2529    /* f1() = f2() RETURN TYPE RECORD */
     2530    case (DAE.CALL(path=path, attr=ca), DAE.CALL(path=path1, attr=ca1))
     2531      guard(Types.isRecord(ca.ty) and Types.isRecord(ca1.ty))
     2532    equation
     2533      // tmp1 = f1()
     2534      uniqueEqIndex = iuniqueEqIndex;
     2535      tp = Expression.typeof(inExp);
     2536      ident = AbsynUtil.pathStringUnquoteReplaceDot(path, "_");
     2537      cr = ComponentReference.makeCrefIdent("$TMP_" + ident + intString(uniqueEqIndex), tp, {});
     2538      e1 = Expression.makeCrefExp(cr, tp);
     2539      stms = DAE.STMT_ASSIGN(tp, e1, inExp, source);
     2540      simeqn_complex = SimCode.SES_ALGORITHM(uniqueEqIndex, {stms}, eqAttr);
     2541      uniqueEqIndex = uniqueEqIndex + 1;
     2542
     2543      // tmp2 = f2()
     2544      tp1 = Expression.typeof(inExp1);
     2545      ident1 =  AbsynUtil.pathStringUnquoteReplaceDot(path1, "_");
     2546      cr1 = ComponentReference.makeCrefIdent("$TMP_" + ident + intString(uniqueEqIndex), tp1, {});
     2547      e2 = Expression.makeCrefExp(cr1, tp1);
     2548      stms1 = DAE.STMT_ASSIGN(tp1, e2, inExp1, source);
     2549      simeqn_complex1 = SimCode.SES_ALGORITHM(uniqueEqIndex, {stms1}, eqAttr);
     2550      uniqueEqIndex = uniqueEqIndex + 1;
     2551
     2552      // tmp1 - tmp2 = 0
     2553      crexplst = Expression.splitRecord(e1, tp);
     2554      crexplst1 = Expression.splitRecord(e2, tp1);
     2555      exptl = List.zip(crexplst, crexplst1);
     2556      (eqSystlst, uniqueEqIndex) = List.map2Fold(exptl, makeSES_RESIDUAL1, source, eqAttr, uniqueEqIndex);
     2557
     2558      eqSystlst = simeqn_complex :: simeqn_complex1 :: eqSystlst;
     2559
     2560      tempvars = createTempVarsforCrefs(listReverse(crexplst), itempvars);
     2561      tempvars = createTempVarsforCrefs(listReverse(crexplst1), tempvars);
     2562    then (eqSystlst, uniqueEqIndex, tempvars);
     2563
    25982564    // failure
    25992565    else equation
     
    26202586  (equations_, ouniqueEqIndex, otempvars) := match (inExp, inExp1)
    26212587    local
    2622       DAE.ComponentRef cr;
     2588      DAE.ComponentRef cr, cr1;
     2589      DAE.Exp e1, e2, e1_1, e2_1;
    26232590      list<DAE.ComponentRef> callCrefs;
    2624       DAE.Statement stms;
    2625       DAE.Type tp;
    2626       list<DAE.Exp> expl, callExps, crexplst, lhsExpLstRes, rhsExpLstRes, lhsExpLstAss, rhsExpLstAss;
    2627       SimCode.SimEqSystem simeqn_complex;
     2591      DAE.Statement stms, stms1;
     2592      DAE.Type tp, tp1;
     2593      list<DAE.Exp> expl, e1lst, e2lst, callExps, crexplst, crexplst1, lhsExpLstRes, rhsExpLstRes, lhsExpLstAss, rhsExpLstAss;
     2594      SimCode.SimEqSystem simeqn_complex, simeqn_complex1;
    26282595      list<SimCode.SimEqSystem> eqSystlst, eqSystlst_simpAss;
    26292596      list<tuple<DAE.Exp, DAE.Exp>> exptl;
    26302597      Integer uniqueEqIndex;
    2631       Absyn.Path path;
    2632       String ident;
     2598      Absyn.Path path, path1, rpath;
     2599      String ident, ident1;
     2600      list<DAE.Var> varLst;
    26332601      list<SimCodeVar.SimVar> tempvars;
     2602      DAE.CallAttributes ca, ca1;
     2603
     2604    /* casts */
     2605    case (DAE.CAST(_, e1), _)
     2606    then createNonlinearResidualEquationsComplex(e1, inExp1, source, eqAttr, iuniqueEqIndex, itempvars);
     2607
     2608    /* casts */
     2609    case (_, DAE.CAST(_, e2))
     2610    then createNonlinearResidualEquationsComplex(inExp, e2, source, eqAttr, iuniqueEqIndex, itempvars);
     2611
     2612    /* a = f() */
     2613    case (DAE.CREF(componentRef=cr), _)
     2614    then createNonlinearResidualEquationsComplexCref(inExp, inExp1, cr, source, eqAttr, iuniqueEqIndex, itempvars);
     2615
     2616    /* f() = a */
     2617    case (_, DAE.CREF(componentRef=cr))
     2618    then createNonlinearResidualEquationsComplexCref(inExp1, inExp, cr, source, eqAttr, iuniqueEqIndex, itempvars);
     2619
     2620    /* Record() = f() */
     2621    case (DAE.CALL(expLst=e2lst, attr=DAE.CALL_ATTR(ty= tp as DAE.T_COMPLEX(varLst=varLst, complexClassType=ClassInf.RECORD(rpath)))), DAE.CALL(path=path))
     2622      guard(AbsynUtil.pathEqual(path, rpath))
     2623    then createNonlinearResidualEquationsComplexRecord(inExp, inExp1, source, eqAttr, path, tp, e2lst, varLst, iuniqueEqIndex, itempvars);
     2624    /* f() = Record() */
     2625
     2626    case (DAE.CALL(path=path), DAE.CALL(expLst=e2lst, attr=DAE.CALL_ATTR(ty= tp as DAE.T_COMPLEX(varLst=varLst, complexClassType=ClassInf.RECORD(rpath)))))
     2627      guard(AbsynUtil.pathEqual(path, rpath))
     2628    then createNonlinearResidualEquationsComplexRecord(inExp1, inExp, source, eqAttr, path, tp, e2lst, varLst, iuniqueEqIndex, itempvars);
    26342629
    26352630    /* Tuple() = f()  */
     
    26672662    then (eqSystlst, uniqueEqIndex, tempvars);
    26682663
    2669     /* To-Do: Add other cases
    2670        - a = f()
    2671        - f() = a
    2672        - Record() = f()
    2673        - f() = Record()
    2674     */
     2664    /* f1() = f2() RETURN TYPE RECORD*/
     2665    case (DAE.CALL(path=path, attr=ca), DAE.CALL(path=path1, attr=ca1))
     2666      guard(Types.isRecord(ca.ty) and Types.isRecord(ca1.ty))
     2667    equation
     2668      uniqueEqIndex = iuniqueEqIndex;
     2669      tp = Expression.typeof(inExp);
     2670      ident = AbsynUtil.pathStringUnquoteReplaceDot(path, "_");
     2671      cr = ComponentReference.makeCrefIdent("$TMP_" + ident + intString(uniqueEqIndex), tp, {});
     2672      e1 = Expression.makeCrefExp(cr, tp);
     2673      stms = DAE.STMT_ASSIGN(tp, e1, inExp, source);
     2674      simeqn_complex = SimCode.SES_ALGORITHM(uniqueEqIndex, {stms}, eqAttr);
     2675      uniqueEqIndex = uniqueEqIndex + 1;
     2676
     2677      // tmp2 = f2()
     2678      tp1 = Expression.typeof(inExp1);
     2679      ident1 =  AbsynUtil.pathStringUnquoteReplaceDot(path1, "_");
     2680      cr1 = ComponentReference.makeCrefIdent("$TMP_" + ident + intString(uniqueEqIndex), tp1, {});
     2681      e2 = Expression.makeCrefExp(cr1, tp1);
     2682      stms1 = DAE.STMT_ASSIGN(tp1, e2, inExp1, source);
     2683      simeqn_complex1 = SimCode.SES_ALGORITHM(uniqueEqIndex, {stms1}, eqAttr);
     2684      uniqueEqIndex = uniqueEqIndex + 1;
     2685
     2686      // tmp1 - tmp2 = 0
     2687      crexplst = Expression.splitRecord(e1, tp);
     2688      crexplst1 = Expression.splitRecord(e2, tp1);
     2689      exptl = List.zip(crexplst, crexplst1);
     2690      (eqSystlst, uniqueEqIndex) = List.map2Fold(exptl, makeSES_RESIDUAL1, source, eqAttr, uniqueEqIndex);
     2691
     2692      eqSystlst = simeqn_complex :: simeqn_complex1 :: eqSystlst;
     2693
     2694      tempvars = createTempVarsforCrefs(listReverse(crexplst), itempvars);
     2695      tempvars = createTempVarsforCrefs(listReverse(crexplst1), tempvars);
     2696    then (eqSystlst, uniqueEqIndex, tempvars);
     2697
     2698    else fail();
     2699
    26752700  end match;
    26762701end createNonlinearResidualEquationsSingleComplex;
     2702
     2703protected function createNonlinearResidualEquationsComplexCref
     2704  input DAE.Exp inExp;
     2705  input DAE.Exp inExp1;
     2706  input DAE.ComponentRef cr;
     2707  input DAE.ElementSource source;
     2708  input BackendDAE.EquationAttributes eqAttr;
     2709  output list<SimCode.SimEqSystem> eqSystlst;
     2710  input output Integer uniqueEqIndex;
     2711  input output list<SimCodeVar.SimVar> tempvars;
     2712protected
     2713  DAE.Exp exp, etmp;
     2714  DAE.Type tp;
     2715  Absyn.Path path;
     2716  list<DAE.Var> varLst;
     2717  String ident;
     2718  DAE.ComponentRef crtmp;
     2719  list<DAE.Exp> e1lst, e2lst;
     2720  list<tuple<DAE.Exp, DAE.Exp>> exptl;
     2721  DAE.Statement stms;
     2722algorithm
     2723  // ((e1_1, _)) = Expression.extendArrExp((inExp, false));
     2724  (exp, _) := Expression.extendArrExp(inExp1, false);
     2725  // true = ComponentReference.crefEqualNoStringCompare(cr, cr2);
     2726  (tp as DAE.T_COMPLEX(varLst=varLst, complexClassType=ClassInf.RECORD(path))) := Expression.typeof(inExp);
     2727  // tmp
     2728  ident := AbsynUtil.pathStringUnquoteReplaceDot(path, "_");
     2729  crtmp := ComponentReference.makeCrefIdent("$TMP_" + ident + intString(uniqueEqIndex), tp, {});
     2730  tempvars := createTempVars(varLst, crtmp, tempvars);
     2731  // 0 = a - tmp
     2732  e1lst := List.map1(varLst, Expression.generateCrefsExpFromExpVar, cr);
     2733  e2lst := List.map1(varLst, Expression.generateCrefsExpFromExpVar, crtmp);
     2734  exptl := List.zip(e1lst, e2lst);
     2735  (eqSystlst, uniqueEqIndex) := List.map2Fold(exptl, makeSES_RESIDUAL1, source, eqAttr, uniqueEqIndex);
     2736  // tmp = f(x, y)
     2737  etmp := Expression.crefExp(crtmp);
     2738  stms := DAE.STMT_ASSIGN(tp, etmp, exp, source);
     2739  eqSystlst := SimCode.SES_ALGORITHM(uniqueEqIndex, {stms}, eqAttr)::eqSystlst;
     2740  uniqueEqIndex := uniqueEqIndex + 1;
     2741end createNonlinearResidualEquationsComplexCref;
     2742
     2743protected function createNonlinearResidualEquationsComplexRecord
     2744  input DAE.Exp inExp;
     2745  input DAE.Exp inExp1;
     2746  input DAE.ElementSource source;
     2747  input BackendDAE.EquationAttributes eqAttr;
     2748  input Absyn.Path path;
     2749  input DAE.Type tp;
     2750  input list<DAE.Exp> e2lst;
     2751  input list<DAE.Var> varLst;
     2752  output list<SimCode.SimEqSystem> eqSystlst;
     2753  input output Integer uniqueEqIndex;
     2754  input output list<SimCodeVar.SimVar> tempvars;
     2755protected
     2756  DAE.ComponentRef cr;
     2757  DAE.Exp e1_1, e2_1;
     2758  list<DAE.Exp> e1lst;
     2759  list<tuple<DAE.Exp, DAE.Exp>> exptl;
     2760  String ident;
     2761  DAE.Statement stms;
     2762  SimCode.SimEqSystem simeqn_complex;
     2763algorithm
     2764  (e2_1, _) := Expression.extendArrExp(inExp1, false);
     2765  // tmp = f()
     2766  ident := AbsynUtil.pathStringUnquoteReplaceDot(path, "_");
     2767  cr := ComponentReference.makeCrefIdent("$TMP_" + ident + intString(uniqueEqIndex), tp, {});
     2768  e1_1 := Expression.crefToExp(cr);
     2769  stms := DAE.STMT_ASSIGN(tp, e1_1, e2_1, source);
     2770  simeqn_complex := SimCode.SES_ALGORITHM(uniqueEqIndex, {stms}, eqAttr);
     2771  uniqueEqIndex := uniqueEqIndex + 1;
     2772  // Record()-tmp = 0
     2773  /* Expand the tmp record and any arrays */
     2774  e1lst := Expression.expandExpression(e1_1, expandRecord = true);
     2775  /* Expand the varLst. Each var might be an array or record. */
     2776  /* pair each of the expanded expressions to coressponding one*/
     2777  exptl := List.zip(e1lst, List.mapFlat(e2lst, function Expression.expandExpression(expandRecord = true)));
     2778  /* Create residual equations for each pair*/
     2779  (eqSystlst, uniqueEqIndex) := List.map2Fold(exptl, makeSES_RESIDUAL1, source, eqAttr, uniqueEqIndex);
     2780  eqSystlst := simeqn_complex::eqSystlst;
     2781  tempvars := createTempVars(varLst, cr, tempvars);
     2782end createNonlinearResidualEquationsComplexRecord;
    26772783
    26782784protected function createTmpCrefExpsForComplexEqnSys
     
    27222828      list<DAE.Exp> tmp_lhsExpLstRes = {}, tmp_rhsExpLstRes = {}, tmp_lhsExpLstAss = {}, tmp_rhsExpLstAss = {};
    27232829      Boolean isEqCref, createTmpVar = false;
     2830      Absyn.Path path;
    27242831
    27252832    // Wild cref
     
    28002907        end if;
    28012908      then e;
     2909
     2910    case DAE.CALL(path = path, attr = DAE.CALL_ATTR(ty = ty))
     2911      algorithm
     2912        // if there is a call, create a temporary variable for it
     2913        // kabdelhak: fix for dataReconciliation, maybe needs rework!
     2914        name := AbsynUtil.pathStringUnquoteReplaceDot(path, "_");
     2915        cr := ComponentReference.makeCrefIdent("$TMP_" + name + intString(System.tmpTick()), ty, {});
     2916        e := Expression.makeCrefExp(cr, ty);
     2917        lhsExpLstAss := e :: lhsExpLstAss;
     2918        rhsExpLstAss := inExp :: rhsExpLstAss;
     2919    then e;
    28022920
    28032921    else
     
    49865104          print("analytical Jacobians -> creating SimCode equations for Matrix " + name + " time: " + realString(clock()) + "\n");
    49875105        end if;
    4988         (allEquations, constantEqns, uniqueEqIndex, _) = getSimEqSystemForJacobians(systs, shared, uniqueEqIndex, {});
     5106        (allEquations, constantEqns, uniqueEqIndex, tempvars) = getSimEqSystemForJacobians(systs, shared, uniqueEqIndex, {});
     5107        crefToSimVarHTJacobian = List.fold(tempvars, HashTableCrefSimVar.addSimVarToHashTable, crefToSimVarHTJacobian);
    49895108        if Flags.isSet(Flags.JAC_DUMP2) then
    49905109          print("analytical Jacobians -> created all SimCode equations for Matrix " + name +  " time: " + realString(clock()) + "\n");
Note: See TracChangeset for help on using the changeset viewer.