# Path: pyamg/gallery/fem.py
# def check_mesh(V, E):
# def generate_quadratic(V, E, return_edges=False):
# def diameter(V, E):
# def refine2dtri(V, E, marked_elements=None):
# def l2norm(u, mesh):
#         def basis1(x, y):
#         def basis2(x, y):
#     def __init__(self, V, E, degree=1):
#     def generate_quadratic(self):
#     def refine(self, levels):
#     def smooth(self, maxit=10, tol=0.01):
# def _compute_diffusion_matrix(kappa_lmbda, x, y):
# def gradgradform(mesh, kappa=None, f=None, degree=1):
#         def f(_x, _y):
#         def kappa(_x, _y):
# def divform(mesh):
# def applybc(A, b, mesh, bc):
# def stokes(mesh, fu, fv):
# def model(num=0):
#     E01 = np.vstack((V[E[:, 1], 0] - V[E[:, 0], 0],
#                      V[E[:, 1], 1] - V[E[:, 0], 1],
#                      np.zeros(E.shape[0]))).T
#     E12 = np.vstack((V[E[:, 2], 0] - V[E[:, 1], 0],
#                      V[E[:, 2], 1] - V[E[:, 1], 1],
#                      np.zeros(E.shape[0]))).T
#     ID = np.kron(np.arange(0, ne), np.ones((3,), dtype=int))
#     G = sparse.coo_matrix((np.ones((ne*3,), dtype=int), (E.ravel(), ID,)))
#     V2V = G * G.T
#     V = np.vstack((V, Vmid))
#     E = np.hstack((E, np.zeros((E.shape[0], 3), dtype=int)))
#     E[:, 3] = V2Vmid[E[:, 0], E[:, 1]]
#     E[:, 4] = V2Vmid[E[:, 1], E[:, 2]]
#     E[:, 5] = V2Vmid[E[:, 2], E[:, 0]]
#     I = [0, 1, 2, 0]
#     V2V = sparse.coo_matrix((data, (row, col)), shape=(Nel, Nv))
#     V2V = V2V.T * V2V
#     V = np.vstack((V, V_new))
#         V = mesh.V
#         E = mesh.E
#         V = mesh.V2
#         E = mesh.E2
#         I = np.arange(3)
#         I = np.arange(6)
#             I = np.where(ids)[0]
#             J = np.arange(E.max()+1)
#             J[I] = np.arange(nv)
#             E = J[E]
#             V = V[I, :]
#         G = sparse.coo_matrix((data, (edge0, edge1)), shape=(nv, nv))
#         W = np.array(G.sum(axis=1)).flatten()
#         E = mesh.E
#         X = mesh.X
#         Y = mesh.Y
#         E = mesh.E2
#         X = mesh.X2
#         Y = mesh.Y2
#     AA = np.zeros((ne, m**2))
#     IA = np.zeros((ne, m**2), dtype=int)
#     JA = np.zeros((ne, m**2), dtype=int)
#         K = E[ei, :]
#         J = np.array([[x1 - x0, x2 - x0],
#                       [y1 - y0, y2 - y0]])
#     A = sparse.coo_matrix((AA.ravel(), (IA.ravel(), JA.ravel())))
#     X, Y = mesh.X, mesh.Y
#     E = mesh.E2
#     DX = np.zeros((ne, m1*m2))
#     DXI = np.zeros((ne, m1*m2), dtype=int)
#     DXJ = np.zeros((ne, m1*m2), dtype=int)
#     DY = np.zeros((ne, m1*m2))
#     DYI = np.zeros((ne, m1*m2), dtype=int)
#     DYJ = np.zeros((ne, m1*m2), dtype=int)
#         K = E[ei, :]
#         J = np.array([[x1 - x0, x2 - x0],
#                       [y1 - y0, y2 - y0]])
#         BX = sparse.coo_matrix((DX.ravel(), (DXI.ravel(), DXJ.ravel())))
#         BY = sparse.coo_matrix((DY.ravel(), (DYI.ravel(), DYJ.ravel())))
#             X = mesh.X
#             Y = mesh.Y
#             X = mesh.X2
#             Y = mesh.Y2
#     BX, BY = divform(mesh)
#     C = sparse.bmat([[Au, None, BX.T],
#                      [None, Av, BY.T],
#                      [BX, BY, None]])
# class Mesh:


