Evaluate PETSc matrix for form that has gradient of test function

Hi All,

I am trying to get PETSc matrix for following expression;

D = \int_{\Omega}(u \nabla v(\bf{x_r}) \cdot \bf{n_{ref}} )dx

where u is trial function and v is test function, n_{ref} is a some reference vector.

And x_r is reference points in the domain and it is numpy array.

Is it possible to get PETSc matrix for this expression in dolfinx?

My very basic try fails at derivative of test function at x_r;

from dolfinx.fem import Function, FunctionSpace
from dolfinx.generation import UnitCubeMesh
from dolfinx.fem.assemble import assemble_matrix
from mpi4py import MPI
import numpy as np
from ufl import TestFunction, TrialFunction

mesh = UnitCubeMesh(MPI.COMM_WORLD,10,10,10)

V = FunctionSpace(mesh, ("CG", 2))

x_r = np.array([[0.2, 0., 0.], [0.2, 0.2, 0.]])

n_ref = np.array([[0, 0, 1]]).T

u = TrialFunction(V)
v = TestFunction(V)

form = u * ... # ...... Stuck at here!

D = assemble_matrix(form)
D.assemble()


Is it achievable with dolfinx and ufl forms?

Thanks for your responses in advance.

As what you are doing is quite specific and does not really fall into the category of what ufl is used for, i would suggest creating a custom integration kernel.
Examples on how to do this with numba is for instance shown in:

shows how to compute the gradient based on tabulated data from basix