How to compute functional involving test function

5 months ago by
Generally speaking, how does one compute a post-processing functional involving the computed solution and the test function?
Community: FEniCS Project

1 Answer

5 months ago by
Using the same syntax as usual (The following is a MWE, check out the last couple of lines):
from fenics import *

mesh = UnitSquareMesh(4,4)
FE = FiniteElement('Lagrange', mesh.ufl_cell(), 1)
V = FunctionSpace(mesh, FE)

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

# Simple Poisson problem
def boundary(x, on_boundary):
    return on_boundary
dbc = DirichletBC(V, Constant(0.), boundary)

f = Expression('pow(x[0],2)', element = FE)

a = inner(grad(u), grad(v))*dx
L = f*v*dx

#  u will contain the solution
u = Function(V)
solve(a==L, u, bcs=dbc)

# compute bilinear form with computed solution u
form = assemble(inner(grad(u),grad(v))*dx)
print form.get_local()[:]​
Please login to add an answer/comment or follow this question.

Similar posts:
Search »