Skip to content

Commit

Permalink
update integrator interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRackauckas committed Feb 10, 2017
1 parent a3c5949 commit 671b207
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 19 deletions.
58 changes: 41 additions & 17 deletions docs/src/basics/integrator.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,44 +127,68 @@ for safe modifications of the integrator type, and allows for uniform usage
throughout the ecosystem (for packages/algorithms which implement the functions).
The following functions make up the interface:

* `u_modified!(integrator,bool)`: Bool which states whether a change to `u` occurred,
allowing the solver to handle the discontinuity.
### Saving Controls

* `savevalues!(integrator)`: Adds the current state to the `sol`.
* `modify_proposed_dt(integrator,factor)`: Multiplies the proposed `dt` for the
next timestep by the scaling `factor`.
* `proposed_dt(integrator)`: Returns the `dt` of the proposed step.

### Cache Iterators

* `user_cache(integrator)`: Returns an iterator over the user-facing cache arrays.
* `u_cache(integrator)`: Returns an iterator over the cache arrays for `u` in the method.
This can be used to change internal values as needed.
* `du_cache(integrator)`: Returns an iterator over the cache arrays for rate quantities the method.
This can be used to change internal values as needed.
* `full_cache(integrator)`: Returns an iterator over the cache arrays of the method.
This can be used to change internal values as needed.

### Stepping Controls

* `u_modified!(integrator,bool)`: Bool which states whether a change to `u` occurred,
allowing the solver to handle the discontinuity.
* `modify_proposed_dt(integrator,factor)`: Multiplies the proposed `dt` for the
next timestep by the scaling `factor`.
* `proposed_dt(integrator)`: Returns the `dt` of the proposed step.
* `terminate!(integrator)`: Terminates the integrator by emptying `tstops`. This
can be used in events and callbacks to immediately end the solution process.
* `change_t_via_interpolation(integrator,t,modify_save_endpoint=Val{false})`: This
option lets one modify the current `t` and changes all of the corresponding
values using the local interpolation. If the current solution has already
been saved, one can provide the optional value `modify_save_endpoint` to also
modify the endpoint of `sol` in the same manner.

### Resizing

* `resize!(integrator,k)`: Resizes the DE to a size `k`. This chops off the end
of the array, or adds blank values at the end, depending on whether `k>length(integrator.u)`.
* `resize_non_user_cache!(integrator,k)`: Resizes the non-user facing caches to be
compatible with a DE of size `k`. This includes resizing Jacobian caches. Note
that in many cases, `resize!` simple resizes `user_cache` variables and then
calls this function. This finer control is required for some `AbstractArray`
operations.
* `terminate!(integrator)`: Terminates the integrator by emptying `tstops`. This
can be used in events and callbacks to immediately end the solution process.
* `deleteat!(integrator,k)`: Shrinks the ODE by deleting the `i`th component.
* `deleteat_non_user_cache!(integrator,idxs)`: `deleteat!`s the non-user facing caches
at indices `idxs`. This includes resizing Jacobian caches. Note
that in many cases, `deleteat!` simple `deleteat!`s `user_cache` variables and then
calls this function. This finer control is required for some `AbstractArray`
operations.
* `addat_non_user_cache!(integrator,idxs)`: `addat!`s the non-user facing caches
at indices `idxs`. This includes resizing Jacobian caches. Note
that in many cases, `addat!` simple `addat!`s `user_cache` variables and then
calls this function. This finer control is required for some `AbstractArray`
operations.
* `deleteat!(integrator,idxs)`: Shrinks the ODE by deleting the `idxs` components.
* `addat!(integrator,idxs)`: Grows the ODE by adding the `idxs` components.
Must be contiguous indices.

### Misc

* `get_du(integrator)`: Returns the derivative at `t`.
* `change_t_via_interpolation(integrator,t,modify_save_endpoint=Val{false})`: This
option lets one modify the current `t` and changes all of the corresponding
values using the local interpolation. If the current solution has already
been saved, one can provide the optional value `modify_save_endpoint` to also
modify the endpoint of `sol` in the same manner.

#### Note

Note that not all of these functions will be implemented for every algorithm.
Some have hard limitations. For example, Sundials.jl cannot resize problems.
When a function is not limited, an error will be thrown.

#### Note

Currently, many of these functions are not implemented.

## Additional Options

The following options can additionally be specified in `init` (or be mutated in
Expand Down
4 changes: 2 additions & 2 deletions docs/src/tutorials/discrete_stochastic_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ Reaction(rate_constant,reactants,stoichiometry)

The first value is the rate constant. We will use `1e-4`. Secondly, we pass in the
indices for the reactants. In this case, since it uses the susceptible and infected
persons, the indices are `[2,3]`. Lastly, we detail the stoichometric changes. These
persons, the indices are `[1,2]`. Lastly, we detail the stoichometric changes. These
are tuples `(i,j)` where `i` is the reactant and `j` is the number to change by.
Thus `(1,-1)` means "decrease the number of susceptible persons by 1" and
`(2,1)` means "increase the number of infected persons by 1".

Therefore, in total, our reaction is:

```julia
r1 = Reaction(1e-4,[2,3],[(1,-1),(2,1)])
r1 = Reaction(1e-4,[1,2],[(1,-1),(2,1)])
```

To finish the model, we define one more reaction. Over time, infected people become
Expand Down

0 comments on commit 671b207

Please sign in to comment.