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 we identify the matrix M with entries M ij as above and the matrix K with<br />

entries<br />

∫<br />

K ij = ∇ˆφ i ·∇φ j dx. (77)<br />

Ω<br />

The matrix M is often called the ”mass matrix” while ”stiffness matrix” is a<br />

common nickname for K. The associated bilinear forms for these matrices, as<br />

we need them for the assembly process in a <strong>FEniCS</strong> program, become<br />

∫<br />

a K (u,v) = ∇u·∇vdx, (78)<br />

Ω<br />

∫<br />

a M (u,v) = uvdx. (79)<br />

Ω<br />

The linear system at each time level, written as AU k = b, can now be<br />

computed by first computing M and K, and then forming A = M + ∆tK at<br />

t = 0, while b is computed as b = MU k−1 +∆tMF k at each time level.<br />

The following modifications are needed in the d1_d2D.py program from the<br />

previous section in order to implement the new strategy of avoiding assembly<br />

at each time level:<br />

• Define separate forms a M and a K<br />

• Assemble a M to M and a K to K<br />

• Compute A = M +∆tK<br />

• Define f as an Expression<br />

• Interpolate the formula for f to a finite element function F k<br />

• Compute b = MU k−1 +∆tMF k<br />

The relevant code segments become<br />

# 1.<br />

a_K = inner(nabla_grad(u), nabla_grad(v))*dx<br />

a_M = u*v*dx<br />

# 2. and 3.<br />

M = assemble(a_M)<br />

K = assemble(a_K)<br />

A = M + dt*K<br />

# 4.<br />

f = Expression(’beta - 2 - 2*alpha’, beta=beta, alpha=alpha)<br />

# 5. and 6.<br />

while t

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

Saved successfully!

Ooh no, something went wrong!