feat (solver/rk45): state copy is handled by simulation
This commit is contained in:
parent
5bce9e5b01
commit
8497091d0c
5 changed files with 43 additions and 60 deletions
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
open Hsim
|
||||
open Types
|
||||
open Examples
|
||||
open Common
|
||||
|
||||
|
|
@ -12,46 +13,31 @@ let steps = ref 1
|
|||
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 doc_sample = "n \tSample count (default=10)"
|
||||
let doc_stop = "n \tStop time (default=10.0)"
|
||||
let doc_debug = "\tPrint debug information"
|
||||
let doc_greedy = "\tUse greedy simulation"
|
||||
let doc_inplace = "\tUse greedy simulation"
|
||||
let doc_steps = "n \tSplit simulation into [n] steps (default=1)"
|
||||
|
||||
let opts = [
|
||||
"-sample", Arg.Int (gt0i sample), doc_sample;
|
||||
"-stop", Arg.Float (gt0f stop), doc_stop;
|
||||
"-debug", Arg.Set Debug.debug, doc_debug;
|
||||
"-greedy", Arg.Set greedy, doc_greedy;
|
||||
"-inplace", Arg.Set inplace, doc_inplace;
|
||||
"-steps", Arg.Int (gt0i steps), doc_steps;
|
||||
"-sample", Arg.Int (gt0i sample), "n \tSample count (default=10)";
|
||||
"-stop", Arg.Float (gt0f stop), "n \tStop time (default=10.0)";
|
||||
"-debug", Arg.Set Debug.debug, "\tPrint debug information";
|
||||
"-greedy", Arg.Set greedy, "\tUse greedy simulation";
|
||||
"-inplace", Arg.Set inplace, "\tUse greedy simulation";
|
||||
"-steps", Arg.Int (gt0i steps), "n \tSplit into [n] steps (default=1)";
|
||||
]
|
||||
|
||||
let errmsg = "Usage: " ^ Sys.executable_name ^ " [OPTIONS]\nOptions are:"
|
||||
|
||||
let () =
|
||||
try Arg.parse (Arg.align opts) (fun _ -> ()) errmsg
|
||||
with _ -> exit 2
|
||||
let () = try Arg.parse (Arg.align opts) (fun _ -> ()) 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 state = if !inplace then (module State.InPlaceSimState : State.SimState)
|
||||
else (module State.FunctionalSimState : State.SimState)
|
||||
let sim = if !greedy
|
||||
then let open Sim.GreedySim(val state) in run_until_n m s
|
||||
else let open Sim.LazySim(val state) in run_until_n m (d_of_dc s)
|
||||
|
||||
let () = sim !stop !steps output
|
||||
|
||||
let () =
|
||||
let csolver = StatefulRK45.Functional.csolve in
|
||||
let zsolver = StatefulZ.Functional.zsolve in
|
||||
let solver = Solver.solver_c csolver zsolver in
|
||||
let model = Ball.bouncing_ball () in
|
||||
if !inplace then
|
||||
let module S = State.InPlaceSimState in
|
||||
if !greedy then
|
||||
let open Sim.GreedySim(S) in
|
||||
run_until_multiple model solver !stop !steps (Output.print !sample)
|
||||
else
|
||||
let open Sim.LazySim(S) in
|
||||
run_until_multiple model (Solver.solver_from_c solver) !stop !steps (Output.print !sample)
|
||||
else
|
||||
let module S = State.FunctionalSimState in
|
||||
if !greedy then
|
||||
let open Sim.GreedySim(S) in
|
||||
run_until_multiple model solver !stop !steps (Output.print !sample)
|
||||
else
|
||||
let open Sim.LazySim(S) in
|
||||
run_until_multiple model (Solver.solver_from_c solver) !stop !steps (Output.print !sample)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue