L idZddgZddlZddlZddlZddlmZmZmZm Z m Z m Z m Z ddl mZddl mZdd l mZej"j$j&Zej"j$j&Zej"j$j&Zej.Zej.ZGd dZd ZGd deZd ZGddeZGddZ dZ!Gdde Z"e"jFe jHjKe"Gdde"Z&e&jFe jHjKe&Gdde Z'e'jFe jHjKe'Gdde'Z(e(jFe jHjKe(Gdde Z)e)jFre jHjKe)yy)a5 First-order ODE integrators. User-friendly interface to various numerical integrators for solving a system of first order ODEs with prescribed initial conditions:: d y(t)[i] --------- = f(t,y(t))[i], d t y(t=0)[i] = y0[i], where:: i = 0, ..., len(y0) - 1 class ode --------- A generic interface class to numeric integrators. It has the following methods:: integrator = ode(f, jac=None) integrator = integrator.set_integrator(name, **params) integrator = integrator.set_initial_value(y0, t0=0.0) integrator = integrator.set_f_params(*args) integrator = integrator.set_jac_params(*args) y1 = integrator.integrate(t1, step=False, relax=False) flag = integrator.successful() class complex_ode ----------------- This class has the same generic interface as ode, except it can handle complex f, y and Jacobians by transparently translating them into the equivalent real-valued system. It supports the real-valued solvers (i.e., not zvode) and is an alternative to ode with the zvode solver, sometimes performing better. ode complex_odeN)asarrayarrayzerosisscalarrealimagvstack)_vode)_dop)_lsodac\eZdZdZd dZedZddZdZddZ dZ d Z d Z d Z d Zy)ra$ A generic interface class to numeric integrators. Solve an equation system :math:`y'(t) = f(t,y)` with (optional) ``jac = df/dy``. *Note*: The first two arguments of ``f(t, y, ...)`` are in the opposite order of the arguments in the system definition function used by `scipy.integrate.odeint`. Parameters ---------- f : callable ``f(t, y, *f_args)`` Right-hand side of the differential equation. t is a scalar, ``y.shape == (n,)``. ``f_args`` is set by calling ``set_f_params(*args)``. `f` should return a scalar, array or list (not a tuple). jac : callable ``jac(t, y, *jac_args)``, optional Jacobian of the right-hand side, ``jac[i,j] = d f[i] / d y[j]``. ``jac_args`` is set by calling ``set_jac_params(*args)``. Attributes ---------- t : float Current time. y : ndarray Current variable values. See also -------- odeint : an integrator with a simpler interface based on lsoda from ODEPACK quad : for finding the area under a curve Notes ----- Available integrators are listed below. They can be selected using the `set_integrator` method. "vode" Real-valued Variable-coefficient Ordinary Differential Equation solver, with fixed-leading-coefficient implementation. It provides implicit Adams method (for non-stiff problems) and a method based on backward differentiation formulas (BDF) (for stiff problems). Source: http://www.netlib.org/ode/vode.f .. warning:: This integrator is not re-entrant. You cannot have two `ode` instances using the "vode" integrator at the same time. This integrator accepts the following parameters in `set_integrator` method of the `ode` class: - atol : float or sequence absolute tolerance for solution - rtol : float or sequence relative tolerance for solution - lband : None or int - uband : None or int Jacobian band width, jac[i,j] != 0 for i-lband <= j <= i+uband. Setting these requires your jac routine to return the jacobian in packed format, jac_packed[i-j+uband, j] = jac[i,j]. The dimension of the matrix must be (lband+uband+1, len(y)). - method: 'adams' or 'bdf' Which solver to use, Adams (non-stiff) or BDF (stiff) - with_jacobian : bool This option is only considered when the user has not supplied a Jacobian function and has not indicated (by setting either band) that the Jacobian is banded. In this case, `with_jacobian` specifies whether the iteration method of the ODE solver's correction step is chord iteration with an internally generated full Jacobian or functional iteration with no Jacobian. - nsteps : int Maximum number of (internally defined) steps allowed during one call to the solver. - first_step : float - min_step : float - max_step : float Limits for the step sizes used by the integrator. - order : int Maximum order used by the integrator, order <= 12 for Adams, <= 5 for BDF. "zvode" Complex-valued Variable-coefficient Ordinary Differential Equation solver, with fixed-leading-coefficient implementation. It provides implicit Adams method (for non-stiff problems) and a method based on backward differentiation formulas (BDF) (for stiff problems). Source: http://www.netlib.org/ode/zvode.f .. warning:: This integrator is not re-entrant. You cannot have two `ode` instances using the "zvode" integrator at the same time. This integrator accepts the same parameters in `set_integrator` as the "vode" solver. .. note:: When using ZVODE for a stiff system, it should only be used for the case in which the function f is analytic, that is, when each f(i) is an analytic function of each y(j). Analyticity means that the partial derivative df(i)/dy(j) is a unique complex number, and this fact is critical in the way ZVODE solves the dense or banded linear systems that arise in the stiff case. For a complex stiff ODE system in which f is not analytic, ZVODE is likely to have convergence failures, and for this problem one should instead use DVODE on the equivalent real system (in the real and imaginary parts of y). "lsoda" Real-valued Variable-coefficient Ordinary Differential Equation solver, with fixed-leading-coefficient implementation. It provides automatic method switching between implicit Adams method (for non-stiff problems) and a method based on backward differentiation formulas (BDF) (for stiff problems). Source: http://www.netlib.org/odepack .. warning:: This integrator is not re-entrant. You cannot have two `ode` instances using the "lsoda" integrator at the same time. This integrator accepts the following parameters in `set_integrator` method of the `ode` class: - atol : float or sequence absolute tolerance for solution - rtol : float or sequence relative tolerance for solution - lband : None or int - uband : None or int Jacobian band width, jac[i,j] != 0 for i-lband <= j <= i+uband. Setting these requires your jac routine to return the jacobian in packed format, jac_packed[i-j+uband, j] = jac[i,j]. - with_jacobian : bool *Not used.* - nsteps : int Maximum number of (internally defined) steps allowed during one call to the solver. - first_step : float - min_step : float - max_step : float Limits for the step sizes used by the integrator. - max_order_ns : int Maximum order used in the nonstiff case (default 12). - max_order_s : int Maximum order used in the stiff case (default 5). - max_hnil : int Maximum number of messages reporting too small step size (t + h = t) (default 0) - ixpr : int Whether to generate extra printing at method switches (default False). "dopri5" This is an explicit runge-kutta method of order (4)5 due to Dormand & Prince (with stepsize control and dense output). Authors: E. Hairer and G. Wanner Universite de Geneve, Dept. de Mathematiques CH-1211 Geneve 24, Switzerland e-mail: ernst.hairer@math.unige.ch, gerhard.wanner@math.unige.ch This code is described in [HNW93]_. This integrator accepts the following parameters in set_integrator() method of the ode class: - atol : float or sequence absolute tolerance for solution - rtol : float or sequence relative tolerance for solution - nsteps : int Maximum number of (internally defined) steps allowed during one call to the solver. - first_step : float - max_step : float - safety : float Safety factor on new step selection (default 0.9) - ifactor : float - dfactor : float Maximum factor to increase/decrease step size by in one step - beta : float Beta parameter for stabilised step size control. - verbosity : int Switch for printing messages (< 0 for no messages). "dop853" This is an explicit runge-kutta method of order 8(5,3) due to Dormand & Prince (with stepsize control and dense output). Options and references the same as "dopri5". Examples -------- A problem to integrate and the corresponding jacobian: >>> from scipy.integrate import ode >>> >>> y0, t0 = [1.0j, 2.0], 0 >>> >>> def f(t, y, arg1): ... return [1j*arg1*y[0] + y[1], -arg1*y[1]**2] >>> def jac(t, y, arg1): ... return [[1j*arg1, 1], [0, -arg1*2*y[1]]] The integration: >>> r = ode(f, jac).set_integrator('zvode', method='bdf') >>> r.set_initial_value(y0, t0).set_f_params(2.0).set_jac_params(2.0) >>> t1 = 10 >>> dt = 1 >>> while r.successful() and r.t < t1: ... print(r.t+dt, r.integrate(r.t+dt)) 1 [-0.71038232+0.23749653j 0.40000271+0.j ] 2.0 [0.19098503-0.52359246j 0.22222356+0.j ] 3.0 [0.47153208+0.52701229j 0.15384681+0.j ] 4.0 [-0.61905937+0.30726255j 0.11764744+0.j ] 5.0 [0.02340997-0.61418799j 0.09523835+0.j ] 6.0 [0.58643071+0.339819j 0.08000018+0.j ] 7.0 [-0.52070105+0.44525141j 0.06896565+0.j ] 8.0 [-0.15986733-0.61234476j 0.06060616+0.j ] 9.0 [0.64850462+0.15048982j 0.05405414+0.j ] 10.0 [-0.38404699+0.56382299j 0.04878055+0.j ] References ---------- .. [HNW93] E. Hairer, S.P. Norsett and G. Wanner, Solving Ordinary Differential Equations i. Nonstiff Problems. 2nd edition. Springer Series in Computational Mathematics, Springer-Verlag (1993) NcXd|_||_||_d|_d|_g|_y)Nr)stifffjacf_params jac_params_yselfrrs Z/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/scipy/integrate/_ode.py__init__z ode.__init__cs,  c|jSNrrs ryzode.yks wwrc@t|r|g}t|j}|s|jdt ||j j |_||_|j jt|j|jdu|S) Set initial conditions y(t) = y.N) rlenrset_integratorr _integratorscalartresetr)rr"r*n_prevs rset_initial_valuezode.set_initial_valueos{ A;ATWW    #!T--445 s477|TXXT-AB rc rt|}|d|d}tj|d|S|di||_t |j s-d|_tdg|jj|_|jjt |j |jdu|S)z Set integrator by name. Parameters ---------- name : str Name of the integrator. **integrator_params Additional parameters for the integrator. NzNo integrator name match with z or is not available. stacklevelr) find_integratorwarningswarnr(r&rr*rr)r+r)rnameintegrator_params integratormessages rr'zode.set_integrator{s%T*  7th>STG MM'a 0 *>,=>D tww<t'7'7'>'>?    " "3tww<1E F rc |r-|jjr|jj}nE|r-|jjr|jj}n|jj } ||j |jxsd|j|j||j|j\|_|_ |jS#t$r}td|d}~wwxYw)Find y=y(t), set y as an initial condition, and return y. Parameters ---------- t : float The endpoint of the integration step. step : bool If True, and if the integrator supports the step method, then perform a single integration step and return. This parameter is provided in order to expose internals of the implementation, and should not be changed from its default value in most cases. relax : bool If True and if the integrator supports the run_relax method, then integrate until t_1 >= t and return. ``relax`` is not referenced if ``step=True``. This parameter is provided in order to expose internals of the implementation, and should not be changed from its default value in most cases. Returns ------- y : float The integrated value at t cyrrrrrzode.integrate..rz.Function to integrate must not return a tuple.N)r( supports_stepstepsupports_run_relax run_relaxrunrrrr*rr SystemError ValueError)rr*r@relaxmthes r integratez ode.integrates4 D$$22""''C t''::"",,C""&&C !$&&$((*D|"&''4661"&--BODGTVww  @  s6AC C8' C33C8c |j|jjdk(S#t$r|jdY5wxYw)z$Check if integration was successful.r%r )r(AttributeErrorr'successr!s r successfulzode.successfulsH $   ''1,, $    # $s 'AAc |j|jjS#t$r)|jdY|jjSwxYw)a Extracts the return code for the integration to enable better control if the integration fails. In general, a return code > 0 implies success, while a return code < 0 implies failure. Notes ----- This section describes possible return codes and their meaning, for available integrators that can be selected by `set_integrator` method. "vode" =========== ======= Return Code Message =========== ======= 2 Integration successful. -1 Excess work done on this call. (Perhaps wrong MF.) -2 Excess accuracy requested. (Tolerances too small.) -3 Illegal input detected. (See printed message.) -4 Repeated error test failures. (Check all input.) -5 Repeated convergence failures. (Perhaps bad Jacobian supplied or wrong choice of MF or tolerances.) -6 Error weight became zero during problem. (Solution component i vanished, and ATOL or ATOL(i) = 0.) =========== ======= "zvode" =========== ======= Return Code Message =========== ======= 2 Integration successful. -1 Excess work done on this call. (Perhaps wrong MF.) -2 Excess accuracy requested. (Tolerances too small.) -3 Illegal input detected. (See printed message.) -4 Repeated error test failures. (Check all input.) -5 Repeated convergence failures. (Perhaps bad Jacobian supplied or wrong choice of MF or tolerances.) -6 Error weight became zero during problem. (Solution component i vanished, and ATOL or ATOL(i) = 0.) =========== ======= "dopri5" =========== ======= Return Code Message =========== ======= 1 Integration successful. 2 Integration successful (interrupted by solout). -1 Input is not consistent. -2 Larger nsteps is needed. -3 Step size becomes too small. -4 Problem is probably stiff (interrupted). =========== ======= "dop853" =========== ======= Return Code Message =========== ======= 1 Integration successful. 2 Integration successful (interrupted by solout). -1 Input is not consistent. -2 Larger nsteps is needed. -3 Step size becomes too small. -4 Problem is probably stiff (interrupted). =========== ======= "lsoda" =========== ======= Return Code Message =========== ======= 2 Integration successful. -1 Excess work done on this call (perhaps wrong Dfun type). -2 Excess accuracy requested (tolerances too small). -3 Illegal input detected (internal error). -4 Repeated error test failures (internal error). -5 Repeated convergence failures (perhaps bad Jacobian or tolerances). -6 Error weight became zero during problem. -7 Internal workspace insufficient to finish (internal error). =========== ======= r%)r(rKr'istater!s rget_return_codezode.get_return_codesVj $   &&& $    #&&& $s $AAc||_|S)z2Set extra parameters for user-supplied function f.)rrargss r set_f_paramszode.set_f_params$s  rc||_|S)z4Set extra parameters for user-supplied function jac.)rrRs rset_jac_paramszode.set_jac_params)s rc |jjrd|jj||j<|jj t |j|j duyytd) Set callable to be called at every successful integration step. Parameters ---------- solout : callable ``solout(t, y)`` is called at each internal integrator step, t is a scalar providing the current independent position y is the current solution ``y.shape == (n,)`` solout should return -1 to stop integration otherwise it should return None or 0 Nz?selected integrator does not support solout, choose another one)r(supports_solout set_soloutrr+r&rrErsolouts rrZzode.set_solout.sq    + +    ' ' /ww"  &&s477|TXXT5IJ#34 4rrr2FF)__name__ __module__ __qualname____doc__rpropertyr"r-r'rIrMrPrTrVrZrrrrrnsMrh 2+Z-Y'v  4rct|jddz|jdf}|dddddf|dddddf<|dddddf|dddddf<|S)a Convert a real matrix of the form (for example) [0 0 A B] [0 0 0 B] [0 0 C D] [0 0 A D] [E F G H] to [0 F C H] [I J K L] [E J G L] [I 0 K 0] That is, every other column is shifted up one. rr Nr/)rshape)bjacnewjacs r_transform_banded_jacriEsrDJJqMA%tzz!}5 6F1cc6lF12ss7OQ1W F3B319 MrcPeZdZdZd dZdZdZedZdZ d dZ d d Z d Z y)ra A wrapper of ode for complex systems. This functions similarly as `ode`, but re-maps a complex-valued equation system to a real-valued one before using the integrators. Parameters ---------- f : callable ``f(t, y, *f_args)`` Rhs of the equation. t is a scalar, ``y.shape == (n,)``. ``f_args`` is set by calling ``set_f_params(*args)``. jac : callable ``jac(t, y, *jac_args)`` Jacobian of the rhs, ``jac[i,j] = d f[i] / d y[j]``. ``jac_args`` is set by calling ``set_f_params(*args)``. Attributes ---------- t : float Current time. y : ndarray Current variable values. Examples -------- For usage examples, see `ode`. Nc||_||_|"tj||jdytj||j|j yr)cfcjacrr_wrap _wrap_jacrs rrzcomplex_ode.__init__usA ; LLtzz4 0 LLtzz4>> :rc |j||dddd|dddzzf|z}t||jddd<t||jddd<|jSNr/?r )rlr tmpr )rr*r"f_argsrs rrnzcomplex_ode._wrap}sn DGGq!CaC&2!$Q$</069 ;Q1 aAxxrc |j||dddd|dddzzf|z}td|jdzd|jdzf}t|x|ddddddf<|ddddddf<t ||ddddddf<|ddddddf |ddddddf<t |j dd}t |j dd}|| t|}|S)Nr/rrr rmlmu)rmrrfr r getattrr(ri)rr*r"jac_argsrjac_tmprvrws rrozcomplex_ode._wrap_jacs"dii1a!frAaddG|34x?A SYYq\)1syy|+;<=26s);1add gcc3Q3h/!#Y1cc %addCaCi00!QTT  T%%tT 2 T%%tT 2 >R^,G4GrcR|jdddd|jdddzzSrqr r!s rr"z complex_ode.ys,wwss|b47714a4=000rc |dk(r td|jd}|jd}||d|xsdzdz|d<d|xsdzdz|d<tj||fi|S)z Set integrator by name. Parameters ---------- name : str Name of the integrator **integrator_params Additional parameters for the integrator. zvodez,zvode must be used with ode, not complex_odelbandubandr/rr )rEgetrr')rr6r7r~rs rr'zcomplex_ode.set_integrators 7?KL L!%%g.!%%g.   1 *+ejq)9A)= g &)*ejq)9A)= g &!!$B0ABBrct|}t|jdzd|_t ||jddd<t ||jddd<t j||j|S)r$r/floatNr )rrsizersr r rr-)rr"r*s rr-zcomplex_ode.set_initial_valuesf AJ!W-Q1 aA$$T488Q77rcZtj||||}|dddd|dddzzS)r;Nr/rrr )rrI)rr*r@rFr"s rrIzcomplex_ode.integrates94 MM$4 /1vQqt!tW $$rc|jjr|jj|dytd)rXT)complexz@selected integrator does not support solouta, choose another oneN)r(rYrZ TypeErrorr[s rrZzcomplex_ode.set_solouts>    + +    ' ' ' =12 2rrr]r^) r_r`rarbrrnrorcr"r'r-rIrZrrrrrXs?8;.11C48%:2rctjD]5}tj||jtj s3|cSyr)IntegratorBaseintegrator_classesrematchr_I)r6cls rr3r3s9// 88D"++rtt ,I rceZdZdZdZy)IntegratorConcurrencyErrorzu Failure due to concurrent usage of an integrator that can be used only for a single problem at a time. c<d|d}tj||y)Nz Integrator `z` can be used to solve only a single problem at a time. If you want to integrate multiple problems, consider using a different integrator (see `ode.set_integrator`)) RuntimeErrorr)rr6msgs rrz#IntegratorConcurrencyError.__init__s)dV$SS dC(rN)r_r`rarbrrrrrrs  )rrcPeZdZdZdZdZdZdZdZgZ e Z dZ dZ dZdZdZdZy) rNFcx|jxjdz c_|jj|_yNr ) __class__active_global_handlehandler!s racquire_new_handlez!IntegratorBase.acquire_new_handles* ++q0+nn99 rc|j|jjurt|jjyr)rrrrr_r!s r check_handlezIntegratorBase.check_handles3 ;;dnnAA A,T^^-D-DE E Brcy)zPrepare integrator for call: allocate memory, set flags, etc. n - number of equations. has_jac - if user has supplied function for evaluating Jacobian. Nr)rnhas_jacs rr+zIntegratorBase.reset"r>rctd)zIntegrate from t=t0 to t=t1 using y0 as an initial condition. Return 2-tuple (y1,t1) where y1 is the result and t=t1 defines the stoppage coordinate of the result. zIall integrators must define run(f, jac, t0, t1, y0, f_params, jac_params))NotImplementedErrorrrry0t0t1rrs rrCzIntegratorBase.run(s "#RS SrcFt|jjd)z-Make one integration step and return (y1,t1).z does not support step() methodrrr_rs rr@zIntegratorBase.step0s,!T^^%<%<$=>C#CD DrcFt|jjd)z/Integrate from t=t0 to t>=t1 and return (y1,t).z$ does not support run_relax() methodrrs rrBzIntegratorBase.run_relax5s,!T^^%<%<$=>H#HI Ir)r_r`rarunnerrLrOrAr?rYrrr)rrr+rCr@rBrrrrr sN FG FMO F:F SD Irrcfd}|S)zm Wrap a banded Jacobian function with a function that pads the Jacobian with `ml` rows of zeros. cxt||g}t|t|jdff}|Sr)rr rrf)r*r"r padded_jacrjacfuncrvs r jac_wrapperz(_banded_jac_wrapper..jac_wrapperCs@ga0Z01S%SYYq\(:";<= rr)rrvrrs``` r_banded_jac_wrapperr=s  rcveZdZeeddZddddddd Zd Zd Zd Z dd Z d Z dZ dZ dZdZy)vodedvodeNz2Excess work done on this call. (Perhaps wrong MF.)z2Excess accuracy requested. (Tolerances too small.)z.Illegal input detected. (See printed message.)z0Repeated error test failures. (Check all input.)zcRepeated convergence failures. (Perhaps bad Jacobian supplied or wrong choice of MF or tolerances.)zbError weight became zero during problem. (Solution component i vanished, and ATOL or ATOL(i) = 0.))rer rc |tj|dtjrd|_n;tj|dtjrd|_nt d|||_||_||_||_||_ ||_ ||_ | |_ | |_ | |_d|_d|_y)Nadamsr bdfr/zUnknown integration method F)rrrmethrE with_jacobianrtolatolrwrvordernstepsmax_stepmin_step first_steprL initialized) rmethodrrrr~rrrrrrs rrz vode.__init__[s 88FHbdd +DI XXffbdd +DI:6(CD D*        $  rc@|jduxs|jdu}|r&|jd|_|jd|_|r|rd}n>d}n;|r(|j|jcxk(rdk(rnnd}nd}n|jrd}nd}d|jz|z}|S) a Determine the `MF` parameter (Method Flag) for the Fortran subroutine `dvode`. In the Fortran code, the legal values of `MF` are: 10, 11, 12, 13, 14, 15, 20, 21, 22, 23, 24, 25, -11, -12, -14, -15, -21, -22, -24, -25 but this Python wrapper does not use negative values. Returns mf = 10*self.meth + miter self.meth is the linear multistep method: self.meth == 1: method="adams" self.meth == 2: method="bdf" miter is the correction iteration method: miter == 0: Functional iteration; no Jacobian involved. miter == 1: Chord iteration with user-supplied full Jacobian. miter == 2: Chord iteration with internally computed full Jacobian. miter == 3: Chord iteration with internally computed diagonal Jacobian. miter == 4: Chord iteration with user-supplied banded Jacobian. miter == 5: Chord iteration with internally computed banded Jacobian. Side effects: If either self.mu or self.ml is not None and the other is None, then the one that is None is set to 0. Nrr r/ )rwrvrr)rr jac_is_bandedmitermfs r_determine_mf_and_set_bandsz vode._determine_mf_and_set_bands|s:t+Btwwd/B wwww 77dgg**EE%%EE $))^e # rc|j|}|dk(r dd|zz}n|dvrdd|zzd|z|zz}n|dk(r dd|zz}n|d vr,dd |zzd |jzd|jzz|zz}np|dk(r dd |zz}nb|d vrdd |zzd|z|zz}nL|dk(r dd|zz}n>|dvr,dd|zzd |jzd|jzz|zz}ntd||dzdvrd}nd|z}t |ft }|j |d<|j|d<|j|d<||_ t |ft}|j|j|d<|j|j|d<|j|d<|j|d<d|d<||_ |j|jdd|j|j|g|_d|_d|_y)Nr r/ r rrzUnexpected mf=rrrrrr F)rrvrwrErrrrrrwork_vode_int_dtyperriworkrr call_argsrLr)rrrrlrwliwrrs rr+z vode.resets  - -g 6 8rAv+C 8^rAv+A )C 2XrAv+C 8^rAv+TWWq477{!:a ??C 2Xq1u*C 8^q1u*q1uqy(C 2XrAv+C 8^rAv+TWWq477{!:a ??C~bT23 3 7f Cq&Csfe$??a==a==a sfo. 77 wwE!H 77 wwE!H::a;;aa ))TYY1**djj"6  rct|jr|jnd|_|j|j&|jdkDrt ||j|}|||||ft |j z||fz}t5|j|\} } } ddd |_ | dkr]d| d} tj|jjdd|jj| | ddd|_  fSd|j d <d|_   fS#1swYxYw) NTrUnexpected istate=ds: r/r0r)rrrrvrtupler VODE_LOCKrrOr4r5rr_messagesrrL rrrrrrrrrSy1r*rOunexpected_istate_msgs rrCzvode.runsC       #D   # # % 77 477Q;&c477J?CCR$uT^^'<<:&' /'DKK.MB6 / A:&8 $C ! MMT^^44Q7r!]]..v7LMaPR%& (DL1u !"DNN1 DK1u  / /s D..D7c~|jd}d|jd<|j|}||jd<|SNr/rrCrrSitaskrs rr@z vode.step@q!q DHHdO!qrc~|jd}d|jd<|j|}||jd<|SNr/rrrs rrBzvode.run_relax rr) rFư>-q=NNrr2r2r2)r_r`rarxr rrrAr?rrrr+rCr@rBrrrrrKs UGT *FHHDFOG HM $!&#'!B9v.!`>rrc6eZdZeeddZdZdZeZ dZ dZ y)r}Nr rc|j|}|dvrd|z}n|dvrd|zd|dzzz}n|dvr d|z|dzz}n|dvrd|z}n|dvr)d |zd |jzd|jzz|zz}n|d vr&d|zd|jz|jz|zz}n|d vrd |z}n|dvrd |zd|dzzz}np|dvr d |z|dzz}n`|dvrd|z}nV|dvr)d|zd |jzd|jzz|zz}n)|dvr%d|zd|jz|jz|zz}d|z}|dzdvrd}nd|z}tft}||_t|ft }|j|d<|j|d<|j|d<||_ t|ft} |j|j| d<|j|j| d<|j| d<|j| d<d| d<| |_|j|j dd|j |j|j|g|_d|_d|_y)N)rrrr/)ii)rrrrr)ii)rr)ii)rrrr)iirrrrrrrr F)rrvrwrrzworkrrrrrrrrrrrrrLr) rrrrlzwrrrrrs rr+z zvode.reset!s  - -g 6 ;q&C 8^q&1qAv:%C : q&16/C 5[q&C 8^q&AK!dgg+5::C : q&AK$''1Q66C 5[a%C 8^a%!a1f*$C : a%!q&.C 5[a%C 8^q&AK!dgg+5::C : a%1tww;0A55C1f 7f Cq&Csfg& sfe$??a==a==a sfo. 77 wwE!H 77 wwE!H::a;;aa ))TYY1**djj$**bB  r) r_r`rarxr rrAr?rr)rr+rrrr}r}s+ UGT *FM F9!rr}cpeZdZeeddZdZdZddddddd Z dd Z dd Z d Z d Z dZ y)dopri5NTzcomputation successfulz.computation successful (interrupted by solout)zinput is not consistentzlarger nsteps is neededzstep size becomes too smallz'problem is probably stiff (interrupted))r r/rerrrc ||_||_||_||_||_||_||_||_| |_| |_ d|_ |jdyr) rrrrrsafetyifactordfactorbeta verbosityrLrZ) rrrrrrr r r rrrs rrzdopri5.__init__ns]     $    "  rcB||_||_|d|_yd|_y)Nrr )r\ solout_cmplxiout)rr\rs rrZzdopri5.set_solouts$ # >DIDIrctd|zdzft}|j|d<|j|d<|j|d<|j |d<|j |d<|j|d<||_td t}|j|d <|j|d<||_ |j|j|j|j |j|jg|_d|_y) Nrrr r/rrrrrrrrr r r rrrwork_dop_int_dtyperrrrr_soloutrrrLrrrrrs rr+z dopri5.resetsa!ebj]E*++Q,,Q,,Q))Q--Q//Q e^,;;a>>a ))TYY ))TYY < rc8|j||||ft|jz|fz\}} } } | |_| dkrYd| d} t j |j jdd|jj| | ddd|_ | |fS)Nrrrrrr/r0) rrrrOr4r5rr_rrrL) rrrrrrrrxr"rrOrs rrCz dopri5.runs)dkkQBO*/*?-@CK+-NP1eV A:&8 $C ! MMT^^44Q7r!]]..v7LMaPR%& (DL!t rc|j2|jr|dddd|dddzz}|j||Syrq)r\r)rnrxoldrr"ndicompcons rrzdopri5._soloutsI ;; "  ccFR!ADqD'\);;q!$ $r) rrrr2r2?g$@g?r2Nre)F)r_r`rarxrrr6rYrrrZr+rCrrrrr r asl T8T *F DO+C--1= H"'2" rr cReZdZeeddZdZ dfd ZdZxZ S)dop853Nc 8t |||||||||| | | yr)superr) rrrrrrr r r rrrrs rrzdop853.__init__s* tVXz6 '4 Drctd|zdzft}|j|d<|j|d<|j|d<|j |d<|j |d<|j|d<||_td t}|j|d <|j|d<||_ |j|j|j|j |j|jg|_d|_y) Nrrr r/rrrrrrrrs rr+z dop853.resetsb1frk^U+++Q,,Q,,Q))Q--Q//Q e^,;;a>>a ))TYY ))TYY < r) rrrr2r2r"g@g333333?r2Nre) r_r`rarxrrr6rr+ __classcell__)rs@rr$r$sA T8T *F D"' Drr$c reZdZeeddZdZddddddd d d Z dd Zd Z dZ dZ dZ y)lsodaNrzIntegration successful.z8Excess work done on this call (perhaps wrong Dfun type).z1Excess accuracy requested (tolerances too small).z(Illegal input detected (internal error).z.Repeated error test failures (internal error).zCRepeated convergence failures (perhaps bad Jacobian or tolerances).z(Error weight became zero during problem.z;Internal workspace insufficient to finish (internal error).)r/rerrrrric||_||_||_||_||_| |_| |_||_||_||_ | |_ | |_ | |_ d|_ d|_y)Nr F)rrrrwrv max_order_ns max_order_srrrrixprmax_hnilrLr)rrrrr~rrrrrr.r/r,r-rs rrzlsoda.__init__sq+  (&     $     rcp|rD|j|jd}nl|jd|_|jd|_d}nC|j|jd}n(|jd|_|jd|_d}d|jdz|zz}|dvrd|jdz|zz||zz}nE|d vr3d|jdzd|jzz|jz|zz}nt d |t ||}d|z}t |ft}|j|d<|j|d<|j|d <||_ t |ft} |j|j| d<|j|j| d<|j| d<|j| d<|j| d <|j| d <|j| d <| |_|j"|j$dd|j|j |g|_d|_d|_y)Nr rrr/rr)r r/r)rrzUnexpected jt=rrF)rwrvr,r-rEmaxrrrrrr_lsoda_int_dtyper.rr/rrrrrLr) rrrjtlrnlrsrrrrs rr+z lsoda.resets ww477?77?DG77?DGww477?77?DG77?DGD%%)Q.. <((1,11AE9C 6\((1,q477{:TWWDIIC~bT23 3#sm1fsfe$??a==a==a sf./ 77 wwE!H 77 wwE!H99a;;a==a$$a##a ))TYY1**djj"6  rc|jr|jnd|_|j|2|j&|jdkDrt ||j|}||||g|j ddz||j d|d|gz}t 5|j|\} } } ddd |_| dkr]d| d} tj|jjdd|jj| | dd d|_  fSd|j d <d|_  fS#1swYxYw) NTrrerrrrr/r0r)rrrrvrr LSODA_LOCKrrOr4r5rr_rrrLrs rrCz lsoda.runDsV       #D   # # % ?tww2tww{&c477J?C2r2!44T^^B'1jAB /'DKK.MB6 / A:&8 $C ! MMT^^44Q7r!]]..v7LMaPR%& (DL1u !"DNN1 DK1u  / /s D99Ec~|jd}d|jd<|j|}||jd<|Srrrs rr@z lsoda.stepcrrc~|jd}d|jd<|j|}||jd<|Srrrs rrBzlsoda.run_relaxjrr)FrrNNrr2r2r2rrrrN) r_r`rarxrrrrrr+rCr@rBrrrr*r*sx VWd +F % F ? 6 < Q 6 I H %!&#' !B0!d>rr*)*rb__all__r threadingr4numpyrrrrr r r r%r rrtypesintvardtyperrr3Lockr8rrrirr3rrrrrrrappendr}r r$r*rrrrCs%^ -  EEE""((++$$**<<&&,, Y^^  INN  T4T4n&Y2#Y2@ ) )+I+I` G>GT;;%%,,T2A!DA!H <<%%,,U3Q^Qh ==%%,,V4"V"J ==%%,,V4MNM` <<%%,,U3r