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

Error on solving nonlinear variational problem

+1 vote

Hello. Currently I am working on solving forced convective flow. However, there is error said:

No Jacobian form specified for nonlinear variational problem.
Differentiating residual form F to obtain Jacobian J = F'.

I dont know the mistakes. Here, I attach my coding. Thank you for your help.

from __future__ import print_function
from fenics import *

#set parameter values
rho = 997.1 #density water
mu = 1 #0.890*10^-3 #dynamic viscosity water
sigma = 0.05501 #electrical conductivity water
C = 4179 #heat capacitance water
c = 0.591 #thermal conductivity water
B_0 = 0

#create mesh
mesh = UnitSquareMesh(8,8)

#define function space
V = VectorElement('P', mesh.ufl_cell() , 2)
Q = FiniteElement('P', mesh.ufl_cell(), 2)
element = MixedElement([V, Q, Q])
W = FunctionSpace(mesh, element)

#define boundaries
outflow = 'near(x[1],1)'
walls = 'near(x[1],0)'

#define boundary condition

#walls
bcu_walls = DirichletBC(W.sub(0), Constant((0,0)), walls)
bcp_walls = DirichletBC(W.sub(1), Constant(0), walls) #pressure
bcT_walls = DirichletBC(W.sub(2), Constant(290), walls) #T_w

#outflow
bcu_outflow = DirichletBC(W.sub(0), Constant((1,0)), outflow) #u_e=1
bcp_outflow = DirichletBC(W.sub(1), Constant(1), outflow)
bcT_outflow = DirichletBC(W.sub(2), Constant(295), outflow) #uniform temperature

bcu = [bcu_walls, bcu_outflow]
bcT = [bcT_walls, bcT_outflow]
bcp = [bcp_walls, bcp_outflow]

bcs = bcu + bcT + bcp

#define test functions
(v, q, s) = TestFunctions(W)

#define functions
u = Function(W)
p = Function(W)
T = Function(W)

#split functions
w =Function(W)
(u, p, T) = w.split()

#define expression used in variational forms
n = FacetNormal(mesh)
mu = Constant(mu)
rho = Constant(rho)
sigma = Constant(sigma)
C = Constant(C)
c = Constant(c)
B_0 = Constant(B_0)

#define variational problem
F1 = div(u)*q*dx

F2 = rho*dot(dot(u,nabla_grad(u)),v)*dx + div(v)*p*dx - dot(n*p,v)*ds + mu*inner(nabla_grad(u),nabla_grad(v))*dx \
   - mu*dot(nabla_grad(u)*n,v)*ds + sigma*pow(B_0,2)*dot(u,v)*dx

F3 = rho*C*dot(u,grad(T))*s*dx-c*div(grad(T))*s*dx

F = F1 + F2 + F3

# Create VTK files for visualization output
vtkfile_u = File('steady_system/u.pvd')
vtkfile_p = File('steady_system/p.pvd')
vtkfile_T = File('steady_system/T.pvd')

# Solve variational problem for time step
solve(F == 0, w)

# Save solution to file (VTK)
vtkfile_u << u
vtkfile_p << p
vtkfile_T << T

# Plot solution
plot(u, title='Velocity')
plot(p, title='Pressure')
plot(T, title='Temperature')

# Hold plot
interactive()
asked Jun 5, 2017 by Raihan FEniCS Novice (220 points)

1 Answer

+1 vote
 
Best answer

That's not an error, just information. It's stated that the Fréchet derivative is being computed automatically since none was provided. Consider the following instead:

# Solve variational problem for time step
J = derivative(F, w)
solve(F == 0, w, J=J)
answered Jun 5, 2017 by nate FEniCS Expert (17,050 points)
selected Jun 6, 2017 by Raihan

I used the coding above, however no result appeared. So i try to use this coding:

w_ = Function(W)
F = action(F, w_)
J = derivative(F, w_, w)
problem = NonlinearVariationalProblem(F, w_, bcs, J)
solver  = NonlinearVariationalSolver(problem)
prm = solver.parameters
prm['newton_solver']['absolute_tolerance'] = 1E-8
prm['newton_solver']['relative_tolerance'] = 1E-7
prm['newton_solver']['maximum_iterations'] = 25
prm['newton_solver']['relaxation_parameter'] = 1.0
solver.solve()

Unfortunately, there is error:

*** 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.

Could you help me? Thanks in advance.

...