Skip to content

Commit 1808a3a

Browse files
authored
Merge pull request #854 from SciML/add_nonreaction_function
Add `nonreaction` function
2 parents a45a1bc + 19880fc commit 1808a3a

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

docs/src/api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ species
157157
nonspecies
158158
reactionparams
159159
reactions
160+
nonreactions
160161
numspecies
161162
numparams
162163
numreactions

src/Catalyst.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export get_noise_scaling, has_noise_scaling
9898
# The `ReactionSystem` structure and its functions.
9999
include("reactionsystem.jl")
100100
export ReactionSystem, isspatial
101-
export species, nonspecies, reactionparams, reactions, speciesmap, paramsmap
101+
export species, nonspecies, reactionparams, reactions, nonreactions, speciesmap, paramsmap
102102
export numspecies, numreactions, numreactionparams, setdefaults!
103103
export make_empty_network, reactionparamsmap
104104
export dependants, dependents, substoichmat, prodstoichmat, netstoichmat

src/reactionsystem.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,18 @@ function numreactions(network)
811811
nr
812812
end
813813

814+
"""
815+
nonreactions(network)
816+
817+
Return the non-reaction equations within the network (i.e. algebraic and differnetial equations).
818+
819+
Notes:
820+
- Allocates a new array to store the non-species variables.
821+
"""
822+
function nonreactions(network)
823+
equations(network)[(numreactions(network) + 1):end]
824+
end
825+
814826
"""
815827
numreactionparams(network)
816828

test/reactionsystem_core/coupled_equation_crn_systems.jl

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,55 @@ let
211211
end
212212

213213

214+
### Accessor Tests ###
215+
216+
# Checks basic accessor functions for a basic coupled CRN/equation model.
217+
let
218+
# Creates a reaction system.
219+
t = default_t()
220+
D = default_time_deriv()
221+
@parameters p d v
222+
@species X(t)
223+
@variables V(t) W(t)
224+
225+
eqs = [
226+
Reaction(p, [], [X]),
227+
Reaction(d, [X], []),
228+
Reaction(d, [X], nothing, [2], nothing),
229+
D(V) ~ X - v*V,
230+
W^2 ~ log(V) + X
231+
]
232+
@named coupled_rs = ReactionSystem(eqs, t)
233+
234+
# Check unknowns-related accessors.
235+
@test Catalyst.has_species(coupled_rs)
236+
@test issetequal(Catalyst.get_species(coupled_rs), [X])
237+
@test issetequal(species(coupled_rs), [X])
238+
@test issetequal(ModelingToolkit.get_unknowns(coupled_rs), [X, V, W])
239+
@test issetequal(unknowns(coupled_rs), [X, V, W])
240+
@test issetequal(nonspecies(coupled_rs), [V, W])
241+
@test numspecies(coupled_rs) == 1
242+
243+
# Check parameters-related accessors.
244+
@test Catalyst.has_rxs(coupled_rs)
245+
@test issetequal(Catalyst.get_rxs(coupled_rs), eqs[1:3])
246+
@test issetequal(reactions(coupled_rs), eqs[1:3])
247+
@test issetequal(equations(coupled_rs), eqs)
248+
@test issetequal(nonreactions(coupled_rs), eqs[4:5])
249+
@test issetequal(reactionrates(coupled_rs), [p, d, d])
250+
@test numreactions(coupled_rs) == 3
251+
252+
# Check parameters-related accessors.
253+
@test issetequal(parameters(coupled_rs), [p, d, v])
254+
@test issetequal(reactionparams(coupled_rs), [p, d, v])
255+
@test numparams(coupled_rs) == 3
256+
@test numreactionparams(coupled_rs) == 3
257+
258+
# Check other accessors.
259+
@test !isspatial(coupled_rs)
260+
end
261+
262+
214263
### Species, Variables, and Parameter Handling ###
215264

216265
# Checks that coupled systems contain the correct species, variables, and parameters.

0 commit comments

Comments
 (0)