feat: re-hide inner states, properly reset sundials
This commit is contained in:
parent
80d4aef23f
commit
76dc461d44
14 changed files with 162 additions and 253 deletions
|
|
@ -37,48 +37,35 @@ let errmsg = "Usage: " ^ Sys.executable_name ^ " [OPTIONS] MODEL\nOptions are:"
|
|||
let () = try Arg.parse (Arg.align opts) set_model errmsg with _ -> exit 2
|
||||
|
||||
let m =
|
||||
match !model with
|
||||
try match !model with
|
||||
| None -> Format.eprintf "Missing model\n"; exit 2
|
||||
| Some "ball" -> (module Ball : Model.Model)
|
||||
| Some "vdp" -> (module Vdp)
|
||||
| Some "sincos" -> (module Sincos)
|
||||
| Some "sqrt" -> (module Sqrt)
|
||||
| Some "ball" -> Ball.init !modelargs
|
||||
| Some "vdp" -> Vdp.init !modelargs
|
||||
| Some "sincos" -> Sincos.init !modelargs
|
||||
| Some "sqrt" -> Sqrt.init !modelargs
|
||||
| Some s -> Format.eprintf "Unknown model: %s\n" s; exit 2
|
||||
with Invalid_argument s -> Format.eprintf "%s\n" s; exit 2
|
||||
|
||||
let z = if !inplace then (module StatefulZ.InPlace : Zsolver.ZsolverC)
|
||||
else (module StatefulZ.Functional : Zsolver.ZsolverC)
|
||||
let z = StatefulZ.(if !inplace then InPlace.zsolve else Functional.zsolve)
|
||||
|
||||
let st = if !inplace then (module State.InPlaceSimState : State.SimState)
|
||||
else (module State.FunctionalSimState : State.SimState)
|
||||
|
||||
let () =
|
||||
let open (val m) in
|
||||
let m = init !modelargs in
|
||||
let sim =
|
||||
if !sundials then
|
||||
if !greedy then
|
||||
(Format.eprintf "Sundials does not support greedy simulation\n"; exit 2)
|
||||
else
|
||||
let open StatefulSundials in
|
||||
let c = if !inplace then (module InPlace : Csolver.Csolver)
|
||||
else (module Functional : Csolver.Csolver) in
|
||||
let open (val c) in let open (val z) in
|
||||
let s = Solver.solver csolve (d_of_dc zsolve) in
|
||||
let open Sim.LazySim(val st) in run_until_n m s
|
||||
let sim =
|
||||
if !sundials then
|
||||
if !greedy then
|
||||
(Format.eprintf "Sundials does not support greedy simulation\n"; exit 2)
|
||||
else
|
||||
let open StatefulRK45 in
|
||||
let c = if !inplace then (module InPlace : Csolver.CsolverC)
|
||||
else (module Functional : Csolver.CsolverC) in
|
||||
let open (val c) in let open (val z) in
|
||||
let s = Solver.solver_c csolve zsolve in
|
||||
if !greedy then let open Sim.GreedySim(val st) in run_until_n m s
|
||||
else let open Sim.LazySim(val st) in run_until_n m (d_of_dc s)
|
||||
in
|
||||
let open Solver in
|
||||
let HNode { init; csize; zsize; fder; fzer; cget; _ } = m in
|
||||
let state = init () in
|
||||
let init = cget state in
|
||||
let ivp = { size=csize; fder=(fun _ -> fder state ()); init; stop=1.0 } in
|
||||
let zc = { size=zsize; fzer=(fun _ -> fzer state ()); init } in
|
||||
sim !stop !steps ((), (ivp, zc)) (Output.print !sample)
|
||||
let open StatefulSundials in
|
||||
let c = if !inplace then InPlace.csolve else Functional.csolve in
|
||||
let s = Solver.solver c (d_of_dc z) in
|
||||
let open Sim.LazySim(val st) in run_until_n m s
|
||||
else
|
||||
let open StatefulRK45 in
|
||||
let c = if !inplace then InPlace.csolve else Functional.csolve in
|
||||
let s = Solver.solver_c c z in
|
||||
if !greedy then let open Sim.GreedySim(val st) in run_until_n m s
|
||||
else let open Sim.LazySim(val st) in run_until_n m (d_of_dc s)
|
||||
|
||||
let () = sim !stop !steps (Output.print !sample)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue