feat: runtime as library
This commit is contained in:
parent
8f6320b30e
commit
dc8d941b84
24 changed files with 184 additions and 111 deletions
|
|
@ -2,7 +2,7 @@ let g = 9.81
|
|||
let y0 = 0.0
|
||||
let y'0 = 10.0
|
||||
|
||||
let hybrid ball (y0, y'0) = (y, y', z) where
|
||||
let hybrid ball () = (y, y', z) where
|
||||
rec der y = y' init y0
|
||||
and der y' = -. g init y'0 reset z -> -0.8 *. (last y')
|
||||
and z = up(-. y)
|
||||
|
|
@ -10,7 +10,7 @@ let hybrid ball (y0, y'0) = (y, y', z) where
|
|||
let hybrid main () =
|
||||
let der t = 1.0 init 0.0 in
|
||||
let s = period(0.01) in
|
||||
let (y, y', z) = ball (y0, y'0) in
|
||||
let (y, y', z) = ball () in
|
||||
present z | s -> (
|
||||
print_float t;
|
||||
print_string "\t";
|
||||
|
|
|
|||
|
|
@ -1,6 +1,16 @@
|
|||
(env
|
||||
(dev
|
||||
(flags
|
||||
(:standard -w -a))))
|
||||
|
||||
(rule
|
||||
(targets ballz.ml ballz.zci ballz_main.ml)
|
||||
(targets ballz.ml ballz.zci)
|
||||
(deps
|
||||
(:zl ballz.zls))
|
||||
(action
|
||||
(run zeluc -s main -o ballz_main %{zl})))
|
||||
(run zeluc %{zl})))
|
||||
|
||||
(executable
|
||||
(public_name ball.exe)
|
||||
(name main)
|
||||
(libraries std))
|
||||
|
|
|
|||
6
exm/zelus/ballz/main.ml
Normal file
6
exm/zelus/ballz/main.ml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
open Std
|
||||
|
||||
let input _ = ()
|
||||
let output (now, (y, _, _)) = Format.printf "%.10e\t%.10e\n" now y
|
||||
let () = Runtime.go input Ballz.ball output
|
||||
21
exm/zelus/ballz/ztypes.ml
Normal file
21
exm/zelus/ballz/ztypes.ml
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
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 s =
|
||||
let s = Lift.lift_hsim s in
|
||||
let open Hsim in
|
||||
let state = (module State.InPlaceSimState : State.SimState) in
|
||||
let solver =
|
||||
Solver.solver (StatefulSundials.InPlace.csolve)
|
||||
(Types.d_of_dc StatefulZ.InPlace.zsolve) in
|
||||
let open Sim.Sim(val state) in
|
||||
()
|
||||
(* run_until_n (Utils.ignore 0 (run s solver)) 30. 1 ignore *)
|
||||
end
|
||||
end
|
||||
|
|
@ -1,6 +1,16 @@
|
|||
(env
|
||||
(dev
|
||||
(flags
|
||||
(:standard -w -a))))
|
||||
|
||||
(rule
|
||||
(targets sincosz_main.ml sincosz.ml sincosz.zci)
|
||||
(targets sincosz.ml sincosz.zci)
|
||||
(deps
|
||||
(:zl sincosz.zls))
|
||||
(action
|
||||
(run zeluc -s f -o sincosz_main %{zl})))
|
||||
(run zeluc %{zl})))
|
||||
|
||||
(executable
|
||||
(public_name sincos.exe)
|
||||
(name main)
|
||||
(libraries std))
|
||||
|
|
|
|||
6
exm/zelus/sincos/main.ml
Normal file
6
exm/zelus/sincos/main.ml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
open Std
|
||||
|
||||
let input _ = ()
|
||||
let output (now, (sin, cos)) = Format.printf "%.10e\t%.10e\t%.10e\n" now sin cos
|
||||
let () = Runtime.go input Sincosz.g output
|
||||
21
exm/zelus/sincos/ztypes.ml
Normal file
21
exm/zelus/sincos/ztypes.ml
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
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 s =
|
||||
let s = Lift.lift_hsim s in
|
||||
let open Hsim in
|
||||
let state = (module State.InPlaceSimState : State.SimState) in
|
||||
let solver =
|
||||
Solver.solver (StatefulSundials.InPlace.csolve)
|
||||
(Types.d_of_dc StatefulZ.InPlace.zsolve) in
|
||||
let open Sim.Sim(val state) in
|
||||
()
|
||||
(* run_until_n (Utils.ignore 0 (run s solver)) 30. 1 ignore *)
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue