A FEniCS Tutorial - FEniCS Project
A FEniCS Tutorial - FEniCS Project
A FEniCS Tutorial - FEniCS Project
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
can be conveniently written in the standard notation: a 0 (u,v) = L 0 (v) for (70)<br />
and a(u,v) = L(v) for (71), where<br />
∫<br />
a 0 (u,v) = uvdx, (72)<br />
Ω<br />
∫<br />
L 0 (v) = Ivdx, (73)<br />
Ω<br />
∫<br />
a(u,v) = (uv +∆t∇u·∇v) dx, (74)<br />
Ω<br />
∫<br />
(<br />
L(v) = u k−1 +∆tf k) vdx. (75)<br />
Ω<br />
Thecontinuousvariationalproblemistofindu 0 ∈ V suchthata 0 (u 0 ,v) = L 0 (v)<br />
holds for all v ∈ ˆV, and then find u k ∈ V such that a(u k ,v) = L(v) for all v ∈ ˆV,<br />
k = 1,2,....<br />
Approximate solutions inspacearefoundbyrestrictingthefunctional spaces<br />
V and ˆV to finite-dimensional spaces, exactly as we have done in the Poisson<br />
problems. We shall use the symbol u for the finite element approximation at<br />
time t k . In case we need to distinguish this space-time discrete approximation<br />
from the exact solution of the continuous diffusion problem, we use ue for the<br />
latter. By u k−1 we mean, from now on, the finite element approximation of the<br />
solution at time t k−1 .<br />
Note that the forms a 0 and L 0 are identical to the forms met in Section 1.9,<br />
except that the test and trial functions are now scalar fields and not vector<br />
fields. Instead of solving (70) by a finite element method, i.e., projecting I<br />
onto V via the problem a 0 (u,v) = L 0 (v), we could simply interpolate u 0 from<br />
I. That is, if u 0 = ∑ N<br />
j=1 U0 j φ j, we simply set U j = I(x j ,y j ), where (x j ,y j )<br />
are the coordinates of node number j. We refer to these two strategies as<br />
computing the initial condition by either projecting I or interpolating I. Both<br />
operations areeasy to compute through one statement, usingeither theproject<br />
or interpolate function.<br />
3.2 Implementation<br />
Our program needs to perform the time stepping explicitly, but can rely on<br />
<strong>FEniCS</strong> to easily compute a 0 , L 0 , a, and L, and solve the linear systems for<br />
the unknowns. We realize that a does not depend on time, which means that<br />
its associated matrix also will be time independent. Therefore, it is wise to<br />
explicitly create matrices and vectors as in Section 1.15. The matrix A arising<br />
from a can be computed prior to the time stepping, so that we only need to<br />
compute the right-hand side b, corresponding to L, in each pass in the time<br />
loop. Let us express the solution procedure in algorithmic form, writing u for<br />
the unknown spatial function at the new time level (u k ) and u 1 for the spatial<br />
solution at one earlier time level (u k−1 ):<br />
• define Dirichlet boundary condition (u 0 , Dirichlet boundary, etc.)<br />
60