@@ -11,8 +11,8 @@ using ModelingToolkit: get_iv, get_unit, validate, ValidationError
11
11
let
12
12
# Creates a `ReactionSystem` programmatically, while designating units.
13
13
@variables t [unit= u " s" ]
14
- @species A (t) [unit= u "m " ] B (t) [unit= u "m " ] C (t) [unit= u "m " ]
15
- @parameters k1 [unit= u "m/s " ] k2 [unit= u " s" ^ (- 1 )] k3 [unit= u "m*s " ^ ( - 1 ) ]
14
+ @species A (t) [unit= u "mol/m^3 " ] B (t) [unit= u "mol/m^3 " ] C (t) [unit= u "mol/m^3 " ]
15
+ @parameters k1 [unit= u "mol/(m^3*s) " ] k2 [unit= u " s^(-1)" ] k3 [unit= u "(m^3)/(s*mol) " ]
16
16
rxs = [Reaction (k1, nothing , [A]),
17
17
Reaction (k2, [A], [B]),
18
18
Reaction (k3, [A, B], [B], [1 , 1 ], [2 ])]
22
22
23
23
# Test that all reactions have the correct unit.
24
24
for rx in reactions (rs)
25
- @test get_unit (oderatelaw (rx)) == u "m/s "
25
+ @test get_unit (oderatelaw (rx)) == u "mol/(s*m^3) "
26
26
# we don't currently convert units, so they will be the same as for ODEs
27
- @test get_unit (jumpratelaw (rx)) == u "m/s "
27
+ @test get_unit (jumpratelaw (rx)) == u "mol/(s*m^3) "
28
28
end
29
29
30
30
# Tests that the system can be converted to MTK systems without warnings.
34
34
@test_nowarn convert (NonlinearSystem, rs)
35
35
36
36
# Tests that creating `Reaction`s with non-matching units yields warnings.
37
- @species B (t) [unit= u "m " ] D (t) [unit= u " kg" ]
37
+ @species B (t) [unit= u "mol " ] D (t) [unit= u " kg" ]
38
38
bad_rx1 = Reaction (k1, [A], [D])
39
39
bad_rx2 = Reaction (k1, [A], [B, D])
40
40
bad_rx3 = Reaction (k1, [A, D], [B])
@@ -71,14 +71,14 @@ begin
71
71
rs = @reaction_network begin
72
72
@ivs t [unit= u " s" ]
73
73
@species begin
74
- A (t), [unit= u "m " ]
75
- B (t), [unit= u "m " ]
76
- C (t), [unit= u "m " ]
74
+ A (t), [unit= u "mol/m^3 " ]
75
+ B (t), [unit= u "mol/m^3 " ]
76
+ C (t), [unit= u "mol/m^3 " ]
77
77
end
78
78
@parameters begin
79
- k1, [unit= u "m/s " ]
80
- k2, [unit= u " s" ^ (- 1 )]
81
- k3, [unit= u "m*s " ^ ( - 1 ) ]
79
+ k1, [unit= u "mol/(s*m^3) " ]
80
+ k2, [unit= u " s^(-1)" ]
81
+ k3, [unit= u "(m^3)/(s*mol) " ]
82
82
end
83
83
k1, 0 --> A
84
84
k2, A --> B
@@ -87,26 +87,26 @@ begin
87
87
88
88
# Checks that the `ReactionSystem`'s content have the correct units.
89
89
@test get_unit (get_iv (rs)) == u " s"
90
- @test all (get_unit .([rs. A, rs. B, rs. C]) .== [u "m " , u "m " , u "m " ])
91
- @test all (get_unit .([rs. k1, rs. k2, rs. k3]) .== [u "m/s " , u " s" ^ (- 1 ), u "m*s " ^ ( - 1 ) ])
90
+ @test all (get_unit .([rs. A, rs. B, rs. C]) .== [u "mol/m^3 " , u "mol/m^3 " , u "mol/m^3 " ])
91
+ @test all (get_unit .([rs. k1, rs. k2, rs. k3]) .== [u "mol/(s*m^3) " , u " s^(-1)" , u "(m^3)/(s*mol) " ])
92
92
for rx in reactions (rs)
93
- @test get_unit (oderatelaw (rx)) == u "m/s "
93
+ @test get_unit (oderatelaw (rx)) == u "mol/(s*m^3) "
94
94
# we don't currently convert units, so they will be the same as for ODEs
95
- @test get_unit (jumpratelaw (rx)) == u "m/s "
95
+ @test get_unit (jumpratelaw (rx)) == u "mol/(s*m^3) "
96
96
end
97
97
98
98
# Checks that system declarations with erroneous units yields errors.
99
99
@test_logs (:warn , ) match_mode= :any @reaction_network begin
100
100
@ivs t [unit= u " 1/s" ] # Here, t's unit is wrong.
101
101
@species begin
102
- A (t), [unit= u "m " ]
103
- B (t), [unit= u "m " ]
104
- C (t), [unit= u "m " ]
102
+ A (t), [unit= u "mol/m^3 " ]
103
+ B (t), [unit= u "mol/m^3 " ]
104
+ C (t), [unit= u "mol/m^3 " ]
105
105
end
106
106
@parameters begin
107
- k1, [unit= u "m/s " ]
108
- k2, [unit= u " s" ^ (- 1 )]
109
- k3, [unit= u "m*s " ^ ( - 1 ) ]
107
+ k1, [unit= u "mol/(s*m^3) " ]
108
+ k2, [unit= u " s^(-1)" ]
109
+ k3, [unit= u "(m^3)/(s*mol) " ]
110
110
end
111
111
k1, 0 --> A
112
112
k2, A --> B
@@ -115,14 +115,14 @@ begin
115
115
@test_logs (:warn , ) match_mode= :any @reaction_network begin
116
116
@ivs t [unit= u " s" ]
117
117
@species begin
118
- A (t), [unit= u "m " ]
119
- B (t), [unit= u "m " ]
120
- C (t), [unit= u "m " ]
118
+ A (t), [unit= u "mol/m^3 " ]
119
+ B (t), [unit= u "mol/m^3 " ]
120
+ C (t), [unit= u "mol/m^3 " ]
121
121
end
122
122
@parameters begin
123
- k1, [unit= u "m " ] # Here, k1's unit is wrong .
124
- k2, [unit= u " s" ^ (- 1 )]
125
- k3, [unit= u "m*s " ^ ( - 1 ) ]
123
+ k1, [unit= u "mol/(m^3) " ] # Here, k1's unit is missing "/s" .
124
+ k2, [unit= u " s^(-1)" ]
125
+ k3, [unit= u "(m^3)/(s*mol) " ]
126
126
end
127
127
k1, 0 --> A
128
128
k2, A --> B
@@ -131,14 +131,14 @@ begin
131
131
@test_logs (:warn , ) match_mode= :any @reaction_network begin
132
132
@ivs t [unit= u " s" ]
133
133
@species begin
134
- A (t), [unit= u "m*s " ] # Here, A's unit is wrong .
135
- B (t), [unit= u "m " ]
136
- C (t), [unit= u "m " ]
134
+ A (t), [unit= u "mol/(s*m^3) " ] # Here, A's unit got an extra "/s" .
135
+ B (t), [unit= u "mol/m^3 " ]
136
+ C (t), [unit= u "mol/m^3 " ]
137
137
end
138
138
@parameters begin
139
- k1, [unit= u "m/s " ]
140
- k2, [unit= u " s" ^ (- 1 )]
141
- k3, [unit= u "m*s " ^ ( - 1 ) ]
139
+ k1, [unit= u "mol/(s*m^3) " ]
140
+ k2, [unit= u " s^(-1)" ]
141
+ k3, [unit= u "(m^3)/(s*mol) " ]
142
142
end
143
143
k1, 0 --> A
144
144
k2, A --> B
@@ -168,20 +168,20 @@ let
168
168
@test_nowarn @reaction_network begin
169
169
@ivs t [unit= u " s" ]
170
170
@species begin
171
- X1 (t), [unit= u "m " ]
172
- Z1 (t), [unit= u "m " ]
173
- X2 (t), [unit= u "m " ]
174
- Z2 (t), [unit= u "m " ]
175
- X3 (t), [unit= u "m " ]
176
- Y3 (t), [unit= u "m " ]
177
- Z3 (t), [unit= u "m " ]
171
+ X1 (t), [unit= u "mol/m^3 " ]
172
+ Z1 (t), [unit= u "mol/m^3 " ]
173
+ X2 (t), [unit= u "mol/m^3 " ]
174
+ Z2 (t), [unit= u "mol/m^3 " ]
175
+ X3 (t), [unit= u "mol/m^3 " ]
176
+ Y3 (t), [unit= u "mol/m^3 " ]
177
+ Z3 (t), [unit= u "mol/m^3 " ]
178
178
end
179
179
@parameters begin
180
- k1, [unit= u "m^(-2)/s " ]
181
- v2, [unit= u "m^(-2)/s " ]
182
- K2, [unit= u "m " ]
183
- v3, [unit= u "m^(-1)/s " ]
184
- K3, [unit= u "m " ]
180
+ k1, [unit= u "(m^6)/(s*mol^2) " ]
181
+ v2, [unit= u "(m^6)/(s*mol^2) " ]
182
+ K2, [unit= u "mol/m^3 " ]
183
+ v3, [unit= u "(m^3)/(s*mol) " ]
184
+ K3, [unit= u "mol/m^3 " ]
185
185
n3
186
186
end
187
187
k1* X1, 2 X1 --> Z1
0 commit comments