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

Solving time dependent nonlinear PDE

0 votes

I have the following code for solving time dependent nonlinear PDE:
It shows error as:

*** Error: Unable to solve nonlinear system with NewtonSolver.
*** Reason: Newton solver did not converge. Bummer.
*** Where: This error was encountered inside NewtonSolver.cpp.
*** Process: 0

*** DOLFIN version: 1.3.0
*** Git changeset: unknown

Code:

from dolfin import*
import numpy

nx = ny = 20
mesh = UnitSquareMesh(nx, ny)
#plot(mesh)
V = FunctionSpace(mesh, "CG", 1)

Tc = Constant(310)
Tp = Constant(77)

#Define Boundary Conditions
boundary = compile_subdomains('x[0] <= 0.1 && x[1] <= 0.1')
bc = DirichletBC(V, Tp, boundary)

# Initial condition
Tinitial = 'x[0] <= 0.1 && x[1] <= 0.1 ? Tp : Tc'
Temp = Expression(Tinitial, Tp = Tp, Tc = Tc)
T_1 = interpolate(Temp, V)

T21 = TrialFunction(V)
v21 = TestFunction(V)
T21_ = Function(V)

#define Parameters
dt = 0.1    # time step
def k2(T21):
    return 15.98 - 0.0567*T21
def c21(T21):
    return (880 - 3.21*T21)*1E6

F = c21(T21)*(T21 - T_1)*v21*dx + dt*inner(k2(T21)*grad(T21), grad(v21))*dx
F = action(F, T21_)

J = derivative(F, T21_, T21)

duration = 1         # total simulation time
t = dt           # initialise time t

while t <= duration:
    print 'time =', t
    problem = NonlinearVariationalProblem(F, T21_, bc, J)
    solver = NonlinearVariationalSolver(problem)
    solver.solve()
    t += dt
    T_1.assign(T21_)

print T21_.compute_vertex_values().max(), T21_.compute_vertex_values().min()
plot (T21_, title = 'T21 plot')
interactive()

Can anyone tell me what is wrong with the code..?

asked Feb 25, 2014 by iitmayush FEniCS Novice (280 points)
edited Feb 25, 2014 by iitmayush

1 Answer

0 votes

dt too large is my guess :P

answered Feb 26, 2014 by KristianE FEniCS Expert (12,900 points)
...