feat (exm): van der pol example

This commit is contained in:
Henri Saudubray 2025-04-29 10:42:49 +02:00
parent 8497091d0c
commit 9a0d22e880
Signed by: hms
GPG key ID: 7065F57ED8856128
3 changed files with 79 additions and 11 deletions

View file

@ -9,9 +9,15 @@ let stop = ref 30.0
let greedy = ref false
let inplace = ref false
let steps = ref 1
let model = ref ""
let gt0i v i = v := if i <= 0 then 1 else i
let gt0f v f = v := if f <= 0.0 then 1.0 else f
let hasmodel = ref false
let set_model s =
if !hasmodel then raise (Arg.Bad "Too many arguments.") else
model := s; hasmodel := true
let opts = [
"-sample", Arg.Int (gt0i sample), "n \tSample count (default=10)";
@ -22,16 +28,19 @@ let opts = [
"-steps", Arg.Int (gt0i steps), "n \tSplit into [n] steps (default=1)";
]
let errmsg = "Usage: " ^ Sys.executable_name ^ " [OPTIONS]\nOptions are:"
let errmsg = "Usage: " ^ Sys.executable_name ^ " [OPTIONS] MODEL\nOptions are:"
let () = try Arg.parse (Arg.align opts) (fun _ -> ()) errmsg with _ -> exit 2
let () = try Arg.parse (Arg.align opts) set_model errmsg with _ -> exit 2
let output = Output.print !sample
let c = StatefulRK45.(if !inplace then InPlace.csolve else Functional.csolve)
let z = StatefulZ.(Functional.zsolve)
let s = Solver.solver_c c z
let m = Ball.bouncing_ball ()
let m = match !model with
| "ball" -> Ball.bouncing_ball ()
| "vdp" -> Vdp.van_der_pol ()
| _ -> raise (Arg.Bad (Format.sprintf "Unknown model: %s." !model))
let state = if !inplace then (module State.InPlaceSimState : State.SimState)
else (module State.FunctionalSimState : State.SimState)