
    (ph                        S r SS/rSSKrSSKrSSKrSSKJrJrJrJ	r	J
r
JrJr  SSKJr  SSKJr  SS	KJr  \R"                  R$                  R&                  r\R"                  R$                  R&                  r\R"                  R$                  R&                  r\R.                  " 5       r\R.                  " 5       r " S
 S5      rS r " S S\5      rS r " S S\5      r " S S5      r S r! " S S\ 5      r"\"RF                  b  \ RH                  RK                  \"5         " S S\"5      r&\&RF                  b  \ RH                  RK                  \&5         " S S\ 5      r'\'RF                  b  \ RH                  RK                  \'5         " S S\'5      r(\(RF                  b  \ RH                  RK                  \(5         " S S\ 5      r)\)RF                  (       a  \ RH                  RK                  \)5        gg)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_ode    N)asarrayarrayzerosisscalarrealimagvstack   )_vode)_dop)_lsodac                   j    \ rS rSrSrSS jr\S 5       rSS jrS r	SS jr
S	 rS
 rS rS rS rSrg)r   n   a!  
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)

Nc                 T    SU l         Xl        X l        SU l        SU l        / U l        g )Nr    )stifffjacf_params
jac_params_yselfr   r   s      G/var/www/html/venv/lib/python3.13/site-packages/scipy/integrate/_ode.py__init__ode.__init__c  s(    
    c                     U R                   $ Nr   r   s    r   yode.yk  s    wwr   c                 P   [        U5      (       a  U/n[        U R                  5      nU(       d  U R                  S5        [	        XR
                  R                  5      U l        X l        U R
                  R                  [        U R                  5      U R                  SL5        U $ ) Set initial conditions y(t) = y. N)
r   lenr   set_integratorr   _integratorscalartresetr   )r   r$   r-   n_prevs       r   set_initial_valueode.set_initial_valueo  sy    A;;ATWW#!--445s477|TXXT-ABr   c                 |   [        U5      nUc  SU< S3n[        R                  " USS9  U $ U" S0 UD6U l        [	        U R
                  5      (       d-  SU l        [        S/U R                  R                  5      U l        U R                  R                  [	        U R
                  5      U R                  SL5        U $ )z
Set integrator by name.

Parameters
----------
name : str
    Name of the integrator.
**integrator_params
    Additional parameters for the integrator.
NzNo integrator name match with z or is not available.   
stacklevel        r   )find_integratorwarningswarnr+   r)   r   r-   r   r,   r.   r   )r   nameintegrator_params
integratormessages        r   r*   ode.set_integrator{  s     %T*
 7th>STGMM'a0   *>,=>Dtww<<t'7'7'>'>?""3tww<1EFr   c           	      *   U(       a2  U R                   R                  (       a  U R                   R                  nOOU(       a2  U R                   R                  (       a  U R                   R                  nOU R                   R
                  n U" U R                  U R                  =(       d    S U R                  U R                  UU R                  U R                  5      u  U l        U l	        U R                  $ ! [         a  n[        S5      UeSnAff = f)"  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
c                      g r!   r   r   r   r   <lambda>ode.integrate.<locals>.<lambda>  s    tr   z.Function to integrate must not return a tuple.N)r+   supports_stepstepsupports_run_relax	run_relaxrunr   r   r   r-   r   r   SystemError
ValueError)r   r-   rE   relaxmthes         r   	integrateode.integrate  s    4 D$$22""''Ct''::"",,C""&&C	!$&&$((*D|"&''4661"&--BODGTV ww  	@	s   
A!C7 7
DDDc                      U R                     U R                   R                  S:H  $ ! [         a    U R                  S5         N6f = f)z$Check if integration was successful.r(   r   )r+   AttributeErrorr*   successr#   s    r   
successfulode.successful  sH    	$ ''1,,  	$#	$s   ' AAc                      U R                     U R                   R                  $ ! [         a)    U R                  S5         U R                   R                  $ f = f)ad  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+   rQ   r*   istater#   s    r   get_return_codeode.get_return_code  sV    j	$ &&&  	$#&&&	$s   $ AAc                     Xl         U $ )z2Set extra parameters for user-supplied function f.)r   r   argss     r   set_f_paramsode.set_f_params$  s    r   c                     Xl         U $ )z4Set extra parameters for user-supplied function jac.)r   rZ   s     r   set_jac_paramsode.set_jac_params)  s    r   c                    U R                   R                  (       ae  U R                   R                  U5        U R                  b<  U R                   R	                  [        U R                  5      U R                  SL5        gg[        S5      e)t  
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_soloutr   r.   r)   r   rJ   r   solouts     r   rd   ode.set_solout.  sq     ++''/ww"  &&s477|TXXT5IJ #  3 4 4r   )r+   r   r   r   r   r   r   r-   r!   r6   FF)__name__
__module____qualname____firstlineno____doc__r   propertyr$   r0   r*   rN   rS   rW   r\   r_   rd   __static_attributes__r   r   r   r   r   n   sM    rh  
2+Z-Y'v

4r   c                     [        U R                  S   S-   U R                  S   45      nU SS2SSS24   USS2SSS24'   U SS2SSS24   USS2SSS24'   U$ )z
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.
r   r   Nr3   )r   shape)bjacnewjacs     r   _transform_banded_jacrv   E  sr     DJJqMA%tzz!}56F1cc6lF12ss7OQ1WF3B319Mr   c                   ^    \ rS rSrSrSS jrS rS r\S 5       r	S r
SS	 jrSS
 jrS rSrg)r   iX  a  
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                     Xl         X l        Uc!  [        R                  X R                  S 5        g [        R                  X R                  U R
                  5        g r!   )cfcjacr   r   _wrap	_wrap_jacr   s      r   r   complex_ode.__init__u  s9    	;LLzz40LLzz4>>:r   c           	          U R                   " XS S S2   SUSS S2   -  -   4U-   6 n[        U5      U R                  S S S2'   [        U5      U R                  SS S2'   U R                  $ Nr3                 ?r   )ry   r	   tmpr
   )r   r-   r$   f_argsr   s        r   r{   complex_ode._wrap}  sj    GGqCaC&2!$Q$</069; Q1aAxxr   c           	         U R                   " XS S S2   SUSS S2   -  -   4U-   6 n[        SUR                  S   -  SUR                  S   -  45      n[        U5      =USS S2SS S24'   US S S2S S S24'   [	        U5      USS S2S S S24'   USS S2S S S24   * US S S2SS S24'   [        U R                  SS 5      n[        U R                  SS 5      nUc  Ub  [        U5      nU$ )Nr3   r   r   r   mlmu)rz   r   rs   r	   r
   getattrr+   rv   )r   r-   r$   jac_argsr   jac_tmpr   r   s           r   r|   complex_ode._wrap_jac  s   ii1!frAaddG|34x?A SYYq\)1syy|+;<=26s);1add
