|
| 1 | +# Copyright (C) 2022 Jørgen S. Dokken |
| 2 | +# |
| 3 | +# This file is part of FFCx. |
| 4 | +# |
| 5 | +# FFC is free software: you can redistribute it and/or modify |
| 6 | +# it under the terms of the GNU Lesser General Public License as published by |
| 7 | +# the Free Software Foundation, either version 3 of the License, or |
| 8 | +# (at your option) any later version. |
| 9 | +# |
| 10 | +# FFC is distributed in the hope that it will be useful, |
| 11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +# GNU Lesser General Public License for more details. |
| 14 | +# |
| 15 | +# You should have received a copy of the GNU Lesser General Public License |
| 16 | +# along with FFC. If not, see <http://www.gnu.org/licenses/>. |
| 17 | +# |
| 18 | +# Defines an Expression which evaluates the several different functions at |
| 19 | +# a set of interpolation points |
| 20 | + |
| 21 | +import basix |
| 22 | +from ufl import (Coefficient, FiniteElement, FunctionSpace, Mesh, MixedElement, |
| 23 | + VectorElement, grad, triangle) |
| 24 | + |
| 25 | +# Define mesh |
| 26 | +cell = triangle |
| 27 | +v_el = VectorElement("Lagrange", cell, 1) |
| 28 | +mesh = Mesh(v_el) |
| 29 | + |
| 30 | +# Define mixed function space |
| 31 | +el = FiniteElement("CG", cell, 2) |
| 32 | +el_int = VectorElement("Discontinuous Lagrange", cell, 1) |
| 33 | +me = MixedElement([el, el_int]) |
| 34 | +V = FunctionSpace(mesh, me) |
| 35 | +u = Coefficient(V) |
| 36 | + |
| 37 | +# Define expressions on each sub-space |
| 38 | +du0 = grad(u[0]) |
| 39 | +du1 = grad(u[1]) |
| 40 | + |
| 41 | +# Define an expression using quadrature elements |
| 42 | +q_rule = "gauss_jacobi" |
| 43 | +q_degree = 3 |
| 44 | +q_el = FiniteElement("Quadrature", cell, q_degree, quad_scheme=q_rule) |
| 45 | +Q = FunctionSpace(mesh, q_el) |
| 46 | +q = Coefficient(Q) |
| 47 | +powq = 3 * q**2 |
| 48 | + |
| 49 | +# Extract basix cell type |
| 50 | +b_cell = basix.cell.string_to_type(cell.cellname()) |
| 51 | + |
| 52 | +# Find quadrature points for quadrature element |
| 53 | +b_rule = basix.quadrature.string_to_type(q_rule) |
| 54 | +quadrature_points, _ = basix.make_quadrature(b_rule, b_cell, q_degree) |
| 55 | + |
| 56 | +# Get interpolation points for output space |
| 57 | +family = basix.finite_element.string_to_family("Lagrange", cell.cellname()) |
| 58 | +b_element = basix.create_element(family, b_cell, 4, basix.LagrangeVariant.gll_warped, True) |
| 59 | +interpolation_points = b_element.points |
| 60 | + |
| 61 | +# Create expressions that can be used for interpolation |
| 62 | +expressions = [(du0, interpolation_points), (du1, interpolation_points), |
| 63 | + (powq, quadrature_points)] |
0 commit comments