problem solving a simple system of nonlinear equations

Asked by Nansi Xue

I have a simple system of two equations, both with Dirichlet boundary conditions on a 1-D domain. This is part of a larger system of equations, but right now I just need to solve these two.

Eq1: del^2(conc) = 0
Eq2: grad(phi) - 2/conc*grad(conc) = 0

analytically,
conc = Ax + B
phi = 2*log(x + B/A) + C

I've tried to use the built-in Newton solver but no matter what I do, I can't get the solver to converge. Help will be much appreciated. Thank you!

mesh = Interval(100, 0, 1)
V = FunctionSpace(mesh, 'CG', 1)
ME = MixedFunctionSpace([V, V])

u = Function(ME)
du = TrialFunction(ME)
conc, phi2 = split(u)
dconc, dphi2 = split(du)
v3, v4 = TestFunctions(ME)

def left(x, on_boundary):
    return near(x[0], 0.0)

def right(x, on_boundary):
    return near(x[0], 1.0)

bc3a = DirichletBC(ME.sub(0), Constant(2000.0), right)
bc3b = DirichletBC(ME.sub(0), Constant(1000.0), left)
bc4 = DirichletBC(ME.sub(1), Constant(0.0), right)
bc = [bc3a, bc3b, bc4]

def q(conc):
    return 2.0/conc

L3 = -inner(grad(conc), grad(v3))*dx
L4 = grad(phi2)*v4*dx - q(conc)*grad(conc)*v4*dx
L = L3 + L4
# a3 = inner(grad(dconc), grad(v3))*dx
# a4 = grad(dphi2)*v4*dx + Constant(2.0)/conc**2*dconc*v4*dx
a = derivative(L, u, du)

problem = NonlinearVariationalProblem(L, u, bcs=bc, J=a)
solver = NonlinearVariationalSolver(problem)
# solver.parameters['linear_solver'] = "minres"
# solver.parameters["preconditioner"] = "jacobi"
solver.solve()

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Marie Rognes
Solved:
Last query:
Last reply:
Revision history for this message
Best Marie Rognes (meg-simula) said :
#1

Try using a non-zero initial guess, for instance, let

     u.vector()[:] = 1.0

--
Marie

On 11/04/2011 09:21 PM, Nansi Xue wrote:
> New question #177587 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/177587
>
> I have a simple system of two equations, both with Dirichlet boundary conditions on a 1-D domain. This is part of a larger system of equations, but right now I just need to solve these two.
>
> Eq1: del^2(conc) = 0
> Eq2: grad(phi) - 2/conc*grad(conc) = 0
>
> analytically,
> conc = Ax + B
> phi = 2*log(x + B/A) + C
>
> I've tried to use the built-in Newton solver but no matter what I do, I can't get the solver to converge. Help will be much appreciated. Thank you!
>
> mesh = Interval(100, 0, 1)
> V = FunctionSpace(mesh, 'CG', 1)
> ME = MixedFunctionSpace([V, V])
>
> u = Function(ME)
> du = TrialFunction(ME)
> conc, phi2 = split(u)
> dconc, dphi2 = split(du)
> v3, v4 = TestFunctions(ME)
>
> def left(x, on_boundary):
> return near(x[0], 0.0)
>
> def right(x, on_boundary):
> return near(x[0], 1.0)
>
> bc3a = DirichletBC(ME.sub(0), Constant(2000.0), right)
> bc3b = DirichletBC(ME.sub(0), Constant(1000.0), left)
> bc4 = DirichletBC(ME.sub(1), Constant(0.0), right)
> bc = [bc3a, bc3b, bc4]
>
> def q(conc):
> return 2.0/conc
>
> L3 = -inner(grad(conc), grad(v3))*dx
> L4 = grad(phi2)*v4*dx - q(conc)*grad(conc)*v4*dx
> L = L3 + L4
> # a3 = inner(grad(dconc), grad(v3))*dx
> # a4 = grad(dphi2)*v4*dx + Constant(2.0)/conc**2*dconc*v4*dx
> a = derivative(L, u, du)
>
> problem = NonlinearVariationalProblem(L, u, bcs=bc, J=a)
> solver = NonlinearVariationalSolver(problem)
> # solver.parameters['linear_solver'] = "minres"
> # solver.parameters["preconditioner"] = "jacobi"
> solver.solve()
>

Revision history for this message
Nansi Xue (xue-nansi) said :
#2

wonderful it works now! Thank you!

Nansi