@@ -68,7 +68,30 @@ algorithm
6868 DAELow . Variables timevars;
6969 DAELow . Equation dae_equation;
7070 DAE . ElementSource source "the origin of the element" ;
71+ Absyn . Path p;
72+ DAE . FunctionDefinition mapper;
73+ DAE . Type tp;
7174
75+ // Derivatives of Functions
76+ case (DAELow . EQUATION (exp = e1 as DAE . CALL (path= p),scalar = e2,source= source),timevars,inFunctions) /* time varying variables */
77+ equation
78+ e1_1 = differentiateFunctionTime(e1, (timevars,inFunctions));
79+ (mapper,tp) = getFunctionMapper(p,inFunctions);
80+ e2_1 = differentiateFunctionTimeOutputs(e2,mapper,tp,(timevars,inFunctions));
81+ e1_2 = Exp . simplify(e1_1);
82+ e2_2 = Exp . simplify(e2_1);
83+ then
84+ DAELow . EQUATION (e1_2,e2_2,source);
85+ case (DAELow . EQUATION (exp = e1,scalar = e2 as DAE . CALL (path= p),source= source),timevars,inFunctions) /* time varying variables */
86+ equation
87+ e2_1 = differentiateFunctionTime(e2, (timevars,inFunctions));
88+ (mapper,tp) = getFunctionMapper(p,inFunctions);
89+ e1_1 = differentiateFunctionTimeOutputs(e1,mapper,tp,(timevars,inFunctions));
90+ e1_2 = Exp . simplify(e1_1);
91+ e2_2 = Exp . simplify(e2_1);
92+ then
93+ DAELow . EQUATION (e1_2,e2_2,source);
94+
7295 case (DAELow . EQUATION (exp = e1,scalar = e2,source= source),timevars,inFunctions) /* time varying variables */
7396 equation
7497 e1_1 = differentiateExpTime(e1, (timevars,inFunctions));
@@ -339,6 +362,41 @@ algorithm
339362 end matchcontinue;
340363end differentiateExpTime;
341364
365+ protected function differentiateFunctionTimeOutputs
366+ input DAE . Exp inExp;
367+ input DAE . FunctionDefinition mapper;
368+ input DAE . Type tp;
369+ input tuple< DAELow . Variables ,DAE . FunctionTree > inVarsandFuncs;
370+ output DAE . Exp outExp;
371+ algorithm
372+ outExp := matchcontinue (inExp,mapper,tp,inVarsandFuncs)
373+ local
374+ DAELow . Variables timevars;
375+ DAE . FunctionTree functions;
376+ DAE . TType typ;
377+ Integer derivativeOrder;
378+ DAE . Exp e;
379+ // order=1
380+ case (inExp,DAE . FUNCTION_DER_MAPPER (derivativeOrder= derivativeOrder),(typ,_),(timevars,functions))
381+ equation
382+ true = intEq(1 ,derivativeOrder);
383+ // remove all outputs not subtyp of real
384+ /* Frenkel TUD: TODO: implement remove all outputs not subtyp of real*/
385+ // diff exp
386+ e = differentiateExpTime(inExp, (timevars,functions));
387+ then
388+ e;
389+ // order>1
390+ case (inExp,DAE . FUNCTION_DER_MAPPER (derivativeOrder= derivativeOrder),(typ,_),(timevars,functions))
391+ equation
392+ failure(true = intEq(1 ,derivativeOrder));
393+ // diff exp
394+ e = differentiateExpTime(inExp, (timevars,functions));
395+ then
396+ e;
397+ end matchcontinue;
398+ end differentiateFunctionTimeOutputs;
399+
342400protected function differentiateFunctionTime
343401 input DAE . Exp inExp;
344402 input tuple< DAELow . Variables ,DAE . FunctionTree > inVarsandFuncs;
@@ -461,6 +519,7 @@ algorithm
461519 bl = checkDerFunctionConds(bl1,crlst,expl,inVarsandFuncs);
462520 then bl;
463521 // noDerivative
522+ /* Frenkel TUD: TODO: test this case*/
464523 case (inblst,(i,DAE . NO_DERIVATIVE (binding= DAE . CALL (path= p1)))::crlst,expl,inVarsandFuncs)
465524 equation
466525 i_1 = i- 1 ;
0 commit comments