ls_python/spatialDerivative.py
def upwindFirstENO3(data,dim,grid):
    '''
    Third order accurate upwind derivatives
    
    data: 2d or 3d Numpy array
    dim: dimension on which gradients are to be calculated
        I assume dim 0 is x -> so axis 1 in a numpy array
                 dim 1 is y -> axis 0 in numpy array
                 dim 3 is z (same)
        
    grid: grid object - here is used mainly for storing grid spacing, dx
    
    returns: upwind derivative phi_{dim}_plus, downwind derivative phi_{dim}_minus
    '''
    if dim == 0:
        axis = 1
    elif dim == 1:
        axis = 0
    else:
        axis = dim
        
    D1_minus_half = np.diff(data, prepend=1,axis=axis)/grid.dx #phi(i,j) - phi(i-1,j)
    D1_minus_3_2 = np.roll(D1_minus_half, 1, axis=axis) #phi(i-1,j) - phi(i-2,j)
    D1_minus_5_2 = np.roll(D1_minus_half, 2, axis=axis)#phi(i-2,j) - phi(i-3,j)
    
    D1_plus_half = np.roll(D1_minus_half, -1, axis=axis) #phi(i+1,j) - phi(i,j)
    D1_plus_3_2 = np.roll(D1_minus_half, -2, axis=axis) #phi(i+2,j) - phi(i+1,j)
    D1_plus_5_2 = np.roll(D1_minus_half, -3, axis=axis) #phi(i+3,j) - phi(i+2,j)
            
    D2 = (D1_plus_half - D1_minus_half)/(2*grid.dx) # defined at original grid point i
    D2_minus_1 = (D1_minus_half - D1_minus_3_2)/(2*grid.dx)
    D2_minus_2 = (D1_minus_3_2 - D1_minus_5_2)/(2*grid.dx)
    D2_plus_1 = (D1_plus_3_2- D1_plus_half)/(2*grid.dx)
    D2_plus_2 = (D1_plus_5_2-D1_plus_3_2)/(2*grid.dx)
            
    D3_minus_half = (D2 - D2_minus_1)/(3*grid.dx)
    D3_minus_3_2 = (D2_minus_1 - D2_minus_2)/(3*grid.dx)  

    D3_plus_half = (D2_plus_1 - D2)/(3*grid.dx)
    D3_plus_3_2 = (D2_plus_2 - D2_plus_1)/(3*grid.dx)

    cond_D2_plus = (np.abs(D2) < np.abs(D2_plus_1))
    cond_D2_minus = (np.abs(D2_minus_1) < np.abs(D2))

    cond_D3_plus_half_3_2 = (np.abs(D3_plus_half) < np.abs(D3_plus_3_2))    
    cond_D3_minus_3_2_half = (np.abs(D3_minus_3_2) < np.abs(D3_minus_half))
    cond_D3_minus_plus_half = (np.abs(D3_minus_half) < np.abs(D3_plus_half))
    
    
    phi_dim_plus = D1_plus_half + \
        (cond_D2_plus * D2 + (1 - cond_D2_plus) * D2_plus_1) * grid.dx + \
        (cond_D2_plus * (cond_D3_minus_plus_half * D3_minus_half + (1-cond_D3_minus_plus_half) * D3_plus_half) * (-1) + \
         (1-cond_D2_plus) * (cond_D3_plus_half_3_2 * D3_plus_half + (1-cond_D3_plus_half_3_2) * D3_plus_3_2) * 2) * (grid.dx ** 2)    
                
    phi_dim_minus = D1_minus_half + \
                    (cond_D2_minus * D2_minus_1 + (1-cond_D2_minus) * D2)*grid.dx + \
                    (cond_D2_minus * (cond_D3_minus_3_2_half * D3_minus_3_2 + (1-cond_D3_minus_3_2_half) * D3_minus_half)*2 + \
                    (1-cond_D2_minus) * (cond_D3_minus_plus_half * D3_minus_half + (1-cond_D3_minus_plus_half) * D3_plus_half) * (-1))*(grid.dx ** 2)
        
    return phi_dim_minus, phi_dim_plus

    Third order accurate upwind derivatives
    
    data: 2d or 3d Numpy array
    dim: dimension on which gradients are to be calculated
        I assume dim 0 is x -> so axis 1 in a numpy array
                 dim 1 is y -> axis 0 in numpy array
                 dim 3 is z (same)
        
    grid: grid object - here is used mainly for storing grid spacing, dx
    
    returns: upwind derivative phi_{dim}_plus, downwind derivative phi_{dim}_minus
    
