/
test_317.py
36 lines (28 loc) · 871 Bytes
/
test_317.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from dolfin import *
import matplotlib.pyplot as plt
import numpy as np
mesh = UnitIntervalMesh(10)
V = FunctionSpace(mesh, 'CG', 2)
f = interpolate(Expression('x[0]*x[0]', degree=2), V)
y = f.vector().array()
plt.figure()
plt.plot(y, linestyle='none', marker='o')
# As you noticed the coefficients are not ordered according
# to x coord of dofs. Get the x axis 'right' by e.g.
x = interpolate(Expression('x[0]', degree=1), V).vector().array()
# or
x0 = V.tabulate_dof_coordinates()
assert np.linalg.norm(x-x0) < DOLFIN_EPS
plt.figure()
plt.plot(x, y, linestyle='none', marker='o')
# This is better, but what if you wanted a line plot
plt.figure()
plt.plot(x, y)
# You see that the plot isn't quite right; the interior dofs of CG2 element are an
# issue. So finally
indices = np.argsort(x)
x = x[indices]
y = y[indices]
plt.figure()
plt.plot(x, y)
plt.show()