import sys
import numpy as np
import matplotlib as mplt
import matplotlib.pyplot as plt
import shapely.geometry as sg
import pyamg
from scipy.io import loadmat
from shapely.ops import cascaded_union
from pyamg.gallery.fem import mesh, gradgradform
                    coords = list(zip(V[[i,j1], 0], V[[i,j1],1]))
                    newobj = sg.LineString(coords)         # add a line object to the list
                    todraw.append(newobj)

        todraw = cascaded_union(todraw)                    # union all objects in the aggregate
        todraw = todraw.buffer(0.1)                        # expand to smooth
        todraw = todraw.buffer(-0.05)                      # then contract

        try:
            xs, ys = todraw.exterior.xy                    # get all of the exterior points
            ax.fill(xs, ys, color=color,
                    clip_on=False)                         # fill with a color
        except:
            print('uh oh')
            pass                                           # when does this happen

    # aggregate edges
    Edges = np.vstack((A.tocoo().row,A.tocoo().col)).T  # edges of the matrix graph
    inner_edges = AggOp.indices[Edges[:,0]] == AggOp.indices[Edges[:,1]]
    aggs = V[Edges[inner_edges].ravel(),:].reshape((-1, 2, 2))
    col = mplt.collections.LineCollection(aggs,
                                          color=edgecolor,
                                          linewidth=lw)
    ax.add_collection(col, autolim=True)

    ax.set_aspect('equal')

X = loadmat('pyamg.mat')
V = X['vertices']
E = X['elements']

