Changeset fbcb97e in OpenModelica
- Timestamp:
- 2020-10-21T15:15:32+02:00 (3 years ago)
- Children:
- 319df87
- Parents:
- ca0708d0
- git-author:
- arun3688 <rain100falls@…> (09/28/20 14:36:39)
- git-committer:
- Adrian Pop <adrian.pop@…> (10/21/20 15:15:32)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
OMCompiler/Compiler/BackEnd/DataReconciliation.mo
rc0e8727d rfbcb97e 80 80 list<list<String>> allBlocksStatusVarInfo; 81 81 list<tuple<Integer, BackendDAE.Equation>> e_BLT_EquationsWithIndex; 82 ExtAdjacencyMatrix eBltAdjacencyMatrix, sBltAdjacencyMatrix ;82 ExtAdjacencyMatrix eBltAdjacencyMatrix, sBltAdjacencyMatrix, setS_BLTAdjacencyMatrix; 83 83 list<tuple<Integer, Integer>> e_BLTSolvedEqsAndVars; 84 84 list<tuple<list<Integer>, Integer>> e_BLTBlockRanks, s_BLTBlockRanks; … … 91 91 String str, modelicaOutput, modelicaFileName; 92 92 93 list<Integer> allVarsList, knowns, unknowns, boundaryConditionVars, exactEquationVars, extractedVarsfromSetS, constantVars, knownVariablesWithEquationBinding, boundaryConditionTaggedEquationSolvedVars ;93 list<Integer> allVarsList, knowns, unknowns, boundaryConditionVars, exactEquationVars, extractedVarsfromSetS, constantVars, knownVariablesWithEquationBinding, boundaryConditionTaggedEquationSolvedVars, unknownVarsInSetC; 94 94 BackendDAE.Variables inputVars, outDiffVars, outOtherVars, outResidualVars; 95 95 … … 329 329 end if; 330 330 331 extractedVarsfromSetS := getVariablesAfterExtraction({}, tempSetS, sBltAdjacencyMatrix);332 extractedVarsfromSetS := List.setDifferenceOnTrue(extractedVarsfromSetS, knowns, intEq);331 //extractedVarsfromSetS := getVariablesAfterExtraction({}, tempSetS, sBltAdjacencyMatrix); 332 //extractedVarsfromSetS := List.setDifferenceOnTrue(extractedVarsfromSetS, knowns, intEq); 333 333 334 334 setC := List.unique(getAbsoluteIndexHelper(tempSetC, mapIncRowEqn)); 335 335 setS := List.unique(getAbsoluteIndexHelper(tempSetS, mapIncRowEqn)); 336 337 //print("\nFINAL SET OF EQUATIONS After Mapping \n" + UNDERLINE + "\n" +"SET_C: "+dumplistInteger(setC)+"\n" +"SET_S: "+ dumplistInteger(setS)+ "\n\n" );338 336 339 337 setC_Eq := getEquationsFromSBLTAndEBLT(setC, currentSystem.orderedEqs, e_BLT_EquationsWithIndex); … … 344 342 BackendDump.dumpEquationArray(BackendEquation.listEquation(setC_Eq), "SET_C"); 345 343 BackendDump.dumpEquationArray(BackendEquation.listEquation(setS_Eq), "SET_S"); 344 345 unknownVarsInSetC := getVariablesAfterExtraction(tempSetC, {}, sBltAdjacencyMatrix); 346 unknownVarsInSetC := listReverse(List.setDifferenceOnTrue(unknownVarsInSetC, knowns, intEq)); 347 348 // get the blt adjacencyMatrix asscoiated with extracted SET-S 349 setS_BLTAdjacencyMatrix := getSetSAdjacencyMatrix(sBltAdjacencyMatrix, tempSetS); 350 351 if debug then 352 print("\nStart of Extract Minimal Set-S Algorithm\n" + UNDERLINE + "\n"); 353 print("\nSet-S Adjacency MAtrix : " + intString(listLength(setS_BLTAdjacencyMatrix)) + "\n" + UNDERLINE + "\n" + anyString(setS_BLTAdjacencyMatrix)); 354 print("\nS' : {}"); 355 print("\nV_C :" + dumplistInteger(unknownVarsInSetC) + "\n"); 356 end if; 357 358 // run the minimal SET-S extraction algorithm 359 (_, tempSetS) := extractMinimalSetS(unknownVarsInSetC, setS_BLTAdjacencyMatrix, knowns, currentSystem.orderedVars, currentSystem.orderedEqs, mapIncRowEqn, {}, debug); 360 361 if debug then 362 print("\n****End of Minimal extraction Algorithm****\n"); 363 print("\nSet-S after running minimal extraction algorithm \n" + UNDERLINE + "\n" +"SET_S: "+dumplistInteger(tempSetS)+ "\n\n"); 364 end if; 365 366 extractedVarsfromSetS := getVariablesAfterExtraction({}, tempSetS, sBltAdjacencyMatrix); 367 extractedVarsfromSetS := List.setDifferenceOnTrue(extractedVarsfromSetS, knowns, intEq); 368 369 setC := List.unique(getAbsoluteIndexHelper(tempSetC, mapIncRowEqn)); 370 setS := List.unique(getAbsoluteIndexHelper(tempSetS, mapIncRowEqn)); 371 372 //print("\nFINAL SET OF EQUATIONS After Mapping \n" + UNDERLINE + "\n" +"SET_C: "+dumplistInteger(setC)+"\n" +"SET_S: "+ dumplistInteger(setS)+ "\n\n" ); 373 374 setC_Eq := getEquationsFromSBLTAndEBLT(setC, currentSystem.orderedEqs, e_BLT_EquationsWithIndex); 375 setS_Eq := getEquationsFromSBLTAndEBLT(setS, currentSystem.orderedEqs, e_BLT_EquationsWithIndex); 376 377 // dump minimal SET-S equations 378 BackendDump.dumpEquationArray(BackendEquation.listEquation(setS_Eq), "SET_S_After_Minimal_Extraction"); 346 379 347 380 // prepare outdiff vars (i.e) variables of interest … … 418 451 outDAE := BackendDAE.DAE({currentSystem}, shared); 419 452 end extractionAlgorithm; 453 454 protected function getSetSAdjacencyMatrix 455 "return the adjacency matrix associated with set-S" 456 input ExtAdjacencyMatrix sBltAdjacencyMatrix; 457 input list<Integer> setS; 458 output ExtAdjacencyMatrix setS_BltAdjacencyMatrix = {}; 459 protected 460 Integer eq; 461 algorithm 462 for i in sBltAdjacencyMatrix loop 463 (eq, _) := i; 464 if listMember(eq, setS) then 465 setS_BltAdjacencyMatrix := i :: setS_BltAdjacencyMatrix; 466 end if; 467 end for; 468 end getSetSAdjacencyMatrix; 469 470 protected function extractMinimalSetS 471 "construct a minimal set-S using recursive algorithm, which are needed to solve intermediate 472 variables in set-c and also avoid complication when calculating jacobians" 473 input output list<Integer> unknownsInSetC; 474 input ExtAdjacencyMatrix sBltAdjacencyMatrix; 475 input list<Integer> knownVars; 476 input BackendDAE.Variables orderedVars; 477 input BackendDAE.EquationArray orderedEqs; 478 input array<Integer> mapIncRowEqn; 479 input output list<Integer> minimalSetS = {}; 480 input Boolean debug; 481 protected 482 Integer firstMatchedEquation, mappedEq; 483 BackendDAE.Var var; 484 BackendDAE.Equation tmpEq; 485 list<Integer> rest, vars, intermediateVars = {}, V_EQ; 486 algorithm 487 for varIndex in unknownsInSetC loop 488 // break the recursion loop 489 if listEmpty(unknownsInSetC) then 490 break; 491 end if; 492 if debug then 493 print("\nIntermediate varList : " + dumplistInteger(unknownsInSetC) + "\n" + UNDERLINE + "\n"); 494 end if; 495 _ :: rest := unknownsInSetC; 496 (firstMatchedEquation, vars) := getVariableFirstOccurrenceInEquation(sBltAdjacencyMatrix, varIndex, minimalSetS); 497 var := BackendVariable.getVarAt(orderedVars, varIndex); 498 499 if not intEq(firstMatchedEquation, 0) then // equation exists 500 minimalSetS := firstMatchedEquation :: minimalSetS; // insert the equation into S' 501 minimalSetS := List.unique(minimalSetS); 502 intermediateVars := List.setDifferenceOnTrue(vars, knownVars, intEq); // get intermediate vars in matched equations 503 V_EQ := List.unique(listAppend(intermediateVars, rest)); 504 if debug then 505 dumpMininimalExtraction(varIndex, var, firstMatchedEquation, mapIncRowEqn, orderedEqs, minimalSetS, intermediateVars, rest, V_EQ, false); 506 end if; 507 // V_EQ exist, recursive call 508 (unknownsInSetC, minimalSetS) := extractMinimalSetS(V_EQ, sBltAdjacencyMatrix, knownVars, orderedVars, orderedEqs, mapIncRowEqn, minimalSetS, debug); 509 else // equation not exist 510 if debug then 511 dumpMininimalExtraction(varIndex, var, 0, mapIncRowEqn, orderedEqs, {}, {}, rest, {}, true); 512 end if; 513 unknownsInSetC := rest; // update the list with the remaining Vars 514 end if; 515 end for; 516 end extractMinimalSetS; 517 518 protected function dumpMininimalExtraction 519 "dumps the minimal set-S extraction algorithm" 520 input Integer varIndex; 521 input BackendDAE.Var var; 522 input Integer firstMatchedEquation; 523 input array<Integer> mapIncRowEqn; 524 input BackendDAE.EquationArray orderedEqs; 525 input list<Integer> minimalSetS; 526 input list<Integer> intermediateVars; 527 input list<Integer> rest; 528 input list<Integer> V_EQ; 529 input Boolean falseBlock; 530 protected 531 Integer mappedEq; 532 BackendDAE.Equation tmpEq; 533 algorithm 534 if falseBlock then 535 print("\nVarIndex : " + intString(varIndex)); 536 print("\nVariable Name : " + ComponentReference.printComponentRefStr(var.varName)); 537 print("\nEquation Not Exist : " + "NIL"); 538 print("\nRemainingVars : " + dumplistInteger(rest) + "\n"); 539 else 540 mappedEq := listGet(arrayList(mapIncRowEqn), firstMatchedEquation); 541 tmpEq := BackendEquation.get(orderedEqs, mappedEq); 542 //print("\n" + " (" + intString(mappedEq) + "/" + intString(firstMatchedEquation) + "): " + BackendDump.equationString(tmpEq) + "\n"); 543 print("\nVarIndex : " + intString(varIndex)); 544 print("\nVariable Name : " + ComponentReference.printComponentRefStr(var.varName)); 545 print("\nEquation Exist : " + intString(firstMatchedEquation)); 546 print("\nmappedEquation : " + intString(mappedEq)); 547 print("\nMatched Equation : " + BackendDump.equationString(tmpEq)); 548 print("\nS' : " + dumplistInteger(minimalSetS)); 549 print("\nUnknowns in matchedEquation : " + dumplistInteger(intermediateVars)); 550 print("\nRemaining Vars : " + dumplistInteger(rest)); 551 print("\nV_EQ : " + dumplistInteger(V_EQ) + "\n"); 552 end if; 553 end dumpMininimalExtraction; 554 555 protected function getVariableFirstOccurrenceInEquation 556 "returns the first equation that contains the variable index (e.g) 557 var index = 6 558 BLT = {(1, {26, 5}), (2, {25, 6}, (3, {1, 2, 6})} 559 result = (2,{25, 6})" 560 input ExtAdjacencyMatrix m; 561 input Integer varIndex; 562 input list<Integer> minimalSetS; 563 output tuple<Integer, list<Integer>> matchedEquation = (0, {}) "default value 0 means equation does not exist"; 564 protected 565 list<Integer> ret, vars, matchedeq; 566 Integer eq, eqnum, varnum; 567 algorithm 568 for i in m loop 569 (eq, vars) := i; 570 //print("\nVarcheck : " + intString(varIndex) + "=>" + anyString(eq) + " => " + anyString(vars)); 571 if eq > 0 then 572 if not listMember(eq, minimalSetS) then 573 if listMember(varIndex, vars) then 574 //print("\n Found the first equation : " + anyString(i)); 575 matchedEquation := i; 576 break; 577 end if; 578 end if; 579 end if; 580 end for; 581 end getVariableFirstOccurrenceInEquation; 420 582 421 583 protected function dumpResidualVars … … 510 672 511 673 if debug then 512 674 BackendDump.dumpVarList(daeVarsLst, "boundaryConditionVarsTaggedAsParmeters"); 513 675 end if; 514 676 … … 1245 1407 list<tuple<list<String>,Integer>> targetvarlist; 1246 1408 list<String> blockvarlst; 1247 list<Integer> ranklist, blocks1;1409 list<Integer> ranklist, blocks1; 1248 1410 Integer rank; 1249 1411 list<tuple<list<Integer>,Integer>> updatedblocks;
Note: See TracChangeset
for help on using the changeset viewer.