Solution array (u.vector().array()) does not correspond to mesh vertices
Hello,
Calling the solution as an array seems to scramble the results. For instance, printing the vertex coordinates and corresponding solutions in the poisson tutorial yields an erroneous solution. Does calling the expansion coefficients of the solution function indeed result in a scrambled array? If so, is there a work-around?
Thanks for your help.
Toby
Here is my code:
from pylab import *
from dolfin import *
#Create meash and define function space
mesh = UnitSquareMesh(6, 4)
V = FunctionSpace(mesh, 'Lagrange', 1)
#Define boundary conditions
u0 = Expression('1 + x[0]*x[0] + 2*x[1]*x[1]')
def u0_boundary(x, on_boundary):
return on_boundary
bc = DirichletBC(V, u0, u0_boundary)
#Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
f = Constant(-6.0)
a = inner(nabla_
L = f*v*dx
#Compute solution
u = Function(V)
solve(a == L, u, bc, solver_
#Grab all solution values 'u'
u_nodal_values = u.vector()
u_array = u_nodal_
#Get mesh information
coords = mesh.coordinates()
num_cells = mesh.num_cells()
num_vertices = mesh.num_vertices()
print mesh #Print mesh info
#print out solution and coordinates
if num_vertices == len(u_array):
for i in range(num_
print 'u(%8g,%8g) = %g' % (coor[i][0], coor[i][1], u_array[i])
Question information
- Language:
- English Edit question
- Status:
- Solved
- Assignee:
- No assignee Edit question
- Solved by:
- Johan Hake
- Solved:
- Last query:
- Last reply: