Hi
I have a code for a time-dependent problem.There is a part in my code that corresponds to the initial condition:
# Previous solution
W_const = Constant(1.0)
C_previous= interpolate(W_const, V_c)
It works perfectly but only for:
W_const = Constant(1.0)
The problem is when I change the the value of the initial condition (W_const) for example:
W_const = Constant(1200.0)
I get an error indicating it does not converge with NewtonSolver. Here is the error I am getting:
*** 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: 1.6.0
*** Git changeset: unknown
Here is my complete code:
from dolfin import *
import mshr
#Diffusion constant
D = 10 * (10**(-11))
#The gas constant
R = 8.31
#Electrical mobility
mu = 4.11 * (10**(-14.))
#Anion concentration
C_0 = 1200
#Dielectric permittivity
epsilon = 0.025
#Temperature
T = D / (mu*R)
#Faraday number
F = 96485
#length scale
l = 200 * (10**(-6))
#Debye screening length
lambda_d = ((epsilon*R*T)/(2*pow(F,2)*C_0))**(0.5)
eps = lambda_d / l
# Define boundaries
class Left(SubDomain):
def inside(self, x, on_boundary):
return near(x[0], 0.0)
class Right(SubDomain):
def inside(self, x, on_boundary):
return near(x[0], 1.0)
class Bottom(SubDomain):
def inside(self, x, on_boundary):
return near(x[1], 0.0)
class Top(SubDomain):
def inside(self, x, on_boundary):
return near(x[1], 1.0)
# Initialize sub-domain instances
left = Left()
top = Top()
right = Right()
bottom = Bottom()
# Domain
domain = mshr.Rectangle(Point(0,0), Point(1,1))
# Mesh
mesh = mshr.generate_mesh(domain, 60)
# Marking boundary domains
boundaries = FacetFunction("size_t", mesh)
boundaries.set_all(0)
left.mark(boundaries, 2)
top.mark(boundaries, 1)
right.mark(boundaries, 4)
bottom.mark(boundaries, 3)
#Defining the function spaces for the concentration
V_c = FunctionSpace(mesh, 'CG', 1)
#Defining the function spaces for the voltage
V_phi = FunctionSpace(mesh, 'CG', 1)
#Defining the mixed function space
W = MixedFunctionSpace((V_c, V_phi))
#Defining the "Trial" functions
u = Function(W)
c, phi = split(u)
#Defining the test functions
(v_1, v_2) = TestFunctions(W)
# Time variables
dt = 0.05; t = 0; T = 3
#Zero Neumann boundary conditions
g_L=Constant(0.0)
g_R=Constant(0.0)
# Previous solution (equal to C_0)
W_const = Constant(1200.0)
C_previous= interpolate(W_const, V_c)
# Define Dirichlet boundary conditions at top boundary (V=4.0 volt)
Voltage = Constant(4.0)
bc_top = DirichletBC(W.sub(1), Voltage, boundaries, 1)
# Define Dirichlet boundary conditions at bottom boundary (V=0.0 volt)
bc_bottom = DirichletBC(W.sub(1), 0.0, boundaries, 3)
#Collecting the boundary conditions
bcs = [bc_top, bc_bottom]
# Define variational form
a = dot(grad(phi), grad(v_2)) * dx \
+ c*v_1 * dx \
- (1./(2 * (pow(eps,2)))) * c * v_2 * dx \
+ dt * eps * dot(grad(c),grad(v_1)) * dx \
+ dt * eps * c * dot(grad(phi),grad(v_1)) * dx
L = C_previous * v_1 * dx - (1./(2 * (pow(eps,2)))) * v_2 * dx + eps*g_L*v_1*ds(2) + eps*g_L*v_1*ds(4)
# For nonlinear solver
F = a - L
f = File("conscen3.pvd")
while t <= T:
solve(F == 0, u, bcs)
(c, phi) = u.split(True)
C_previous.assign(c)
#print phi(0.8,0.2)
t += dt
plot(c,key="c", interactive=False)
f<<c
Could you please help me figure out this issue?
Thanks in advance!