Skip to content

Commit 20cfa99

Browse files
committed
init
1 parent 34a9223 commit 20cfa99

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/reactionsystem.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,13 @@ struct ReactionSystem{V <: NetworkProperties} <:
367367
end
368368
end
369369

370+
# Checks that no (non-reaction) equation contains a differential w.r.t. a species.
371+
for eq in eqs
372+
(eq isa Reaction) && continue
373+
(hasnode(is_species_diff, eq.lhs) || hasnode(is_species_diff, eq.rhs)) &&
374+
error("An equation ($eq) contains a differential with respect to a species. This is currently not supported. If this is a functionality you require, please raise an issue on the Catalyst GitHub page and we can consider the best way to implement it.")
375+
end
376+
370377
rs = new{typeof(nps)}(
371378
eqs, rxs, iv, sivs, unknowns, spcs, ps, var_to_name, observed,
372379
name, systems, defaults, connection_type, nps, cls, cevs,
@@ -376,6 +383,13 @@ struct ReactionSystem{V <: NetworkProperties} <:
376383
end
377384
end
378385

386+
# Checks if a symbolic expression constains a differential with respect to a species (either directly
387+
# or somehwere within the differential expression).
388+
function is_species_diff(expr)
389+
Symbolics.is_derivative(expr) || return false
390+
return hasnode(ex -> (ex isa Symbolics.BasicSymbolic) && isspecies(ex), expr)
391+
end
392+
379393
# Four-argument constructor. Permits additional inputs as optional arguments.
380394
# Calls the full constructor.
381395
function ReactionSystem(eqs, iv, unknowns, ps;
@@ -482,7 +496,7 @@ function ReactionSystem(rxs::Vector, iv = Catalyst.DEFAULT_IV; kwargs...)
482496
make_ReactionSystem_internal(rxs, iv, [], []; kwargs...)
483497
end
484498

485-
# One-argument constructor. Creates an emtoy `ReactionSystem` from a time independent variable only.
499+
# One-argument constructor. Creates an empty `ReactionSystem` from a time independent variable only.
486500
function ReactionSystem(iv; kwargs...)
487501
ReactionSystem(Reaction[], iv, [], []; kwargs...)
488502
end

test/reactionsystem_core/coupled_equation_crn_systems.jl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,3 +1012,32 @@ let
10121012
ps = [p1 => 2.0, p2 => 3.0]
10131013
@test_throws Exception ODEProblem(rs, u0, (0.0, 1.0), ps; structural_simplify = true)
10141014
end
1015+
1016+
# Checks that equations cannot contain differentials with respect to species.
1017+
let
1018+
# Basic case.
1019+
@test_throws Exception @eval @reaction_network begin
1020+
@equations D(X) ~ 1.0
1021+
d, X --> 0
1022+
end
1023+
1024+
# Complicated differential.
1025+
@test_throws Exception @eval @reaction_network begin
1026+
@equations V + X^2 ~ 1.0 - D(V + log(1 + X))
1027+
d, X --> 0
1028+
end
1029+
1030+
# Case where the species is declared, but not part of a reaction.
1031+
@test_throws Exception @eval @reaction_network begin
1032+
@species Y(t)
1033+
@equations D(Y) ~ 1.0
1034+
d, X --> 0
1035+
end
1036+
1037+
# Case where the equation also declares a new non-species variable.
1038+
# At some point something like this could be supported, however, not right now.
1039+
@test_throws Exception @eval @reaction_network begin
1040+
@equations D(V) ~ 1.0 + D(X)
1041+
d, X --> 0
1042+
end
1043+
end

0 commit comments

Comments
 (0)