I am trying to minimize a goal function subject to constant
and non linear PDE constrains using pure FEniCS and the SNES solver).
I make just a few modifications on demo_contact-vi-snes.py
FEniCS undocumented example in order to put togheter
AdaptativeNonlinearSolver() and SNES solver with constrains:
from dolfin import *
# Check that DOLFIN is configured with PETSc and CGAL
if not has_petsc_snes():
print "DOLFIN must be compiled with PETSc version > 3.2 to run this demo."
exit(0)
# Create mesh
mesh = Mesh("../circle_yplane.xml.gz")
V = VectorFunctionSpace(mesh, "Lagrange", 1)
# Define functions
du = TrialFunction(V) # Incremental displacement
v = TestFunction(V) # Test function
u = Function(V) # Displacement from previous iteration
B = Constant((0.0, -0.05)) # Body force per unit volume
# Kinematics
I = Identity(u.geometric_dimension()) # Identity tensor
F = I + grad(u) # Deformation gradient
C = F.T*F # Right Cauchy-Green tensor
# Invariants of deformation tensors
Ic = tr(C)
J = det(F)
# Elasticity parameters
E, nu = 10.0, 0.3
mu, lmbda = Constant(E/(2*(1 + nu))), Constant(E*nu/((1 + nu)*(1 - 2*nu)))
# Stored strain energy density (compressible neo-Hookean model)
psi = (mu/2)*(Ic - 2) - mu*ln(J) + (lmbda/2)*(ln(J))**2
# Total potential energy
Pi = psi*dx - dot(B, u)*dx
# Compute first variation of Pi (directional derivative about u in the
# direction of v)
F = derivative(Pi, u, v)
# Compute Jacobian of F
J = derivative(F, u, du)
# Symmetry condition (to block rigid body rotations)
tol = mesh.hmin()
def symmetry_line(x):
return abs(x[0]) < DOLFIN_EPS
bc = DirichletBC(V.sub(0), 0., symmetry_line, method="pointwise")
# The displacement u must be such that the current configuration x+u
# remains in the box [xmin,xmax] x [umin,ymax]
constraint_u = Expression(("xmax - x[0]","ymax - x[1]"), \
xmax=1.0+DOLFIN_EPS, ymax=1.0)
constraint_l = Expression(("xmin - x[0]","ymin - x[1]"), \
xmin=-1.0-DOLFIN_EPS, ymin=-1.0)
umin = interpolate(constraint_l, V)
umax = interpolate(constraint_u, V)
# Define the solver parameters
snes_solver_parameters = {"nonlinear_solver": "snes",
# "snes_solver" : { "linear_solver" : "lu",
"snes_solver" : { "linear_solver" : "gmres",
"maximum_iterations": 20,
"report": True,
"error_on_nonconvergence": False,
}}
# Set up the non-linear problem
problem = NonlinearVariationalProblem(F, u, bc, J=J)
## Set up the non-linear solver
#solver = NonlinearVariationalSolver(problem)
# Set up ADAPTATIVE nonlinear variational solver
M = inner(u, u) * dx
solver = AdaptiveNonlinearVariationalSolver(problem, M)
solver.parameters.update(snes_solver_parameters)
info(solver.parameters, True)
# Solve the problem
#(iter, converged) = solver.solve(umin, umax)
tol = 1e-4
(iter, converged) = solver.solve(umin, umax, tol)
# Check for convergence
if not converged:
warning("This demo is a complex nonlinear problem. Convergence is not guaranteed when modifying some parameters or using PETSC 3.2.")
# plot the current configuration
#plot(mesh.leaf_node())
plot(u, mode="displacement", wireframe=True, title="Displacement field")
interactive()
I get the error message on IPython:
UMD has deleted: ffc_form_2c6189ee6e7552f3ae7149cd1a66cafddc787e02, ffc_form_f5d86247182239afb8fc545509df8ef49ecfa185.ffc_form_f5d86247182239afb8fc545509df8ef49ecfa185, dolfin_compile_code_ebc572334aeecce84beea04a5d8b711d, _ffc_form_f5d86247182239afb8fc545509df8ef49ecfa185, _ffc_form_2c6189ee6e7552f3ae7149cd1a66cafddc787e02, ffc_form_2c6189ee6e7552f3ae7149cd1a66cafddc787e02.ffc_form_2c6189ee6e7552f3ae7149cd1a66cafddc787e02, _dolfin_compile_code_ebc572334aeecce84beea04a5d8b711d, ffc_form_f5d86247182239afb8fc545509df8ef49ecfa185, _ffc_form_91664149f2882d60bf1907194a3e878266b41577, ffc_form_91664149f2882d60bf1907194a3e878266b41577.ffc_form_91664149f2882d60bf1907194a3e878266b41577, ffc_form_91664149f2882d60bf1907194a3e878266b41577
Traceback (most recent call last):
File "", line 1, in
runfile('/home/parallels/python_scripts/tese/non_linear_poisson/demo_nonlinear-poisson_snes_solver_v2.py', wdir='/home/parallels/python_scripts/tese/non_linear_poisson')
File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 540, in runfile
execfile(filename, namespace)
File "/home/parallels/python_scripts/tese/non_linear_poisson/demo_nonlinear-poisson_snes_solver_v2.py", line 38, in
solver.parameters.update(snes_solver_parameters)
File "/usr/lib/python2.7/dist-packages/dolfin/cpp/common.py", line 2108, in update
self_value = self[key]
File "/usr/lib/python2.7/dist-packages/dolfin/cpp/common.py", line 2089, in getitem
raise KeyError, "'%s'"%key
KeyError: "'snes_solver'"
How can I solve this problem? Any bound constrained Newton
method with iterative solver sounds well to.