On 21 Nov 2013, at 12:00, [email protected] wrote:

> Send fenics mailing list submissions to
>       [email protected]
> 
> To subscribe or unsubscribe via the World Wide Web, visit
>       http://fenicsproject.org/mailman/listinfo/fenics
> or, via email, send a message with subject or body 'help' to
>       [email protected]
> 
> You can reach the person managing the list at
>       [email protected]
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of fenics digest..."
> 
> 
> Today's Topics:
> 
>   1. Newton and SNES parameters (Anders Logg)
> 
> 
> ----------------------------------------------------------------------
> 
> Message: 1
> Date: Thu, 21 Nov 2013 09:23:48 +0100
> From: Anders Logg <[email protected]>
> To: FEniCS mailing list <[email protected]>
> Subject: [FEniCS] Newton and SNES parameters
> Message-ID: <20131121082348.GP7436@ancalagon>
> Content-Type: text/plain; charset="us-ascii"
> 
> I have made some changes to the handling of parameters in NewtonSolver
> and PETScSNESSolver in order to fix this bug:
> 
> https://bitbucket.org/fenics-project/dolfin/issue/10/nonlinearvariationalsolver-does-not-pass
> 
> The change involves pushing the linear solver parameters down one
> level from NonlinearVariationalSolver to NewtonSolver and PETScSNESSolver
> where these parameters are actually used.
> 
> Please have a look to see if the changes are ok, especially regarding
> PETScSNESSolver which I have never used myself:
> 
> https://bitbucket.org/fenics-project/dolfin/branch/logg/fix-issue-10
> 
> The SNES demo has been updated and seems to work fine.
> 
I tested the part on the linear_solver and and preconditioner and it works 
well. 
I agree that it is much more logical to have them as parameters of NewtonSolver 
and PETScSNESSolver.
You just need to modify also the test in 
test/unit/nls/python/PETScSNESSolver.py for the new parameter layout.

However, the issue is larger than that. 
Many other parameters are not passed, although existing in snes and 
newton_solver. 

For example it is not possible to set the tolerance or the max iterations of 
the krylov_solver used in the newton or snes iterations, which is very bad in 
my opinion. 
I proposed a (ugly) fix some time ago which was declined ( 
https://bitbucket.org/fenics-project/dolfin/pull-request/34/updating-of-ksp-parameters-in/diff
 ). 
However I think that something must be done, because many parameters are shown 
and modifiable, but they are not taken into account. 

To test on snes_solver, run demo_contact_vi-snes.py with

snes_solver_parameters = {"nonlinear_solver": "snes",
                          "snes_solver"     : { "linear_solver"   : "gmres",
                                                "preconditioner"  : "amg", 
                                                "maximum_iterations": 20,
                                                "report": True,
                                                "error_on_nonconvergence": 
False,
                                                "krylov_solver":
                                                {"maximum_iterations": 1, 
                                                 "report": True}
                                                 }}

The issue is that "krylov_solver": {...} are ignored.

To test on newton_solver, consider the following modify version of 
demo_hyperelasticity, where par_new.krylov_solver are ignored:

from dolfin import *

# Optimization options for the form compiler
parameters["form_compiler"]["cpp_optimize"] = True
ffc_options = {"optimize": True, \
               "eliminate_zeros": True, \
               "precompute_basis_const": True, \
               "precompute_ip_const": True}

# Create mesh and define function space
mesh = UnitCubeMesh(24, 16, 16)
V = VectorFunctionSpace(mesh, "Lagrange", 1)

# Mark boundary subdomians
left =  CompiledSubDomain("near(x[0], side) && on_boundary", side = 0.0)
right = CompiledSubDomain("near(x[0], side) && on_boundary", side = 1.0)

# Define Dirichlet boundary (x = 0 or x = 1)
c = Expression(("0.0", "0.0", "0.0"))
r = Expression(("scale*0.0",
                "scale*(y0 + (x[1] - y0)*cos(theta) - (x[2] - z0)*sin(theta) - 
x[1])",
                "scale*(z0 + (x[1] - y0)*sin(theta) + (x[2] - z0)*cos(theta) - 
x[2])"),
                scale = 0.5, y0 = 0.5, z0 = 0.5, theta = pi/3)

bcl = DirichletBC(V, c, left)
bcr = DirichletBC(V, r, right)
bcs = [bcl, bcr]

# Define functions
du = TrialFunction(V)            # Incremental displacement
v  = TestFunction(V)             # Test function
u  = Function(V)                 # Displacement from previous iteration
B  = Constant((0.0, -0.5, 0.0))  # Body force per unit volume
T  = Constant((0.1,  0.0, 0.0))  # Traction force on the boundary

# Kinematics
I = Identity(V.cell().d)    # 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 - 3) - mu*ln(J) + (lmbda/2)*(ln(J))**2

# Total potential energy
Pi = psi*dx - dot(B, u)*dx - dot(T, u)*ds

# 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)

# Solve variational problem
problem = 
NonlinearVariationalProblem(F,u,bcs,J,form_compiler_parameters=ffc_options)
solver = NonlinearVariationalSolver(problem)
par_new = solver.parameters.newton_solver
par_new.linear_solver = "gmres"
par_new.preconditioner = "amg"
par_new.krylov_solver["report"] = True
par_new.krylov_solver["monitor_convergence"] = True
par_new.krylov_solver["maximum_iterations"] = 5
info(par_new, True)
solver.solve()


 

> --
> Anders
> 
> 
> ------------------------------
> 
> _______________________________________________
> fenics mailing list
> [email protected]
> http://fenicsproject.org/mailman/listinfo/fenics
> 
> 
> End of fenics Digest, Vol 8, Issue 17
> *************************************

Corrado Maurini
[email protected]



_______________________________________________
fenics mailing list
[email protected]
http://fenicsproject.org/mailman/listinfo/fenics

Reply via email to