from IPython.core.display import HTML
from dolfin import *
# Create mesh and define function space
mesh = UnitCubeMesh(32, 32, 32)
V = FunctionSpace(mesh, "Lagrange", 1)
# Define Dirichlet boundary at the bottom face
def boundary(x):
return x[0] < DOLFIN_EPS
# Define boundary condition
bc = DirichletBC(V, Constant(0.0), boundary)
# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
f = Expression("10*exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2) + pow(x[2] - 0.5, 2)) / 0.02)", degree=1)
a = inner(grad(u), grad(v))*dx
L = f*v*dx
# Compute solution
u = Function(V)
solve(a == L, u, bc)
Calling FFC just-in-time (JIT) compiler, this may take some time.
HTML(X3DOM.html(u))