Changeset c3cf1e92 in OpenModelica


Ignore:
Timestamp:
2016-04-07T14:45:44+02:00 (8 years ago)
Author:
hudson <openmodelica@…>
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:
2c7da6d
Parents:
f6051a17
git-author:
Martin Sjölund <martin.sjolund@…> (04/07/16 14:45:44)
git-committer:
hudson <openmodelica@…> (04/07/16 14:45:44)
Message:

Improve extractVarsFromList

Send in some variables by closure instead of updating tuples in
each iteration. Only call derVarFromStateVar on state variables.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Compiler/SimCode/SimCodeUtil.mo

    r41d4cef rc3cf1e92  
    62846284  BackendDAE.EqSystems systs1, systs2;
    62856285  DAE.FunctionTree funcTree;
    6286   HashSet.HashSet hs = HashSet.emptyHashSet();
     6286  array<HashSet.HashSet> hs = arrayCreate(1, HashSet.emptyHashSet());
    62876287algorithm
    62886288  BackendDAE.DAE(eqs=systs1, shared=BackendDAE.SHARED(knownVars=knvars1, externalObjects=extvars1, aliasVars=aliasVars1, functionTree=funcTree)) := inSimDAE;
    62896289  BackendDAE.DAE(eqs=systs2, shared=BackendDAE.SHARED(knownVars=knvars2, externalObjects=extvars2, aliasVars=aliasVars2)) := inInitDAE;
    6290 
    6291   systs1 := List.filterOnFalse(systs1, BackendDAEUtil.isClockedSyst);
    6292   systs2 := List.filterOnFalse(systs2, BackendDAEUtil.isClockedSyst);
    62936290
    62946291  if not Flags.isSet(Flags.NO_START_CALC) then
     
    63006297  // ### simulation ###
    63016298  // Extract from variable list
    6302   ((outVars, _, _, hs)) := List.fold1(List.map(systs1, BackendVariable.daeVars), BackendVariable.traverseBackendDAEVars, extractVarsFromList, (SimCodeVar.emptySimVars, aliasVars1, knvars1, hs));
     6299  outVars := List.fold1(list(BackendVariable.daeVars(syst) for syst guard not BackendDAEUtil.isClockedSyst(syst) in systs1), BackendVariable.traverseBackendDAEVars, function extractVarsFromList(aliasVars=aliasVars1, vars=knvars1, hs=hs), SimCodeVar.emptySimVars);
    63036300
    63046301  // Extract from known variable list
    6305   ((outVars, _, _, hs)) := BackendVariable.traverseBackendDAEVars(knvars1, extractVarsFromList, (outVars, aliasVars1, knvars1, hs));
     6302  outVars := BackendVariable.traverseBackendDAEVars(knvars1, function extractVarsFromList(aliasVars=aliasVars1, vars=knvars1, hs=hs), outVars);
    63066303
    63076304  // Extract from removed variable list
    6308   ((outVars, _, _, hs)) := BackendVariable.traverseBackendDAEVars(aliasVars1, extractVarsFromList, (outVars, aliasVars1, knvars1, hs));
     6305  outVars := BackendVariable.traverseBackendDAEVars(aliasVars1, function extractVarsFromList(aliasVars=aliasVars1, vars=knvars1, hs=hs), outVars);
    63096306
    63106307  // Extract from external object list
    6311   ((outVars, _, _, hs)) := BackendVariable.traverseBackendDAEVars(extvars1, extractVarsFromList, (outVars, aliasVars1, knvars1, hs));
     6308  outVars := BackendVariable.traverseBackendDAEVars(extvars1, function extractVarsFromList(aliasVars=aliasVars1, vars=knvars1, hs=hs), outVars);
    63126309
    63136310
    63146311  // ### initialization ###
    63156312  // Extract from variable list
    6316   ((outVars, _, _, hs)) := List.fold1(List.map(systs2, BackendVariable.daeVars), BackendVariable.traverseBackendDAEVars, extractVarsFromList, (outVars, aliasVars2, knvars2, hs));
     6313  outVars := List.fold1(list(BackendVariable.daeVars(syst) for syst guard not BackendDAEUtil.isClockedSyst(syst) in systs2), BackendVariable.traverseBackendDAEVars, function extractVarsFromList(aliasVars=aliasVars2, vars=knvars2, hs=hs), outVars);
    63176314
    63186315  // Extract from known variable list
    6319   ((outVars, _, _, hs)) := BackendVariable.traverseBackendDAEVars(knvars2, extractVarsFromList, (outVars, aliasVars2, knvars2, hs));
     6316  outVars := BackendVariable.traverseBackendDAEVars(knvars2, function extractVarsFromList(aliasVars=aliasVars2, vars=knvars2, hs=hs), outVars);
    63206317
    63216318  // Extract from removed variable list
    6322   ((outVars, _, _, hs)) := BackendVariable.traverseBackendDAEVars(aliasVars2, extractVarsFromList, (outVars, aliasVars2, knvars2, hs));
     6319  outVars := BackendVariable.traverseBackendDAEVars(aliasVars2, function extractVarsFromList(aliasVars=aliasVars2, vars=knvars2, hs=hs), outVars);
    63236320
    63246321  // Extract from external object list
    6325   ((outVars, _, _, hs)) := BackendVariable.traverseBackendDAEVars(extvars2, extractVarsFromList, (outVars, aliasVars2, knvars2, hs));
     6322  outVars := BackendVariable.traverseBackendDAEVars(extvars2, function extractVarsFromList(aliasVars=aliasVars2, vars=knvars2, hs=hs), outVars);
    63266323
    63276324  //BaseHashSet.printHashSet(hs);
     
    64476444
    64486445protected function extractVarsFromList
    6449   input BackendDAE.Var inVar;
    6450   input tuple<SimCodeVar.SimVars, BackendDAE.Variables, BackendDAE.Variables, HashSet.HashSet /*all processed crefs*/> inTpl;
    6451   output BackendDAE.Var outVar = inVar;
    6452   output tuple<SimCodeVar.SimVars, BackendDAE.Variables, BackendDAE.Variables, HashSet.HashSet /*all processed crefs*/> outTpl;
    6453 protected
    6454   SimCodeVar.SimVars vars;
    6455   BackendDAE.Variables aliasVars, v;
    6456   HashSet.HashSet hs;
    6457 algorithm
    6458   (vars, aliasVars, v, hs) := inTpl;
    6459 
    6460   if not BaseHashSet.has(inVar.varName, hs) and not ComponentReference.isPreCref(inVar.varName) then
    6461     (vars, hs) := extractVarFromVar(inVar, aliasVars, v, vars, hs);
     6446  input output BackendDAE.Var var;
     6447  input output SimCodeVar.SimVars simVars;
     6448  input BackendDAE.Variables aliasVars, vars;
     6449  input array<HashSet.HashSet> hs;
     6450algorithm
     6451  if if ComponentReference.isPreCref(var.varName) then false else not BaseHashSet.has(var.varName, arrayGet(hs,1)) then
     6452    simVars := extractVarFromVar(var, aliasVars, vars, simVars, hs);
    64626453  //  print("Added  " + ComponentReference.printComponentRefStr(inVar.varName) + "\n");
    64636454  //else
    64646455  //  print("Skiped " + ComponentReference.printComponentRefStr(inVar.varName) + "\n");
    64656456  end if;
    6466 
    6467   outTpl := (vars, aliasVars, v, hs);
    64686457end extractVarsFromList;
    64696458
     
    64756464  input BackendDAE.Variables inVars;
    64766465  input SimCodeVar.SimVars varsIn;
    6477   input HashSet.HashSet inHS "all processed crefs";
     6466  input array<HashSet.HashSet> hs "all processed crefs";
    64786467  output SimCodeVar.SimVars varsOut;
    6479   output HashSet.HashSet outHS = inHS;
    64806468protected
    64816469  list<SimCodeVar.SimVar> stateVars;
     
    65186506  // extract the sim var
    65196507  simvar := dlowvarToSimvar(dlowVar, SOME(inAliasVars), inVars);
    6520   derivSimvar := derVarFromStateVar(simvar);
    65216508  isalias := isAliasVar(simvar);
    65226509
    65236510
    65246511  // update HashSet
    6525   outHS := BaseHashSet.add(simvar.name, outHS);
     6512  arrayUpdate(hs, 1, BaseHashSet.add(simvar.name, arrayGet(hs,1)));
    65266513  if (not isalias) and (BackendVariable.isStateVar(dlowVar) or BackendVariable.isAlgState(dlowVar)) then
    6527     outHS := BaseHashSet.add(derivSimvar.name, outHS);
     6514    derivSimvar := derVarFromStateVar(simvar);
     6515    arrayUpdate(hs, 1, BaseHashSet.add(derivSimvar.name, arrayGet(hs,1)));
     6516  else
     6517    derivSimvar := simvar; // Just in case
    65286518  end if;
    65296519
Note: See TracChangeset for help on using the changeset viewer.