feat: a LOT of stuff (final report, examples, simulation of a single assert, move from node instances to node definitions, etc.)

This commit is contained in:
Henri Saudubray 2025-08-20 18:20:46 +02:00
parent ba5db5bd99
commit f2c545ce2c
Signed by: hms
GPG key ID: 7065F57ED8856128
49 changed files with 12377 additions and 1898 deletions

17
exm/zelus/vdp/dune Normal file
View file

@ -0,0 +1,17 @@
(env
(dev
(flags
(:standard -w -a))))
(rule
(targets main.ml vdp.ml vdp.zci)
(deps
(:zl vdp.zls)
(:zli solve.zli))
(action
(run zeluc -deps -s main_d -o main %{zli} %{zl})))
(executable
(public_name vdp.exe)
(name main)
(libraries std))

27
exm/zelus/vdp/solve.zli Normal file
View file

@ -0,0 +1,27 @@
type time = float
type 'a value
type 'a signal = 'a value option
type 'a signal_t = ('a value * time) option
val horizon : 'a value -> time
val make : time * (time -> 'a) -> 'a value
val apply : 'a value * time -> 'a
val sustain : 'a -> 'a value
val solve_ode45 : ('a -C-> 'b) -S-> 'a signal -D-> 'b signal_t
val solve_sundials : ('a -C-> 'b) -S-> 'a signal -D-> 'b signal_t
val synchr :
('a signal -D-> 'b signal_t) -S->
('a signal -D-> 'c signal_t) -S->
'a signal -D-> ('b * 'c) signal_t
val iter : int -S-> ('a -D-> unit) -S-> 'a signal_t -D-> unit
val iter_t : int -S-> (time * 'a -D-> unit) -S-> 'a signal_t -D-> unit
val check : int -S-> ('a -D-> bool) -S-> 'a signal_t -D-> unit
val check_t : int -S-> (time * 'a -D-> bool) -S-> 'a signal_t -D-> unit
val period' : float -S-> ('a -D-> unit) -S-> 'a signal_t -D-> unit
val period'_t : float -S-> (time * 'a -D-> unit) -S-> 'a signal_t -D-> unit

54
exm/zelus/vdp/vdp.zls Normal file
View file

@ -0,0 +1,54 @@
let mu = 5.0
let hybrid vdp_c() = (x, y) where
rec der x = y init 1.0
and der y = (mu *. (1.0 -. (x *. x)) *. y) -. x init 1.0
let node forward(h)(x0, x') = x where
rec x = x0 fby (x +. h *. x')
let node backward(h)(x0, x') = x where
rec x = x0 -> pre x +. h *. x'
let node vdp_d(h)() = (x, y) where
rec x = backward(h)(1.0, y)
and y = forward(h)(1.0, (mu *. (1.0 -. (x *. x)) *. y) -. x)
let stop_time = 50.0
let node print (t, (x, y)) =
print_endline (String.concat ",\t" (List.map string_of_float [t;x;y]))
let node main_d() =
let rec t = 0.0 -> pre t +. 0.001 in
print(t, vdp_d(0.001)())
let node main_dc() =
let rec (t0, (x0, y0)) = ((0.0 -> pre t0 +. 0.1), vdp_d(0.1)()) in
let rec (t1, (x1, y1)) = ((0.0 -> pre t1 +. 0.2), vdp_d(0.2)()) in
let rec (t2, (x2, y2)) = ((0.0 -> pre t2 +. 0.3), vdp_d(0.3)()) in
let rec (t3, (x3, y3)) = ((0.0 -> pre t3 +. 0.4), vdp_d(0.4)()) in
let rec (t4, (x4, y4)) = ((0.0 -> pre t4 +. 0.5), vdp_d(0.5)()) in
let rec (t5, (x5, y5)) = ((0.0 -> pre t5 +. 0.6), vdp_d(0.6)()) in
let rec (t6, (x6, y6)) = ((0.0 -> pre t6 +. 0.7), vdp_d(0.7)()) in
let rec (t7, (x7, y7)) = ((0.0 -> pre t7 +. 0.8), vdp_d(0.8)()) in
let rec (t8, (x8, y8)) = ((0.0 -> pre t8 +. 0.9), vdp_d(0.9)()) in
let rec (t9, (x9, y9)) = ((0.0 -> pre t9 +. 1.0), vdp_d(1.0)()) in
print_endline (String.concat "\t" [string_of_float t0; "x0"; string_of_float x0; "y0"; string_of_float y0]);
print_endline (String.concat "\t" [string_of_float t1; "x1"; string_of_float x1; "y1"; string_of_float y1]);
print_endline (String.concat "\t" [string_of_float t2; "x2"; string_of_float x2; "y2"; string_of_float y2]);
print_endline (String.concat "\t" [string_of_float t3; "x3"; string_of_float x3; "y3"; string_of_float y3]);
print_endline (String.concat "\t" [string_of_float t4; "x4"; string_of_float x4; "y4"; string_of_float y4]);
print_endline (String.concat "\t" [string_of_float t5; "x5"; string_of_float x5; "y5"; string_of_float y5]);
print_endline (String.concat "\t" [string_of_float t6; "x6"; string_of_float x6; "y6"; string_of_float y6]);
print_endline (String.concat "\t" [string_of_float t7; "x7"; string_of_float x7; "y7"; string_of_float y7]);
print_endline (String.concat "\t" [string_of_float t8; "x8"; string_of_float x8; "y8"; string_of_float y8]);
print_endline (String.concat "\t" [string_of_float t9; "x9"; string_of_float x9; "y9"; string_of_float y9])
let input _ = ()
let vdp_s = Solve.solve_sundials vdp_c
let node main_c() =
let o = run vdp_s (Some (Solve.make(stop_time, input)) fby None) in
Solve.period'_t 1.0 print o

16
exm/zelus/vdp/ztypes.ml Normal file
View file

@ -0,0 +1,16 @@
include Std
include Ztypes
include Solvers
module type IGNORE = sig end
module Defaultsolver : IGNORE = struct end
module Zlsrun = struct
module Make (S : IGNORE) = struct
let go _ = ()
end
end
module Stdlib = struct
type nonrec 'a option = 'a option
end