This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Local assembly of bilinear form

+1 vote

How can one retrieve the local (elementwise) matrices corresponding to a bilinear form? I have tried to use a DG0 function and assemble the form but can't get it right. I know the following code does the trick but I'm asking if there are alternative ways as this isn't really efficient for large number of cells.

u = TrialFunction(V)
v = TestFunction(V)
cell_domains = CellFunction('size_t',mesh)
elnum = 10 % example
for c in cells(mesh):
    cell_domains[c] = c.index()
ml = assemble(inner(u,v)*dx(elnum), cell_domains = cell_domains)

Using a DG0 function is a nice trick for case of a linear form but it doesn't seem to work in this case as I don't think DOLFIN supports the assemby of multilinear forms.

asked Aug 24, 2014 by luftiq FEniCS Novice (560 points)
edited Sep 19, 2014 by luftiq

1 Answer

0 votes

What about something like this?

from dolfin import *

mesh = UnitSquareMesh(32,32)

V = FunctionSpace(mesh,'CG',1)

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

L = inner(grad(u),grad(v))*dx
local_matrices = [assemble_local(u*v*dx, c) for c in cells(mesh)]
answered Nov 25, 2016 by croci FEniCS Novice (140 points)
...