From f8332aea1c8efcbf056d45fe5835a124c87cd378 Mon Sep 17 00:00:00 2001 From: Torkel Date: Mon, 18 Sep 2023 19:31:42 -0400 Subject: [PATCH 1/2] Initiate --- .../catalyst_functionality/dsl_description.md | 20 +++++++++++++++++++ .../reactionsystem.jl | 11 ++++++++++ 2 files changed, 31 insertions(+) diff --git a/docs/src/catalyst_functionality/dsl_description.md b/docs/src/catalyst_functionality/dsl_description.md index 7e2a140113..12af0e9db2 100644 --- a/docs/src/catalyst_functionality/dsl_description.md +++ b/docs/src/catalyst_functionality/dsl_description.md @@ -412,6 +412,26 @@ sol = solve(oprob) plot(sol) ``` +## Setting initial conditions that depend on parameters +It is possible to set the initial condition of one (or several) species so that they depend on some system parameter. This is done in a similar way as default initial conditions, but giving the parameter instead of a value. When doing this, we also need to ensure that the initial condition parameter is a variable of the system: +```@example tut2 +rn = @reaction_network begin + @species X(t)=X0 + @parameters X0 + p, 0 --> X + d, X --> ∅ +end +``` +We can now simulate the network without providing any initial conditions: +```@example tut2 +u0 = [] +tspan = (0.0, 10.0) +p = [:p => 2.0, :d => .1, :X0 => 1.0] +oprob = ODEProblem(rn, u0, tspan, p) +sol = solve(oprob) +plot(sol) +``` + ## Naming the generated `ReactionSystem` ModelingToolkit uses system names to allow for compositional and hierarchical models. To specify a name for the generated `ReactionSystem` via the diff --git a/test/reactionsystem_structure/reactionsystem.jl b/test/reactionsystem_structure/reactionsystem.jl index 21e95f54bd..8fbc5f8f07 100644 --- a/test/reactionsystem_structure/reactionsystem.jl +++ b/test/reactionsystem_structure/reactionsystem.jl @@ -631,6 +631,17 @@ let @test issetequal(parameters(rs), [k, b]) end +# Test parameteric initial conditions. +let + @parameters d X0 + @variables t + @species X(t)=X0 + rx = Reaction(d, [X], nothing, [1], nothing) + @named rs = ReactionSystem([rx], t) + prob = ODEProblem(rs, [], (0.0, 1.0), [d => 1.0, X0 => 7.6]) + @test prob[X] == 7.6 +end + # Test balanced_bc_check. let @variables t From ef8e7e03d7aa4c8c91daddb9e1b955ff87ba3bab Mon Sep 17 00:00:00 2001 From: Torkel Date: Mon, 18 Sep 2023 19:56:44 -0400 Subject: [PATCH 2/2] Update docs/src/catalyst_functionality/dsl_description.md Co-authored-by: Sam Isaacson --- docs/src/catalyst_functionality/dsl_description.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/catalyst_functionality/dsl_description.md b/docs/src/catalyst_functionality/dsl_description.md index 12af0e9db2..7a52176f11 100644 --- a/docs/src/catalyst_functionality/dsl_description.md +++ b/docs/src/catalyst_functionality/dsl_description.md @@ -416,8 +416,8 @@ plot(sol) It is possible to set the initial condition of one (or several) species so that they depend on some system parameter. This is done in a similar way as default initial conditions, but giving the parameter instead of a value. When doing this, we also need to ensure that the initial condition parameter is a variable of the system: ```@example tut2 rn = @reaction_network begin - @species X(t)=X0 @parameters X0 + @species X(t)=X0 p, 0 --> X d, X --> ∅ end