Changeset f11f59c2 in OpenModelica


Ignore:
Timestamp:
2016-04-08T17:42:27+02:00 (8 years ago)
Author:
Willi Braun <wbraun@…>
Branches:
Added-citation-metadata, maintenance/v1.14, maintenance/v1.15, maintenance/v1.16, maintenance/v1.17, maintenance/v1.18, maintenance/v1.19, maintenance/v1.20, maintenance/v1.21, maintenance/v1.22, maintenance/v1.23, master, omlib-staging
Children:
6e3121a4
Parents:
1299763
git-author:
Willi Braun <wbraun@…> (04/08/16 15:52:52)
git-committer:
Willi Braun <wbraun@…> (04/08/16 17:42:27)
Message:

fixing ticket:3786

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Compiler/BackEnd/SymbolicJacobian.mo

    r18c51d6e rf11f59c2  
    10031003  cols with the same color."
    10041004  input BackendDAE.BackendDAE inBackendDAE;
    1005   input list<BackendDAE.Var> inDiffVars "vars";
    1006   input list<BackendDAE.Var> inDiffedVars "eqns";
     1005  input list<BackendDAE.Var> inIndependentVars "vars";
     1006  input list<BackendDAE.Var> inDependentVars "eqns";
    10071007  output BackendDAE.SparsePattern outSparsePattern;
    10081008  output BackendDAE.SparseColoring outColoredCols;
    10091009protected
    1010   constant Boolean debug = false;
    1011 algorithm
    1012   (outSparsePattern,outColoredCols) := matchcontinue(inBackendDAE,inDiffVars,inDiffedVars)
     1010  constant Boolean debug = true;
     1011algorithm
     1012  (outSparsePattern,outColoredCols) := matchcontinue(inBackendDAE,inIndependentVars,inDependentVars)
    10131013    local
    10141014      BackendDAE.Shared shared;
     
    10251025      list<Integer> nodesList, nodesEqnsIndex;
    10261026      list<list<Integer>> sparsepattern,sparsepatternT, coloredlist;
    1027       list<BackendDAE.Var> jacDiffVars, indiffVars, indiffedVars;
     1027      list<BackendDAE.Var> jacDiffVars, dependentVars, independentVars;
    10281028      BackendDAE.Variables varswithDiffs;
    10291029      BackendDAE.EquationArray orderedEqns;
     
    10321032      array<list<Integer>> coloredArray;
    10331033
    1034       list<DAE.ComponentRef> diffCompRefsLst, diffedCompRefsLst;
    1035       array<DAE.ComponentRef> diffCompRefs, diffedCompRefs;
     1034      list<DAE.ComponentRef> depCompRefsLst, inDepCompRefsLst;
     1035      array<DAE.ComponentRef> depCompRefs, inDepCompRefs;
    10361036
    10371037      array<list<Integer>> eqnSparse, varSparse, sparseArray, sparseArrayT;
     
    10421042      list<tuple<DAE.ComponentRef,list<DAE.ComponentRef>>> sparsetuple, sparsetupleT;
    10431043
    1044     case (_,{},_) then (({},{},({},{}), -1),{});
    1045     case (_,_,{}) then (({},{},({},{}), -1),{});
    1046     case(BackendDAE.DAE(eqs = (syst as BackendDAE.EQSYSTEM(matching=bdaeMatching as BackendDAE.MATCHING(comps=comps, ass1=ass1)))::{}),indiffVars,indiffedVars)
     1044    // if there are no independent var, no pattern needed, otherwise there
     1045    // is an empty pattern for the dependent variables
     1046    case (_,_,{}) then (({},{},({},{}),-1),{});
     1047    case(BackendDAE.DAE(eqs = (syst as BackendDAE.EQSYSTEM(matching=bdaeMatching as BackendDAE.MATCHING(comps=comps, ass1=ass1)))::{}),independentVars,dependentVars)
    10471048      equation
    10481049        if Flags.isSet(Flags.DUMP_SPARSE_VERBOSE) then
    1049           print(" start getting sparsity pattern diff Vars : " + intString(listLength(indiffedVars))  + " diffed vars: " + intString(listLength(indiffVars)) +"\n");
     1050          print(" start getting sparsity pattern for variables : " + intString(listLength(dependentVars))  + " and the independent vars: " + intString(listLength(independentVars)) +"\n");
    10501051        end if;
    10511052        if debug then execStat("generateSparsePattern -> do start "); end if;
    10521053        // prepare crefs
    1053         diffCompRefsLst = List.map(indiffVars, BackendVariable.varCref);
    1054         diffedCompRefsLst = List.map(indiffedVars, BackendVariable.varCref);
    1055         diffCompRefs = listArray(diffCompRefsLst);
    1056         diffedCompRefs = listArray(diffedCompRefsLst);
     1054        depCompRefsLst = List.map(dependentVars, BackendVariable.varCref);
     1055        inDepCompRefsLst = List.map(independentVars, BackendVariable.varCref);
     1056        depCompRefs = listArray(depCompRefsLst);
     1057        inDepCompRefs = listArray(inDepCompRefsLst);
    10571058        // create jacobian vars
    1058         jacDiffVars =  list(BackendVariable.createpDerVar(v) for v in indiffVars);
    1059         sizeN = arrayLength(diffCompRefs);
     1059        jacDiffVars =  list(BackendVariable.createpDerVar(v) for v in independentVars);
     1060        sizeN = arrayLength(inDepCompRefs);
    10601061
    10611062        // generate adjacency matrix including diff vars
     
    10751076
    10761077        // get indexes of diffed vars (rows)
    1077         nodesEqnsIndex = BackendVariable.getVarIndexFromVars(indiffedVars,varswithDiffs);
     1078        nodesEqnsIndex = BackendVariable.getVarIndexFromVars(dependentVars,varswithDiffs);
    10781079        nodesEqnsIndex = List.map1(nodesEqnsIndex, Array.getIndexFirst, ass1);
    10791080
     
    10911092        mark = arrayCreate(adjSizeT, 0);
    10921093        usedvar = arrayCreate(adjSizeT, 0);
    1093         usedvar = Array.setRange(adjSizeT-(sizeN-1), adjSizeT, usedvar, 1);
     1094
     1095        // make dependent variables as used if there are some
     1096        // otherwise Array.setRange fails start is greater than end
     1097        if (sizeN>0) then
     1098          usedvar = Array.setRange(adjSizeT-(sizeN-1), adjSizeT, usedvar, 1);
     1099        end if;
    10941100
    10951101        if debug then execStat("generateSparsePattern -> start "); end if;
     
    11251131
    11261132        // translated to DAE.ComRefs
    1127         translated = list(list(arrayGet(diffCompRefs, i) for i in lst) for lst in sparsepattern);
    1128         sparsetuple = list((cr,t) threaded for cr in diffedCompRefs, t in translated);
    1129         translated = list(list(arrayGet(diffedCompRefs, i) for i in lst) for lst in sparsepatternT);
    1130         sparsetupleT = list((cr,t) threaded for cr in diffCompRefs, t in translated);
     1133        translated = list(list(arrayGet(inDepCompRefs, i) for i in lst) for lst in sparsepattern);
     1134        sparsetuple = list((cr,t) threaded for cr in depCompRefs, t in translated);
     1135        translated = list(list(arrayGet(depCompRefs, i) for i in lst) for lst in sparsepatternT);
     1136        sparsetupleT = list((cr,t) threaded for cr in inDepCompRefs, t in translated);
    11311137
    11321138        // build up a bi-partied graph of pattern
     
    11531159        arraysparseGraph = listArray(sparseGraph);
    11541160        if debug then execStat("generateSparsePattern -> coloring start "); end if;
    1155         Graph.partialDistance2colorInt(sparseGraphT, forbiddenColor, nodesList, arraysparseGraph, colored);
     1161        if (sizeN>0) then
     1162          Graph.partialDistance2colorInt(sparseGraphT, forbiddenColor, nodesList, arraysparseGraph, colored);
     1163        end if;
    11561164        if debug then execStat("generateSparsePattern -> coloring end "); end if;
    11571165        // get max color used
     
    11601168        // map index of that array into colors
    11611169        coloredArray = arrayCreate(maxColor, {});
    1162         mapIndexColors(colored, arrayLength(diffCompRefs), coloredArray);
     1170        mapIndexColors(colored, arrayLength(inDepCompRefs), coloredArray);
    11631171
    11641172        if Flags.isSet(Flags.DUMP_SPARSE) then
     
    11671175        end if;
    11681176
    1169         coloring = list(list(arrayGet(diffCompRefs, i) for i in lst) for lst in coloredArray);
     1177        coloring = list(list(arrayGet(inDepCompRefs, i) for i in lst) for lst in coloredArray);
    11701178
    11711179        //without coloring
    1172         //coloring = List.transposeList({diffCompRefs});
     1180        //coloring = List.transposeList({inDepCompRefs});
    11731181        if Flags.isSet(Flags.DUMP_SPARSE_VERBOSE) then
    11741182          print("analytical Jacobians[SPARSE] -> ready! " + realString(clock()) + "\n");
    11751183        end if;
    11761184        if debug then execStat("generateSparsePattern -> final end "); end if;
    1177       then ((sparsetupleT, sparsetuple, (diffCompRefsLst, diffedCompRefsLst), nonZeroElements), coloring);
     1185      then ((sparsetupleT, sparsetuple, (inDepCompRefsLst, depCompRefsLst), nonZeroElements), coloring);
    11781186    else
    11791187      algorithm
Note: See TracChangeset for help on using the changeset viewer.