Third order accurate upwind derivatives
data: 2d or 3d Numpy array
dim: dimension on which gradients are to be calculated
I assume dim 0 is x -> so axis 1 in a numpy array
dim 1 is y -> axis 0 in numpy array
dim 3 is z (same)

grid object - here is used mainly for storing grid spacing, dx

upwind derivative phi_{dim}_plus, downwind derivative phi_{dim}_minus
Third order accurate upwind derivatives data : 2d or 3d Numpy array dim : dimension on which gradients are to be calculated I assume dim 0 is x - > so axis 1 in a numpy array dim 1 is y - > axis 0 in numpy array dim 3 is z ( same ) grid object - here is used mainly for storing grid spacing dx upwind derivative phi_ { dim } _plus downwind derivative phi_ { dim } _minus
def upwindFirstENO3(data,dim,grid):
    if dim == 0:
        axis = 1
    elif dim == 1:
        axis = 0
    else:
        axis = dim
    D1_minus_half = np.diff(data, prepend=1,axis=axis)/grid.dx 
    D1_minus_3_2 = np.roll(D1_minus_half, 1, axis=axis) 
    D1_minus_5_2 = np.roll(D1_minus_half, 2, axis=axis)
    D1_plus_half = np.roll(D1_minus_half, -1, axis=axis) 
    D1_plus_3_2 = np.roll(D1_minus_half, -2, axis=axis) 
    D1_plus_5_2 = np.roll(D1_minus_half, -3, axis=axis) 
    D2 = (D1_plus_half - D1_minus_half)/(2*grid.dx) 
    D2_minus_1 = (D1_minus_half - D1_minus_3_2)/(2*grid.dx)
    D2_minus_2 = (D1_minus_3_2 - D1_minus_5_2)/(2*grid.dx)
    D2_plus_1 = (D1_plus_3_2- D1_plus_half)/(2*grid.dx)
    D2_plus_2 = (D1_plus_5_2-D1_plus_3_2)/(2*grid.dx)
    D3_minus_half = (D2 - D2_minus_1)/(3*grid.dx)
    D3_minus_3_2 = (D2_minus_1 - D2_minus_2)/(3*grid.dx)  
    D3_plus_half = (D2_plus_1 - D2)/(3*grid.dx)
    D3_plus_3_2 = (D2_plus_2 - D2_plus_1)/(3*grid.dx)
    cond_D2_plus = (np.abs(D2) < np.abs(D2_plus_1))
    cond_D2_minus = (np.abs(D2_minus_1) < np.abs(D2))
    cond_D3_plus_half_3_2 = (np.abs(D3_plus_half) < np.abs(D3_plus_3_2))    
    cond_D3_minus_3_2_half = (np.abs(D3_minus_3_2) < np.abs(D3_minus_half))
    cond_D3_minus_plus_half = (np.abs(D3_minus_half) < np.abs(D3_plus_half))
    phi_dim_plus = D1_plus_half + \
        (cond_D2_plus * D2 + (1 - cond_D2_plus) * D2_plus_1) * grid.dx + \
        (cond_D2_plus * (cond_D3_minus_plus_half * D3_minus_half + (1-cond_D3_minus_plus_half) * D3_plus_half) * (-1) + \
         (1-cond_D2_plus) * (cond_D3_plus_half_3_2 * D3_plus_half + (1-cond_D3_plus_half_3_2) * D3_plus_3_2) * 2) * (grid.dx ** 2)    
    phi_dim_minus = D1_minus_half + \
                    (cond_D2_minus * D2_minus_1 + (1-cond_D2_minus) * D2)*grid.dx + \
                    (cond_D2_minus * (cond_D3_minus_3_2_half * D3_minus_3_2 + (1-cond_D3_minus_3_2_half) * D3_minus_half)*2 + \
                    (1-cond_D2_minus) * (cond_D3_minus_plus_half * D3_minus_half + (1-cond_D3_minus_plus_half) * D3_plus_half) * (-1))*(grid.dx ** 2)
    return phi_dim_minus, phi_dim_plus
