19.06.2015 Views

A FEniCS Tutorial - FEniCS Project

A FEniCS Tutorial - FEniCS Project

A FEniCS Tutorial - FEniCS Project

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Figure 4: Example of visualizing the vector field ∇u by arrows at the nodes.<br />

V_g = VectorFunctionSpace(mesh, ’Lagrange’, 1)<br />

w = TrialFunction(V_g)<br />

v = TestFunction(V_g)<br />

a = inner(w, v)*dx<br />

L = inner(grad(u), v)*dx<br />

grad_u = Function(V_g)<br />

solve(a == L, grad_u)<br />

plot(grad_u, title=’grad(u)’)<br />

The boundary condition argument to solve is dropped since there are no essential<br />

boundary conditions in this problem. The new thing is basically that we<br />

work with a VectorFunctionSpace, since the unknown is now a vector field,<br />

instead of the FunctionSpace object for scalar fields. Figure 4 shows example<br />

of how Viper can visualize such a vector field.<br />

The scalar component fields of the gradient can be extracted as separate<br />

fields and, e.g., visualized:<br />

grad_u_x, grad_u_y = grad_u.split(deepcopy=True) # extract components<br />

plot(grad_u_x, title=’x-component of grad(u)’)<br />

plot(grad_u_y, title=’y-component of grad(u)’)<br />

The deepcopy=True argument signifies a deep copy, which is a general term in<br />

computer science implying that a copy of the data is returned. (The opposite,<br />

deepcopy=False, means a shallow copy, where the returned objects are just<br />

pointers to the original data.)<br />

27

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!