chore: update

This commit is contained in:
Henri Saudubray 2026-03-27 10:53:26 +01:00
parent 4776edc9db
commit 416d97c513
Signed by: hms
GPG key ID: 7065F57ED8856128
25 changed files with 1653 additions and 283 deletions

View file

@ -145,11 +145,11 @@ let compose_solvers :
type ('i, 'o, 'r, 'y, 'yder, 'zin, 'zout) hnode =
HNode : {
state : 's; (** current state *)
step : 's -> 'i -> 's * 'o; (** discrete step function *)
step : 's -> time -> 'i -> 's * 'o; (** discrete step function *)
fder : 's -> time -> 'i -> 'y -> 'yder; (** derivative function *)
fzer : 's -> time -> 'i -> 'y -> 'zin; (** zero-crossing function *)
fout : 's -> time -> 'i -> 'y -> 'o; (** continuous output function *)
reset : 's -> 'r -> 's; (** reset function *)
fder : 's -> 'i -> 'y -> 'yder; (** derivative function *)
fzer : 's -> 'i -> 'y -> 'zin; (** zero-crossing function *)
fout : 's -> 'i -> 'y -> 'o; (** continuous output function *)
cget : 's -> 'y; (** continuous state getter *)
cset : 's -> 'y -> 's; (** continuous state setter *)
zset : 's -> 'zout -> 's; (** zero-crossing information setter *)
@ -189,13 +189,11 @@ type mode = D | C
time, and step mode. *)
type ('i, 'o, 'r, 'y) state =
State : {
solver : (** solver state *)
('y, 'yder, 'zin, 'zout) solver;
model : (** model state *)
('i, 'o, 'r, 'y, 'yder, 'zin, 'zout) hnode;
input : 'i signal; (** current input *)
time : time; (** current time *)
mode : mode; (** current step mode *)
solver : ('y, 'yder, 'zin, 'zout) solver; (** solver state *)
model : ('i, 'o, 'r, 'y, 'yder, 'zin, 'zout) hnode; (** model state *)
input : 'i signal; (** current input *)
time : time; (** current time *)
mode : mode; (** current step mode *)
} -> ('i, 'o, 'r, 'y) state
@ -206,7 +204,7 @@ type ('i, 'o, 'r, 'y) state =
let dstep (State ({ model = HNode m; solver = DNode s; _ } as st)) =
let i = Option.get st.input in
(* Step the model *)
let ms, o = m.step m.state (i.f st.time) in
let ms, o = m.step m.state st.time (i.f st.time) in
let model = HNode { m with state = ms } in
let st =
if m.jump ms then
@ -217,11 +215,12 @@ let dstep (State ({ model = HNode m; solver = DNode s; _ } as st)) =
State { st with input = None; model; time = 0. }
else
(* otherwise, reset the solver and switch to continuous mode. *)
let y0 = m.cget ms and h = i.h -. st.time in
let ivp = { h; y0; fder = fun t -> m.fder ms (i.f (t +. st.time)) } in
let zcp = { h; y0; fzer = fun t -> m.fzer ms (i.f (t +. st.time)) } in
let y0 = m.cget ms and h = i.h -. st.time and ofs = (+.) st.time in
let ivp = { h; y0; fder = fun t -> m.fder ms (ofs t) (i.f (ofs t)) } in
let zcp = { h; y0; fzer = fun t -> m.fzer ms (ofs t) (i.f (ofs t)) } in
let solver = DNode { s with state = s.reset s.state (ivp, zcp) } in
State { st with model; solver; mode = C } in
let input = Some { h = i.h -. st.time; f = fun t -> i.f (ofs t) } in
State { model; solver; mode = C; time = 0.; input } in
(* Return the state and the output function (defined only at [0.0]). *)
st, Some { h = 0.; f = fun _ -> o }
@ -232,15 +231,15 @@ let dstep (State ({ model = HNode m; solver = DNode s; _ } as st)) =
let cstep (State ({ model = HNode m; solver = DNode s; _ } as st)) =
let i = Option.get st.input in
(* Step the solver. *)
let ss, (y, z) = s.step s.state i.h in
let ss, (y, z) = s.step s.state i.h in
let solver = DNode { s with state = ss } in
(* Update the model's state. *)
let ms = m.zset (m.cset m.state (y.f y.h)) z in
let model = HNode { m with state = ms } in
(* Create the output function. *)
let out = { y with f = fun t -> m.fout ms (i.f (t +. st.time)) (y.f t) } in
let out = { y with f = fun t -> m.fout ms (st.time +. t) (i.f (st.time +. t)) (y.f t) } in
(* Compute the mode for the next step. *)
let mode = if m.jump ms || st.time +. y.h >= i.h then D else C in
let model = HNode { m with state = ms } in
let solver = DNode { s with state = ss } in
(* Return the state and the output function. *)
State { st with model; solver; mode; time = st.time +. y.h }, Some out