Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file common.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130(*
* OWL - OCaml Scientific and Engineering Computing
* OWL-ODE - Ordinary Differential Equation Solvers
*
* Copyright (c) 2019 Ta-Chu Kao <tck29@cam.ac.uk>
* Copyright (c) 2019 Marcello Seri <m.seri@rug.nl>
*)(* TODO: update implementations of multiple order RK on the line of
* symplectic.ml *)(* TODO: find a better place to place this module *)moduleMake(M:Owl_types_ndarray_algodiff.Sigwithtypeelt=float)=structletstepst0t1dt=(t1-.t0)/.dt|>floor|>int_of_float|>succtypestate_type=|Rowofint|Colofint|Arrofintarrayletget_state_ty0=letdims=M.shapey0inletdim1,dim2=dims.(0),dims.(1)inifdim1=1thenRowdim2elseifdim2=1thenColdim1elseArrdimsletintegrate~step~tspan:(t0,t1)~dty0=letn_steps=stepst0t1dtinletstate_t=get_state_ty0inletys=matchstate_twith|Rown->M.empty[|n_steps;n|]|Coln->M.empty[|n;n_steps|]|Arrs->M.empty(Array.append[|n_steps|]s)inletts=ref[]inlett=reft0inlety=refy0infori=0topredn_stepsdoifi>0then(lety',t'=step!y!tiny:=y';t:=t');ts:=!t::!ts;matchstate_twith|Row_->M.set_slice[[i];[]]ys!y|Col_->M.set_slice[[];[i]]ys!y|Arr_->M.set_slice[[i];[]]ys!ydone;letts=[|!ts|>List.rev|>Array.of_list|]|>M.of_arraysinmatchstate_twith|Row_|Arr_->M.(transposets),ys|Col_->ts,ysletsymplectic_integrate~step~tspan:(t0,t1)~dt(x0,p0)=ifM.shapex0<>M.shapep0thenraiseOwl_exception.(DIFFERENT_SHAPE(M.shapex0,M.shapep0));letstate_t=get_state_tx0inletn_steps=stepst0t1dtinletxs,ps=matchstate_twith|Rown->M.empty[|n_steps;n|],M.empty[|n_steps;n|]|Coln->M.empty[|n;n_steps|],M.empty[|n;n_steps|]|Arrs->M.emptyArray.(append[|n_steps|]s),M.emptyArray.(append[|n_steps|]s)inletts=ref[]inlett=reft0inletx=refx0inletp=refp0infori=0topredn_stepsdoifi>0then(let(x',p'),t'=step(!x,!p)!tinx:=x';p:=p';t:=t');ts:=!t::!ts;matchstate_twith|Row_->M.set_slice[[i];[]]xs!x;M.set_slice[[i];[]]ps!p|Col_->M.set_slice[[];[i]]xs!x;M.set_slice[[];[i]]ps!p|Arr_->M.set_slice[[i];[]]xs!x;M.set_slice[[i];[]]ps!pdone;letts=[|!ts|>List.rev|>Array.of_list|]|>M.of_arraysinmatchstate_twith|Row_|Arr_->M.transposets,xs,ps|Col_->ts,xs,psletadaptive_integrate~step~tspan:(t0,t1)~dtmaxy0=letstate_t=get_state_ty0inletdt=dtmax/.4.0inletrecgo(ts,ys)(t0:float)y0dt=ift0>=t1thents,yselse(letdt=mindt(t1-.t0)inift0+.dt<=t0thenfailwith"Singular ODE";lety,t,dt,err_ok=step~dty0t0iniferr_okthen(* Update solution if error is OK *)go(t::ts,y::ys)tydtelsego(ts,ys)t0y0dt)inletts,ys=go([t0],[y0])t0y0dtinletts=[|ts|>List.rev|>Array.of_list|]|>M.of_arraysinletys=matchstate_twith|Row_->ys|>List.rev|>Array.of_list|>M.of_rows|Col_->ys|>List.rev|>Array.of_list|>M.of_cols|Arrs->ys|>List.rev|>Array.of_list|>Array.map(funy->M.expandy(succArray.(lengths)))|>M.concatenate~axis:0inmatchstate_twith|Row_|Arr_->M.transposets,ys|Col_->ts,ysend