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.
Here, Γ 0 is the boundary x = 0, while Γ 1 corresponds to the boundary x = 1.<br />
We have that u L = 1+2y 2 , u R = 2+2y 2 , and g = −4y. For the left boundary<br />
Γ 0 we define the usual triple of a function for the boundary value, a function<br />
for defining the boundary of interest, and a DirichletBC object:<br />
u_L = Expression(’1 + 2*x[1]*x[1]’)<br />
def left_boundary(x, on_boundary):<br />
tol = 1E-14 # tolerance for coordinate comparisons<br />
return on_boundary and abs(x[0]) < tol<br />
Gamma_0 = DirichletBC(V, u_L, left_boundary)<br />
For the boundary x = 1 we write a similar code snippet:<br />
u_R = Expression(’2 + 2*x[1]*x[1]’)<br />
def right_boundary(x, on_boundary):<br />
tol = 1E-14 # tolerance for coordinate comparisons<br />
return on_boundary and abs(x[0] - 1) < tol<br />
Gamma_1 = DirichletBC(V, u_R, right_boundary)<br />
The various essential conditions are then collected in a list and used in the<br />
solution process:<br />
bcs = [Gamma_0, Gamma_1]<br />
...<br />
solve(a == L, u, bcs)<br />
# or<br />
problem = LinearVariationalProblem(a, L, u, bcs)<br />
solver = LinearVariationalSolver(problem)<br />
solver.solve()<br />
In other problems, where the u values are constant at a part of the boundary,<br />
we may use a simple Constant object instead of an Expression object.<br />
The file dn2_p2D.py contains a complete program which demonstrates the<br />
constructions above. An extended example with multiple Neumann conditions<br />
would have been quite natural now, but this requires marking various parts of<br />
theboundaryusingthemeshfunctionconceptandisthereforelefttoSection5.3.<br />
1.15 A Linear Algebra Formulation<br />
Given a(u,v) = L(v), the discrete solution u is computed by inserting u =<br />
∑ N<br />
j=1 U jφ j into a(u,v) and demanding a(u,v) = L(v) to be fulfilled for N test<br />
functions ˆφ 1 ,..., ˆφ N . This implies<br />
N∑<br />
a(φ j , ˆφ i )U j = L(ˆφ i ), i = 1,...,N,<br />
j=1<br />
43