Hello,
I have a function space $X$ on a mesh and a basis $v_1,\dots,v_n$ for a subspace $V\subseteq X$. Furthermore I have a second function space $U$ with basis $u_1,\dots,u_m$ and an operator $T:U \rightarrow X$.
I now want to assemble the matrix $L_{ij} := \langle T u_i, v_j \rangle$.
As a concrete example consider the following code snippet:
...
mesh = Mesh(...)
U = FunctionSpace(mesh, 'Lagrange', 1)
X = VectorFunctionSpace(mesh, 'DG', 0)
T = grad
u = TestFunction(U)
v = Function(X)
for j in range(n):
v.vector()[:] = V_basis[j]
a = inner(T(u),v)*dx
L[:,j] = assemble(a)
where V_basis
is a numpy array of length $n$, entry $j$ being an array of length X.dim()
, representing the DoF vector for the basis vector $v_j$.
This code seems to work but is really slow because of the many calls to assemble
.
Q: How can this be efficiently done in Fenics?
My hope is that I can somehow define a new VectorFunctionSpace
$V$ by providing my basis. Then the assembly would reduce to a simple
u = TestFunction(U)
v = TestFunction(V)
a = inner(T(u),v)*dx
L = assemble(a)
But I haven't figured out how to do this. What's the best way?
Thanks