Outer Product between two vectors to form a sparse matrix

Hi,

I want to assemble cross product of 2 vectors to the matrix. Here is the matrix;

D_{jk} = \int_{\Omega} \phi_i e^{i \omega \tau(\textbf{x})} d\textbf{x} \int_{\Omega} \frac{1}{\rho_0 (\chi)} \nabla{\phi_j} \cdot \textbf{n}_{ref} d\chi

When I try that, I am having ufl error;

  File "/home/ekrem/Dev/Venvs/dolfinx_v050/lib/python3.10/site-packages/ufl/constantvalue.py", line 437, in as_ufl
    raise UFLValueError("Invalid type conversion: %s can not be converted"
ufl.log.UFLValueError: Invalid type conversion: <dolfinx.fem.forms.Form object at 0x7f324e9b1710> can not be converted to any UFL type.

Here is my MWE;

from dolfinx.fem import Function, FunctionSpace, form
from ufl import Measure, TestFunction, TrialFunction, inner, as_vector, grad, exp, cross, dx
from dolfinx.mesh import create_unit_cube
from mpi4py import MPI
from dolfinx.fem.petsc import assemble_matrix

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

rho = 1.25

degree = 1
V = FunctionSpace(mesh, ("Lagrange", degree))
 
phi_i = TrialFunction(V)
phi_j = TestFunction(V)

omega = 10
tau = 0.001

n_ref = as_vector([0,0,1])
        
left_vector  = form( phi_i  *  exp(1j*omega*tau)  *  dx)
right_vector = form(inner(n_ref,grad(phi_j)) / rho  * dx)

total_form = cross(left_vector, right_vector)

D = assemble_matrix(total_form)
D.assemble()

How could I get my matrix assembled?

Thanks in advance.

What you are doing here is mixing compiled forms (i.e. C kernels for assembly) with ufl syntax.

The operation that you are trying to do, the outer product of two vectors is not trivial as far as I’m aware, as it requires quite alot of communication to make a dense matrix. PETSc for instance does not recommend ever assembling this matrix: [petsc-users] vector outer product

1 Like