RacRho.py
def rdPDE(t, y, D, Di, dx):
    """
    The ODEs are derived using the method of lines.
    https://docs.scipy.org/doc/scipy/reference/tutorial/integrate.html#mol
    """
    # The vectors R, Ri, rho, rhoi are interleaved in y for computational speed
    # every fourth entry is...
    R = y[0::4]
    Ri = y[1::4]
    rho = y[2::4]
    rhoi = y[3::4]

    # dydt is the return value of this function.
    dydt = np.empty_like(y)

    dRdt = dydt[0::4]
    dRidt = dydt[1::4]
    drhodt = dydt[2::4]
    drhoidt = dydt[3::4]

    dRdt[0]    = f(R[0],    Ri[0],    rho[0],    rhoi[0]) +  D * (-2.0*R[0] + 2.0*R[1]) / dx**2
    dRdt[1:-1] = f(R[1:-1], Ri[1:-1], rho[1:-1], rhoi[1:-1]) +  D * np.diff(R,2) / dx**2
    dRdt[-1]   = f(R[-1],   Ri[-1],   rho[-1],   rhoi[-1]) +  D * (-2.0*R[-1] + 2.0*R[-2]) / dx**2

    dRidt[0]    = -f(R[0],    Ri[0],    rho[0],    rhoi[0]) +  Di * (-2.0*Ri[0] + 2.0*Ri[1]) / dx**2
    dRidt[1:-1] = -f(R[1:-1], Ri[1:-1], rho[1:-1], rhoi[1:-1]) +  Di * np.diff(Ri,2) / dx**2
    dRidt[-1]   = -f(R[-1],   Ri[-1],   rho[-1],   rhoi[-1]) +  Di * (-2.0*Ri[-1] + 2.0*Ri[-2]) / dx**2

    drhodt[0]    = g(R[0],    Ri[0],    rho[0],    rhoi[0]) +  D * (-2.0*rho[0] + 2.0*rho[1]) / dx**2
    drhodt[1:-1] = g(R[1:-1], Ri[1:-1], rho[1:-1], rhoi[1:-1]) +  D * np.diff(rho,2) / dx**2
    drhodt[-1]   = g(R[-1],   Ri[-1],   rho[-1],   rhoi[-1]) +  D * (-2.0*rho[-1] + 2.0*rho[-2]) / dx**2

    drhoidt[0]    = -g(R[0],    Ri[0],    rho[0],    rhoi[0]) +  Di * (-2.0*rhoi[0] + 2.0*rhoi[1]) / dx**2
    drhoidt[1:-1] = -g(R[1:-1], Ri[1:-1], rho[1:-1], rhoi[1:-1]) +  Di * np.diff(rhoi,2) / dx**2
    drhoidt[-1]   = -g(R[-1],   Ri[-1],   rho[-1],   rhoi[-1]) +  Di * (-2.0*rhoi[-1] + 2.0*rhoi[-2]) / dx**2

    dydt[0::4] = dRdt
    dydt[1::4] = dRidt
    dydt[2::4] = drhodt
    dydt[3::4] = drhoidt

    return dydt

    The ODEs are derived using the method of lines.
    https://docs.scipy.org/doc/scipy/reference/tutorial/integrate.html#mol
    
The ODEs are derived using the method of lines.
The ODEs are derived using the method of lines .
def rdPDE(t, y, D, Di, dx):
    R = y[0::4]
    Ri = y[1::4]
    rho = y[2::4]
    rhoi = y[3::4]
    dydt = np.empty_like(y)
    dRdt = dydt[0::4]
    dRidt = dydt[1::4]
    drhodt = dydt[2::4]
    drhoidt = dydt[3::4]
    dRdt[0]    = f(R[0],    Ri[0],    rho[0],    rhoi[0]) +  D * (-2.0*R[0] + 2.0*R[1]) / dx**2
    dRdt[1:-1] = f(R[1:-1], Ri[1:-1], rho[1:-1], rhoi[1:-1]) +  D * np.diff(R,2) / dx**2
    dRdt[-1]   = f(R[-1],   Ri[-1],   rho[-1],   rhoi[-1]) +  D * (-2.0*R[-1] + 2.0*R[-2]) / dx**2
    dRidt[0]    = -f(R[0],    Ri[0],    rho[0],    rhoi[0]) +  Di * (-2.0*Ri[0] + 2.0*Ri[1]) / dx**2
    dRidt[1:-1] = -f(R[1:-1], Ri[1:-1], rho[1:-1], rhoi[1:-1]) +  Di * np.diff(Ri,2) / dx**2
    dRidt[-1]   = -f(R[-1],   Ri[-1],   rho[-1],   rhoi[-1]) +  Di * (-2.0*Ri[-1] + 2.0*Ri[-2]) / dx**2
    drhodt[0]    = g(R[0],    Ri[0],    rho[0],    rhoi[0]) +  D * (-2.0*rho[0] + 2.0*rho[1]) / dx**2
    drhodt[1:-1] = g(R[1:-1], Ri[1:-1], rho[1:-1], rhoi[1:-1]) +  D * np.diff(rho,2) / dx**2
    drhodt[-1]   = g(R[-1],   Ri[-1],   rho[-1],   rhoi[-1]) +  D * (-2.0*rho[-1] + 2.0*rho[-2]) / dx**2
    drhoidt[0]    = -g(R[0],    Ri[0],    rho[0],    rhoi[0]) +  Di * (-2.0*rhoi[0] + 2.0*rhoi[1]) / dx**2
    drhoidt[1:-1] = -g(R[1:-1], Ri[1:-1], rho[1:-1], rhoi[1:-1]) +  Di * np.diff(rhoi,2) / dx**2
    drhoidt[-1]   = -g(R[-1],   Ri[-1],   rho[-1],   rhoi[-1]) +  Di * (-2.0*rhoi[-1] + 2.0*rhoi[-2]) / dx**2
    dydt[0::4] = dRdt
    dydt[1::4] = dRidt
    dydt[2::4] = drhodt
    dydt[3::4] = drhoidt
    return dydt
