1
"""This demo program solves Poisson's equation
3
- div grad u(x, y) = f(x, y)
5
on the unit square with source f given by
7
f(x, y) = 500*exp(-((x-0.5)^2 + (y-0.5)^2)/0.02)
9
and boundary conditions given by
16
# Create mesh and finite element
17
mesh = UnitSquare(32, 32)
18
element = FiniteElement("Lagrange", "triangle", 1)
21
class Source(Function):
22
def __init__(self, element, mesh):
23
Function.__init__(self, element, mesh)
24
def eval(self, values, x):
27
values[0] = 500.0*exp(-(dx*dx + dy*dy)/0.02)
29
# Define variational problem
30
v = TestFunction(element)
31
u = TrialFunction(element)
32
f = Source(element, mesh)
34
a = dot(grad(v), grad(u))*dx
49
c = z.inner(b)/b.size()
51
print "type(b) ", type(b)
52
print "type(c) ", type(c)
57
print "zzzzzzzzzzzzzzz"
63
solve(A, x, b, gmres, amg)
69
u = Function(element, mesh, x)
72
# Save solution to file
73
file = File("poisson.pvd")