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.
tol = 1E-14<br />
def left_boundary(x, on_boundary):<br />
return on_boundary and abs(x[0]) < tol<br />
def right_boundary(x, on_boundary):<br />
return on_boundary and abs(x[0]-1) < tol<br />
Gamma_0 = DirichletBC(V, Constant(0.0), left_boundary)<br />
Gamma_1 = DirichletBC(V, Constant(1.0), right_boundary)<br />
bcs = [Gamma_0, Gamma_1]<br />
# Define variational problem for initial guess (q(u)=1, i.e., m=0)<br />
u = TrialFunction(V)<br />
v = TestFunction(V)<br />
a = inner(nabla_grad(u), nabla_grad(v))*dx<br />
f = Constant(0.0)<br />
L = f*v*dx<br />
A, b = assemble_system(a, L, bcs)<br />
u_k = Function(V)<br />
U_k = u_k.vector()<br />
solve(A, U_k, b)<br />
Here, u_k denotes the solution function for the previous iteration, so that the<br />
solution after each Newton iteration is u = u_k + omega*du. Initially, u_k is<br />
the initial guess we call u 0 in the mathematics.<br />
TheDirichletboundaryconditionsforδu, intheproblemtobesolvedineach<br />
Newton iteration, are somewhat different than the conditions for u. Assuming<br />
that u k fulfills the Dirichlet conditions for u, δu must be zero at the boundaries<br />
where the Dirichlet conditions apply, in order for u k+1 = u k + ωδu to fulfill<br />
the right boundary values. We therefore define an additional list of Dirichlet<br />
boundary conditions objects for δu:<br />
Gamma_0_du = DirichletBC(V, Constant(0), left_boundary)<br />
Gamma_1_du = DirichletBC(V, Constant(0), right_boundary)<br />
bcs_du = [Gamma_0_du, Gamma_1_du]<br />
The nonlinear coefficient and its derivative must be defined before coding the<br />
weak form of the Newton system:<br />
def q(u):<br />
return (1+u)**m<br />
def Dq(u):<br />
return m*(1+u)**(m-1)<br />
du = TrialFunction(V) # u = u_k + omega*du<br />
a = inner(q(u_k)*nabla_grad(du), nabla_grad(v))*dx + \<br />
inner(Dq(u_k)*du*nabla_grad(u_k), nabla_grad(v))*dx<br />
L = -inner(q(u_k)*nabla_grad(u_k), nabla_grad(v))*dx<br />
The Newton iteration loop is very similar to the Picard iteration loop in<br />
Section 2.1:<br />
53