def test_vandermond_matrix_type(cell): points = np.ones((4, cell.dim)) v = vandermonde_matrix(cell, 2, points) assert isinstance(v, np.ndarray), \ "vandermonde matrix must return a numpy array, not a %s" % type(v)
def test_vandermond_matrix_rank(cell): points = np.ones((4, cell.dim)) v = vandermonde_matrix(cell, 2, points) assert len(v.shape) == 2, \ "vandermonde matrix must return a rank 2 array, not rank %s" % len(v.shape)
def test_init_finite_element(cell): nodes = cell.vertices fe = FiniteElement(cell, 1, nodes) v = vandermonde_matrix(cell, 1, nodes) assert (np.round(np.dot(fe.basis_coefs, v) - np.eye(cell.dim + 1)) == 0).all()
def test_vandermonde_matrix_size(cell, degree): points = np.ones((1, cell.dim)) shape = vandermonde_matrix(cell, degree, points).shape correct_shape = (1, np.round(comb(degree + cell.dim, cell.dim))) assert shape == correct_shape, \ "vandermonde matrix should have returned an array of shape %s, not %s"\ % (correct_shape, shape)
def test_vandermonde_matrix_values_1D(degree): points = np.array([[0.], [1.], [2.]]) V = vandermonde_matrix(ReferenceInterval, degree, points) V_t = np.array([[1] + [0] * (V.shape[1] - 1), [1] * V.shape[1], [2**d for d in range(V.shape[1])]]) print "Vandermonde matrix is:" print V print "Correct answer is:" print V_t assert (V == V_t).all()
def test_vandermonde_matrix_grad_values_1D(degree): points = np.array([[0], [1]]) V = vandermonde_matrix(ReferenceInterval, degree, points, grad=True) V_t = np.array([[0] + ([1] if degree > 0 else []) + [0] * (V.shape[1]-2), range(V.shape[1])]).reshape((2, V.shape[1], 1)) print "Vandermonde matrix is:" print V print "Correct answer is:" print V_t assert (V == V_t).all()
def test_vandermonde_matrix_values_2D(degree): points = np.array([[0., 0.], [1., 1.], [1., 0.], [0., 1.]]) V = vandermonde_matrix(ReferenceTriangle, degree, points) V_t = np.array([[1] + [0] * (V.shape[1] - 1), [1] * V.shape[1], [1 if p == 0 else 0 for d in range(degree+1) for p in range(d+1)], [1 if p == d else 0 for d in range(degree+1) for p in range(d+1)]]) print("Vandermonde matrix is:") print(V) print("Correct answer is:") print(V_t) assert (V == V_t).all()
def test_vandermonde_matrix_grad_values_2D(degree): points = np.array([[0., 0.], [1., 0.], [0., 1.]]) V = vandermonde_matrix(ReferenceTriangle, degree, points, grad=True) V_t = np.array([[[0, 0]] + ([[1, 0], [0, 1]] if degree > 0 else []) + [[0, 0]] * (V.shape[1] - 3), [[d, 0] if p == 0 else [0, 1] if p == 1 else [0, 0] for d in range(degree+1) for p in range(d+1)], [[0, d] if p == d else [1, 0] if p == d - 1 else [0, 0] for d in range(degree+1) for p in range(d+1)]]) print "Vandermonde matrix is:" print V print "Correct answer is:" print V_t assert (V == V_t).all()