Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation of initial conditions that depend on a parameter #681

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@species X(t)=X0
@parameters X0
TorkelE marked this conversation as resolved.
Show resolved Hide resolved
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