feat: some ideas on resets
This commit is contained in:
parent
ac4e066bf8
commit
8f6320b30e
4 changed files with 24 additions and 21 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
let g = 9.81
|
let g = 9.81
|
||||||
let y0 = 50.0
|
let y0 = 0.0
|
||||||
let y'0 = 0.0
|
let y'0 = 10.0
|
||||||
|
|
||||||
let hybrid ball (y0, y'0) = (y, y', z) where
|
let hybrid ball (y0, y'0) = (y, y', z) where
|
||||||
rec der y = y' init y0
|
rec der y = y' init y0
|
||||||
|
|
@ -15,7 +15,7 @@ let hybrid main () =
|
||||||
print_float t;
|
print_float t;
|
||||||
print_string "\t";
|
print_string "\t";
|
||||||
print_float y;
|
print_float y;
|
||||||
print_string "\t";
|
(* print_string "\t";
|
||||||
print_float y';
|
print_float y'; *)
|
||||||
print_newline ()
|
print_newline ()
|
||||||
); ()
|
); ()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
(rule
|
(rule
|
||||||
(targets sincosz.ml sincosz.zci)
|
(targets sincosz_main.ml sincosz.ml sincosz.zci)
|
||||||
(deps
|
(deps
|
||||||
(:zl sincosz.zls))
|
(:zl sincosz.zls))
|
||||||
(action
|
(action
|
||||||
(run zeluc %{zl})))
|
(run zeluc -s f -o sincosz_main %{zl})))
|
||||||
|
|
|
||||||
|
|
@ -64,10 +64,11 @@ let m =
|
||||||
try
|
try
|
||||||
if !zelus then
|
if !zelus then
|
||||||
match !model with
|
match !model with
|
||||||
| None -> Format.eprintf "Missing model\n"; exit 2
|
| None -> Format.eprintf "Missing model\n"; exit 2
|
||||||
| Some "ballz" -> wrap_zelus (lift Ballz.main)
|
| Some "ballz" -> wrap_zelus (lift Ballz.main)
|
||||||
| Some "ballzm" -> wrap_zelus (lift_hsim Ballz_main.main)
|
| Some "ballzm" -> wrap_zelus (lift_hsim Ballz_main.main)
|
||||||
| Some "sincosz" -> wrap_zelus (lift Sincosz.f)
|
| Some "sincosz" -> wrap_zelus (lift Sincosz.f)
|
||||||
|
| Some "sincoszm" -> wrap_zelus (lift_hsim Sincosz_main.main)
|
||||||
(* | Some "count" -> wrap_zelus (lift Count.count) *)
|
(* | Some "count" -> wrap_zelus (lift Count.count) *)
|
||||||
| Some s -> Format.eprintf "Unknown model: %s\n" s; exit 2
|
| Some s -> Format.eprintf "Unknown model: %s\n" s; exit 2
|
||||||
else
|
else
|
||||||
|
|
@ -86,7 +87,7 @@ let st = if !inplace then (module State.InPlaceSimState : State.SimState)
|
||||||
else (module State.FunctionalSimState : State.SimState)
|
else (module State.FunctionalSimState : State.SimState)
|
||||||
|
|
||||||
let output =
|
let output =
|
||||||
if !no_print then Hsim.Utils.ignore
|
if !no_print || !zelus then Hsim.Utils.ignore
|
||||||
else if !speed then Output.print_h
|
else if !speed then Output.print_h
|
||||||
else Output.print (* Output.ignore *)
|
else Output.print (* Output.ignore *)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,9 @@ module Sim (S : SimState) =
|
||||||
struct
|
struct
|
||||||
include S
|
include S
|
||||||
|
|
||||||
let step_discrete s step hor fder fzer cget zset csize zsize jump reset =
|
let step_discrete
|
||||||
let ms, ss, zin = get_mstate s, get_sstate s, get_zin s in
|
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 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 i, now, stop = get_input s, get_now s, get_stop s in
|
||||||
let o, ms = step ms now (i.u now) in
|
let o, ms = step ms now (i.u now) in
|
||||||
|
|
@ -16,7 +17,7 @@ module Sim (S : SimState) =
|
||||||
let h = hor ms in
|
let h = hor ms in
|
||||||
if h <= 0.0 then set_mstate ms s
|
if h <= 0.0 then set_mstate ms s
|
||||||
else if now >= stop then set_idle 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 init = cget ms and stop = stop -. now in
|
||||||
let fder t = fder ms t (Utils.offset i.u now t) 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
|
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)
|
(DNode s : ('y, 'yder, 'zin, 'zout) solver)
|
||||||
: ('p * (('y, 'yder) ivp * ('y, 'zout) zc), 'a, 'b) sim
|
: ('p * (('y, 'yder) ivp * ('y, 'zout) zc), 'a, 'b) sim
|
||||||
= let state = get_init m.state s.state in
|
= 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
|
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
|
Some o, s in
|
||||||
let step_continuous st =
|
let step_continuous st =
|
||||||
let o, s, _ = step_continuous st s.step m.cset m.fout m.horizon in
|
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
|
let step st = function
|
||||||
| Some i ->
|
| Some i ->
|
||||||
let mode, now, stop = Discrete, 0.0, i.h in
|
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 ->
|
| None ->
|
||||||
if is_running st then match get_mode st with
|
if is_running st then match get_mode st with
|
||||||
| Discrete -> step_discrete st
|
| 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 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 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 m=m.body in
|
||||||
let o, st =
|
let o, st =
|
||||||
step_discrete st m.step m.horizon m.fder m.fzer m.cget m.zset m.csize
|
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 al = List.map (fun (DNode a) ->
|
||||||
let _, state = a.step a.state @@ Some (Utils.dot @@ get_mstate st) in
|
let _, state = a.step a.state @@ Some (Utils.dot @@ get_mstate st) in
|
||||||
DNode { a with state }) al in
|
DNode { a with state }) al in
|
||||||
|
|
@ -134,9 +136,9 @@ module Sim (S : SimState) =
|
||||||
(DNodeC s : ('y, 'yder, 'zin, 'zout) solver_c)
|
(DNodeC s : ('y, 'yder, 'zin, 'zout) solver_c)
|
||||||
: ('p * (('y, 'yder) ivp * ('y, 'zout) zc), 'a, 'b) sim
|
: ('p * (('y, 'yder) ivp * ('y, 'zout) zc), 'a, 'b) sim
|
||||||
= let state = get_init m.state s.state in
|
= 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
|
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
|
Some o, st in
|
||||||
let step_continuous st =
|
let step_continuous st =
|
||||||
let o, st, _ = step_continuous st s.step m.cset m.fout m.horizon in
|
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