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.

• if u 1 is to be computed by projecting I:<br />

– define a 0 and L 0<br />

– assemble matrix M from a 0 and vector b from L 0<br />

– solve MU = b and store U in u 1<br />

• else: (interpolation)<br />

– let u 1 interpolate I<br />

• define a and L<br />

• assemble matrix A from a<br />

• set some stopping time T<br />

• t = ∆t<br />

• while t ≤ T<br />

– assemble vector b from L<br />

– apply essential boundary conditions<br />

– solve AU = b for U and store in u<br />

– t ← t+∆t<br />

– u 1 ← u (be ready for next step)<br />

Before starting the coding, we shall construct a problem where it is easy to<br />

determine if the calculations are correct. The simple backward time difference<br />

is exact for linear functions, so we decide to have a linear variation in time.<br />

Combining a second-degree polynomial in space with a linear term in time,<br />

u = 1+x 2 +αy 2 +βt, (76)<br />

yields a function whose computed values at the nodes may be exact, regardless<br />

of the size of the elements and ∆t, as long as the mesh is uniformly partitioned.<br />

By inserting (76) in the PDE problem (64), it follows that u 0 must be given as<br />

(76) and that f(x,y,t) = β −2−2α and I(x,y) = 1+x 2 +αy 2 .<br />

Anewprogrammingissueishowtodealwithfunctionsthatvaryinspaceand<br />

time, such as the the boundary condition u 0 given by (76). A natural solution<br />

is to apply an Expression object with time t as a parameter, in addition to the<br />

parameters α and β (see Section 1.7 forExpression objects with parameters):<br />

alpha = 3; beta = 1.2<br />

u0 = Expression(’1 + x[0]*x[0] + alpha*x[1]*x[1] + beta*t’,<br />

alpha=alpha, beta=beta, t=0)<br />

The time parameter can later be updated by assigning values to u0.t.<br />

Given a mesh and an associated function space V, we can specify the u 0<br />

function as<br />

61

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

Saved successfully!

Ooh no, something went wrong!