Skip to content

Commit 2ee5ecd

Browse files
committed
fix sampled data docs
1 parent 4de943f commit 2ee5ecd

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

docs/src/tutorials/input_component.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,15 @@ plot(sol2)
157157
The below code shows how to include data using a `Ref` and registered `get_sampled_data` function. This example uses a very basic function which requires non-adaptive solving and sampled data. As can be seen, the data can easily be set and changed before solving.
158158

159159
```@example custom_component_external_data
160+
using ModelingToolkit
161+
using ModelingToolkit: t_nounits as t, D_nounits as D
162+
using ModelingToolkitStandardLibrary.Blocks
163+
using OrdinaryDiffEq
164+
160165
const rdata = Ref{Vector{Float64}}()
161166
167+
dt = 4e-4
168+
time = 0:dt:0.1
162169
# Data Sets
163170
data1 = sin.(2 * pi * time * 100)
164171
data2 = cos.(2 * pi * time * 50)
@@ -211,6 +218,11 @@ Additional code could be added to resolve this issue, for example by using a `Re
211218
To resolve the issues presented above, the `ModelingToolkitStandardLibrary.Blocks.SampledData` component can be used which allows for a resusable `ODESystem` and self contained data which ensures a solution which remains valid for it's lifetime. Now it's possible to also parallelize the call to `solve()`.
212219

213220
```@example sampled_data_component
221+
using ModelingToolkit
222+
using ModelingToolkit: t_nounits as t, D_nounits as D
223+
using ModelingToolkitStandardLibrary.Blocks
224+
using OrdinaryDiffEq
225+
214226
function System(; name)
215227
src = SampledData(Float64, name=:src)
216228
@@ -228,6 +240,12 @@ end
228240
@named system = System()
229241
sys = structural_simplify(system, split=false)
230242
s = complete(system)
243+
244+
dt = 4e-4
245+
time = 0:dt:0.1
246+
data1 = sin.(2 * pi * time * 100)
247+
data2 = cos.(2 * pi * time * 50)
248+
231249
prob = ODEProblem(sys, [], (0, time[end]); tofloat = false, use_union=true)
232250
defs = ModelingToolkit.defaults(sys)
233251

0 commit comments

Comments
 (0)