(A, b, mesh, bc)
return A, b
Apply boundary conditions.

    Parameters
    ----------
    A : sparse matrix
        Fully assembled sparse matrix
    b : ndarray
        Fully assembled right-hand side
    mesh : Mesh
        Mesh object
    bc : list
       list of boundary conditions
       bc = [bc1, bc2, ..., bck]
       where bck = {'id': id,    a list of vertices for boundary "k"
                     'g': g,     g = g(x,y) is a function for the vertices on boundary "k"
                   'var': var    the variable, given as a start in the dof list
                'degree': degree degree of the variable, either 1 or 2
                   }

    Returns
    -------
    A : sparse matrix
        Modified, assembled sparse matrix
    b : ndarray
        Modified, assembled right-hand side
Apply boundary conditions.
Apply boundary conditions .
def applybc(A, b, mesh, bc):
    """Apply boundary conditions.

    Parameters
    ----------
    A : sparse matrix
        Fully assembled sparse matrix
    b : ndarray
        Fully assembled right-hand side
    mesh : Mesh
        Mesh object
    bc : list
       list of boundary conditions
       bc = [bc1, bc2, ..., bck]
       where bck = {'id': id,    a list of vertices for boundary "k"
                     'g': g,     g = g(x,y) is a function for the vertices on boundary "k"
                   'var': var    the variable, given as a start in the dof list
                'degree': degree degree of the variable, either 1 or 2
                   }

    Returns
    -------
    A : sparse matrix
        Modified, assembled sparse matrix
    b : ndarray
        Modified, assembled right-hand side
    """
    for c in bc:
        if not callable(c['g']):
            raise ValueError('each bc g must be callable functions')

        if 'degree' not in c.keys():
            c['degree'] = 1

        if 'var' not in c.keys():
            c['var'] = 0

    # now extend the BC
    # for each new id, are the orignal neighboring ids in a bc?
    for c in bc:
        if c['degree'] == 2:
            idx = c['id']
            newidx = []
            for j, ed in zip(mesh.newID, mesh.Edges):
                if ed[0] in idx and ed[1] in idx:
                    newidx.append(j)
            c['id'] = np.hstack((idx, newidx))

    # set BC in the right hand side
    # set the lifting function (1 of 3)
    u0 = np.zeros((A.shape[0],))
    for c in bc:
        idx = c['var'] + c['id']
        if c['degree'] == 1:
            X = mesh.X
            Y = mesh.Y
        elif c['degree'] == 2:
            X = mesh.X2
            Y = mesh.Y2
        u0[idx] = c['g'](X[idx], Y[idx])

    # lift (2 of 3)
    b = b - A * u0

    # fix the values (3 of 3)
    for c in bc:
        idx = c['var'] + c['id']
        b[idx] = u0[idx]

    # set BC to identity in the matrix
    # collect all BC indices (1 of 2)
    Dflag = np.full((A.shape[0],), False)
    for c in bc:
        idx = c['var'] + c['id']
        Dflag[idx] = True
    # write identity (2 of 2)
    for k, (i, j) in enumerate(zip(A.row, A.col)):
        if Dflag[i] or Dflag[j]:
            if i == j:
                A.data[k] = 1.0
            else:
                A.data[k] = 0.0

    return A, b
def applybc ( A , b , mesh , bc ) : for c in bc : if not callable ( c [ 'g' ] ) : raise ValueError ( 'each bc g must be callable functions' ) if 'degree' not in c . keys ( ) : c [ 'degree' ] = 1 if 'var' not in c . keys ( ) : c [ 'var' ] = 0 # now extend the BC # for each new id, are the orignal neighboring ids in a bc? for c in bc : if c [ 'degree' ] == 2 : idx = c [ 'id' ] newidx = [ ] for j , ed in zip ( mesh . newID , mesh . Edges ) : if ed [ 0 ] in idx and ed [ 1 ] in idx : newidx . append ( j ) c [ 'id' ] = np . hstack ( ( idx , newidx ) ) # set BC in the right hand side # set the lifting function (1 of 3) u0 = np . zeros ( ( A . shape [ 0 ] , ) ) for c in bc : idx = c [ 'var' ] + c [ 'id' ] if c [ 'degree' ] == 1 : X = mesh . X Y = mesh . Y elif c [ 'degree' ] == 2 : X = mesh . X2 Y = mesh . Y2 u0 [ idx ] = c [ 'g' ] ( X [ idx ] , Y [ idx ] ) # lift (2 of 3) b = b - A * u0 # fix the values (3 of 3) for c in bc : idx = c [ 'var' ] + c [ 'id' ] b [ idx ] = u0 [ idx ] # set BC to identity in the matrix # collect all BC indices (1 of 2) Dflag = np . full ( ( A . shape [ 0 ] , ) , False ) for c in bc : idx = c [ 'var' ] + c [ 'id' ] Dflag [ idx ] = True # write identity (2 of 2) for k , ( i , j ) in enumerate ( zip ( A . row , A . col ) ) : if Dflag [ i ] or Dflag [ j ] : if i == j : A . data [ k ] = 1.0 else : A . data [ k ] = 0.0 return A , b