-
Notifications
You must be signed in to change notification settings - Fork 298
/
simpleStiffFMU.mos
77 lines (71 loc) · 2.76 KB
/
simpleStiffFMU.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
// name: simpleStiffFMU
// keywords: fmu export simulation flags
// status: correct
// teardown_command: rm -rf stiffProblem.fmu stiffProblem*
// cflags: -d=-newInst
//
// Export simple stiff model as 2.0 CS FMU with CVODE solver
// For explicit Euler with step size bigger than 0.5 this will explode
// Generate FMU
loadString("
model stiffProblem
Real x(start=x0, fixed=true);
Real solution;
parameter Real x0 = 1;
equation
der(x)=-4*(x-2);
solution = 2-exp(-4*time);
end stiffProblem;
"); getErrorString();
setCommandLineOptions("-d=newInst --fmiFlags=s:cvode"); getErrorString();
buildModelFMU(stiffProblem, version = "2.0", fmuType="me_cs"); getErrorString();
// Check _flags.json for simulation flags
system("unzip -cqq stiffProblem.fmu resources/stiffProblem_flags.json > stiffProblem_flags_dynamic.json"); getErrorString();
readFile("stiffProblem_flags_dynamic.json"); getErrorString();
// Simulate with OMSimulator
system(getInstallationDirectoryPath() + "/bin/OMSimulator stiffProblem.fmu --mode=cs --tolerance=1e-6 --stopTime=250.0 --stepSize=0.01 --resultFile=\"stiffProblem_Dynamic_res.mat\" --suppressPath=true --tempDir=\"stiffProblem-dynamic-tmp\"", "stiffProblem_cs_systemCall.log"); getErrorString();
readFile("stiffProblem_cs_systemCall.log"); getErrorString();
// Check results
val(x, 0.0, "stiffProblem_Dynamic_res.mat"); getErrorString();
val(solution, 0.0, "stiffProblem_Dynamic_res.mat"); getErrorString();
val(x, 250.0, "stiffProblem_Dynamic_res.mat"); getErrorString();
val(solution, 250.0, "stiffProblem_Dynamic_res.mat"); getErrorString();
// Result:
// true
// ""
// true
// ""
// "stiffProblem.fmu"
// ""
// 0
// ""
// "{
// \"s\" : \"cvode\"
// }"
// ""
// 0
// ""
// "LOG_SOLVER | info | CVODE linear multistep method CV_BDF
// LOG_SOLVER | info | CVODE maximum integration order CV_ITER_NEWTON
// LOG_SOLVER | info | CVODE use equidistant time grid YES
// LOG_SOLVER | info | CVODE Using relative error tolerance 1.000000e-06
// LOG_SOLVER | info | CVODE Using dense internal linear solver SUNLinSol_Dense.
// LOG_SOLVER | info | CVODE Use internal dense numeric jacobian method.
// LOG_SOLVER | info | CVODE uses internal root finding method NO
// LOG_SOLVER | info | CVODE maximum absolut step size 0
// LOG_SOLVER | info | CVODE initial step size is set automatically
// LOG_SOLVER | info | CVODE maximum integration order 5
// LOG_SOLVER | info | CVODE maximum number of nonlinear convergence failures permitted during one step 10
// LOG_SOLVER | info | CVODE BDF stability limit detection algorithm OFF
// info: Result file: stiffProblem_Dynamic_res.mat (bufferSize=1)
// "
// ""
// 1.0
// ""
// 1.0
// ""
// 2.0
// ""
// 2.0
// ""
// endResult