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.

which is nothing but a linear system,<br />

AU = b,<br />

where the entries in A and b are given by<br />

A ij = a(φ j , ˆφ i ),<br />

b i = L(ˆφ i ).<br />

The examples so far have specified the left- and right-hand side of the variational<br />

formulation and then asked <strong>FEniCS</strong> to assemble the linear system and<br />

solve it. An alternative to is explicitly call functions for assembling the coefficient<br />

matrix A and the right-side vector b, and then solve the linear system<br />

AU = b with respect to the U vector. Instead of solve(a == L, u, bc) we<br />

now write<br />

A = assemble(a)<br />

b = assemble(L)<br />

bc.apply(A, b)<br />

u = Function(V)<br />

U = u.vector()<br />

solve(A, U, b)<br />

The variables a and L are as before. That is, a refers to the bilinear form<br />

involving a TrialFunction object (say u) and a TestFunction object (v), and<br />

L involves a TestFunction object (v). From a and L, the assemble function<br />

can compute A and b.<br />

The matrix A and vector b are first assembled without incorporating essential<br />

(Dirichlet) boundary conditions. Thereafter, the call bc.apply(A, b)<br />

performs the necessary modifications of the linear system such that u is guaranteed<br />

to equal the prescribed boundary values. When we have multiple Dirichlet<br />

conditions stored in a list bcs, as explained in Section 1.14, we must apply each<br />

condition in bcs to the system:<br />

# bcs is a list of DirichletBC objects<br />

for bc in bcs:<br />

bc.apply(A, b)<br />

There is an alternative function assemble_system, which can assemble the<br />

system and take boundary conditions into account in one call:<br />

A, b = assemble_system(a, L, bcs)<br />

The assemble_system function incorporates the boundary conditions in the<br />

element matrices and vectors, prior to assembly. The conditions are also incorporated<br />

in a symmetric way to preserve eventual symmetry of the coefficient<br />

matrix. Withbc.apply(A, b) the matrix A is modified in an unsymmetric way.<br />

Note that the solution u is, as before, a Function object. The degrees of<br />

freedom, U = A −1 b, are filled into ‘u‘’s Vector object (u.vector()) by the<br />

solve function.<br />

44

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

Saved successfully!

Ooh no, something went wrong!