Skip to content

Commit

Permalink
[NB] Differentiate delay (#11945)
Browse files Browse the repository at this point in the history
  • Loading branch information
phannebohm committed Feb 10, 2024
1 parent 4a7b1ae commit 9a763fc
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions OMCompiler/Compiler/NBackEnd/Util/NBDifferentiate.mo
Expand Up @@ -846,6 +846,30 @@ public
Expression ret, ret1, ret2, arg1, arg2, arg3, diffArg1, diffArg2, diffArg3;
list<Expression> rest;
Type ty;
DifferentiationType diffType;

// DELAY
// d/dz delay(x, delta) = (dt/dz - d delta/dz) * delay(der(x), delta)
case (Expression.CALL()) guard(name == "delay")
algorithm
{arg1, arg2, arg3} := Call.arguments(exp.call);
// if z = t then dt/dz = 1 else dt/dz = 0
ret1 := Expression.REAL(if diffArguments.diffType == DifferentiationType.TIME then 1.0 else 0.0);
// d delta/dz
(ret2, diffArguments) := differentiateExpression(arg2, diffArguments);
// dt/dz - d delta/dz
ret2 := SimplifyExp.simplify(Expression.MULTARY({ret1}, {ret2}, addOp));
if Expression.isZero(ret2) then
ret := Expression.makeZero(Expression.typeOf(arg1));
else
diffType := diffArguments.diffType;
diffArguments.diffType := DifferentiationType.TIME;
(ret1, diffArguments) := differentiateExpression(arg1, diffArguments);
diffArguments.diffType := diffType;
exp.call := Call.setArguments(exp.call, {ret1, arg2, arg3});
ret := Expression.MULTARY({ret2, exp}, {}, mulOp);
end if;
then ret;

// SMOOTH
case (Expression.CALL()) guard(name == "smooth")
Expand Down

0 comments on commit 9a763fc

Please sign in to comment.