Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 808888c

Browse files
Willi BraunOpenModelica-Hudson
authored andcommitted
[BE] added debug for diff exp and calls
Belonging to [master]: - #2203 - OpenModelica/OpenModelica-testsuite#856
1 parent 846ccc5 commit 808888c

File tree

1 file changed

+20
-56
lines changed

1 file changed

+20
-56
lines changed

Compiler/BackEnd/Differentiate.mo

Lines changed: 20 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,12 @@ protected function differentiateExp
533533
input Integer maxIter;
534534
output DAE.Exp outDiffedExp;
535535
output DAE.FunctionTree outFunctionTree;
536+
protected
537+
constant Boolean debug = false;
536538
algorithm
539+
if debug then print("\nDifferentiate Exp: "+ExpressionDump.printExpStr(inExp)+
540+
" w.r.t. "+ComponentReference.printComponentRefStr(inDiffwrtCref)+"\n"); end if;
541+
537542
/*
538543
// This check does not seem to be necessary since looking through the stack of expression seems to stop iteration in most cases, and you get a spam of messages from this check.
539544
if maxIter < 1 then
@@ -552,7 +557,7 @@ algorithm
552557
DAE.Operator op;
553558
DAE.Type tp;
554559
Integer i;
555-
String s1, s2;
560+
String s1, s2, stp;
556561
list<String> strLst;
557562
//String se1;
558563
list<DAE.Exp> sub, expl;
@@ -578,8 +583,6 @@ algorithm
578583

579584
// differentiate cref
580585
case DAE.CREF(componentRef=cref, ty=tp) equation
581-
//se1 = ExpressionDump.printExpStr(inExp);
582-
//print("\nExp-Cref\nDifferentiate exp: " + se1);
583586

584587
if ComponentReference.isStartCref(cref) then
585588
// differentiate start value
@@ -589,8 +592,6 @@ algorithm
589592
(res, functionTree) = differentiateCrefs(inExp, inDiffwrtCref, inInputData, inDiffType, inFunctionTree, maxIter-1);
590593
end if;
591594

592-
//se1 = ExpressionDump.printExpStr(res);
593-
//print("\nresults to exp: " + se1);
594595
then (res, functionTree);
595596

596597
// differentiate homotopy
@@ -602,93 +603,64 @@ algorithm
602603

603604
// differentiate call
604605
case DAE.CALL() equation
605-
//se1 = ExpressionDump.printExpStr(inExp);
606-
//print("\nExp-Call\nDifferentiate exp: " + se1);
607606

608607
(res, functionTree) = differentiateCalls(inExp, inDiffwrtCref, inInputData, inDiffType, inFunctionTree, maxIter-1);
609608
(res,_) = ExpressionSimplify.simplify1(res);
610609

611-
//se1 = ExpressionDump.printExpStr(res);
612-
//print("\nresults to exp: " + se1);
613610
then (res, functionTree);
614611

615612
// differentiate binary
616613
case DAE.BINARY() equation
617-
//se1 = ExpressionDump.printExpStr(inExp);
618-
//print("\nExp-BINARY\nDifferentiate exp: " + se1);
619614

620615
(res, functionTree) = differentiateBinary(inExp, inDiffwrtCref, inInputData, inDiffType, inFunctionTree, maxIter-1);
621616
(res) = ExpressionSimplify.simplifyBinaryExp(res);
622617

623-
//se1 = ExpressionDump.printExpStr(res);
624-
//print("\nresults to exp: " + se1);
625618
then (res, functionTree);
626619

627620
// differentiate operator
628621
case DAE.UNARY(operator=op, exp=e1) equation
629-
//se1 = ExpressionDump.printExpStr(inExp);
630-
//print("\nExp-UNARY\nDifferentiate exp: " + se1);
631622

632623
(res, functionTree) = differentiateExp(e1, inDiffwrtCref, inInputData, inDiffType, inFunctionTree, maxIter-1);
633624

634625
res = DAE.UNARY(op,res);
635626
(res) = ExpressionSimplify.simplifyUnaryExp(res);
636627

637-
//se1 = ExpressionDump.printExpStr(res);
638-
//print("\nresults to exp: " + se1);
639628
then (res, functionTree);
640629

641630
// differentiate cast
642631
case DAE.CAST(ty=tp, exp=e1) equation
643-
//se1 = ExpressionDump.printExpStr(inExp);
644-
//print("\nExp-CAST\nDifferentiate exp: " + se1);
645632

646633
(res, functionTree) = differentiateExp(e1, inDiffwrtCref, inInputData, inDiffType, inFunctionTree, maxIter-1);
647634
(res,_) = ExpressionSimplify.simplify1(res);
648635

649-
//se1 = ExpressionDump.printExpStr(res);
650-
//print("\nresults to exp: " + se1);
651636
then (DAE.CAST(tp, res), functionTree);
652637

653638
// differentiate asub
654639
case DAE.ASUB(exp=e1, sub=sub) equation
655-
//se1 = ExpressionDump.printExpStr(inExp);
656-
//print("\nExp-ASUB\nDifferentiate exp: " + se1);
657640

658641
(res1, functionTree) = differentiateExp(e1, inDiffwrtCref, inInputData, inDiffType, inFunctionTree, maxIter-1);
659642

660643
res = Expression.makeASUB(res1,sub);
661644
(res,_) = ExpressionSimplify.simplify1(res);
662645

663-
//se1 = ExpressionDump.printExpStr(res);
664-
//print("\nresults to exp: " + se1);
665646
then (res, functionTree);
666647

667648
case DAE.ARRAY(ty=tp, scalar=b, array=expl) equation
668-
//se1 = ExpressionDump.printExpStr(inExp);
669-
//print("\nExp-ARRAY\nDifferentiate exp: " + se1);
670649

671650
(expl, functionTree) = List.map3Fold(expl, function differentiateExp(maxIter=maxIter-1), inDiffwrtCref, inInputData, inDiffType, inFunctionTree);
672651

673652
res = DAE.ARRAY(tp, b, expl);
674653
(res,_) = ExpressionSimplify.simplify1(res);
675-
//(res,_) = ExpressionSimplify.simplify(res);
676654

677-
//se1 = ExpressionDump.printExpStr(res);
678-
//print("\nresults to exp: " + se1);
679655
then (res, functionTree);
680656

681657
case DAE.MATRIX(ty=tp, integer=i, matrix=matrix) equation
682-
//se1 = ExpressionDump.printExpStr(inExp);
683-
//print("\nExp-MARTIX\nDifferentiate exp: " + se1);
684658

685659
(dmatrix, functionTree) = List.map3FoldList(matrix, function differentiateExp(maxIter=maxIter-1), inDiffwrtCref, inInputData, inDiffType, inFunctionTree);
686660

687661
res = DAE.MATRIX(tp, i, dmatrix);
688662
(res,_) = ExpressionSimplify.simplify1(res);
689663

690-
//se1 = ExpressionDump.printExpStr(res);
691-
//print("\nresults to exp: " + se1);
692664
then (res, functionTree);
693665

694666
// differentiate tsub
@@ -705,7 +677,7 @@ algorithm
705677
then (res, functionTree);
706678

707679

708-
// differentiate tsub
680+
// differentiate tsub
709681
case e1 as DAE.RSUB()
710682
algorithm
711683
(res1, functionTree) := differentiateExp(e1.exp, inDiffwrtCref, inInputData, inDiffType, inFunctionTree, maxIter-1);
@@ -715,32 +687,24 @@ algorithm
715687
end if;
716688
then (e1, functionTree);
717689

718-
// differentiate tuple
690+
// differentiate tuple
719691
case DAE.TUPLE(PR=expl) equation
720-
//se1 = ExpressionDump.printExpStr(inExp);
721-
//print("\nExp-TUPLE\nDifferentiate exp: " + se1);
722692

723693
(expl, functionTree) = List.map3Fold(expl, function differentiateExp(maxIter=maxIter-1), inDiffwrtCref, inInputData, inDiffType, inFunctionTree);
724694

725695
res = DAE.TUPLE(expl);
726696
(res,_) = ExpressionSimplify.simplify1(res);
727697

728-
//se1 = ExpressionDump.printExpStr(res);
729-
//print("\nresults to exp: " + se1);
730698
then (res, functionTree);
731699

732700
case DAE.IFEXP(expCond=e1, expThen=e2, expElse=e3) equation
733-
//se1 = ExpressionDump.printExpStr(inExp);
734-
//print("\nExp-IF-EXP\nDifferentiate exp: " + se1);
735701

736702
(res1, functionTree) = differentiateExp(e2, inDiffwrtCref, inInputData, inDiffType, inFunctionTree, maxIter-1);
737703
(res2, functionTree) = differentiateExp(e3, inDiffwrtCref, inInputData, inDiffType, functionTree, maxIter-1);
738704

739705
res = DAE.IFEXP(e1, res1, res2);
740706
(res,_) = ExpressionSimplify.simplify1(res);
741707

742-
//se1 = ExpressionDump.printExpStr(res);
743-
//print("\nresults to exp: " + se1);
744708
then (res, functionTree);
745709

746710
// boolean expression, e.g. relation, are left as they are
@@ -757,9 +721,11 @@ algorithm
757721
true = Flags.isSet(Flags.FAILTRACE);
758722
s1 = ExpressionDump.printExpStr(inExp);
759723
s2 = ComponentReference.printComponentRefStr(inDiffwrtCref);
760-
Debug.trace("- differentiateExp " + s1 + " w.r.t " + s2 + " failed\n");
724+
stp = Types.printTypeStr(Expression.typeof(inExp));
725+
Debug.trace("- differentiateExp " + s1 + " type: " + stp + " w.r.t " + s2 + " failed\n");
761726
then fail();
762727
end match;
728+
if debug then print("Differentiate-Exp-result: " + ExpressionDump.printExpStr(outDiffedExp) + "\n"); end if;
763729
end differentiateExp;
764730

765731
protected function differentiateStatements
@@ -1230,7 +1196,7 @@ algorithm
12301196
then
12311197
fail();
12321198
end matchcontinue;
1233-
if debug then print("Differentiate-Exp-result: " + ExpressionDump.printExpStr(outDiffedExp) + "\n"); end if;
1199+
if debug then print("Differentiate-ExpCref-result: " + ExpressionDump.printExpStr(outDiffedExp) + "\n"); end if;
12341200
end differentiateCrefs;
12351201

12361202
public function createDiffedCrefName
@@ -1320,7 +1286,12 @@ function: differentiateCalls
13201286
input Integer maxIter;
13211287
output DAE.Exp outDiffedExp;
13221288
output DAE.FunctionTree outFunctionTree;
1289+
protected
1290+
constant Boolean debug = false;
13231291
algorithm
1292+
if debug then print("\nDifferentiate Exp-Call: "+ExpressionDump.printExpStr(inExp)+
1293+
" w.r.t. "+ComponentReference.printComponentRefStr(inDiffwrtCref)+"\n"); end if;
1294+
13241295
(outDiffedExp, outFunctionTree) :=
13251296
match(inExp, inDiffwrtCref, inInputData, inDiffType, inFunctionTree)
13261297
local
@@ -1397,11 +1368,7 @@ algorithm
13971368
// differentiate builtin calls with 1 argument
13981369
case (DAE.CALL(path=Absyn.IDENT(name),attr=DAE.CALL_ATTR(builtin=true),expLst={e}), _, _, _, _)
13991370
equation
1400-
//s1 = ExpressionDump.printExpStr(e);
1401-
//print("\nExp-CALL\n build-funcs "+ name + "(" + s1 + ")\n");
14021371
(res, funcs) = differentiateCallExp1Arg(name, e, inDiffwrtCref, inInputData, inDiffType, inFunctionTree, maxIter);
1403-
//s1 = ExpressionDump.printExpStr(e);
1404-
//print("\nresults to exp: " + s1);
14051372
then (res, funcs);
14061373

14071374
// differentiate builtin calls with N arguments with match
@@ -1413,11 +1380,7 @@ algorithm
14131380
// differentiate builtin calls with N arguments as match
14141381
case (DAE.CALL(path=Absyn.IDENT(name),attr=(attr as DAE.CALL_ATTR(builtin=true)),expLst= (expl as (_::_::_))), _, _, _, _)
14151382
equation
1416-
//s1 = ExpressionDump.printExpStr(e);
1417-
//print("\nExp-CALL\n build-funcs "+ name + "(" + s1 + ")\n");
14181383
(res, funcs) = differentiateCallExpNArg(name, expl, attr, inDiffwrtCref, inInputData, inDiffType, inFunctionTree, maxIter);
1419-
//s1 = ExpressionDump.printExpStr(e);
1420-
//print("\nresults to exp: " + s1);
14211384
then (res, funcs);
14221385

14231386
case (e as DAE.CALL(), _, _, _, _)
@@ -1433,7 +1396,7 @@ algorithm
14331396
then
14341397
fail();
14351398
*/
1436-
else
1399+
else
14371400
equation
14381401
true = Flags.isSet(Flags.FAILTRACE);
14391402
s1 = ExpressionDump.printExpStr(inExp);
@@ -1442,7 +1405,8 @@ algorithm
14421405
Debug.trace(serr);
14431406
then
14441407
fail();
1445-
end match;
1408+
end match;
1409+
if debug then print("Differentiate-ExpCall-result: " + ExpressionDump.printExpStr(outDiffedExp) + "\n"); end if;
14461410
end differentiateCalls;
14471411

14481412
protected function differentiateCallExp1Arg

0 commit comments

Comments
 (0)