def plot_basis(self, p=2, q=20, plot=True): node = np.array([ (0.0, 0.0), (1.0, 0.0), (0.5, np.sqrt(3)/2)], dtype=np.float) cell = np.array([(0, 1, 2)], dtype=np.int) mesh = TriangleMesh(node, cell) space = LagrangeFiniteElementSpace(mesh, p=p) bc = space.multi_index_matrix[1](q)/q node = mesh.bc_to_point(bc) #( NQ, 1, 2) phi = space.basis(bc) # (NQ, 1, ldof) fig = plt.figure() axes = fig.gca(projection='3d') axes.plot_trisurf( node[..., 0].reshape(-1), node[..., 1].reshape(-1), phi[..., 0].reshape(-1), cmap='rainbow', lw=0.0, antialiased=True) axes.plot_trisurf( node[..., 0].reshape(-1), node[..., 1].reshape(-1), phi[..., 1].reshape(-1), cmap='rainbow', lw=0.0, antialiased=True) plt.show()
def uuu(p): x = p[..., 0] y = p[..., 1] pi = np.float128('3.141592653589793238462643383279502884197') val = np.sin(pi*x)*np.sin(pi*y) return val one = np.float128('1.0') zero = np.float128('0.0') node = np.array([ (zero, zero), (one, zero), (one, one), (zero, one)], dtype=np.float128) cell = np.array([(1, 2, 0), (3, 0, 2)], dtype=np.uint32) mesh = TriangleMesh(node, cell) area = mesh.entity_measure('cell') qf = TriangleQuadrature(k, ftype=node.dtype.type) bcs, ws = qf.quadpts, qf.weights p = mesh.bc_to_point(bcs) val = uu(p) a = np.float128('2.952492442012559756509852517869682817665821383151928174153192567074420535371962574241548128028788940') b = np.einsum('i, ij, j->', ws, val, area) print(np.abs(b - a))