Ticket #6106: TestNewton.mo

File TestNewton.mo, 2.5 KB (added by Francesco Casella, 6 years ago)
Line 
1package TestNewton
2 model Test1
3 Real p0;
4 Real T0;
5 Real rho0;
6 Real p0rel;
7 Real p1;
8 Real p1rel;
9 Real rho1T0;
10 Real rho1T2;
11 Real p2;
12 Real p2rel(stateSelect = StateSelect.prefer, start = 0, fixed = true);
13 Real T2(stateSelect = StateSelect.prefer, start = Tatm, fixed = true);
14 Real rho2;
15 Real rho01;
16 Real rho12;
17 Real dp1 = p0 - p1;
18 Real dp2 = p1 - p2;
19 Real w(nominal = 1e-5);
20 Real M(stateSelect = StateSelect.avoid);
21 Real E(stateSelect = StateSelect.avoid);
22 Real V;
23 constant Real R = 289;
24 constant Real cp = 1000;
25 constant Real cv = cp - R;
26 parameter Real patm = 101325;
27 parameter Real Tatm = 300;
28 parameter Real V0 = 1e-4;
29 parameter Real wn = 1e-4;
30 parameter Real ws = 1e-2 * wn;
31 parameter Real dps = 1;
32 parameter Real k1 = 2e-2;
33 parameter Real k2 = k1;
34
35 function rho_pT
36 input Real p;
37 input Real T;
38 output Real rho;
39 algorithm
40 rho := p / (R * T);
41 annotation(
42 Inline = false,
43 smoothOrder = 2);
44 end rho_pT;
45 equation
46 p0 = patm;
47 T0 = 300;
48 rho0 = rho_pT(p0, T0);
49 rho1T0 = rho_pT(p1, T0);
50 rho1T2 = rho_pT(p1, T2);
51 rho2 = rho_pT(p2, T2);
52 M = rho2 * V;
53 E = cv * T2 * M;
54 der(M) = w;
55 der(E) = w * noEvent(if w > 0 then cp * T0 else cp * T2);
56 p0rel - p1rel = k1 * w / rho01;
57 p1rel - p2rel = k2 * w / rho12;
58 rho01 = Modelica.Fluid.Utilities.regStep(p0 - p1, rho0, rho1T2, dps);
59 rho12 = Modelica.Fluid.Utilities.regStep(p1 - p2, rho1T0, rho2, dps);
60 p0rel = p0 - patm;
61 p1rel = p1 - patm;
62 p2rel = p2 - patm;
63 V = V0 * (1 + 0.5 * cos(time));
64 annotation(
65 experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-05, Interval = 0.002),
66 __OpenModelica_simulationFlags(lv = "LOG_STATS", s = "dassl", noEquidistantTimeGrid = "()", outputFormat = "mat"),
67 __OpenModelica_commandLineOptions = "--matchingAlgorithm=PFPlusExt --indexReductionMethod=dynamicStateSelection -d=initialization,NLSanalyticJacobian,newInst -d=stateselection --showStructuralAnnotations -d=stateselection --showStructuralAnnotations ");
68 end Test1;
69
70 model Test2
71 extends TestNewton.Test1;
72 annotation(
73 experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-05, Interval = 0.002),
74 __OpenModelica_simulationFlags(lv = "LOG_STATS", s = "dassl", noEquidistantTimeGrid = "()", nls = "kinsol", outputFormat = "mat"));
75
76
77 end Test2;
78end TestNewton;