-
Notifications
You must be signed in to change notification settings - Fork 297
/
function_diff.mos
94 lines (90 loc) · 2.72 KB
/
function_diff.mos
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// name: function_diff
// keywords: NewBackend
// status: correct
loadString("
model function_diff
Real x;
Real y;
Real z;
equation
y = sin(x);
der(x) = f(y);
der(z) = f(x);
end function_diff;
function f
input Real a;
output Real b;
algorithm
if a >= 0 then
b := a^2;
else
b := f(-a);
end if;
annotation(Inline=false);
end f;
"); getErrorString();
setCommandLineOptions("--newBackend --generateSymbolicJacobian -d=debugDifferentiation"); getErrorString();
simulate(function_diff); getErrorString();
// Result:
// true
// ""
// true
// ""
// ### debugDifferentiation | NBJacobian.jacobianSymbolic ###
// [BEFORE] [SCAL] (1) y = sin(x) ($RES_$AUX_5)
// [AFTER ] [SCAL] (1) $pDER_ODE_JAC.y = cos(x) * $SEED_ODE_JAC.x ($RES_$AUX_5)
//
// ### debugDifferentiation | NBJacobian.jacobianSymbolic ###
// [BEFORE] [SCAL] (1) $FUN_3 = f(x) ($RES_$AUX_3)
//
// [BEFORE] function 'f'
// input Real 'a';
// output Real 'b';
// algorithm
// if 'a' >= 0.0 then
// 'b' := 'a' ^ 2.0;
// elseif true then
// 'b' := 'f'(-'a');
// end if;
// annotation(derivative(order = 1) = '$fDER0.f', Inline = false);
// end 'f'
//
// [AFTER ] function '$fDER0.f'
// input Real 'a';
// input Real '$fDER_a';
// output Real '$fDER_b';
// Real 'b';
// algorithm
// if 'a' >= 0.0 then
// '$fDER_b' := 2.0 * 'a' * '$fDER_a';
// 'b' := 'a' ^ 2.0;
// elseif true then
// '$fDER_b' := '$fDER0.f'(-'a', -'$fDER_a');
// 'b' := 'f'(-'a');
// end if;
// annotation(Inline = false);
// end '$fDER0.f'
//
// [AFTER ] [SCAL] (1) $pDER_ODE_JAC.$FUN_3 = $fDER0.f(x, $SEED_ODE_JAC.x) ($RES_$AUX_3)
//
// ### debugDifferentiation | NBJacobian.jacobianSymbolic ###
// [BEFORE] [SCAL] (1) $FUN_2 = f(y) ($RES_$AUX_4)
// [AFTER ] [SCAL] (1) $pDER_ODE_JAC.$FUN_2 = $fDER0.f(y, $pDER_ODE_JAC.y) ($RES_$AUX_4)
//
// ### debugDifferentiation | NBJacobian.jacobianSymbolic ###
// [BEFORE] [SCAL] (1) $DER.z = $FUN_3 ($RES_SIM_0)
// [AFTER ] [SCAL] (1) $pDER_ODE_JAC.$DER.z = $pDER_ODE_JAC.$FUN_3 ($RES_SIM_0)
//
// ### debugDifferentiation | NBJacobian.jacobianSymbolic ###
// [BEFORE] [SCAL] (1) $DER.x = $FUN_2 ($RES_SIM_1)
// [AFTER ] [SCAL] (1) $pDER_ODE_JAC.$DER.x = $pDER_ODE_JAC.$FUN_2 ($RES_SIM_1)
//
// record SimulationResult
// resultFile = "function_diff_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-6, method = 'dassl', fileNamePrefix = 'function_diff', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
// messages = "LOG_SUCCESS | info | The initialization finished successfully without homotopy method.
// LOG_SUCCESS | info | The simulation finished successfully.
// "
// end SimulationResult;
// ""
// endResult