def upwindFirstENO3 ( data , dim , grid ) : if dim == 0 : axis = 1 elif dim == 1 : axis = 0 else : axis = dim D1_minus_half = np . diff ( data , prepend = 1 , axis = axis ) / grid . dx D1_minus_3_2 = np . roll ( D1_minus_half , 1 , axis = axis ) D1_minus_5_2 = np . roll ( D1_minus_half , 2 , axis = axis ) D1_plus_half = np . roll ( D1_minus_half , - 1 , axis = axis ) D1_plus_3_2 = np . roll ( D1_minus_half , - 2 , axis = axis ) D1_plus_5_2 = np . roll ( D1_minus_half , - 3 , axis = axis ) D2 = ( D1_plus_half - D1_minus_half ) / ( 2 * grid . dx ) D2_minus_1 = ( D1_minus_half - D1_minus_3_2 ) / ( 2 * grid . dx ) D2_minus_2 = ( D1_minus_3_2 - D1_minus_5_2 ) / ( 2 * grid . dx ) D2_plus_1 = ( D1_plus_3_2 - D1_plus_half ) / ( 2 * grid . dx ) D2_plus_2 = ( D1_plus_5_2 - D1_plus_3_2 ) / ( 2 * grid . dx ) D3_minus_half = ( D2 - D2_minus_1 ) / ( 3 * grid . dx ) D3_minus_3_2 = ( D2_minus_1 - D2_minus_2 ) / ( 3 * grid . dx ) D3_plus_half = ( D2_plus_1 - D2 ) / ( 3 * grid . dx ) D3_plus_3_2 = ( D2_plus_2 - D2_plus_1 ) / ( 3 * grid . dx ) cond_D2_plus = ( np . abs ( D2 ) < np . abs ( D2_plus_1 ) ) cond_D2_minus = ( np . abs ( D2_minus_1 ) < np . abs ( D2 ) ) cond_D3_plus_half_3_2 = ( np . abs ( D3_plus_half ) < np . abs ( D3_plus_3_2 ) ) cond_D3_minus_3_2_half = ( np . abs ( D3_minus_3_2 ) < np . abs ( D3_minus_half ) ) cond_D3_minus_plus_half = ( np . abs ( D3_minus_half ) < np . abs ( D3_plus_half ) ) phi_dim_plus = D1_plus_half + ( cond_D2_plus * D2 + ( 1 - cond_D2_plus ) * D2_plus_1 ) * grid . dx + ( cond_D2_plus * ( cond_D3_minus_plus_half * D3_minus_half + ( 1 - cond_D3_minus_plus_half ) * D3_plus_half ) * ( - 1 ) + ( 1 - cond_D2_plus ) * ( cond_D3_plus_half_3_2 * D3_plus_half + ( 1 - cond_D3_plus_half_3_2 ) * D3_plus_3_2 ) * 2 ) * ( grid . dx ** 2 ) phi_dim_minus = D1_minus_half + ( cond_D2_minus * D2_minus_1 + ( 1 - cond_D2_minus ) * D2 ) * grid . dx + ( cond_D2_minus * ( cond_D3_minus_3_2_half * D3_minus_3_2 + ( 1 - cond_D3_minus_3_2_half ) * D3_minus_half ) * 2 + ( 1 - cond_D2_minus ) * ( cond_D3_minus_plus_half * D3_minus_half + ( 1 - cond_D3_minus_plus_half ) * D3_plus_half ) * ( - 1 ) ) * ( grid . dx ** 2 ) return phi_dim_minus , phi_dim_plus
Third order accurate upwind derivatives
data: 2d or 3d Numpy array
dim: dimension on which gradients are to be calculated
I assume dim 0 is x -> so axis 1 in a numpy array
dim 1 is y -> axis 0 in numpy array
dim 3 is z (same)
Third order accurate upwind derivatives data : 2d or 3d Numpy array dim : dimension on which gradients are to be calculated I assume dim 0 is x - > so axis 1 in a numpy array dim 1 is y - > axis 0 in numpy array dim 3 is z ( same )
'''
    Third order accurate upwind derivatives
    
    data: 2d or 3d Numpy array
    dim: dimension on which gradients are to be calculated
        I assume dim 0 is x -> so axis 1 in a numpy array
                 dim 1 is y -> axis 0 in numpy array
                 dim 3 is z (same)
        
    grid: grid object - here is used mainly for storing grid spacing, dx
    
    returns: upwind derivative phi_{dim}_plus, downwind derivative phi_{dim}_minus
    ''' #phi(i,j) - phi(i-1,j) #phi(i-1,j) - phi(i-2,j) #phi(i-2,j) - phi(i-3,j) #phi(i+1,j) - phi(i,j) #phi(i+2,j) - phi(i+1,j) #phi(i+3,j) - phi(i+2,j) # defined at original grid point i
data
dim
grid