Changeset 79681708 in OpenModelica
- Timestamp:
- 2023-03-21T17:40:12+01:00 (14 months ago)
- Branches:
- maintenance/v1.21, maintenance/v1.22, maintenance/v1.23, master
- Children:
- b15dde7
- Parents:
- 16cbb66
- git-author:
- phannebohm <phannebohm@…> (03/21/23 17:40:12)
- git-committer:
- GitHub <noreply@…> (03/21/23 17:40:12)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
OMCompiler/Compiler/BackEnd/Differentiate.mo
r567163d9 r79681708 594 594 595 595 // types that are not differentiated 596 case DAE.SCONST() then (inExp, inFunctionTree); 596 597 case DAE.BCONST() then (inExp, inFunctionTree); 597 case DAE. SCONST()then (inExp, inFunctionTree);598 case DAE.CLKCONST() then (inExp, inFunctionTree); 598 599 case DAE.ENUM_LITERAL() then (inExp, inFunctionTree); 599 600 … … 602 603 case DAE.RCONST() then (DAE.RCONST(0.0), inFunctionTree); 603 604 604 case DAE.RECORD(path = p, exps = expl, comp = strLst, ty=tp) 605 algorithm 606 sub := {}; 607 functionTree := inFunctionTree; 608 for e in expl loop 609 (e1, functionTree) := differentiateExp(e,inDiffwrtCref, inInputData, inDiffType, functionTree, maxIter); 610 sub := e1 :: sub; 611 end for; 612 then (DAE.RECORD(p, listReverse(sub), strLst, tp), functionTree); 613 614 // differentiate cref 615 case DAE.CREF(componentRef=cref, ty=tp) equation 616 605 case DAE.CREF(componentRef=cref, ty=tp) algorithm 617 606 if ComponentReference.isStartCref(cref) then 618 607 // differentiate start value 619 res = Expression.makeConstZero(tp);620 functionTree = inFunctionTree;608 res := Expression.makeConstZero(tp); 609 functionTree := inFunctionTree; 621 610 else 622 (res, functionTree) = differentiateCrefs(inExp, inDiffwrtCref, inInputData, inDiffType, inFunctionTree, maxIter-1);611 (res, functionTree) := differentiateCrefs(inExp, inDiffwrtCref, inInputData, inDiffType, inFunctionTree, maxIter-1); 623 612 end if; 624 613 then (res, functionTree); 614 615 case DAE.BINARY() algorithm 616 (res, functionTree) := differentiateBinary(inExp, inDiffwrtCref, inInputData, inDiffType, inFunctionTree, maxIter-1); 617 res := ExpressionSimplify.simplifyBinaryExp(res); 618 then (res, functionTree); 619 620 case DAE.UNARY(operator=op, exp=e1) algorithm 621 (res, functionTree) := differentiateExp(e1, inDiffwrtCref, inInputData, inDiffType, inFunctionTree, maxIter-1); 622 res := DAE.UNARY(op, res); 623 res := ExpressionSimplify.simplifyUnaryExp(res); 624 then (res, functionTree); 625 626 // boolean expression, e.g. relation, are left as they are 627 case DAE.LBINARY() then (inExp, inFunctionTree); 628 case DAE.LUNARY() then (inExp, inFunctionTree); 629 case DAE.RELATION() then (inExp, inFunctionTree); 630 631 case DAE.IFEXP(expCond=e1, expThen=e2, expElse=e3) algorithm 632 (res1, functionTree) := differentiateExp(e2, inDiffwrtCref, inInputData, inDiffType, inFunctionTree, maxIter-1); 633 (res2, functionTree) := differentiateExp(e3, inDiffwrtCref, inInputData, inDiffType, functionTree, maxIter-1); 634 res := DAE.IFEXP(e1, res1, res2); 635 (res, _) := ExpressionSimplify.simplify1(res); 625 636 then (res, functionTree); 626 637 … … 642 653 */ 643 654 case DAE.CALL(path=p as Absyn.IDENT(name="semiLinear"), expLst={e1, e2, e3}, attr=attr) 644 guard(Expression.expHasCref(e2, inDiffwrtCref) or 655 guard(Expression.expHasCref(e2, inDiffwrtCref) or Expression.expHasCref(e3, inDiffwrtCref)) 645 656 then fail(); 646 657 647 658 // differentiate call 648 case DAE.CALL() equation 649 650 (res, functionTree) = differentiateCalls(inExp, inDiffwrtCref, inInputData, inDiffType, inFunctionTree, maxIter-1); 651 (res,_) = ExpressionSimplify.simplify1(res); 652 659 case DAE.CALL() algorithm 660 (res, functionTree) := differentiateCalls(inExp, inDiffwrtCref, inInputData, inDiffType, inFunctionTree, maxIter-1); 661 (res, _) := ExpressionSimplify.simplify1(res); 653 662 then (res, functionTree); 654 663 655 // differentiate binary 656 case DAE.BINARY() equation 657 658 (res, functionTree) = differentiateBinary(inExp, inDiffwrtCref, inInputData, inDiffType, inFunctionTree, maxIter-1); 659 (res) = ExpressionSimplify.simplifyBinaryExp(res); 660 664 case DAE.RECORD(path = p, exps = expl, comp = strLst, ty=tp) algorithm 665 sub := {}; 666 functionTree := inFunctionTree; 667 for e in expl loop 668 (e1, functionTree) := differentiateExp(e, inDiffwrtCref, inInputData, inDiffType, functionTree, maxIter); 669 sub := e1 :: sub; 670 end for; 671 then (DAE.RECORD(p, listReverse(sub), strLst, tp), functionTree); 672 673 case DAE.ARRAY(ty=tp, scalar=b, array=expl) algorithm 674 (expl, functionTree) := List.map3Fold(expl, function differentiateExp(maxIter=maxIter-1), inDiffwrtCref, inInputData, inDiffType, inFunctionTree); 675 res := DAE.ARRAY(tp, b, expl); 676 (res, _) := ExpressionSimplify.simplify1(res); 661 677 then (res, functionTree); 662 678 663 // differentiate operator 664 case DAE.UNARY(operator=op, exp=e1) equation 665 666 (res, functionTree) = differentiateExp(e1, inDiffwrtCref, inInputData, inDiffType, inFunctionTree, maxIter-1); 667 668 res = DAE.UNARY(op,res); 669 (res) = ExpressionSimplify.simplifyUnaryExp(res); 670 679 case DAE.MATRIX(ty=tp, integer=i, matrix=matrix) algorithm 680 (dmatrix, functionTree) := List.map3FoldList(matrix, function differentiateExp(maxIter=maxIter-1), inDiffwrtCref, inInputData, inDiffType, inFunctionTree); 681 res := DAE.MATRIX(tp, i, dmatrix); 682 (res, _) := ExpressionSimplify.simplify1(res); 671 683 then (res, functionTree); 672 684 673 // differentiate cast 674 case DAE.CAST(ty=tp, exp=e1) equation 675 676 (res, functionTree) = differentiateExp(e1, inDiffwrtCref, inInputData, inDiffType, inFunctionTree, maxIter-1); 677 (res,_) = ExpressionSimplify.simplify1(res); 678 685 case DAE.RANGE() then (inExp, inFunctionTree); 686 687 case DAE.TUPLE(PR=expl) algorithm 688 (expl, functionTree) := List.map3Fold(expl, function differentiateExp(maxIter=maxIter-1), inDiffwrtCref, inInputData, inDiffType, inFunctionTree); 689 res := DAE.TUPLE(expl); 690 (res, _) := ExpressionSimplify.simplify1(res); 691 then (res, functionTree); 692 693 case DAE.CAST(ty=tp, exp=e1) algorithm 694 (res, functionTree) := differentiateExp(e1, inDiffwrtCref, inInputData, inDiffType, inFunctionTree, maxIter-1); 695 (res, _) := ExpressionSimplify.simplify1(res); 679 696 then (DAE.CAST(tp, res), functionTree); 680 697 681 // differentiate asub 682 case DAE.ASUB(exp=e1, sub=sub) equation 683 684 (res1, functionTree) = differentiateExp(e1, inDiffwrtCref, inInputData, inDiffType, inFunctionTree, maxIter-1); 685 686 res = Expression.makeASUB(res1,sub); 687 (res,_) = ExpressionSimplify.simplify1(res); 688 698 case DAE.ASUB(exp=e1, sub=sub) algorithm 699 (res1, functionTree) := differentiateExp(e1, inDiffwrtCref, inInputData, inDiffType, inFunctionTree, maxIter-1); 700 res := Expression.makeASUB(res1,sub); 701 (res, _) := ExpressionSimplify.simplify1(res); 689 702 then (res, functionTree); 690 703 691 case DAE.ARRAY(ty=tp, scalar=b, array=expl) equation692 693 (expl, functionTree) = List.map3Fold(expl, function differentiateExp(maxIter=maxIter-1), inDiffwrtCref, inInputData, inDiffType, inFunctionTree);694 695 res = DAE.ARRAY(tp, b, expl);696 (res,_) = ExpressionSimplify.simplify1(res);697 698 then (res, functionTree);699 700 case DAE.MATRIX(ty=tp, integer=i, matrix=matrix) equation701 702 (dmatrix, functionTree) = List.map3FoldList(matrix, function differentiateExp(maxIter=maxIter-1), inDiffwrtCref, inInputData, inDiffType, inFunctionTree);703 704 res = DAE.MATRIX(tp, i, dmatrix);705 (res,_) = ExpressionSimplify.simplify1(res);706 707 then (res, functionTree);708 709 // differentiate tsub710 704 case DAE.TSUB(exp=e1, ix=i, ty=tp) 711 705 algorithm … … 720 714 then (res, functionTree); 721 715 722 723 // differentiate rsub724 716 case e1 as DAE.RSUB() 725 717 algorithm … … 749 741 then (res, functionTree); 750 742 751 // differentiate tuple 752 case DAE.TUPLE(PR=expl) equation 753 754 (expl, functionTree) = List.map3Fold(expl, function differentiateExp(maxIter=maxIter-1), inDiffwrtCref, inInputData, inDiffType, inFunctionTree); 755 756 res = DAE.TUPLE(expl); 757 (res,_) = ExpressionSimplify.simplify1(res); 758 759 then (res, functionTree); 760 761 case DAE.IFEXP(expCond=e1, expThen=e2, expElse=e3) equation 762 763 (res1, functionTree) = differentiateExp(e2, inDiffwrtCref, inInputData, inDiffType, inFunctionTree, maxIter-1); 764 (res2, functionTree) = differentiateExp(e3, inDiffwrtCref, inInputData, inDiffType, functionTree, maxIter-1); 765 766 res = DAE.IFEXP(e1, res1, res2); 767 (res,_) = ExpressionSimplify.simplify1(res); 768 769 then (res, functionTree); 770 771 // boolean expression, e.g. relation, are left as they are 772 case DAE.RELATION() 773 then (inExp, inFunctionTree); 774 775 case DAE.LBINARY() 776 then (inExp, inFunctionTree); 777 778 case DAE.LUNARY() 779 then (inExp, inFunctionTree); 780 781 case DAE.SIZE() 782 then (inExp, inFunctionTree); 783 784 case DAE.RANGE() 785 then (inExp, inFunctionTree); 743 case DAE.SIZE() then (inExp, inFunctionTree); 786 744 787 745 case DAE.REDUCTION()
Note: See TracChangeset
for help on using the changeset viewer.