Example #1
0
s  = assemble(dot(grad(u), N) * v * ds)
M  = assemble(w * v * dx)
b  = assemble(l)
K  = assemble(a)

t  = (np.dot(K.array(),uv) - b.array())

q = Function(Q, name='q')
q.vector().set_local(t)
q.vector().apply('insert')

File('output/q.pvd') << q

fx = Function(Q, name='fx')
solve(M, fx.vector(), s)
File('output/fx.pvd') << fx

fig = figure(figsize=(10,5))
ax1 = fig.add_subplot(121)
ax2 = fig.add_subplot(122)

plot_matrix(M.array(), ax1, r'mass matrix $M$',      continuous=True)
plot_matrix(K.array(), ax2, r'stiffness matrix $K$', continuous=False)

tight_layout()
show()




Example #2
0
  return x[0] == 0 and on_boundary

bc = DirichletBC(Q, 0.0, left)

solve(a == l, u, bc)

File('output/u.pvd') << u

uv = u.vector().array()
b  = assemble(l).array()
A  = assemble(a).array()

t  = np.dot(A,uv) - b

q = Function(Q, name='q')
q.vector().set_local(t)
q.vector().apply('insert')

File('output/q.pvd') << q

fig = figure()
ax  = fig.add_subplot(111)

plot_matrix(A, ax, r'stiffness matrix $K$', continuous=False)

tight_layout()
show()