# Path: pyamg/gallery/fem.py
# def check_mesh(V, E):
# def generate_quadratic(V, E, return_edges=False):
# def diameter(V, E):
# def refine2dtri(V, E, marked_elements=None):
# def l2norm(u, mesh):
#         def basis1(x, y):
#         def basis2(x, y):
#     def __init__(self, V, E, degree=1):
#     def generate_quadratic(self):
#     def refine(self, levels):
#     def smooth(self, maxit=10, tol=0.01):
# def _compute_diffusion_matrix(kappa_lmbda, x, y):
# def gradgradform(mesh, kappa=None, f=None, degree=1):
#         def f(_x, _y):
#         def kappa(_x, _y):
# def divform(mesh):
# def applybc(A, b, mesh, bc):
# def stokes(mesh, fu, fv):
# def model(num=0):
#     E01 = np.vstack((V[E[:, 1], 0] - V[E[:, 0], 0],
#                      V[E[:, 1], 1] - V[E[:, 0], 1],
#                      np.zeros(E.shape[0]))).T
#     E12 = np.vstack((V[E[:, 2], 0] - V[E[:, 1], 0],
#                      V[E[:, 2], 1] - V[E[:, 1], 1],
#                      np.zeros(E.shape[0]))).T
#     ID = np.kron(np.arange(0, ne), np.ones((3,), dtype=int))
#     G = sparse.coo_matrix((np.ones((ne*3,), dtype=int), (E.ravel(), ID,)))
#     V2V = G * G.T
#     V = np.vstack((V, Vmid))
#     E = np.hstack((E, np.zeros((E.shape[0], 3), dtype=int)))
#     E[:, 3] = V2Vmid[E[:, 0], E[:, 1]]
#     E[:, 4] = V2Vmid[E[:, 1], E[:, 2]]
#     E[:, 5] = V2Vmid[E[:, 2], E[:, 0]]
#     I = [0, 1, 2, 0]
#     V2V = sparse.coo_matrix((data, (row, col)), shape=(Nel, Nv))
#     V2V = V2V.T * V2V
#     V = np.vstack((V, V_new))
#         V = mesh.V
#         E = mesh.E
#         V = mesh.V2
#         E = mesh.E2
#         I = np.arange(3)
#         I = np.arange(6)
#             I = np.where(ids)[0]
#             J = np.arange(E.max()+1)
#             J[I] = np.arange(nv)
#             E = J[E]
#             V = V[I, :]
#         G = sparse.coo_matrix((data, (edge0, edge1)), shape=(nv, nv))
#         W = np.array(G.sum(axis=1)).flatten()
#         E = mesh.E
#         X = mesh.X
#         Y = mesh.Y
#         E = mesh.E2
#         X = mesh.X2
#         Y = mesh.Y2
#     AA = np.zeros((ne, m**2))
#     IA = np.zeros((ne, m**2), dtype=int)
#     JA = np.zeros((ne, m**2), dtype=int)
#         K = E[ei, :]
#         J = np.array([[x1 - x0, x2 - x0],
#                       [y1 - y0, y2 - y0]])
#     A = sparse.coo_matrix((AA.ravel(), (IA.ravel(), JA.ravel())))
#     X, Y = mesh.X, mesh.Y
#     E = mesh.E2
#     DX = np.zeros((ne, m1*m2))
#     DXI = np.zeros((ne, m1*m2), dtype=int)
#     DXJ = np.zeros((ne, m1*m2), dtype=int)
#     DY = np.zeros((ne, m1*m2))
#     DYI = np.zeros((ne, m1*m2), dtype=int)
#     DYJ = np.zeros((ne, m1*m2), dtype=int)
#         K = E[ei, :]
#         J = np.array([[x1 - x0, x2 - x0],
#                       [y1 - y0, y2 - y0]])
#         BX = sparse.coo_matrix((DX.ravel(), (DXI.ravel(), DXJ.ravel())))
#         BY = sparse.coo_matrix((DY.ravel(), (DYI.ravel(), DYJ.ravel())))
#             X = mesh.X
#             Y = mesh.Y
#             X = mesh.X2
#             Y = mesh.Y2
#     BX, BY = divform(mesh)
#     C = sparse.bmat([[Au, None, BX.T],
#                      [None, Av, BY.T],
#                      [BX, BY, None]])
# class Mesh:


# Path: docs/logo/pyamg_logo.py
import sys
import numpy as np
import matplotlib as mplt
import matplotlib.pyplot as plt
import shapely.geometry as sg
import pyamg
from scipy.io import loadmat
from shapely.ops import cascaded_union
from pyamg.gallery.fem import mesh, gradgradform

                    coords = list(zip(V[[i,j1], 0], V[[i,j1],1]))
                    newobj = sg.LineString(coords)         # add a line object to the list
                    todraw.append(newobj)

        todraw = cascaded_union(todraw)                    # union all objects in the aggregate
        todraw = todraw.buffer(0.1)                        # expand to smooth
        todraw = todraw.buffer(-0.05)                      # then contract

        try:
            xs, ys = todraw.exterior.xy                    # get all of the exterior points
            ax.fill(xs, ys, color=color,
                    clip_on=False)                         # fill with a color
        except:
            print('uh oh')
            pass                                           # when does this happen

    # aggregate edges
    Edges = np.vstack((A.tocoo().row,A.tocoo().col)).T  # edges of the matrix graph
    inner_edges = AggOp.indices[Edges[:,0]] == AggOp.indices[Edges[:,1]]
    aggs = V[Edges[inner_edges].ravel(),:].reshape((-1, 2, 2))
    col = mplt.collections.LineCollection(aggs,
                                          color=edgecolor,
                                          linewidth=lw)
    ax.add_collection(col, autolim=True)

    ax.set_aspect('equal')

X = loadmat('pyamg.mat')
V = X['vertices']
E = X['elements']

mesh = mesh(V, E)