@@ -6,29 +6,9 @@ using Catalyst, Graphs, OrdinaryDiffEq, Test
6
6
# Fetch test networks.
7
7
include (" ../spatial_test_networks.jl" )
8
8
9
- # Pre declares a grid .
9
+ # Pre- declares a set of grids .
10
10
grids = [very_small_2d_cartesian_grid, very_small_2d_masked_grid, very_small_2d_graph_grid]
11
11
12
- # ## Test Spatial Reactions ###
13
-
14
- # Test creation of TransportReaction with non-parameters in rate.
15
- # Tests that it works even when rate is highly nested.
16
- let
17
- @variables t
18
- @species X (t) Y (t)
19
- @parameters D1 D2 D3
20
- @test_throws ErrorException TransportReaction (D1 + D2* (D3 + Y), X)
21
- @test_throws ErrorException TransportReaction (Y, X)
22
- end
23
-
24
- # Checks that the `hash` functions works for `TransportReaction`s.
25
- let
26
- tr1 = @transport_reaction D1 X
27
- tr2 = @transport_reaction D1 X
28
- tr3 = @transport_reaction D2 X
29
- hash (tr1, 0x0000000000000001 ) == hash (tr2, 0x0000000000000001 )
30
- hash (tr2, 0x0000000000000001 ) != hash (tr3, 0x0000000000000001 )
31
- end
32
12
33
13
# ## Tests LatticeReactionSystem Getters Correctness ###
34
14
@@ -179,110 +159,6 @@ let
179
159
@test isequal (independent_variables (lrs), [t])
180
160
end
181
161
182
- # ## Tests Spatial Reactions Getters Correctness ###
183
-
184
- # Test case 1.
185
- let
186
- tr_1 = @transport_reaction dX X
187
- tr_2 = @transport_reaction dY1* dY2 Y
188
-
189
- # @test ModelingToolkit.getname.(species(tr_1)) == ModelingToolkit.getname.(spatial_species(tr_1)) == [:X] # species(::TransportReaction) currently not supported.
190
- # @test ModelingToolkit.getname.(species(tr_2)) == ModelingToolkit.getname.(spatial_species(tr_2)) == [:Y]
191
- @test ModelingToolkit. getname .(spatial_species (tr_1)) == [:X ]
192
- @test ModelingToolkit. getname .(spatial_species (tr_2)) == [:Y ]
193
- @test ModelingToolkit. getname .(parameters (tr_1)) == [:dX ]
194
- @test ModelingToolkit. getname .(parameters (tr_2)) == [:dY1 , :dY2 ]
195
-
196
- # @test issetequal(species(tr_1), [tr_1.species])
197
- # @test issetequal(species(tr_2), [tr_2.species])
198
- @test issetequal (spatial_species (tr_1), [tr_1. species])
199
- @test issetequal (spatial_species (tr_2), [tr_2. species])
200
- end
201
-
202
- # Test case 2.
203
- let
204
- rs = @reaction_network begin
205
- @species X (t) Y (t)
206
- @parameters dX dY1 dY2
207
- end
208
- @unpack X, Y, dX, dY1, dY2 = rs
209
- tr_1 = TransportReaction (dX, X)
210
- tr_2 = TransportReaction (dY1* dY2, Y)
211
- # @test isequal(species(tr_1), [X])
212
- # @test isequal(species(tr_1), [X])
213
- @test issetequal (spatial_species (tr_2), [Y])
214
- @test issetequal (spatial_species (tr_2), [Y])
215
- @test issetequal (parameters (tr_1), [dX])
216
- @test issetequal (parameters (tr_2), [dY1, dY2])
217
- end
218
-
219
- # ## Tests Spatial Reactions Generation ###
220
-
221
- # Tests TransportReaction with non-trivial rate.
222
- let
223
- rs = @reaction_network begin
224
- @parameters dV dE [edgeparameter= true ]
225
- (p,1 ), 0 <--> X
226
- end
227
- @unpack dV, dE, X = rs
228
-
229
- tr = TransportReaction (dV* dE, X)
230
- @test isequal (tr. rate, dV* dE)
231
- end
232
-
233
- # Tests transport_reactions function for creating TransportReactions.
234
- let
235
- rs = @reaction_network begin
236
- @parameters d
237
- (p,1 ), 0 <--> X
238
- end
239
- @unpack d, X = rs
240
- trs = TransportReactions ([(d, X), (d, X)])
241
- @test isequal (trs[1 ], trs[2 ])
242
- end
243
-
244
- # Test reactions with constants in rate.
245
- let
246
- @variables t
247
- @species X (t) Y (t)
248
-
249
- tr_1 = TransportReaction (1.5 , X)
250
- tr_1_macro = @transport_reaction 1.5 X
251
- @test isequal (tr_1. rate, tr_1_macro. rate)
252
- @test isequal (tr_1. species, tr_1_macro. species)
253
-
254
- tr_2 = TransportReaction (π, Y)
255
- tr_2_macro = @transport_reaction π Y
256
- @test isequal (tr_2. rate, tr_2_macro. rate)
257
- @test isequal (tr_2. species, tr_2_macro. species)
258
- end
259
-
260
- # ## Test Interpolation ###
261
-
262
- # Does not currently work. The 3 tr_macro_ lines generate errors.
263
- # Test case 1.
264
- let
265
- rs = @reaction_network begin
266
- @species X (t) Y (t) Z (t)
267
- @parameters dX dY1 dY2 dZ
268
- end
269
- @unpack X, Y, Z, dX, dY1, dY2, dZ = rs
270
- rate1 = dX
271
- rate2 = dY1* dY2
272
- species3 = Z
273
- tr_1 = TransportReaction (dX, X)
274
- tr_2 = TransportReaction (dY1* dY2, Y)
275
- tr_3 = TransportReaction (dZ, Z)
276
- tr_macro_1 = @transport_reaction $ dX X
277
- tr_macro_2 = @transport_reaction $ (rate2) Y
278
- @test_broken false
279
- # tr_macro_3 = @transport_reaction dZ $species3 # Currently does not work, something with meta programming.
280
-
281
- @test isequal (tr_1, tr_macro_1)
282
- @test isequal (tr_2, tr_macro_2)
283
- # @test isequal(tr_3, tr_macro_3)
284
- end
285
-
286
162
# ## Tests Error generation ###
287
163
288
164
# Network where diffusion species is not declared in non-spatial network.
@@ -375,13 +251,13 @@ end
375
251
# Tests for hierarchical input system.
376
252
let
377
253
t = default_t ()
378
- @parameters d
254
+ @parameters d D
379
255
@species X (t)
380
256
rxs = [Reaction (d, [X], [])]
381
257
@named rs1 = ReactionSystem (rxs, t)
382
258
@named rs2 = ReactionSystem (rxs, t; systems = [rs1])
383
259
rs2 = complete (rs2)
384
- @test_throws ArgumentError LatticeReactionSystem (rs2, [tr ], short_path )
260
+ @test_throws ArgumentError LatticeReactionSystem (rs2, [TransportReaction (D, X) ], CartesianGrid (( 2 , 2 )) )
385
261
end
386
262
387
263
# Tests for non-complete input `ReactionSystem`.
390
266
rs = @network_component begin
391
267
(p,d), 0 <--> X
392
268
end
393
- @test_throws ArgumentError LatticeReactionSystem (rs1 , [tr], short_path )
269
+ @test_throws ArgumentError LatticeReactionSystem (rs , [tr], CartesianGrid (( 2 , 2 )) )
394
270
end
395
271
396
272
# ## Tests Grid Vertex and Edge Number Computation ###
@@ -409,14 +285,14 @@ let
409
285
random_1d_masked_grid, random_2d_masked_grid, random_3d_masked_grid]
410
286
lrs1 = LatticeReactionSystem (SIR_system, SIR_srs_1, lattice)
411
287
lrs2 = LatticeReactionSystem (SIR_system, SIR_srs_1, lattice; diagonal_connections= true )
412
- @test lrs1 . num_edges == iterator_count (edge_iterator (lrs1))
413
- @test lrs2 . num_edges == iterator_count (edge_iterator (lrs2))
288
+ @test num_edges (lrs1) == iterator_count (edge_iterator (lrs1))
289
+ @test num_edges (lrs2) == iterator_count (edge_iterator (lrs2))
414
290
end
415
291
416
292
# Graph grids (cannot test diagonal connections).
417
293
for lattice in [small_2d_graph_grid, small_3d_graph_grid, undirected_cycle, small_directed_cycle, unconnected_graph]
418
294
lrs1 = LatticeReactionSystem (SIR_system, SIR_srs_1, lattice)
419
- @test lrs1 . num_edges == iterator_count (edge_iterator (lrs1))
295
+ @test num_edges (lrs1) == iterator_count (edge_iterator (lrs1))
420
296
end
421
297
end
422
298
@@ -462,33 +338,33 @@ let
462
338
lrs = LatticeReactionSystem (rn, [tr], CartesianGrid (n))
463
339
ps = [:D => make_directed_edge_values (lrs, (10.0 , 0.0 ))]
464
340
oprob = ODEProblem (lrs, u0, tspan, ps)
465
- @test isapprox (solve (oprob, Tsit5 ())[end ][5 ], n, rtol= 1e-6 )
341
+ @test isapprox (solve (oprob, Tsit5 ()). u [end ][5 ], n, rtol= 1e-6 )
466
342
467
343
# Checks the 2d case (both with 1d and 2d flow).
468
344
lrs = LatticeReactionSystem (rn, [tr], CartesianGrid ((n,n)))
469
345
470
346
ps = [:D => make_directed_edge_values (lrs, (1.0 , 0.0 ), (0.0 , 0.0 ))]
471
347
oprob = ODEProblem (lrs, u0, tspan, ps)
472
- @test all (isapprox .(solve (oprob, Tsit5 ())[end ][5 : 5 : 25 ], n, rtol= 1e-6 ))
348
+ @test all (isapprox .(solve (oprob, Tsit5 ()). u [end ][5 : 5 : 25 ], n, rtol= 1e-6 ))
473
349
474
350
ps = [:D => make_directed_edge_values (lrs, (1.0 , 0.0 ), (1.0 , 0.0 ))]
475
351
oprob = ODEProblem (lrs, u0, tspan, ps)
476
- @test isapprox (solve (oprob, Tsit5 ())[end ][25 ], n^ 2 , rtol= 1e-6 )
352
+ @test isapprox (solve (oprob, Tsit5 ()). u [end ][25 ], n^ 2 , rtol= 1e-6 )
477
353
478
354
# Checks the 3d case (both with 1d and 2d flow).
479
355
lrs = LatticeReactionSystem (rn, [tr], CartesianGrid ((n,n,n)))
480
356
481
357
ps = [:D => make_directed_edge_values (lrs, (1.0 , 0.0 ), (0.0 , 0.0 ), (0.0 , 0.0 ))]
482
358
oprob = ODEProblem (lrs, u0, tspan, ps)
483
- @test all (isapprox .(solve (oprob, Tsit5 ())[end ][5 : 5 : 125 ], n, rtol= 1e-6 ))
359
+ @test all (isapprox .(solve (oprob, Tsit5 ()). u [end ][5 : 5 : 125 ], n, rtol= 1e-6 ))
484
360
485
361
ps = [:D => make_directed_edge_values (lrs, (1.0 , 0.0 ), (1.0 , 0.0 ), (0.0 , 0.0 ))]
486
362
oprob = ODEProblem (lrs, u0, tspan, ps)
487
- @test all (isapprox .(solve (oprob, Tsit5 ())[end ][25 : 25 : 125 ], n^ 2 , rtol= 1e-6 ))
363
+ @test all (isapprox .(solve (oprob, Tsit5 ()). u [end ][25 : 25 : 125 ], n^ 2 , rtol= 1e-6 ))
488
364
489
365
ps = [:D => make_directed_edge_values (lrs, (1.0 , 0.0 ), (1.0 , 0.0 ), (1.0 , 0.0 ))]
490
366
oprob = ODEProblem (lrs, u0, tspan, ps)
491
- @test isapprox (solve (oprob, Tsit5 ())[end ][125 ], n^ 3 , rtol= 1e-6 )
367
+ @test isapprox (solve (oprob, Tsit5 ()). u [end ][125 ], n^ 3 , rtol= 1e-6 )
492
368
end
493
369
494
370
# Checks that erroneous input yields errors.
0 commit comments