This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

solving nonlinear problem on subdomain gives nan

+1 vote

The problem below converges inside the subdomain except that it gives a bunch of nan for the cells not inside the subdomain resulting in overall non convergence. Anyway to solve this?

from dolfin import *
mesh = UnitSquareMesh(10, 10)

class Left(SubDomain):
    def inside(self, x, on_boundary):
        return near(x[0],0.0) and on_boundary

left = Left()

Q = FunctionSpace(mesh,'CG',1)
u = Function(Q)
v = TestFunction(Q)
du = TrialFunction(Q)

facet_domains = FacetFunction('size_t',mesh)
facet_domains.set_all(0)
left.mark(facet_domains,1)

cell_domains = CellFunction('size_t', mesh)
cell_domains.set_all(0)

for f in SubsetIterator(facet_domains,1):
    for c in cells(f):
        cell_domains[c] = 1

dx = Measure('dx')[cell_domains]
F = (exp(u)-2.0)*v*dx(1)
J = derivative(F,u,du)

problem = NonlinearVariationalProblem(F, u, J=J)
solver = NonlinearVariationalSolver(problem)

solver_parameters = {
                          "newton_solver"     : { "linear_solver"   : "lu",
                                                "maximum_iterations": 10,
                                                "report": True,
                                                "error_on_nonconvergence": True,
                                                'absolute_tolerance': 1e-6,
                                                'relative_tolerance': 1e-30,
                                                'convergence_criterion': 'incremental',
                                                'relaxation_parameter': 1.0,

                                               }}

solver.parameters.update(solver_parameters)

u.assign(Constant(0.0))
(iter_num, converged) = solver.solve()
u.vector().array() #gives right solution on selected cells
asked Feb 27, 2014 by chaffra FEniCS User (1,830 points)
edited Feb 27, 2014 by chaffra

1 Answer

+1 vote

Use

'convergence_criterion': 'residual',

Initial increment outside {facet_domains == 1} is zero, hence division by zero.

answered Mar 6, 2014 by Jan Blechta FEniCS Expert (51,420 points)
...