def test_morley(): ref_cell = FIAT.ufc_simplex(2) ref_element = finat.Morley(ref_cell, 2) ref_pts = finat.point_set.PointSet(ref_cell.make_points(2, 0, 4)) phys_cell = FIAT.ufc_simplex(2) phys_cell.vertices = ((0.0, 0.1), (1.17, -0.09), (0.15, 1.84)) mapping = MyMapping(ref_cell, phys_cell) z = (0, 0) finat_vals_gem = ref_element.basis_evaluation(0, ref_pts, coordinate_mapping=mapping)[z] finat_vals = evaluate([finat_vals_gem])[0].arr phys_cell_FIAT = FIAT.Morley(phys_cell) phys_points = phys_cell.make_points(2, 0, 4) phys_vals = phys_cell_FIAT.tabulate(0, phys_points)[z] assert np.allclose(finat_vals, phys_vals.T)
def test_awnc(): ref_cell = FIAT.ufc_simplex(2) ref_el_finat = finat.ArnoldWintherNC(ref_cell, 2) ref_element = ref_el_finat._element ref_pts = ref_cell.make_points(2, 0, 3) ref_vals = ref_element.tabulate(0, ref_pts)[0, 0] phys_cell = FIAT.ufc_simplex(2) phys_cell.vertices = ((0.0, 0.0), (2.0, 0.1), (0.0, 1.0)) phys_element = ref_element.__class__(phys_cell, 2) phys_pts = phys_cell.make_points(2, 0, 3) phys_vals = phys_element.tabulate(0, phys_pts)[0, 0] # Piola map the reference elements J, b = FIAT.reference_element.make_affine_mapping(ref_cell.vertices, phys_cell.vertices) detJ = np.linalg.det(J) ref_vals_piola = np.zeros(ref_vals.shape) for i in range(ref_vals.shape[0]): for k in range(ref_vals.shape[3]): ref_vals_piola[i, :, :, k] = \ J @ ref_vals[i, :, :, k] @ J.T / detJ**2 # Zany map the results mappng = MyMapping(ref_cell, phys_cell) Mgem = ref_el_finat.basis_transformation(mappng) M = evaluate([Mgem])[0].arr ref_vals_zany = np.zeros((15, 2, 2, len(phys_pts))) for k in range(ref_vals_zany.shape[3]): for ell1 in range(2): for ell2 in range(2): ref_vals_zany[:, ell1, ell2, k] = \ M @ ref_vals_piola[:, ell1, ell2, k] assert np.allclose(ref_vals_zany[:12], phys_vals[:12])
def __init__(self, L, order): assert L.ref_el == FIAT.ufc_simplex(1) for ell in L.dual.nodes: assert isinstance(ell, FIAT.functional.PointEvaluation) c = numpy.asarray([list(ell.pt_dict.keys())[0][0] for ell in L.dual.nodes]) num_stages = len(c) Q = FIAT.make_quadrature(L.ref_el, 2*num_stages) qpts = Q.get_points() qwts = Q.get_weights() Lvals = L.tabulate(0, qpts)[0, ] # integrates them all! b = Lvals @ qwts # now for A, which means we have to adjust the interval A = numpy.zeros((num_stages, num_stages)) for i in range(num_stages): qpts_i = qpts * c[i] qwts_i = qwts * c[i] Lvals_i = L.tabulate(0, qpts_i)[0, ] A[i, :] = Lvals_i @ qwts_i Aexplicit = numpy.zeros((num_stages, num_stages)) for i in range(num_stages): qpts_i = 1 + qpts * c[i] qwts_i = qwts * c[i] Lvals_i = L.tabulate(0, qpts_i)[0, ] Aexplicit[i, :] = Lvals_i @ qwts_i self.Aexplicit = Aexplicit V = vander(c, increasing=True) rhs = numpy.array([1.0/(s+1) for s in range(num_stages-1)] + [0]) btilde = numpy.linalg.solve(V.T, rhs) super(CollocationButcherTableau, self).__init__(A, b, btilde, c, order)
def cell(request): dim = request.param return FIAT.ufc_simplex(dim)
def gauss_lobatto_legendre_line_rule(degree): fiat_make_rule = FIAT.quadrature.GaussLobattoLegendreQuadratureLineRule fiat_rule = fiat_make_rule(FIAT.ufc_simplex(1), degree + 1) finat_ps = finat.point_set.GaussLobattoLegendrePointSet finat_qr = finat.quadrature.QuadratureRule return finat_qr(finat_ps(fiat_rule.get_points()), fiat_rule.get_weights())
def reference_cell(dim): if isinstance(dim, int): return FIAT.ufc_simplex(dim) else: return FIAT.ufc_simplex(cellname2dim[dim])
def test_assembly_into_quadrature_function(): """Test assembly into a Quadrature function. This test evaluates a UFL Expression into a Quadrature function space by evaluating the Expression on all cells of the mesh, and then inserting the evaluated values into a PETSc Vector constructed from a matching Quadrature function space. Concretely, we consider the evaluation of: e = B*(K(T)))**2 * grad(T) where K = 1/(A + B*T) where A and B are Constants and T is a Coefficient on a P2 finite element space with T = x + 2*y. The result is compared with interpolating the analytical expression of e directly into the Quadrature space. In parallel, each process evaluates the Expression on both local cells and ghost cells so that no parallel communication is required after insertion into the vector. """ mesh = dolfinx.UnitSquareMesh(MPI.COMM_WORLD, 3, 6) quadrature_degree = 2 quadrature_points = FIAT.create_quadrature(FIAT.ufc_simplex( mesh.topology.dim), quadrature_degree, scheme="default").get_points() Q_element = ufl.VectorElement("Quadrature", ufl.triangle, quadrature_degree, quad_scheme="default") Q = dolfinx.FunctionSpace(mesh, Q_element) def T_exact(x): return x[0] + 2.0 * x[1] P2 = dolfinx.FunctionSpace(mesh, ("P", 2)) T = dolfinx.Function(P2) T.interpolate(T_exact) A = dolfinx.Constant(mesh, 1.0) B = dolfinx.Constant(mesh, 2.0) K = 1.0 / (A + B * T) e = B * K**2 * ufl.grad(T) e_expr = dolfinx.Expression(e, quadrature_points) map_c = mesh.topology.index_map(mesh.topology.dim) num_cells = map_c.size_local + map_c.num_ghosts cells = np.arange(0, num_cells, dtype=np.int32) e_eval = e_expr.eval(cells) # Assemble into Function e_Q = dolfinx.Function(Q) with e_Q.vector.localForm() as e_Q_local: e_Q_local.setValues(Q.dofmap.list.array, e_eval, addv=PETSc.InsertMode.INSERT) def e_exact(x): T = x[0] + 2.0 * x[1] K = 1.0 / (A.value + B.value * T) grad_T = np.zeros((2, x.shape[1])) grad_T[0, :] = 1.0 grad_T[1, :] = 2.0 e = B.value * K**2 * grad_T return e e_exact_Q = dolfinx.Function(Q) e_exact_Q.interpolate(e_exact) assert (np.isclose((e_exact_Q.vector - e_Q.vector).norm(), 0.0))
def __init__(self, num_stages): assert num_stages > 0 U = FIAT.ufc_simplex(1) L = FIAT.GaussLegendre(U, num_stages - 1) super(GaussLegendre, self).__init__(L, 2 * num_stages)
def __init__(self, num_stages): assert num_stages >= 1 U = FIAT.ufc_simplex(1) L = FIAT.GaussRadau(U, num_stages - 1) super(RadauIIA, self).__init__(L, 2 * num_stages - 1)
def __init__(self, num_stages): assert num_stages > 1 U = FIAT.ufc_simplex(1) L = FIAT.GaussLobattoLegendre(U, num_stages - 1) super(LobattoIIIA, self).__init__(L, 2 * num_stages - 2)