feat: runtime as library
This commit is contained in:
parent
8f6320b30e
commit
dc8d941b84
24 changed files with 184 additions and 111 deletions
45
exm/builtins/vdp.ml
Normal file
45
exm/builtins/vdp.ml
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
|
||||
open Hsim.Types
|
||||
open Solvers.Zls
|
||||
|
||||
let of_array a : carray =
|
||||
Bigarray.Array1.of_array Bigarray.Float64 Bigarray.c_layout a
|
||||
|
||||
type state = { lx : carray; i : bool }
|
||||
|
||||
let mu = 5.0
|
||||
let x0 = 1.0
|
||||
let y0 = 1.0
|
||||
|
||||
let csize = 2
|
||||
let zsize = 1
|
||||
|
||||
let fder y yd =
|
||||
yd.{0} <- y.{1};
|
||||
yd.{1} <- (mu *. (1.0 -. (y.{0} *. y.{0})) *. y.{1}) -. y.{0};
|
||||
yd
|
||||
let fout _ _ _ y = of_array [| y.{0}; y.{1} |]
|
||||
let step { i; lx } _ _ =
|
||||
let lx = if i then of_array [| x0; y0 |] else lx in
|
||||
of_array [| lx.{0}; lx.{1} |], { lx; i=false }
|
||||
let cget s = s.lx
|
||||
let cset s lx = { s with lx }
|
||||
let zset s _ = s
|
||||
let jump _ = true
|
||||
let horizon _ = max_float
|
||||
|
||||
let van_der_pol () : (_, _, carray, carray, carray, zarray, carray) hnode =
|
||||
let yd = cmake csize in
|
||||
let zout = cmake zsize in
|
||||
let fder _ _ _ y = fder y yd in
|
||||
let fzer _ _ _ _ = zout in
|
||||
let state = { lx=of_array [| x0; y0 |]; i=true } in
|
||||
let reset _ _ = state in
|
||||
HNode { state; fder; fzer; fout; step; reset; horizon;
|
||||
jump; cset; cget; zset; csize; zsize }
|
||||
|
||||
let errmsg = "Too many arguments for the model (needed: 0)"
|
||||
let init = function
|
||||
| [] -> van_der_pol ()
|
||||
| _ -> raise (Invalid_argument errmsg)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue