19.06.2015 Views

A FEniCS Tutorial - FEniCS Project

A FEniCS Tutorial - FEniCS Project

A FEniCS Tutorial - FEniCS Project

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

numerical u at the center point: [ 1.83333333]<br />

exact u at the center point: [ 1.75]<br />

The discrepancy is due to the fact that the center point is not a node in this<br />

particular mesh, but a point in the interior of a cell, and u varies linearly over<br />

the cell while u0 is a quadratic function.<br />

We have seen how to extract the nodal values in a numpy array. If desired,<br />

we can adjust the nodal values too. Say we want to normalize the solution such<br />

that max j U j = 1. Then we must divide all U j values by max j U j . The following<br />

snippet performs the task:<br />

max_u = u_array.max()<br />

u_array /= max_u<br />

u.vector()[:] = u_array<br />

u.vector().set_local(u_array) # alternative<br />

print u.vector().array()<br />

That is, we manipulate u_array as desired, and then we insert this array into<br />

‘u‘’s Vector object. The /= operator implies an in-place modification of the<br />

object on the left-hand side: all elements of the u_array are divided by the<br />

value max_u. Alternatively, one could write u_array = u_array/max_u, which<br />

implies creating a new array on the right-hand side and assigning this array to<br />

the name u_array.<br />

A call like u.vector().array() returns a copy of the data in u.vector().<br />

Onemustthereforeneverperformassignmentslikeu.vector.array()[:] = ...,<br />

but instead extract the numpy array (i.e., a copy), manipulate it, and insert it<br />

back with u.vector()[:] = or u.set_local(...).<br />

All the code in this subsection can be found in the file d4_p2D.py in the<br />

stationary/poisson directory. We have commented out the plotting statements<br />

in this version of the program, but if you want plotting to happen, make<br />

sure that interactive is called at the very end of the program.<br />

1.7 Solving a Real Physical Problem<br />

Perhaps you are not particularly amazed by viewing the simple surface of u in<br />

the test problem from Section 1.3. However, solving a real physical problem<br />

with a more interesting and amazing solution on the screen is only a matter of<br />

specifying a more exciting domain, boundary condition, and/or right-hand side<br />

f.<br />

One possible physical problem regards the deflection D(x,y) of an elastic<br />

circular membrane with radius R, subject to a localized perpendicular pressure<br />

force, modeled as a Gaussian function. The appropriate PDE model is<br />

−T∇ 2 D = p(x,y) in Ω = {(x,y)|x 2 +y 2 ≤ R}, (14)<br />

with<br />

p(x,y) = A<br />

2πσ exp (− 1 2<br />

( ) 2 x−x0<br />

− 1 ( ) ) 2 y −y0<br />

. (15)<br />

σ 2 σ<br />

20

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

Saved successfully!

Ooh no, something went wrong!