Skip to content

Commit

Permalink
Merge pull request #854 from SciML/add_nonreaction_function
Browse files Browse the repository at this point in the history
Add `nonreaction` function
  • Loading branch information
TorkelE committed May 21, 2024
2 parents a45a1bc + 19880fc commit 1808a3a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ species
nonspecies
reactionparams
reactions
nonreactions
numspecies
numparams
numreactions
Expand Down
2 changes: 1 addition & 1 deletion src/Catalyst.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export get_noise_scaling, has_noise_scaling
# The `ReactionSystem` structure and its functions.
include("reactionsystem.jl")
export ReactionSystem, isspatial
export species, nonspecies, reactionparams, reactions, speciesmap, paramsmap
export species, nonspecies, reactionparams, reactions, nonreactions, speciesmap, paramsmap
export numspecies, numreactions, numreactionparams, setdefaults!
export make_empty_network, reactionparamsmap
export dependants, dependents, substoichmat, prodstoichmat, netstoichmat
Expand Down
12 changes: 12 additions & 0 deletions src/reactionsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,18 @@ function numreactions(network)
nr
end

"""
nonreactions(network)
Return the non-reaction equations within the network (i.e. algebraic and differnetial equations).
Notes:
- Allocates a new array to store the non-species variables.
"""
function nonreactions(network)
equations(network)[(numreactions(network) + 1):end]
end

"""
numreactionparams(network)
Expand Down
49 changes: 49 additions & 0 deletions test/reactionsystem_core/coupled_equation_crn_systems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,55 @@ let
end


### Accessor Tests ###

# Checks basic accessor functions for a basic coupled CRN/equation model.
let
# Creates a reaction system.
t = default_t()
D = default_time_deriv()
@parameters p d v
@species X(t)
@variables V(t) W(t)

eqs = [
Reaction(p, [], [X]),
Reaction(d, [X], []),
Reaction(d, [X], nothing, [2], nothing),
D(V) ~ X - v*V,
W^2 ~ log(V) + X
]
@named coupled_rs = ReactionSystem(eqs, t)

# Check unknowns-related accessors.
@test Catalyst.has_species(coupled_rs)
@test issetequal(Catalyst.get_species(coupled_rs), [X])
@test issetequal(species(coupled_rs), [X])
@test issetequal(ModelingToolkit.get_unknowns(coupled_rs), [X, V, W])
@test issetequal(unknowns(coupled_rs), [X, V, W])
@test issetequal(nonspecies(coupled_rs), [V, W])
@test numspecies(coupled_rs) == 1

# Check parameters-related accessors.
@test Catalyst.has_rxs(coupled_rs)
@test issetequal(Catalyst.get_rxs(coupled_rs), eqs[1:3])
@test issetequal(reactions(coupled_rs), eqs[1:3])
@test issetequal(equations(coupled_rs), eqs)
@test issetequal(nonreactions(coupled_rs), eqs[4:5])
@test issetequal(reactionrates(coupled_rs), [p, d, d])
@test numreactions(coupled_rs) == 3

# Check parameters-related accessors.
@test issetequal(parameters(coupled_rs), [p, d, v])
@test issetequal(reactionparams(coupled_rs), [p, d, v])
@test numparams(coupled_rs) == 3
@test numreactionparams(coupled_rs) == 3

# Check other accessors.
@test !isspatial(coupled_rs)
end


### Species, Variables, and Parameter Handling ###

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

0 comments on commit 1808a3a

Please sign in to comment.