Beispiel #1
0
def lap_div(pdof, grids, point):
    s = grids[0].shape
    ndim = len(grids)

    # Center div equation
    center_eq = div_eq( grids, point )

    # Initialize the equations
    div_lap_eqs = []
    for x in range( ndim ):
        div_lap_eqs.append( Equation() )

    for pp in ndimed.perturb(point):
        # PBC correction
        pp = ndimed.roller(pp, s)

        # If there is a single -3 dof, it must be a solid square
        if pdof[pp] < 0:
            continue
        
        pert_eq = div_eq(grids, pp)

        for dim in range(ndim):
            div_lap_eqs[dim] = div_lap_eqs[dim] + ( pert_eq[dim] - center_eq[dim] )

    return div_lap_eqs
Beispiel #2
0
def momentum_eq(dof_grid, point):
    # Correct for pbc's
    shape = dof_grid.shape
    ndim = len(shape)

    point = ndimed.roller(point, shape)
    
    # If solid . . . there is no momentum equation
    if dof_grid[ point ] < 0:
        return Equation()

    # DOF at the center point
    center_dof_num = dof_grid[ point ]

    m_eq = Equation()
    m_eq[ center_dof_num ]  = -2 * ndim

    # Move one step in each direction
    for p in ndimed.perturb( point ):
        # Wrap where necessary
        p = ndimed.roller(p, shape)

        # Get the current dof number
        current_dof = dof_grid[p]

        # If moving in one direction is a dof
        if   current_dof >=  0:
            # This could glitch if the domain is small enough
            # For the laplacian est. to touch itself (3x3 or smaller . . .)
            m_eq[ current_dof ] = 1

        # If it is solid
        elif current_dof == -2:
            continue

        # If it is completely enclosed solid
        elif current_dof == -3:
            m_eq[ center_dof_num ] -= 1
            
    return  m_eq