@@ -6,6 +6,8 @@ export dasslIterator, dasslSolve
66
77using Reexport
88@reexport using DiffEqBase
9+ using LinearAlgebra
10+
911import DiffEqBase: solve
1012
1113export dassl
@@ -20,7 +22,8 @@ mutable struct JacData
2022 jac # Jacobian matrix for the newton solver
2123end
2224
23- function dasslStep (F,
25+ function dasslStep (channel,
26+ F,
2427 y0:: AbstractVector{T} ,
2528 tstart:: Real ;
2629 reltol = 1e-3 ,
@@ -45,9 +48,9 @@ function dasslStep(F,
4548 ord = 1 # initial method order
4649 tout = [tstart] # initial time
4750 h = initstep # current step size
48- yout = Array ( typeof (y0),1 )
51+ yout = Array { typeof(y0)} (undef ,1 )
4952 yout[1 ] = y0
50- dyout = Array ( typeof (y0),1 )
53+ dyout = Array { typeof(y0)} (undef ,1 )
5154 dyout[1 ] = dy0 # initial guess for dy0
5255 num_rejected = 0 # number of rejected steps
5356 num_fail = 0 # number of consecutive failures
@@ -128,12 +131,12 @@ function dasslStep(F,
128131
129132 # remove old results
130133 if length (tout) > ord+ 3
131- shift ! (tout)
132- shift ! (yout)
133- shift ! (dyout)
134+ popfirst ! (tout)
135+ popfirst ! (yout)
136+ popfirst ! (dyout)
134137 end
135138
136- produce ( tout[end ],yout[end ],dyout[end ])
139+ push! (channel,( tout[end ],yout[end ],dyout[end ]) )
137140
138141 # determine the new step size and order, including the current step
139142 (r,ord) = newStepOrder (tout,yout,normy,err,ord,num_fail,maxorder)
@@ -147,14 +150,13 @@ end
147150
148151
149152# the iterator version of the dasslSolve
150- dasslIterator (F, y0, t0; args... ) = Task (()-> dasslStep (F, y0, t0; args... ))
151-
153+ dasslIterator (F, y0, t0; args... ) = Channel ((channel)-> dasslStep (channel,F, y0, t0; args... ))
152154
153155# solves the equation F with initial data y0 over for times t in tspan=[t0,t1]
154156function dasslSolve (F, y0:: AbstractVector , tspan; dy0 = zero (y0), args... )
155- tout = Array ( typeof (tspan[1 ]),1 )
156- yout = Array ( typeof (y0),1 )
157- dyout = Array ( typeof (y0),1 )
157+ tout = Array { typeof(tspan[1])} (undef ,1 )
158+ yout = Array { typeof(y0)} (undef ,1 )
159+ dyout = Array { typeof(y0)} (undef ,1 )
158160 tout[1 ] = tspan[1 ]
159161 yout[1 ] = y0
160162 dyout[1 ] = dy0
@@ -451,7 +453,7 @@ function stepper(ord::Integer,
451453 f_newton, # we want to find zeroes of this function
452454 normy) # the norm used to estimate error needs weights
453455
454- alpha = Array ( eltype (t),ord+ 1 )
456+ alpha = Array { eltype(t)} (undef ,ord+ 1 )
455457
456458 for i = 1 : ord
457459 alpha[i] = h_next/ (t_next- t[end - i+ 1 ])
@@ -470,7 +472,7 @@ function stepper(ord::Integer,
470472 alpha[ord+ 1 ] = h_next/ (t_next- t0)
471473
472474 alpha0 = - sum (alpha[1 : ord])
473- M = max (alpha[ord+ 1 ],abs (alpha[ord+ 1 ]+ alphas- alpha0))
475+ M = max (alpha[ord+ 1 ],abs . (alpha[ord+ 1 ]+ alphas- alpha0))
474476 err:: eltype (t) = normy ((yc- y0))* M
475477
476478
@@ -540,7 +542,7 @@ function newton_iteration(f,
540542 # after the first iteration the normy turned out to be very small,
541543 # terminate and return the first correction step
542544
543- ep = eps (eltype (abs (y0))) # this is the epsilon for type y0
545+ ep = eps (eltype (abs . (y0))) # this is the epsilon for type y0
544546
545547 if norm1 < 100 * ep* normy (y0)
546548 status= 0
@@ -586,7 +588,7 @@ function dassl_norm(v, wt)
586588end
587589
588590function dassl_weights (y,reltol,abstol)
589- reltol* abs (y). + abstol
591+ @. reltol* abs (y)+ abstol
590592end
591593
592594# returns the value of the interpolation polynomial at the point x0
@@ -689,13 +691,13 @@ function numerical_jacobian(F,reltol,abstol,weights)
689691 # delta for approximation of jacobian. I removed the
690692 # sign(h_next*dy0) from the definition of delta because it was
691693 # causing trouble when dy0==0 (which happens for ord==1)
692- edelta = diagm (max (abs (y),abs (h* dy),wt)* sqrt (ep))
694+ edelta = diagm (0 => max . (abs . (y),abs . (h* dy),wt)* sqrt (ep))
693695
694696 b= dy- a* y
695697 f (y1) = F (t,y1,a* y1+ b)
696698
697699 n = length (y)
698- jac = Array ( eltype (y),n,n)
700+ jac = Array { eltype(y)} (undef ,n,n)
699701 for i= 1 : n
700702 jac[:,i]= (f (y+ edelta[:,i])- f (y))/ edelta[i,i]
701703 end
0 commit comments