Skip to content

Commit

Permalink
Merge pull request #681 from SciML/parametric_initialconditions_doc
Browse files Browse the repository at this point in the history
Documentation of initial conditions that depend on a parameter
  • Loading branch information
TorkelE authored Sep 19, 2023
2 parents c74ad14 + ef8e7e0 commit 401a775
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/src/catalyst_functionality/dsl_description.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
@parameters X0
@species X(t)=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
Expand Down
11 changes: 11 additions & 0 deletions test/reactionsystem_structure/reactionsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 401a775

Please sign in to comment.