1
# This demo program dmonstrates how to create simple finite
2
# element matrices like the stiffness matrix and mass matrix.
4
# Modified by Anders Logg, 2008
6
__author__ = "Kristian B. Oelgaard (k.b.oelgaard@tudelft.nl)"
7
__date__ = "2007-11-15 -- 2008-01-15"
8
__copyright__ = "Copyright (C) 2007 Kristian B. Oelgaard"
9
__license__ = "GNU LGPL Version 2.1"
14
# Load reference mesh (just a simple tetrahedron)
15
mesh = Mesh("../tetrahedron.xml.gz");
17
# Assemble stiffness and mass matrices
18
element = FiniteElement("Lagrange", "tetrahedron", 1)
19
v = TestFunction(element)
20
u = TrialFunction(element)
21
A = assemble(dot(grad(v), grad(u))*dx, mesh)
22
M = assemble(v*u*dx, mesh)
24
# Create reference matrices and set entries
27
pos = numpy.array([0, 1, 2, 3], dtype='I')
28
A0.set(numpy.array([[1.0/2.0, -1.0/6.0, -1.0/6.0, -1.0/6.0],
29
[-1.0/6.0, 1.0/6.0, 0.0, 0.0],
30
[-1.0/6.0, 0.0, 1.0/6.0, 0.0],
31
[-1.0/6.0, 0.0, 0.0, 1.0/6.0]]), pos, pos)
33
M0.set(numpy.array([[1.0/60.0, 1.0/120.0, 1.0/120.0, 1.0/120.0],
34
[1.0/120.0, 1.0/60.0, 1.0/120.0, 1.0/120.0],
35
[1.0/120.0, 1.0/120.0, 1.0/60.0, 1.0/120.0],
36
[1.0/120.0, 1.0/120.0, 1.0/120.0, 1.0/60.0]]), pos, pos)
42
print "Assembled stiffness matrix:"
47
print "Reference stiffness matrix:"
51
print "Assembled mass matrix:"
55
print "Reference mass matrix:"