gcc3Q3h/!#Y1cc	%addCaCi00!QTT	T%%tT2T%%tT2>R^ ,G4Gr   c                 R    U R                   S S S2   SU R                   SS S2   -  -   $ r   r"   r#   s    r   r$   complex_ode.y  s,    wwss|b47714a4=000r   c                     US:X  a  [        S5      eUR                  S5      nUR                  S5      nUc  Ub(  SU=(       d    S-  S-   US'   SU=(       d    S-  S-   US'   [        R                  " X40 UD6$ )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_odelbandubandr3   r   r   )rJ   getr   r*   )r   r:   r;   r   r   s        r   r*   complex_ode.set_integrator  s     7?KLL!%%g.!%%g. 1
 *+ejq)9A)=g&)*ejq)9A)=g&!!$B0ABBr   c                     [        U5      n[        UR                  S-  S5      U l        [	        U5      U R                  SSS2'   [        U5      U R                  SSS2'   [        R                  X R                  U5      $ )r'   r3   floatNr   )r   r   sizer   r	   r
   r   r0   )r   r$   r-   s      r   r0   complex_ode.set_initial_value  sd    AJ!W-Q1aA$$T88Q77r   c                 V    [         R                  XX#5      nUSSS2   SUSSS2   -  -   $ )r@   Nr3   r   r   )r   rN   )r   r-   rE   rK   r$   s        r   rN   complex_ode.integrate  s5    4 MM$4/1vQqt!tW$$r   c                     U R                   R                  (       a  U R                   R                  USS9  g[        S5      e)rb   T)complexz@selected integrator does not support solouta, choose another oneN)r+   rc   rd   	TypeErrorre   s     r   rd   complex_ode.set_solout  s>     ++'''= 1 2 2r   )ry   rz   r   r!   rh   ri   )rj   rk   rl   rm   rn   r   r{   r|   ro   r$   r*   r0   rN   rd   rp   r   r   r   r   r   X  s?    8;. 1 1C48%:2r   c                     [         R                   H;  n[        R                  " XR                  [        R
                  5      (       d  M9  Us  $    g r!   )IntegratorBaseintegrator_classesrematchrj   I)r:   cls     r   r7   r7     s5    //88D++rtt,,I 0 r   c                       \ rS rSrSrS rSrg)IntegratorConcurrencyErrori  zi
Failure due to concurrent usage of an integrator that can be used
only for a single problem at a time.

c                 :    SU S3n[         R                  X5        g )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   )r   r:   msgs      r   r   #IntegratorConcurrencyError.__init__  s'    dV $S S 	d(r   r   N)rj   rk   rl   rm   rn   r   rp   r   r   r   r   r     s    )r   r   c                   X    \ rS rSrSrSrSrSrSrSr	/ r
\rS rS rS rS rS rS	 rS
rg)r   i  NFc                 x    U R                   =R                  S-  sl        U R                   R                  U l        g Nr   )	__class__active_global_handlehandler#   s    r   acquire_new_handle!IntegratorBase.acquire_new_handle  s*     	++q0+nn99r   c                     U R                   U R                  R                  La  [        U R                  R                  5      eg r!   )r   r   r   r   rj   r#   s    r   check_handleIntegratorBase.check_handle  s3    ;;dnnAAA,T^^-D-DEE Br   c                     g)zPrepare integrator for call: allocate memory, set flags, etc.
n - number of equations.
has_jac - if user has supplied function for evaluating Jacobian.
Nr   )r   nhas_jacs      r   r.   IntegratorBase.reset"  s    r   c                     [        S5      e)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))NotImplementedErrorr   r   r   y0t0t1r   r   s           r   rH   IntegratorBase.run(  s    
 " #R S 	Sr   c                 F    [        U R                  R                   S35      e)z-Make one integration step and return (y1,t1).z does not support step() methodr   r   rj   r   s           r   rE   IntegratorBase.step0  s,    !T^^%<%<$= >C #C D 	Dr   c                 F    [        U R                  R                   S35      e)z/Integrate from t=t0 to t>=t1 and return (y1,t).z$ does not support run_relax() methodr   r   s           r   rG   IntegratorBase.run_relax5  s,    !T^^%<%<$= >H #H I 	Ir   )r   )rj   rk   rl   rm   runnerrR   rV   rF   rD   rc   r   r   r,   r   r   r.   rH   rE   rG   rp   r   r   r   r   r     sN    FGFMOF:FSD
