@@ -665,7 +665,7 @@ algorithm
665
665
666
666
(res, functionTree) = differentiateCrefs(e, inDiffwrtCref, inInputData, inDiffType, inFunctionTree);
667
667
(res,_) = ExpressionSimplify . simplify1(res);
668
-
668
+
669
669
// se1 = ExpressionDump.printExpStr(res);
670
670
// print("\nresults to exp: " +& se1);
671
671
then (res, functionTree);
@@ -2146,9 +2146,9 @@ algorithm
2146
2146
(outDiffedExp, outFunctionTree) :=
2147
2147
matchcontinue(inExp, inDiffwrtCref, inInputData, inDiffType, inFunctionTree)
2148
2148
local
2149
-
2149
+
2150
2150
BackendDAE . DifferentiateInputData inputData, diffFuncData;
2151
-
2151
+
2152
2152
DAE . Exp e, zero, ezero;
2153
2153
list< DAE . Exp > expl,expl1,dexpl,dexplZero;
2154
2154
BackendDAE . Variables timevars;
@@ -2165,13 +2165,13 @@ algorithm
2165
2165
String typstring, dastring, funstring, str;
2166
2166
list< String > typlststring;
2167
2167
DAE . TailCall tc;
2168
-
2168
+
2169
2169
list< DAE . Element > funcbody, funcbodyDer;
2170
2170
list< DAE . Element > inputVars, inputVarsNoDer, inputVarsDer;
2171
2171
list< DAE . Element > outputVars, outputVarsNoDer, outputVarsDer;
2172
2172
list< DAE . Element > protectedVars, protectedVarsNoDer, protectedVarsDer, newProtectedVars;
2173
2173
list< DAE . Statement > bodyStmts, derbodyStmts;
2174
-
2174
+
2175
2175
DAE . FunctionDefinition derfuncdef;
2176
2176
DAE . Function func ,dfunc;
2177
2177
list< DAE . Function > fns;
@@ -2187,7 +2187,7 @@ algorithm
2187
2187
(mapper, tp) = getFunctionMapper(path, inFunctionTree);
2188
2188
(dpath, blst) = differentiateFunction1(path,mapper, tp, expl, (inDiffwrtCref, inInputData, inDiffType, inFunctionTree));
2189
2189
SOME (DAE . FUNCTION (type_= dtp,inlineType= dinl)) = DAEUtil . avlTreeGet(inFunctionTree, dpath);
2190
- // check if derivativ function has all expected inputs
2190
+ // check if derivativ function has all expected inputs
2191
2191
(true ,_) = checkDerivativeFunctionInputs(blst, tp, dtp);
2192
2192
(expl1,_) = List . splitOnBoolList(expl, blst);
2193
2193
(dexpl, functions) = List . map3Fold(expl1, differentiateExp, inDiffwrtCref, inInputData, inDiffType, inFunctionTree);
@@ -2197,7 +2197,7 @@ algorithm
2197
2197
// dexpl = listAppend(expl, dexpl);
2198
2198
// print("Start creation of partial Der\n");
2199
2199
// print("Diffed ExpList: \n");
2200
- // print(stringDelimitList(List.map(dexpl, ExpressionDump.printExpStr), ", ") +& "\n");
2200
+ // print(stringDelimitList(List.map(dexpl, ExpressionDump.printExpStr), ", ") +& "\n");
2201
2201
e = DAE . CALL (dpath,expl1,DAE . CALL_ATTR (ty,b,c,isImpure,dinl,tc));
2202
2202
e = createPartialArguments(ty, dexpl, dexplZero, expl, e);
2203
2203
then
@@ -2206,11 +2206,11 @@ algorithm
2206
2206
case (DAE . CALL (path= path,expLst= expl), _, _, _, _)
2207
2207
equation
2208
2208
// get function mapper
2209
- // print("Search for function mapper2\n");
2209
+ // print("Search for function mapper2\n");
2210
2210
(mapper, tp) = getFunctionMapper(path, inFunctionTree);
2211
2211
(dpath, blst) = differentiateFunction1(path, mapper, tp, expl, (inDiffwrtCref, inInputData, inDiffType, inFunctionTree));
2212
2212
SOME (DAE . FUNCTION (type_= dtp,inlineType= dinl)) = DAEUtil . avlTreeGet(inFunctionTree, dpath);
2213
- // check if derivativ function has all expected inputs
2213
+ // check if derivativ function has all expected inputs
2214
2214
(false , tlst) = checkDerivativeFunctionInputs(blst, tp, dtp);
2215
2215
// add Warning
2216
2216
typlststring = List . map(tlst, Types . unparseType);
@@ -2224,22 +2224,22 @@ algorithm
2224
2224
// differentiate function
2225
2225
case (e as DAE . CALL (path= path,expLst= expl,attr= DAE . CALL_ATTR (tuple_= b,builtin= false ,isImpure= isImpure,ty= ty,tailCall= tc)), _, _, _, _)
2226
2226
equation
2227
- // TODO: FIXIT! expressionSolve and analyticJacobian don't
2227
+ // TODO: FIXIT! expressionSolve and analyticJacobian don't
2228
2228
// return new functionTree, so we can't differentiate functions then.
2229
2229
failure(BackendDAE . SIMPLE_DIFFERENTAION () = inDiffType);
2230
2230
failure(BackendDAE . DIFF_FULL_JACOBIAN () = inDiffType);
2231
-
2231
+
2232
2232
// get algorithm of the function
2233
2233
SOME (func ) = DAEUtil . avlTreeGet(inFunctionTree,path);
2234
-
2234
+
2235
2235
// differentiate function
2236
2236
(dfunc, functions, blst) = differentiatePartialFunction(func , inDiffwrtCref, NONE (), inInputData, inDiffType, inFunctionTree);
2237
2237
2238
2238
dpath = DAEUtil . functionName(dfunc);
2239
2239
// debug
2240
2240
// funstring = Tpl.tplString(DAEDumpTpl.dumpFunction, dfunc);
2241
2241
// print("\n\nDER.Function: \n" +& funstring +& "\n\n");
2242
-
2242
+
2243
2243
functions = DAEUtil . addDaeFunction({dfunc}, functions);
2244
2244
// add differentiated function as function mapper
2245
2245
func = DAEUtil . addFunctionDefinition(func , DAE . FUNCTION_DER_MAPPER (path, dpath, 1 , {}, NONE (), {}));
@@ -2253,8 +2253,8 @@ algorithm
2253
2253
// print(stringDelimitList(List.map(expl, ExpressionDump.printExpStr), ", ") +& "\n");
2254
2254
// print("Diff ExpList Types: \n");
2255
2255
// print(stringDelimitList(List.map(List.map(expl, Expression.typeof), Types.printTypeStr), " | ") +& "\n");
2256
-
2257
-
2256
+
2257
+
2258
2258
// create differentiated call arguments
2259
2259
expBoolLst = List . threadTuple(expl, blst);
2260
2260
expBoolLst = List . filterOnTrue(expBoolLst, Util . tuple22);
@@ -2268,19 +2268,19 @@ algorithm
2268
2268
// print(" output Type: " +& Types.printTypeStr(ty) +& "\n");
2269
2269
e = DAE . CALL (dpath,dexpl,DAE . CALL_ATTR (ty,b,false ,isImpure,DAE . NO_INLINE (),tc));
2270
2270
e = createPartialArguments(ty, dexpl, dexplZero, expl, e);
2271
-
2271
+
2272
2272
// debug
2273
2273
// print("Finished differentiate Expression in Call.\n");
2274
2274
// print("DER.Function call : \n" +& ExpressionDump.printExpStr(e) +& "\n");
2275
-
2275
+
2276
2276
then
2277
2277
(e, functions);
2278
-
2278
+
2279
2279
else
2280
2280
equation
2281
2281
str = "Differentiate.differentiateFunctionCallPartial failed for " +& ExpressionDump . printExpStr(inExp) +& " \n " ;
2282
2282
Debug . fprint(Flags . FAILTRACE , str);
2283
- then fail();
2283
+ then fail();
2284
2284
end matchcontinue;
2285
2285
end differentiateFunctionCallPartial;
2286
2286
@@ -2471,7 +2471,7 @@ algorithm
2471
2471
DAE . Function dfunc;
2472
2472
Absyn . Path path, dpath;
2473
2473
String str;
2474
-
2474
+
2475
2475
case (_, {}, _, _, _, _) then (inFunction, inFunctionTree);
2476
2476
2477
2477
// differentiate functions
@@ -2542,7 +2542,7 @@ algorithm
2542
2542
outputVars = DAEUtil . getFunctionOutputVars(func );
2543
2543
protectedVars = DAEUtil . getFunctionProtectedVars(func );
2544
2544
bodyStmts = DAEUtil . getFunctionAlgorithmStmts(func );
2545
-
2545
+
2546
2546
path = DAEUtil . functionName(func );
2547
2547
funcname = Util . modelicaStringToCStr(Absyn . pathString(path), false );
2548
2548
diffFuncData = BackendDAE . DIFFINPUTDATA (NONE (),NONE (),NONE (),NONE (),NONE (),NONE (),SOME (funcname));
@@ -2558,29 +2558,29 @@ algorithm
2558
2558
2559
2559
// add protected variables to dependent Vars
2560
2560
(inputData,_) = addElementVars2Dep(protectedVarsNoDer, functions, inputData);
2561
-
2561
+
2562
2562
// differentiate algorithm statemeants
2563
2563
// print("Function diff: statemeants");
2564
2564
(derbodyStmts, functions) = differentiateStatements(listReverse(bodyStmts), inDiffwrtCref, inputData, BackendDAE . DIFFERENTAION_FUNCTION (), {}, functions);
2565
2565
2566
2566
// create function and add it to function tree
2567
2567
dpath = Util . getOptionOrDefault(dpathOption, Absyn . stringPath("$DER" +& funcname));
2568
-
2568
+
2569
2569
tp = DAEUtil . getFunctionType(func );
2570
2570
dtp = Types . extendsFunctionTypeArgs(tp, inputVarsDer, blst);
2571
-
2571
+
2572
2572
inputVars = listAppend(inputVars, inputVarsDer);
2573
2573
protectedVars = listAppend(protectedVars, protectedVarsDer);
2574
2574
funcbodyDer = listAppend(inputVars, outputVarsDer);
2575
2575
funcbodyDer = listAppend(funcbodyDer, protectedVars);
2576
-
2576
+
2577
2577
// change output vars to protected vars and direction bidir
2578
2578
newProtectedVars = List . map1(outputVars, DAEUtil . setElementVarVisibility, DAE . PROTECTED ());
2579
2579
newProtectedVars = List . map1(newProtectedVars, DAEUtil . setElementVarDirection, DAE . BIDIR ());
2580
2580
funcbodyDer = listAppend(funcbodyDer, newProtectedVars);
2581
-
2581
+
2582
2582
funcbodyDer = listAppend(funcbodyDer, {DAE . ALGORITHM (DAE . ALGORITHM_STMTS (derbodyStmts), DAE . emptyElementSource)});
2583
-
2583
+
2584
2584
isImpure = DAEUtil . getFunctionImpureAttribute(func );
2585
2585
dinl = DAEUtil . getFunctionInlineType(func );
2586
2586
dfunc = DAE . FUNCTION (dpath, {DAE . FUNCTION_DEF (funcbodyDer)}, dtp, false , isImpure, dinl, DAE . emptyElementSource, NONE ());
0 commit comments