Runtime error while trying to solve a non linear equation with periodic boundary condition

Hello All,
I am trying to solve the following non linear equation with Periodic boundary condition.

u" = u + 25/(1+exp(u)) on x ∈ [0, 2*pi].

Here is my code for the same

from fenics import *

mesh_size = 10000
mesh = IntervalMesh(mesh_size, 0, L)
plot(mesh)

class PeriodicBoundary(SubDomain):
    def inside(self, x, on_boundary):
        return bool(x[0] < DOLFIN_EPS and x[0] > L-DOLFIN_EPS and on_boundary)
    def map(self, x, y):
        y[0] = x[0] - L

pbc = PeriodicBoundary()


V = FunctionSpace(mesh, "CG", 1, constrained_domain=pbc)


u = Function(V)
v = TestFunction(V)

F = dot(grad(u), grad(v))*dx + u*v*dx + ((25*v)/(1+exp(u)))*dx
J = derivative(F,u)

solve(F == 0, u, J=J)

However when I run this I get the following error message

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[29], line 7
      4 F = dot(grad(u), grad(v))*dx + u*v*dx + ((25*v)/(1+exp(u)))*dx
      5 J = derivative(F,u)
----> 7 solve(F == 0, u, J=J)

File /usr/lib/petsc/lib/python3/dist-packages/dolfin/fem/solving.py:233, in solve(*args, **kwargs)
    230 # Call variational problem solver if we get an equation (but not a
    231 # tolerance)
    232 elif isinstance(args[0], ufl.classes.Equation):
--> 233     _solve_varproblem(*args, **kwargs)
    235 # Default case, just call the wrapped C++ solve function
    236 else:
    237     if kwargs:

File /usr/lib/petsc/lib/python3/dist-packages/dolfin/fem/solving.py:314, in _solve_varproblem(*args, **kwargs)
    312 solver = NonlinearVariationalSolver(problem)
    313 solver.parameters.update(solver_parameters)
--> 314 solver.solve()

RuntimeError: 

*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
***     fenics-support@googlegroups.com
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error:   Unable to solve nonlinear system with NewtonSolver.
*** Reason:  Newton solver did not converge because maximum number of iterations reached.
*** Where:   This error was encountered inside NewtonSolver.cpp.
*** Process: 0
*** 
*** DOLFIN version: 2019.2.0.dev0
*** Git changeset:  ubuntu
*** --------------------------------------------------------------------

Please help me resolve this issue.

Regards

I would suggest having a look at Default absolute tolerance and relative tolerance - #4 by nate

1 Like