ls_python/spatialDerivative.py
def upwindFirstENO2(data,dim,grid):
    '''
    Second order accurate upwind derivatives using ENO2
    
    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_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)
            
    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_plus_1 = (D1_plus_3_2- D1_plus_half)/(2*grid.dx)

    cond_D2_plus = (np.abs(D2) < np.abs(D2_plus_1))
    cond_D2_minus = (np.abs(D2_minus_1) < np.abs(D2))
    
    phi_dim_plus = D1_plus_half + \
        (cond_D2_plus * D2 + (1 - cond_D2_plus) * D2_plus_1) * grid.dx
                
    phi_dim_minus = D1_minus_half + \
                    (cond_D2_minus * D2_minus_1 + (1-cond_D2_minus) * D2)*grid.dx         
    return phi_dim_minus, phi_dim_plus

    Second order accurate upwind derivatives using ENO2
    
    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
    
Second order accurate upwind derivatives using ENO2
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
Second order accurate upwind derivatives using ENO2 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 upwindFirstENO2(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_plus_half = np.roll(D1_minus_half, -1, axis=axis) 
    D1_plus_3_2 = np.roll(D1_minus_half, -2, 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_plus_1 = (D1_plus_3_2- D1_plus_half)/(2*grid.dx)
    cond_D2_plus = (np.abs(D2) < np.abs(D2_plus_1))
    cond_D2_minus = (np.abs(D2_minus_1) < np.abs(D2))
    phi_dim_plus = D1_plus_half + \
        (cond_D2_plus * D2 + (1 - cond_D2_plus) * D2_plus_1) * grid.dx
    phi_dim_minus = D1_minus_half + \
                    (cond_D2_minus * D2_minus_1 + (1-cond_D2_minus) * D2)*grid.dx         
    return phi_dim_minus, phi_dim_plus
def upwindFirstENO2 ( 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_plus_half = np . roll ( D1_minus_half , - 1 , axis = axis ) D1_plus_3_2 = np . roll ( D1_minus_half , - 2 , 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_plus_1 = ( D1_plus_3_2 - D1_plus_half ) / ( 2 * grid . dx ) cond_D2_plus = ( np . abs ( D2 ) < np . abs ( D2_plus_1 ) ) cond_D2_minus = ( np . abs ( D2_minus_1 ) < np . abs ( D2 ) ) phi_dim_plus = D1_plus_half + ( cond_D2_plus * D2 + ( 1 - cond_D2_plus ) * D2_plus_1 ) * grid . dx phi_dim_minus = D1_minus_half + ( cond_D2_minus * D2_minus_1 + ( 1 - cond_D2_minus ) * D2 ) * grid . dx return phi_dim_minus , phi_dim_plus
Second order accurate upwind derivatives using ENO2
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)
Second order accurate upwind derivatives using ENO2 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 )
'''
    Second order accurate upwind derivatives using ENO2
    
    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+1,j) - phi(i,j) #phi(i+2,j) - phi(i+1,j) # defined at original grid point i
data
dim
grid