def test_point_average(cell, degree): p = lagrange_points(cell, degree) average = np.sum(p, 0) / p.shape[0] assert all(np.round(average - 1./(cell.dim + 1), 12) == 0)
def test_point_count(cell, degree): p = lagrange_points(cell, degree) assert p.shape[0] == np.round(comb(degree + cell.dim, cell.dim))
def test_point_shape(): assert lagrange_points(ReferenceInterval, 1).shape == (2, 1), \ "In 1D, lagrange_points must return a list of 1-vectors, not a list of floats"
def test_point_type(cell): assert isinstance(lagrange_points(cell, 1), np.ndarray), \ "Return type of lagrange_points must be numpy array"
fe = LagrangeElement(cells[dim], degree) if dim == 1: x = np.linspace(0, 1, 100) x.shape = (100, 1) fig = plt.figure() ax = fig.add_subplot(111) y = fe.tabulate(x) for y_ in y.T: plt.plot(x, y_) if dim == 2: x = lagrange_points(ReferenceTriangle, 20) z = fe.tabulate(x) fig = plt.figure(figsize=(20, 4)) ax = fig.gca(projection='3d') offsets = fe.nodes * fe.degree * 1.1 for o, z_ in zip(offsets, z.T): ax.plot_trisurf(x[:, 0] + o[0], x[:, 1] + o[1], z_, cmap=cm.RdBu, linewidth=0) plt.show()
from matplotlib import pyplot as plt from fe_utils.finite_elements import lagrange_points from fe_utils import ReferenceTriangle from argparse import ArgumentParser parser = ArgumentParser(description="""Plot the nodes on the reference triangle""") parser.add_argument("degree", type=int, nargs=1, help="The degree of Lagrange polynomials for which to plot the nodes") if __name__=="__main__": args = parser.parse_args() fig = plt.figure() ax = fig.add_subplot(111) p = lagrange_points(ReferenceTriangle, args.degree[0]) plt.plot(p[:, 0], p[:, 1], 'bo') for i, x in enumerate(p): ax.annotate(str(i), xy=x, xytext=(10, 0), textcoords='offset points') ax.axis([-.1, 1.1, -.1, 1.1]) plt.show()