a
    BCCfʻ                     @   s  d Z ddgZddlZddlZddlmZmZmZmZm	Z	m
Z
mZ ddlmZ ddlmZ dd	lmZ ejjjZejjjZejjjZG d
d dZdd ZG dd deZdd ZG dd deZG dd dZdd ZG dd deZejdurej !e G dd deZ"e"jdur$ej !e" G dd deZ#e#jdurLej !e# G dd de#Z$e$jdurtej !e$ G dd deZ%e%jrej !e% dS ) 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                   @   sj   e Zd ZdZdddZedd Zddd	Zd
d ZdddZ	dd Z
dd Zdd Zdd Zdd ZdS )r   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                 C   s(   d| _ || _|| _d| _d| _g | _d S )Nr    )Zstifffjacf_params
jac_params_yselfr   r   r   r   P/var/www/html/django/DPS/env/lib/python3.9/site-packages/scipy/integrate/_ode.py__init__\  s    zode.__init__c                 C   s   | j S Nr   r   r   r   r   yd  s    zode.y        c                 C   sZ   t |r|g}t| j}|s&| d t|| jj| _|| _| jt| j| j	du | S ) Set initial conditions y(t) = y. N)
r   lenr   set_integratorr   _integratorscalartresetr   )r   r   r$   Zn_prevr   r   r   set_initial_valueh  s    

zode.set_initial_valuec                 K   s|   t |}|du r,d|d}tj|dd nL|f i || _t| js^d| _tdg| jj| _| j	t| j| j
du | S )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.   
stacklevelr   )find_integratorwarningswarnr"   r    r   r$   r   r#   r%   r   )r   nameintegrator_paramsZ
integratormessager   r   r   r!   t  s    
zode.set_integratorFc              
   C   s   |r| j jr| j j}n|r,| j jr,| j j}n| j j}z4|| j| jpHdd | j| j	|| j
| j\| _| _	W n. ty } ztd|W Y d}~n
d}~0 0 | jS )  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                   S   s   d S r   r   r   r   r   r   <lambda>      zode.integrate.<locals>.<lambda>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$   r4   relaxZmther   r   r   	integrate  s"    


zode.integratec                 C   s4   z
| j  W n ty&   | d Y n0 | j jdkS )z$Check if integration was successful.r   r   )r"   AttributeErrorr!   successr   r   r   r   
successful  s
    
zode.successfulc                 C   s0   z
| j  W n ty&   | d Y n0 | j jS )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"   r=   r!   istater   r   r   r   get_return_code  s
    U
zode.get_return_codec                 G   s
   || _ | S )z2Set extra parameters for user-supplied function f.)r   r   argsr   r   r   set_f_params  s    zode.set_f_paramsc                 G   s
   || _ | S )z4Set extra parameters for user-supplied function jac.)r   rB   r   r   r   set_jac_params"  s    zode.set_jac_paramsc                 C   sF   | j jr:| j | | jdurB| j t| j| jdu ntddS )  
        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   r9   r   soloutr   r   r   rH   '  s
    
zode.set_solout)N)r   )FF)__name__
__module____qualname____doc__r   propertyr   r&   r!   r<   r?   rA   rD   rE   rH   r   r   r   r   r   g   s    u



-[c                 C   sp   t | jd d | jd f}| dddddf |dddddf< | dddddf |dddddf< |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.
    r   r   Nr'   )r   shape)ZbjacZnewjacr   r   r   _transform_banded_jac>  s    ((rR   c                   @   sZ   e Zd ZdZdddZdd Zdd Zed	d
 Zdd Z	dddZ
dddZdd ZdS )r   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                 C   s<   || _ || _|d u r&t| | jd  nt| | j| j d S r   )cfcjacr   r   _wrap	_wrap_jacr   r   r   r   r   n  s
    zcomplex_ode.__init__c                 G   s\   | j ||d d d d|dd d   f|  }t|| jd d d< t|| jdd d< | jS Nr'                 ?r   )rS   r   tmpr	   )r   r$   r   Zf_argsr   r   r   r   rU   v  s    .zcomplex_ode._wrapc                 G   s  | j ||d d d d|dd d   f|  }td|jd  d|jd  f}t| |dd ddd df< |d d dd d df< t||dd dd d df< |dd dd d df  |d d ddd df< t| jdd }t| jdd }|d us|d urt|}|S )Nr'   rX   r   r   mlmu)rT   r   rQ   r   r	   getattrr"   rR   )r   r$   r   Zjac_argsr   Zjac_tmprZ   r[   r   r   r   rV   ~  s    . 4.zcomplex_ode._wrap_jacc                 C   s$   | j d d d d| j dd d   S rW   r   r   r   r   r   r     s    zcomplex_ode.yc                 K   sp   |dkrt d|d}|d}|dus4|dur\d|p<d d |d< d|pPd d |d< tj| |fi |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_odelbandubandNr'   r   r   )r9   getr   r!   )r   r-   r.   r^   r_   r   r   r   r!     s    

zcomplex_ode.set_integratorr   c                 C   sR   t |}t|jd d| _t|| jddd< t|| jddd< t| | j|S )r   r'   floatNr   )r   r   sizerY   r   r	   r   r&   )r   r   r$   r   r   r   r&     s
    zcomplex_ode.set_initial_valueFc                 C   s0   t | |||}|ddd d|ddd   S )r0   Nr'   rX   r   )r   r<   )r   r$   r4   r:   r   r   r   r   r<     s    zcomplex_ode.integratec                 C   s&   | j jr| j j|dd ntddS )rF   T)complexz?selected integrator does not support solouta,choose another oneN)r"   rG   rH   	TypeErrorrI   r   r   r   rH     s    zcomplex_ode.set_solout)N)r   )FF)rK   rL   rM   rN   r   rU   rV   rO   r   r!   r&   r<   rH   r   r   r   r   r   Q  s   



c                 C   s*   t jD ]}t| |jtjr|  S qd S r   )IntegratorBaseintegrator_classesrematchrK   I)r-   clr   r   r   r*     s    

r*   c                   @   s   e Zd ZdZdd ZdS )IntegratorConcurrencyErrorzu
    Failure due to concurrent usage of an integrator that can be used
    only for a single problem at a time.

    c                 C   s   d| }t | | d S )NzIntegrator `%s` 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-   msgr   r   r   r     s    z#IntegratorConcurrencyError.__init__N)rK   rL   rM   rN   r   r   r   r   r   rk     s   rk   c                   @   s\   e Zd ZdZdZdZdZdZdZg Z	e
Zdd Zdd Zdd Zd	d
 Zdd Zdd ZdS )re   NFc                 C   s   | j  jd7  _| j j| _d S Nr   )	__class__active_global_handlehandler   r   r   r   acquire_new_handle  s    z!IntegratorBase.acquire_new_handlec                 C   s   | j | jjurt| jjd S r   )rq   ro   rp   rk   rK   r   r   r   r   check_handle  s    zIntegratorBase.check_handlec                 C   s   dS )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_jacr   r   r   r%     s    zIntegratorBase.resetc                 C   s   t ddS )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)N)NotImplementedErrorr   r   r   y0t0t1r   r   r   r   r   r7   "  s    zIntegratorBase.runc                 C   s   t d| jj dS )z-Make one integration step and return (y1,t1).z!%s does not support step() methodNrv   ro   rK   rw   r   r   r   r4   *  s    zIntegratorBase.stepc                 C   s   t d| jj dS )z/Integrate from t=t0 to t>=t1 and return (y1,t).z&%s does not support run_relax() methodNr{   rw   r   r   r   r6   /  s    zIntegratorBase.run_relax)rK   rL   rM   runnerr>   r@   r5   r3   rG   rf   ra   r#   rr   rs   r%   r7   r4   r6   r   r   r   r   re     s   re   c                    s    fdd}|S )zm
    Wrap a banded Jacobian function with a function that pads
    the Jacobian with `ml` rows of zeros.
    c                    s4   t | |g R  }t|t|jd ff}|S rn   )r   r
   r   rQ   )r$   r   r   Z
padded_jacr   jacfuncrZ   r   r   jac_wrapper=  s    z-_vode_banded_jac_wrapper.<locals>.jac_wrapperr   )r~   rZ   r   r   r   r}   r   _vode_banded_jac_wrapper7  s    r   c                   @   sh   e Zd ZeeddZddddddd	Zd
Zd
ZdZ	dddZ
dd Zdd Zdd Zdd Zdd ZdS ) vodeZ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.))rP   r   r   adamsFư>-q=     r   c                 C   s   t |dt jrd| _n$t |dt jr0d| _ntd| || _|| _|| _|| _|| _	|| _
|| _|	| _|
| _|| _d| _d| _d S )Nr   r   Zbdfr'   zUnknown integration method %sF)rg   rh   ri   methr9   with_jacobianrtolatolr[   rZ   ordernstepsmax_stepmin_step
first_stepr>   initialized)r   methodr   r   r   r^   r_   r   r   r   r   r   r   r   r   r   U  s"    zvode.__init__c                 C   s   | j dup| jdu}|r8| j du r(d| _ | jdu r8d| _|rL|rFd}qd}n<|rx| j| j   krhdkrrn nd}qd}n| jrd}nd}d| j | }|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.
        Nr      r         r'   
   )r[   rZ   r   r   )r   ru   Zjac_is_bandedZmitermfr   r   r   _determine_mf_and_set_bandsv  s&    

z vode._determine_mf_and_set_bandsc                 C   s  |  |}|dkr dd|  }n|dv rBdd|  d| |  }n|dkrXdd|  }n|d	v rdd
|  d| j d| j  |  }n|dkrdd|  }nt|dv rdd|  d| |  }nR|dkrdd|  }n<|dv rdd|  d| j d| j  |  }ntd| |d dv r$d}nd| }t|ft}| j|d< | j|d< | j|d< || _	t|ft
}| jd ur~| j|d< | jd ur| j|d< | j|d< | j|d< d|d< || _| j| jdd| j	| j|g| _d| _d| _d S )Nr            r      r'                  r   	      r            r   zUnexpected mf=%sr   r      r   r      r   r   F)r   rZ   r[   r9   r   ra   r   r   r   rwork_vode_int_dtyper   r   iworkr   r   	call_argsr>   r   )r   rt   ru   r   lrwliwr   r   r   r   r   r%     sP    
&
&







z
vode.resetc                 C   s   | j r|   nd| _ |   | jd ur@| jdkr@t|| j|}|||||ft| j ||f }| j| \}	}
}|| _|dk rd|d}t	j
d| jj| j||dd d| _nd| jd< d| _|	|
fS )	NTr   Unexpected istate=d
{:s}: {:s}r'   r(   r   )r   rs   rr   rZ   r   tupler   r|   r@   r+   r,   formatro   rK   messagesr`   r>   r   r   r   rx   ry   rz   r   r   rC   y1r$   r@   unexpected_istate_msgr   r   r   r7     s,    

zvode.runc                 G   s,   | j d }d| j d< | j| }|| j d< |S Nr'   r   r7   r   rC   Zitaskrr   r   r   r4     s
    



z	vode.stepc                 G   s,   | j d }d| j d< | j| }|| j d< |S Nr'   r   r   r   r   r   r   r6     s
    



zvode.run_relax)r   Fr   r   NNr   r   r   r   r   )rK   rL   rM   r\   r   r|   r   r5   r3   rp   r   r   r%   r7   r4   r6   r   r   r   r   r   E  s4   	         
!;0r   c                   @   s0   e Zd Zeed dZdZdZeZ	dZ
dd ZdS )r]   Nr   r   c           
      C   s`  |  |}|dv rd| }nR|dv r>d| d|d   }n2|dv rZd| |d  }n|dv rnd| }n|dv rd	| d
| j d| j  |  }n|dv rd| d| j | j |  }n|dv rd| }n|dv rd| d|d   }n|dv r
d| |d  }nf|dv rd| }nR|dv rJd| d
| j d| j  |  }n&|dv rpd| d| j | j |  }d| }|d dv rd}nd| }t|ft}|| _t|ft}| j|d< | j|d< | j	|d< || _
t|ft}	| jd ur| j|	d< | jd ur| j|	d< | j|	d< | j|	d< d|	d< |	| _| j| jdd| j| j
| j|g| _d| _d| _d S )N)r   r   r   r'   )ii)r   r   r   r   r   )ii)r      r   )ii)r   r   r   r   )iir   r   r   r   r   r   r   r   F)r   rZ   r[   r   rc   zworkra   r   r   r   r   r   r   r   r   r   r   r   r>   r   )
r   rt   ru   r   Zlzwr   r   r   r   r   r   r   r   r%     sd    
"




"







zzvode.reset)rK   rL   rM   r\   r   r|   r5   r3   rc   r#   rp   r%   r   r   r   r   r]     s   r]   c                   @   s^   e Zd Zeed dZd ZdZddddddd	ZdddZ	dddZ
dd Zdd Zdd ZdS )dopri5NTz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   r'   rP   r   r   r   r   r   r   r   ?      $@皙?rP   c                 C   sP   || _ || _|| _|| _|| _|| _|| _|| _|	| _|| _	d| _
| d  d S rn   )r   r   r   r   r   safetyifactordfactorbeta	verbosityr>   rH   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   e  s    zdopri5.__init__Fc                 C   s&   || _ || _|d u rd| _nd| _d S )Nr   r   )rJ   solout_cmplxiout)r   rJ   rc   r   r   r   rH   ~  s
    zdopri5.set_soloutc                 C   s   t d| d ft}| j|d< | j|d< | j|d< | j|d< | j|d< | j|d< || _t d	t	}| j
|d
< | j|d< || _| j| j| j| j| j| jg| _d| _d S )Nr   r   r   r'   r   r   r   r   r   r   r   ra   r   r   r   r   r   r   work_dop_int_dtyper   r   r   r   r   _soloutr   r   r>   r   rt   ru   r   r   r   r   r   r%     s     








zdopri5.resetc                 C   sv   | j ||||ft| j |f  \}}	}
}|| _|dk rnd|d}tjd| jj| j	
||dd d| _|	|fS )Nr   r   r   r   r'   r(   )r|   r   r   r@   r+   r,   r   ro   rK   r   r`   r>   )r   r   r   rx   ry   rz   r   r   xr   r   r@   r   r   r   r   r7     s    z
dopri5.runc                 C   sD   | j d ur<| jr0|d d d d|dd d   }|  ||S dS d S rW   )rJ   r   )r   nrZxoldr   r   ndZicompconr   r   r   r     s
    
 zdopri5._solout)r   r   r   r   r   r   r   r   r   NrP   )F)rK   rL   rM   r\   r   r|   r-   rG   r   r   rH   r%   r7   r   r   r   r   r   r   X  s2   	          

r   c                       s6   e Zd Zeed dZd Zd fd
d	Zdd Z  Z	S )dop853Nr   r   r   r   r         @333333?rP   c                    s$   t  |||||||||	|
| d S r   )superr   r   ro   r   r   r     s    
zdop853.__init__c                 C   s   t d| d ft}| j|d< | j|d< | j|d< | j|d< | j|d< | j|d< || _t d	t	}| j
|d
< | j|d< || _| j| j| j| j| j| jg| _d| _d S )Nr   r   r   r'   r   r   r   r   r   r   r   r   r   r   r   r%     s     








zdop853.reset)r   r   r   r   r   r   r   r   r   NrP   )
rK   rL   rM   r\   r   r|   r-   r   r%   __classcell__r   r   r   r   r     s             r   c                   @   s\   e Zd Zeed dZdZddddddd	d
dZdddZdd Z	dd Z
dd Zdd ZdS )lsodaNr   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).)r'   rP   r   r   r   r   r   iFr   r   r   r   r   r   c                 C   s^   || _ || _|| _|| _|| _|| _|| _|| _|| _|| _	|	| _
|
| _|| _d| _d| _d S )Nr   F)r   r   r   r[   rZ   max_order_nsmax_order_sr   r   r   r   ixprmax_hnilr>   r   )r   r   r   r   r^   r_   r   r   r   r   r   r   r   r   r   r   r   r   r     s    zlsoda.__init__c           
      C   s  |rD| j d u r| jd u rd}q| j d u r.d| _ | jd u r>d| _d}n>| j d u r^| jd u r^d}n$| j d u rnd| _ | jd u r~d| _d}d| jd |  }|dv rd| jd |  ||  }n8|d	v rd| jd d| j  | j  |  }ntd
| t||}d| }t|ft}| j|d< | j	|d< | j
|d< || _t|ft}	| jd urT| j|	d< | j d urj| j |	d< | j|	d< | j|	d< | j|	d< | j|	d< | j|	d< |	| _| j| jdd| j| j|g| _d| _d| _d S )Nr   r   r   r'   r   r   )r   r'   r   )r   r   zUnexpected jt=%sr      r   F)r[   rZ   r   r   r9   maxr   ra   r   r   r   r   _lsoda_int_dtyper   r   r   r   r   r   r   r>   r   )
r   rt   ru   ZjtZlrnZlrsr   r   r   r   r   r   r   r%   	  sX    



$











zlsoda.resetc                 C   s   | j r|   nd| _ |   ||||g| jd d  || jd |d|g }| j| \}	}
}|| _|dk rd|d}tjd| j	j
| j||dd d| _nd| jd	< d| _|	|
fS )
NTrP   r   r   r   r   r'   r(   r   )r   rs   rr   r   r|   r@   r+   r,   r   ro   rK   r   r`   r>   r   r   r   r   r7   ;  s(    

z	lsoda.runc                 G   s,   | j d }d| j d< | j| }|| j d< |S r   r   r   r   r   r   r4   P  s
    



z
lsoda.stepc                 G   s,   | j d }d| j d< | j| }|| j d< |S r   r   r   r   r   r   r6   W  s
    



zlsoda.run_relax)Fr   r   NNr   r   r   r   r   r   r   r   N)rK   rL   rM   r\   r   r|   rp   r   r   r%   r7   r4   r6   r   r   r   r   r     s8               
!2r   )&rN   __all__rg   r+   numpyr   r   r   r   r   r	   r
   r   r   r   r   typesZintvarZdtyper   r   r   r   rR   r   r*   rl   rk   re   r   r   r|   rf   appendr]   r   r   r   r   r   r   r   <module>   sL   O$


   Z !0 H
DT% 