def rdPDE ( t , y , D , Di , dx ) : R = y [ 0 : : 4 ] Ri = y [ 1 : : 4 ] rho = y [ 2 : : 4 ] rhoi = y [ 3 : : 4 ] dydt = np . empty_like ( y ) dRdt = dydt [ 0 : : 4 ] dRidt = dydt [ 1 : : 4 ] drhodt = dydt [ 2 : : 4 ] drhoidt = dydt [ 3 : : 4 ] dRdt [ 0 ] = f ( R [ 0 ] , Ri [ 0 ] , rho [ 0 ] , rhoi [ 0 ] ) + D * ( - 2.0 * R [ 0 ] + 2.0 * R [ 1 ] ) / dx ** 2 dRdt [ 1 : - 1 ] = f ( R [ 1 : - 1 ] , Ri [ 1 : - 1 ] , rho [ 1 : - 1 ] , rhoi [ 1 : - 1 ] ) + D * np . diff ( R , 2 ) / dx ** 2 dRdt [ - 1 ] = f ( R [ - 1 ] , Ri [ - 1 ] , rho [ - 1 ] , rhoi [ - 1 ] ) + D * ( - 2.0 * R [ - 1 ] + 2.0 * R [ - 2 ] ) / dx ** 2 dRidt [ 0 ] = - f ( R [ 0 ] , Ri [ 0 ] , rho [ 0 ] , rhoi [ 0 ] ) + Di * ( - 2.0 * Ri [ 0 ] + 2.0 * Ri [ 1 ] ) / dx ** 2 dRidt [ 1 : - 1 ] = - f ( R [ 1 : - 1 ] , Ri [ 1 : - 1 ] , rho [ 1 : - 1 ] , rhoi [ 1 : - 1 ] ) + Di * np . diff ( Ri , 2 ) / dx ** 2 dRidt [ - 1 ] = - f ( R [ - 1 ] , Ri [ - 1 ] , rho [ - 1 ] , rhoi [ - 1 ] ) + Di * ( - 2.0 * Ri [ - 1 ] + 2.0 * Ri [ - 2 ] ) / dx ** 2 drhodt [ 0 ] = g ( R [ 0 ] , Ri [ 0 ] , rho [ 0 ] , rhoi [ 0 ] ) + D * ( - 2.0 * rho [ 0 ] + 2.0 * rho [ 1 ] ) / dx ** 2 drhodt [ 1 : - 1 ] = g ( R [ 1 : - 1 ] , Ri [ 1 : - 1 ] , rho [ 1 : - 1 ] , rhoi [ 1 : - 1 ] ) + D * np . diff ( rho , 2 ) / dx ** 2 drhodt [ - 1 ] = g ( R [ - 1 ] , Ri [ - 1 ] , rho [ - 1 ] , rhoi [ - 1 ] ) + D * ( - 2.0 * rho [ - 1 ] + 2.0 * rho [ - 2 ] ) / dx ** 2 drhoidt [ 0 ] = - g ( R [ 0 ] , Ri [ 0 ] , rho [ 0 ] , rhoi [ 0 ] ) + Di * ( - 2.0 * rhoi [ 0 ] + 2.0 * rhoi [ 1 ] ) / dx ** 2 drhoidt [ 1 : - 1 ] = - g ( R [ 1 : - 1 ] , Ri [ 1 : - 1 ] , rho [ 1 : - 1 ] , rhoi [ 1 : - 1 ] ) + Di * np . diff ( rhoi , 2 ) / dx ** 2 drhoidt [ - 1 ] = - g ( R [ - 1 ] , Ri [ - 1 ] , rho [ - 1 ] , rhoi [ - 1 ] ) + Di * ( - 2.0 * rhoi [ - 1 ] + 2.0 * rhoi [ - 2 ] ) / dx ** 2 dydt [ 0 : : 4 ] = dRdt dydt [ 1 : : 4 ] = dRidt dydt [ 2 : : 4 ] = drhodt dydt [ 3 : : 4 ] = drhoidt return dydt
The ODEs are derived using the method of lines.
The ODEs are derived using the method of lines .
"""
    The ODEs are derived using the method of lines.
    https://docs.scipy.org/doc/scipy/reference/tutorial/integrate.html#mol
    """ # The vectors R, Ri, rho, rhoi are interleaved in y for computational speed # every fourth entry is... # dydt is the return value of this function.
t
y
D
Di
dx