Ir   r   c                    ^ ^^ UU U4S jnU$ )za
Wrap a banded Jacobian function with a function that pads
the Jacobian with `ml` rows of zeros.
c                 v   > [        T" X/TQ76 5      n[        U[        TUR                  S   45      45      nU$ r   )r   r   r   rs   )r-   r$   r   
padded_jacr   jacfuncr   s       r   jac_wrapper-_vode_banded_jac_wrapper.<locals>.jac_wrapperC  s>    ga0Z01S%SYYq\(:";<=
r   r   )r   r   r   r   s   ``` r   _vode_banded_jac_wrapperr   =  s    
 r   c                       \ rS rSr\" \SS5      rSSSSSS	S
.rSrSr	Sr
         SS jrS rS rS rS rS rSrg)vodeiK  dvodeNz2Excess 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.))rr   r   r   c                    [         R                  " US[         R                  5      (       a  SU l        OA[         R                  " US[         R                  5      (       a  SU l        O[	        SU 35      eX l        X0l        X@l        X`l        XPl	        Xpl
        Xl        Xl        Xl        Xl        SU l        SU l        g )Nadamsr   bdfr3   zUnknown integration method F)r   r   r   methrJ   with_jacobianrtolatolr   r   ordernstepsmax_stepmin_step
first_steprR   initialized)r   methodr   r   r   r   r   r   r   r   r   r   s               r   r   vode.__init__[  s     88FHbdd++DIXXffbdd++DI:6(CDD*		
  $ r   c                    U R                   SL=(       d    U R                  SLnU(       a(  U R                   c  SU l         U R                  c  SU l        U(       a  U(       a  SnOJSnOGU(       a*  U R                  U R                   s=:X  a  S:X  a  O  OSnOSnOU R                  (       a  SnOSnSU R                  -  U-   nU$ )	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.
Nr      r         r3   
   )r   r   r   r   )r   r   jac_is_bandedmitermfs        r   _determine_mf_and_set_bands vode._determine_mf_and_set_bands|  s    : t+Btwwd/Bwwww 77dgg**EE %%EE$))^e#	r   c                    U R                  U5      nUS:X  a	  SSU-  -   nOUS;   a  SSU-  -   SU-  U-  -   nOUS:X  a	  SSU-  -   nOUS	;   a,  SS
U-  -   SU R                  -  SU R                  -  -   U-  -   nOvUS:X  a	  SSU-  -   nOgUS;   a  SSU-  -   SU-  U-  -   nOOUS:X  a	  SSU-  -   nO@US;   a,  SSU-  -   SU R                  -  SU R                  -  -   U-  -   nO[        SU 35      eUS-  S;   a  SnOSU-   n[	        U4[
        5      nU R                  US'   U R                  US'   U R                  US'   X`l	        [	        U4[        5      nU R                  b  U R                  US'   U R                  b  U R                  US'   U R                  US'   U R                  US'   SUS'   Xpl        U R                  U R                  SSU R                  U R                  U/U l        SU l        SU l        g )Nr                  r3                  r   	      r            r   zUnexpected mf=r   r      r   r      r   r   F)r   r   r   rJ   r   r   r   r   r   rwork_vode_int_dtyper   r   iworkr   r   	call_argsrR   r   )r   r   r   r   lrwliwr  r  s           r   r.   
vode.reset  s   --g68rAv+C8^rAv+A	)C2XrAv+C8^rAv+TWWq477{!:a ??C2Xq1u*C8^q1u*q1uqy(C2XrAv+C8^rAv+TWWq477{!:a ??C~bT2337fCq&Csfe$??a==a==a
sfo.77wwE!H77wwE!H::a;;aa
))TYY1**djj"6 r   c                 ~   U R                   (       a  U R                  5         OSU l         U R                  5         U R                  b&  U R                  S:  a  [	        X R                  U5      nXX4U4[        U R                  5      -   Xg4-   n[           U R                  " U6 u  pnS S S 5        WU l	        US:  aZ  SUS 3n[        R                  " U R                  R                  S SU R                  R                  X5      S 3SS9  SU l        W	W
4$ SU R                  S	'   SU l	        W	W
4$ ! , (       d  f       N= f)
NTr   Unexpected istate=ds: r3   r4   r   )r   r   r   r   r   tupler  	VODE_LOCKr   rV   r8   r9   r   rj   messagesr   rR   r   r   r   r   r   r   r   r   r[   y1r-   rV   unexpected_istate_msgs                r   rH   vode.run  s,   #D##%77477Q; +3DC$uT^^'<<&'  KK.MB6  A:&8
$C!MMT^^44Q7r!]]..vMaPR%&( DL 1u !"DNN1DK1u Ys   D..
D<c                 |    U R                   S   nSU R                   S'   U R                  " U6 nX R                   S'   U$ Nr3   r  rH   r   r[   itaskrs       r   rE   	vode.step  <    q!qHHdO!qr   c                 |    U R                   S   nSU R                   S'   U R                  " U6 nX R                   S'   U$ Nr3   r   r  r  s       r   rG   vode.run_relax  r  r   )r   r  r   r   rV   r  r   r   r   r   r   r   r   r   r  rR   r   )r   Fư>-q=NNr     r6   r6   r6   )rj   rk   rl   rm   r   r   r   r  rF   rD   r   r   r   r.   rH   rE   rG   rp   r   r   r   r   r   K  s    UGT*FHHDFOGH M  $!&#'!B9v.!`>r   r   c                   >    \ rS rSr\" \S S5      rSrSr\	r
SrS rSrg)r   i  Nr   r   c                    U R                  U5      nUS;   a  SU-  nGO)US;   a  SU-  SUS-  -  -   nGOUS;   a  SU-  US-  -   nGO US;   a  SU-  nOUS;   a)  S	U-  S
U R                  -  SU R                  -  -   U-  -   nOUS;   a&  SU-  SU R                  -  U R                  -   U-  -   nOUS;   a  SU-  nOUS;   a  SU-  SUS-  -  -   nOxUS;   a  SU-  US-  -   nOfUS;   a  SU-  nOZUS;   a)  SU-  S
U R                  -  SU R                  -  -   U-  -   nO+US;   a%  SU-  SU R                  -  U R                  -   U-  -   nSU-   nUS-  S;   a  SnOSU-   n[        W4[        5      nXpl        [        U4[        5      nU R                  US'   U R                  US'   U R                  US'   Xl
        [        U4[        5      n	U R                  b  U R                  U	S'   U R                  b  U R                  U	S'   U R                  U	S'   U R                  U	S'   SU	S'   Xl        U R                  U R                   SSU R
                  U R                  U R                  U/U l        SU l        SU l        g )N)r   r   r   r3   )ii)r   r   r   r   r   )ii)r      r   )ii)r   r   r   r   )iir   r  r  r   r   r  r   r   F)r   r   r   r   r   zworkr   r   r   r   r  r  r   r   r  r   r   r  rR   r   )
r   r   r   r   lzwr	  r
  r)  r  r  s
             r   r.   zvode.reset!  s   --g6;q&C8^q&1qAv:%C:q&16/C5[q&C8^q&AK!dgg+5::C:q&AK$''1Q66C5[a%C8^a%!a1f*$C:a%!q&.C5[a%C8^q&AK!dgg+5::C:a%1tww;0A55C1f7fCq&Csfg&
sfe$??a==a==a
sfo.77wwE!H77wwE!H::a;;aa
))TYY1**djj$**bB r   )r  r   r  r  rR   r)  )rj   rk   rl   rm   r   r   r   rF   rD   r   r,   r   r.   rp   r   r   r   r   r     s+    UGT*FMF9!r   r   c                   |    \ rS rSr\" \S S5      rS rSrSSSSSS	S
.r	          SS jr
SS jrS rS rS rSrg)dopri5ia  NTzcomputation successfulz.computation successful (interrupted by solout)zinput is not consistentzlarger nsteps is neededzstep size becomes too smallz'problem is probably stiff (interrupted))r   r3   rr   r   r   r   c                     Xl         X l        X0l        X@l        XPl        X`l        Xpl        Xl        Xl        Xl	        SU l
        U R                  S 5        g r   )r   r   r   r   r   safetyifactordfactorbeta	verbosityrR   rd   )r   r   r   r   r   r   r/  r0  r1  r2  r   r3  s               r   r   dopri5.__init__n  sI     		 $	"r   c                 @    Xl         X l        Uc  SU l        g SU l        g )Nr   r   )rf   solout_cmplxiout)r   rf   r   s      r   rd   dopri5.set_solout  s     #>DIDIr   c                    [        SU-  S-   4[        5      nU R                  US'   U R                  US'   U R                  US'   U R
                  US'   U R                  US'   U R                  US'   X0l        [        S	[        5      nU R                  US
'   U R                  US'   X@l        U R                  U R                  U R                  U R                   U R                  U R                  /U l        SU l        g )Nr(  r   r   r3   r   r   r   r  r   r   r   r   r/  r1  r0  r2  r   r   work_dop_int_dtyper   r3  r  r   r   _soloutr7  r  rR   r   r   r   r<  r  s        r   r.   dopri5.reset  s    a!ebj]E*++Q,,Q,,Q))Q--Q//Q	e^,;;a>>a
))TYY))TYY

<r   c                 (   U R                   " XX54[        U R                  5      -   U4-   6 u  ppXl        US:  aV  SUS 3n[        R
                  " U R                  R                  S SU R                  R                  X5      S 3SS9  SU l
        X4$ )Nr   r  r  r  r  r3   r4   )r   r  r  rV   r8   r9   r   rj   r  r   rR   )r   r   r   r   r   r   r   r   xr$   r  rV   r  s                r   rH   
dopri5.run  s    "kkQBO*/*?-@CK+-N PeA:&8
$C!MMT^^44Q7r!]]..vMaPR%&( DLtr   c                     U R                   b6  U R                  (       a  US S S2   SUSS S2   -  -   nU R                  X45      $ gr   )rf   r6  )r   nrxoldrB  r$   ndicompcons           r   r>  dopri5._solout  sG    ;;"  ccFR!ADqD'\);;q$$r   )r   r2  r  r1  r   r0  r7  rV   r  r   r   r   r/  rf   r6  rR   r3  r<  )r#  r$  r%  r6   r6   ?g      $@g?r6   Nrr   )F)rj   rk   rl   rm   r   r   r   r:   rc   r  r   rd   r.   rH   r>  rp   r   r   r   r-  r-  a  sl    T8T*FDO+C--1=H "'2"
r   r-  c                   ^   ^  \ rS rSr\" \S S5      rS r          SU 4S jjrS r	Sr
U =r$ )dop853i  Nc                 .   > [         TU ]  XX4XVXxXU5        g r!   )superr   )r   r   r   r   r   r   r/  r0  r1  r2  r   r3  r   s               r   r   dop853.__init__  s      	Vz 4	Dr   c                    [        SU-  S-   4[        5      nU R                  US'   U R                  US'   U R                  US'   U R
                  US'   U R                  US'   U R                  US'   X0l        [        S	[        5      nU R                  US
'   U R                  US'   X@l        U R                  U R                  U R                  U R                   U R                  U R                  /U l        SU l        g )Nr   r   r   r3   r   r   r   r  r:  r   r;  r?  s        r   r.   dop853.reset  s    b1frk^U+++Q,,Q,,Q))Q--Q//Q	e^,;;a>>a
))TYY))TYY

