feat: some ideas on resets
This commit is contained in:
parent
ac4e066bf8
commit
8f6320b30e
4 changed files with 24 additions and 21 deletions
|
|
@ -7,8 +7,9 @@ module Sim (S : SimState) =
|
|||
struct
|
||||
include S
|
||||
|
||||
let step_discrete s step hor fder fzer cget zset csize zsize jump reset =
|
||||
let ms, ss, zin = get_mstate s, get_sstate s, get_zin s in
|
||||
let step_discrete
|
||||
s step hor fder fzer cget zset csize zsize jump reset reinit
|
||||
= let ms, ss, zin = get_mstate s, get_sstate s, get_zin s in
|
||||
let ms = match zin with Some z -> zset ms z | None -> ms in
|
||||
let i, now, stop = get_input s, get_now s, get_stop s in
|
||||
let o, ms = step ms now (i.u now) in
|
||||
|
|
@ -16,7 +17,7 @@ module Sim (S : SimState) =
|
|||
let h = hor ms in
|
||||
if h <= 0.0 then set_mstate ms s
|
||||
else if now >= stop then set_idle s
|
||||
else if jump ms then begin
|
||||
else if jump ms || reinit then begin
|
||||
let init = cget ms and stop = stop -. now in
|
||||
let fder t = fder ms t (Utils.offset i.u now t) in
|
||||
let fzer t = fzer ms t (Utils.offset i.u now t) in
|
||||
|
|
@ -54,9 +55,9 @@ module Sim (S : SimState) =
|
|||
(DNode s : ('y, 'yder, 'zin, 'zout) solver)
|
||||
: ('p * (('y, 'yder) ivp * ('y, 'zout) zc), 'a, 'b) sim
|
||||
= let state = get_init m.state s.state in
|
||||
let step_discrete st =
|
||||
let step_discrete ?(reinit=false) st =
|
||||
let o, s = step_discrete st m.step m.horizon m.fder m.fzer m.cget m.zset
|
||||
m.csize m.zsize m.jump s.reset in
|
||||
m.csize m.zsize m.jump s.reset reinit in
|
||||
Some o, s in
|
||||
let step_continuous st =
|
||||
let o, s, _ = step_continuous st s.step m.cset m.fout m.horizon in
|
||||
|
|
@ -65,7 +66,8 @@ module Sim (S : SimState) =
|
|||
let step st = function
|
||||
| Some i ->
|
||||
let mode, now, stop = Discrete, 0.0, i.h in
|
||||
step_discrete (set_running ~mode ~input:i ~now ~stop st)
|
||||
let reinit = i.c = Discontinuous in
|
||||
step_discrete ~reinit (set_running ~mode ~input:i ~now ~stop st)
|
||||
| None ->
|
||||
if is_running st then match get_mode st with
|
||||
| Discrete -> step_discrete st
|
||||
|
|
@ -88,11 +90,11 @@ module Sim (S : SimState) =
|
|||
let al = List.map (fun a -> run_assert a get_s) m.assertions in
|
||||
let state = get_init m.body.state s.state, al in
|
||||
|
||||
let step_discrete (st, al) =
|
||||
let step_discrete ?(reinit=false) (st, al) =
|
||||
let m=m.body in
|
||||
let o, st =
|
||||
step_discrete st m.step m.horizon m.fder m.fzer m.cget m.zset m.csize
|
||||
m.zsize m.jump s.reset in
|
||||
m.zsize m.jump s.reset reinit in
|
||||
let al = List.map (fun (DNode a) ->
|
||||
let _, state = a.step a.state @@ Some (Utils.dot @@ get_mstate st) in
|
||||
DNode { a with state }) al in
|
||||
|
|
@ -134,9 +136,9 @@ module Sim (S : SimState) =
|
|||
(DNodeC s : ('y, 'yder, 'zin, 'zout) solver_c)
|
||||
: ('p * (('y, 'yder) ivp * ('y, 'zout) zc), 'a, 'b) sim
|
||||
= let state = get_init m.state s.state in
|
||||
let step_discrete st =
|
||||
let step_discrete ?(reinit=false) st =
|
||||
let o, st = step_discrete st m.step m.horizon m.fder m.fzer m.cget
|
||||
m.zset m.csize m.zsize m.jump s.reset in
|
||||
m.zset m.csize m.zsize m.jump s.reset reinit in
|
||||
Some o, st in
|
||||
let step_continuous st =
|
||||
let o, st, _ = step_continuous st s.step m.cset m.fout m.horizon in
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue