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.

mesh = UnitCircle(n)<br />

where n is the typical number of elements in the radial direction.<br />

The function f is represented by an Expression object. There are many<br />

physical parameters in the formula for f that enter the expression string and<br />

these parameters must have their values set by keyword arguments:<br />

f = Expression(’4*exp(-0.5*(pow((R*x[0] - x0)/sigma, 2)) ’<br />

’ - 0.5*(pow((R*x[1] - y0)/sigma, 2)))’,<br />

R=R, x0=x0, y0=y0, sigma=sigma)<br />

ThecoordinatesinExpressionobjectsmust beavectorwithindices0, 1, and2,<br />

and with the namex. Otherwise we are free to introduce names of parameters as<br />

long as these are given default values by keyword arguments. All the parameters<br />

initialized by keyword arguments can at any time have their values modified.<br />

For example, we may set<br />

f.sigma = 50<br />

f.x0 = 0.3<br />

It would be of interest to visualize f along with w so that we can examine<br />

the pressure force and its response. We must then transform the formula<br />

(Expression) to a finite element function (Function). The most natural approach<br />

is to construct a finite element function whose degrees of freedom (values<br />

at the nodes in this case) are calculated from f. That is, we interpolate f (see<br />

Section 1.6):<br />

f = interpolate(f, V)<br />

Callingplot(f) will produce a plot of f. Note that the assignment tofdestroys<br />

the previous Expression object f, so if it is of interest to still have access to<br />

this object, another name must be used for the Function object returned by<br />

interpolate.<br />

We need some evidence that the program works, and to this end we may use<br />

the analytical solution listed above for the case σ → ∞. In scaled coordinates<br />

the solution reads<br />

w(x,y) = 1−x 2 −y 2 .<br />

Practical values for an infinite σ may be 50 or larger, and in such cases the<br />

program will report the maximum deviation between the computed w and the<br />

(approximate) exact w e .<br />

Note that the variational formulation remains the same as in the program<br />

from Section 1.3, except that u is replaced by w and u 0 = 0. The final program<br />

is found in the file membrane1.py, located in the stationary/poisson directory,<br />

and also listed below. We have inserted capabilities for iterative solution<br />

methods and hence large meshes (Section 1.4), used objects for the variational<br />

problem and solver (Section 1.5), and made numerical comparison of the numerical<br />

and (approximate) analytical solution (Section 1.6).<br />

22

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

Saved successfully!

Ooh no, something went wrong!