← Back to team overview

dolfin team mailing list archive

Re: [Question #155649]: VariationalProblem(a, L, bcs, nonlinear=True) fails

 

Question #155649 on DOLFIN changed:
https://answers.launchpad.net/dolfin/+question/155649

    Status: Answered => Open

Kyle is still having a problem:
Thanks Emek,

I have followed your example and I am getting a "RuntimeError: *** Error: Newton solver did not converge.
" error. I didn't use the exter_B part of the code, I am not sure if this has anything to do with it... I copied my code below.

#CODE

#!/usr/bin/python

from dolfin import *
import numpy, sys

# MESHING
mesh = Rectangle(0.0, -0.5, 1.0, 0.5, 10, 10, "right/left")

# FUNCTION SPACE
scalar = FunctionSpace(mesh, "CG", 1) #Pressure
vector = VectorFunctionSpace(mesh, "CG", 2) #Velocity
system = vector * scalar #Mixed Function Space

# BOUNDARIES
right = compile_subdomains('x[0] == 1.0')
left = compile_subdomains('x[0] == 0.0')
top = compile_subdomains('x[1] == 0.5')
bottom = compile_subdomains('x[1] == -0.5')

# INFLOW VELOCITY BC FOR TOP
bc1 = DirichletBC(system.sub(0), Constant((1.0, 0.0)), top)

# NO-SLIP BC FOR TOP-BOTTOM
noslip = Constant((0.0, 0.0))
bc0 = DirichletBC(system.sub(0), noslip, left)
bc3 = DirichletBC(system.sub(0), noslip, bottom)
bc2 = DirichletBC(system.sub(0), noslip, right)

# STORAGE OF BCs
bcs = [bc1, bc2, bc0, bc3]

# VARIATIONAL PROBLEM
class NavierStokes(NonlinearProblem):
    def __init__(self, a, L, bc):
        NonlinearProblem.__init__(self)
        self.L = L
        self.a = a
        self.bc = bc
    def F(self, b, x):
        assemble(self.L, tensor=b)
        for condition in self.bc: condition.apply(b, x)
    def J(self, A, x):
        assemble(self.a, tensor=A)
        for condition in self.bc: condition.apply(A)


ts = TestFunction(system)
ds = TrialFunction(system)
s = Function(system)

v, q = split(ts)
dv, dq = split(ds)
u , p = split(s)

f = Constant((0, 0))
nu = 0.1 

F = (nu*inner(grad(v), grad(u)) - div(v)*p + q*div(u) + v[i]*u[j]*Dx(u[i], j) - inner(v,f))*dx # Navier-Stokes 2
J = derivative(F,s,ds)

# SET UP PDE
problem = NavierStokes(J, F, bcs)
solver = NewtonSolver("lu")
solver.parameters["convergence_criterion"] = "incremental"
solver.parameters["relative_tolerance"] = 1e-6

# SOLVE PDE
solver.solve(problem,s.vector())
(U, P) = s.split()

# FILES FOR PARAVIEW
ufile_pvd = File("velocity.pvd")
ufile_pvd << U
pfile_pvd = File("pressure.pvd")
pfile_pvd << P

# PLOTS
plot(U)
plot(P)
interactive()

-- 
You received this question notification because you are a member of
DOLFIN Team, which is an answer contact for DOLFIN.