Skip to content

Commit

Permalink
Merge pull request #989 from SciML/more_t_isa_parameter
Browse files Browse the repository at this point in the history
More t is now a parameter test
  • Loading branch information
TorkelE authored Jul 21, 2024
2 parents 27ce254 + a119ef4 commit 196d244
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/src/model_creation/chemistry_related_functionality.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ In all of these cases, the left-hand side must be enclosed within `()`.
While we generally do not need to specify independent variables for compound, if the components (together) have more than one independent variable, this *must be done*:
```@example chem1
t = default_t()
@variables s
@parameters s
@species N(s) O(t)
@compound NO2(t,s) ~ N + 2O
```
Expand Down
2 changes: 1 addition & 1 deletion docs/unpublished/pdes.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ end
We now define the reaction model
```julia
t = default_t()
@variables x y
@parameters x y
@species U(x,y,t) V(x,y,t) W(x,y,t)
rxs = [Reaction(k[1], [U, W], [V, W]),
Reaction(k[2], [V], [W], [2], [1]),
Expand Down
3 changes: 2 additions & 1 deletion test/dsl/dsl_options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,8 @@ let
end

@parameters k k2
@variables s x D(x) E(s) F(s,x)
@parameters s x
@variables D(x) E(s) F(s,x)
@species A(s,x) B(s) C(x) C2(s,x)
rx = Reaction(k*k2*D, [A, B], [C, C2], [E, 1], [F, 1])
@named ivstest = ReactionSystem([rx], s; spatial_ivs = [x])
Expand Down
2 changes: 1 addition & 1 deletion test/miscellaneous_tests/compound_macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ end

# Test using different independent variable combinations.
let
@variables x y z
@parameters x y z
@species C(t) H(x) N(x) O(t) P(t,x) S(x,y)

# Checks that wrong (or absent) independent variable produces errors.
Expand Down
2 changes: 1 addition & 1 deletion test/miscellaneous_tests/reactionsystem_serialisation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ end
# Checks for system with non-default independent variable.
let
# Prepares parameters/variables/species with complicated dependencies.
@variables τ
@parameters τ
@parameters begin
b = 3.0
c
Expand Down
14 changes: 9 additions & 5 deletions test/reactionsystem_core/coupled_equation_crn_systems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ end
# The system is mostly made up to be non-trivial, but reliably solvable.
let
@parameters p d a b c
@variables τ A(τ) B(τ) C(τ)
@parameters τ
@variables A(τ) B(τ) C(τ)
@species X(τ)
Δ = Differential(τ)
eqs = [
Expand Down Expand Up @@ -265,7 +266,8 @@ end
# Checks that non-default iv is inferred correctly from reactions/equations.
let
# Create coupled model.
@variables τ A(τ) B(τ)
@parameters τ
@variables A(τ) B(τ)
@species X(τ) X2(τ)
@parameters k1 k2 k b1 b2
D = Differential(τ)
Expand Down Expand Up @@ -607,7 +609,8 @@ let

# Declares the model in a messy fashion, and simulates it.
osol_messy = let
@variables τ M(τ) H(τ)=h_max
@parameters τ
@variables M(τ) H(τ)=h_max
@species S(τ) I(τ) R(τ)
Δ = Differential(τ)
eqs_messy = [
Expand Down Expand Up @@ -972,7 +975,8 @@ end
# Checks that various erroneous coupled system declarations yield errors.
let
@parameters p1 p2
@variables τ U1(τ) V1(t)
@parameters τ
@variables U1(τ) V1(t)
@species R1(τ) R2(τ) S1(t) S2(t)
E = Differential(τ)

Expand All @@ -989,7 +993,7 @@ let
# Equation with variable using non-declared independent variable.
@test_throws Exception ReactionSystem([
Reaction(p1, [S1], [S2]),
U1 ~ S1 + p2
E(U1) ~ S1 + p2
], t; name = :rs)

# Differential with respect to non-declared independent variable.
Expand Down
3 changes: 2 additions & 1 deletion test/reactionsystem_core/custom_crn_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ end
# Tests `Equation`s.
# Tests using non-default independent variable.
let
@variables T X(T) Y(T)
@parameters T
@variables X(T) Y(T)
@parameters K V N

eq1 = 0 ~ mm(X, V, K)
Expand Down
24 changes: 24 additions & 0 deletions test/reactionsystem_core/reactionsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,30 @@ let
@test_throws Exception convert(NonlinearSystem, nc)
end

# Checks that the same name cannot be used for two different of parameters/species/variables.
let
# Stores a parameter, a species, and a variable (with identical names) in different variables.
x_p = let
only(@parameters x)
end
x_sp = let
only(@species x(t))
end
x_v = let
only(@variables x(t))
end

# Checks that creating systems with different in combination produces errors.
# Currently broken on MTK, potentially fix in Catalyst once sorted out there (https://github.com/SciML/ModelingToolkit.jl/issues/2883).
@parameters d
@species X(t)
rx = Reaction(d, [X], [])
@test_broken false # (not sure how to mark a `@test_throws` as broken)
# @test_throws rs1 = ReactionSystem([rx], t, [X, x_sp,], [d, x_p]; name = :rs)
# @test_throws rs2 = ReactionSystem([rx], t, [X, X, x_v], [d, x_p]; name = :rs)
# @test_throws rs2 = ReactionSystem([rx], t, [X, x_sp, x_v], [d]; name = :rs)
end

### Other Tests ###

# Test for https://github.com/SciML/ModelingToolkit.jl/issues/436.
Expand Down
2 changes: 1 addition & 1 deletion test/spatial_modelling/simulate_PDEs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ end
let
t = default_t()
@parameters k[1:7] D[1:3] n0[1:3] A
@variables x y
@parameters x y
@species U(x, y, t) V(x, y, t) W(x, y, t)
rxs = [Reaction(k[1], [U, W], [V, W]),
Reaction(k[2], [V], [W], [2], [1]),
Expand Down

0 comments on commit 196d244

Please sign in to comment.