chore: improve main

This commit is contained in:
Henri Saudubray 2025-04-29 16:24:13 +02:00
parent ebcceefe4c
commit 3b5e01b163
Signed by: hms
GPG key ID: 7065F57ED8856128

View file

@ -9,16 +9,16 @@ let stop = ref 30.0
let greedy = ref false let greedy = ref false
let inplace = ref false let inplace = ref false
let steps = ref 1 let steps = ref 1
let model = ref "" let model = ref None
let gt0i v i = v := if i <= 0 then 1 else i 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 gt0f v f = v := if f <= 0.0 then 1.0 else f
let hasmodel = ref false
let modelargs = ref [] let modelargs = ref []
let set_model s = let set_model s =
if !hasmodel then modelargs := s :: !modelargs match !model with
else model := s; hasmodel := true | None -> model := Some s
| Some _ -> modelargs := s :: !modelargs
let opts = [ let opts = [
"-sample", Arg.Int (gt0i sample), "n \tSample count (default=10)"; "-sample", Arg.Int (gt0i sample), "n \tSample count (default=10)";
@ -40,11 +40,12 @@ let z = StatefulZ.(Functional.zsolve)
let s = Solver.solver_c c z let s = Solver.solver_c c z
open Format open Format
let m = match !model with let m = match !model with
| "ball" -> Ball.bouncing_ball | None -> eprintf "Missing model\n"; exit 2
| "vdp" -> Vdp.van_der_pol | Some "ball" -> Ball.bouncing_ball
| "sincos" -> Sincos.sinus_cosinus | Some "vdp" -> Vdp.van_der_pol
| "sqrt" -> Sqrt.sqrt | Some "sincos" -> Sincos.sinus_cosinus
| _ -> eprintf "Unknown model: %s\n" !model; exit 2 | Some "sqrt" -> Sqrt.sqrt
| Some s -> eprintf "Unknown model: %s\n" s; exit 2
let m = try m !modelargs with Invalid_argument s -> eprintf "%s\n" s; exit 2 let m = try m !modelargs with Invalid_argument s -> eprintf "%s\n" s; exit 2
let state = if !inplace then (module State.InPlaceSimState : State.SimState) let state = if !inplace then (module State.InPlaceSimState : State.SimState)