<r   )r  r  rR   r<  )r#  r$  r%  r6   r6   rK  g      @g333333?r6   Nrr   )rj   rk   rl   rm   r   r   r   r:   r   r.   rp   __classcell__)r   s   @r   rM  rM    sF    T8T*FD "'D r   rM  c            	       |    \ rS rSr\" \S S5      rSrSSSSSS	S
SS.r            SS jr	S r
S rS rS rSrg)lsodai  Nr   zIntegration 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).)r3   rr   r   r   r   r   r   ic                     Xl         X l        X0l        XPl        X@l        Xl        Xl        X`l        Xpl        Xl	        Xl
        Xl        Xl        SU l        SU l        g )Nr   F)r   r   r   r   r   max_order_nsmax_order_sr   r   r   r   ixprmax_hnilrR   r   )r   r   r   r   r   r   r   r   r   r   rY  rZ  rW  rX  r   s                  r   r   lsoda.__init__  sW     +		(&  $	  r   c                    U(       aH  U R                   c  U R                  c  SnOrU R                   c  SU l         U R                  c  SU l        SnOGU R                   c  U R                  c  SnO*U R                   c  SU l         U R                  c  SU l        SnSU R                  S-   U-  -   nUS;   a  SU R                  S-   U-  -   X-  -   nOGUS	;   a3  SU R                  S-   SU R                  -  -   U R                   -   U-  -   nO[	        S
U 35      e[        XE5      nSU-   n[        U4[        5      nU R                  US'   U R                  US'   U R                  US'   Xl        [        U4[        5      n	U R                  b  U R                  U	S'   U R                   b  U R                   U	S'   U R                  U	S'   U R                  U	S'   U R                  U	S'   U R                  U	S'   U R                  U	S'   Xl        U R"                  U R$                  SSU R                  U R                   U/U l        SU l        SU l        g )Nr   r   r   r3   r   r   )r   r3   r   )r   r   zUnexpected jt=r     r(  F)r   r   rW  rX  rJ   maxr   r   r   r   r   r  _lsoda_int_dtyperY  r   rZ  r  r   r   r  rR   r   )
r   r   r   jtlrnlrsr	  r
  r  r  s
             r   r.   lsoda.reset  s   ww477?77?DG77?DGww477?77?DG77?DGD%%)Q..<((1,11AE9C6\((1,q477{:TWWDIIC~bT233#m1fsfe$??a==a==a
sf./77wwE!H77wwE!H99a;;a==a$$a##a
))TYY1**djj"6 r   c                 *   U R                   (       a  U R                  5         OSU l         U R                  5         XXE/U R                  S S -   X R                  S   USU/-   n[           U R
                  " U6 u  pnS S S 5        WU l        US:  aZ  SUS 3n[        R                  " U R                  R                  S SU R                  R                  X5      S 3SS	9  SU l        W	W
4$ SU R                  S
'   SU l        W	W
4$ ! , (       d  f       N= f)NTrr   r   r  r  r  r  r3   r4   r   )r   r   r   r  
LSODA_LOCKr   rV   r8   r9   r   rj   r  r   rR   r  s                r   rH   	lsoda.runD  s   #D##%r!44^^B'1jAB  KK.MB6  A:&8
$C!MMT^^44Q7r!]]..vMaPR%&( DL 1u !"DNN1DK1u Zs   (D
Dc                 |    U R                   S   nSU R                   S'   U R                  " U6 nX R                   S'   U$ r  r  r  s       r   rE   
lsoda.step\  r  r   c                 |    U R                   S   nSU R                   S'   U R                  " U6 nX R                   S'   U$ r!  r  r  s       r   rG   lsoda.run_relaxc  r  r   )r   r  r   r   rV   r  rY  rZ  rW  rX  r   r   r   r   r   r   r  rR   r   )Fr#  r$  NNr%  r6   r6   r6   r   r   r   r   N)rj   rk   rl   rm   r   r   r   r   r  r   r.   rH   rE   rG   rp   r   r   r   rU  rU    sx    VWd+F %F?6<Q6I	H  %!&#' !B0!d0r   rU  )*rn   __all__r   	threadingr8   numpyr   r   r   r   r	   r
   r   r(   r   r   r   typesintvardtyper=  r  r_  Lockre  r  r   rv   r   r7   r   r   r   r   r   r   r   appendr   r-  rM  rU  r   r   r   <module>rs     s  %^ -
  	   E E E    ""((++$$**<<&&,, 
 ^^
NN	T4 T4n&Y2# Y2@) )+I +I`G> GT ;;%%,,T2A!D A!H 	<<%%,,U3Q^ Qh 
==%%,,V4"V "J 
==%%,,V4FN FR 	<<%%,,U3 r   