-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodels.py
128 lines (109 loc) · 2.99 KB
/
models.py
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#Edited by Ben Wooding for purpose of comparisons with PRoTECT
#Copy these lines into the models.py file in FOSSIL to be used for the case studies for comparison
class DCMotor2(control.DynamicalModel):
n_vars = 2
tau = 0.01
R = 1
L = 0.01
J = 0.01
Kdc = 0.01
b = 1
def f_torch(self, v):
x1, x2 = v[:, 0], v[:, 1]
return [x1 + self.tau*(-self.R/self.L*x1 - self.Kdc/self.L*x2), x2 + self.tau*(self.Kdc/self.J*x1 - self.b/self.J*x2)]
def f_smt(self, v):
x1, x2 = v
return [x1 + self.tau*(-self.R/self.L*x1 - self.Kdc/self.L*x2), x2 + self.tau*(self.Kdc/self.J*x1 - self.b/self.J*x2)]
class Jet2(control.DynamicalModel):
n_vars = 2
def f_torch(self, v):
x1, x2 = v[:, 0], v[:, 1]
return [-x2-1.5*x1**2-0.5*x1**3, x1]
def f_smt(self, v):
x1, x2 = v
return [-x2-1.5*x1**2-0.5*x1**3, x1]
class RoomTemp1d(control.DynamicalModel):
n_vars = 1
tau = 5 * 60 # discretise param
temp_e = 15 # external temp
def f_torch(self, v):
x = v[:, 0]
return [
x + self.tau * (self.temp_e - x)
]
def f_smt(self, v):
x = v[0]
return [
x + self.tau * (self.temp_e - x)
]
class HighOrd8B(control.DynamicalModel):
n_vars = 8
def f_torch(self, v):
x0, x1, x2, x3, x4, x5, x6, x7 = (
v[:, 0],
v[:, 1],
v[:, 2],
v[:, 3],
v[:, 4],
v[:, 5],
v[:, 6],
v[:, 7],
)
return [
x1 - 50*x2,
x2 -50*x3,
x3 -50*x4,
x4 -50*x5,
x5 -50*x6,
x6 -50*x7,
x7 - 50*x0,
-20 * x7
- 170 * x6
- 800 * x5
- 2273 * x4
- 3980 * x3
- 4180 * x2
- 2400 * x1
- 576 * x0,
]
def f_smt(self, v):
x0, x1, x2, x3, x4, x5, x6, x7 = v
return [
x1 -50*x2,
x2 -50*x3,
x3 -50*x4,
x4 -50*x5,
x5 -50*x6,
x6 -50*x7,
x7 -50*x0,
-20 * x7
- 170 * x6
- 800 * x5
- 2273 * x4
- 3980 * x3
- 4180 * x2
- 2400 * x1
- 576 * x0,
]
class HighOrd6B(control.DynamicalModel):
n_vars = 6
def f_torch(self, v):
x0, x1, x2, x3, x4, x5 = v[:, 0], v[:, 1], v[:, 2], v[:, 3], v[:, 4], v[:, 5]
return [
x1-100*x2,
x2,
x3-100*x4,
x4,
x5-100*x0,
-800 * x5 - 2273 * x4 - 3980 * x3 - 4180 * x2 - 2400 * x1 - 576 * x0,
]
def f_smt(self, v):
x0, x1, x2, x3, x4, x5 = v
return [
x1-100*x2,
x2,
x3-100*x4,
x4,
x5-100*x0,
-800 * x5 - 2273 * x4 - 3980 * x3 - 4180 * x2 - 2400 * x1 - 576 * x0,
]