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

Newton-Raphson without boundary condition

+2 votes

Dear all,

First of all thanks for the support in all my silly questions.

I am trying to implement the code below using Newton-Raphson, but this problem has only initial guess (no boundary conditions) and I have no idea how can I do this work.

# Modules
from fenics import*
import time
%matplotlib inline

# Parameters
theta = Constant(0.5)    # theta schema
t_end = 5.0
num_steps = 10
dt = t_end/num_steps

mesh = RectangleMesh(Point(0.0, 0.0), Point(1.0, 4.0), 1, 1,"crossed")    
center = Point(0.5, 0.5)
radius = 0.2
dist = Expression('sqrt((x[0]-A)*(x[0]-A) + (x[1]-B)*(x[1]-B))-r',degree=2, A=center[0], B=center[1],r=radius)

# Difine function space
V = FunctionSpace(mesh, "Lagrange", 1)
u = Function(V)
u0 = Function(V)
w = TestFunction(V)

#initial condition
u0 = interpolate(dist, V)

# Reinitalization
n = grad(u0)
h = CellSize(mesh)
epsilon = 2*h
beta = theta*dt

F = u*w*dx - beta*u*inner(grad(w),n)*dx + epsilon*beta*inner(grad(u),n)*inner(grad(w),n)*dx + \
    epsilon*dt*u*u0*inner(grad(w),n)*dx - (u0*w*dx + beta*u0*inner(grad(w),n)*dx - \
    epsilon*beta*inner(grad(u0),n)*inner(grad(w),n)*dx) 

J = derivative(F, u)
bcs = Constant(0)

ffc_options={"quadrature_degree":4,"optimize":True,"eliminate_zeros":False}
problem=NonlinearVariationalProblem(F,u,bcs,J,ffc_options)
solver=NonlinearVariationalSolver(problem)

prm = solver.parameters
#info(prm, True)
prm['nonlinear_solver'] = 'newton'
prm['newton_solver']['linear_solver'] = 'mumps'
prm['newton_solver']['lu_solver']['report'] = False
prm['newton_solver']['lu_solver']['same_nonzero_pattern']=True
prm['newton_solver']['absolute_tolerance'] = 1E-10
prm['newton_solver']['relative_tolerance'] = 1E-10
prm['newton_solver']['maximum_iterations'] = 20
prm['newton_solver']['report'] = True
#prm['newton_solver']['error_on_nonconvergence'] = False

error:

RuntimeErrorTraceback (most recent call last)
<ipython-input-5-39e0129517f4> in <module>()
      1 ffc_options={"quadrature_degree":4,"optimize":True,"eliminate_zeros":False}
----> 2 problem=NonlinearVariationalProblem(F,u,bcs,J,ffc_options)
      3 solver=NonlinearVariationalSolver(problem)
      4 
      5 prm = solver.parameters

/usr/local/lib/python2.7/dist-packages/dolfin/fem/solving.py in __init__(self, F, u, bcs, J, form_compiler_parameters)
    135         # Extract and check arguments
    136         u = _extract_u(u)
--> 137         bcs = _extract_bcs(bcs)
    138 
    139         # Store input UFL forms and solution Function

/usr/local/lib/python2.7/dist-packages/dolfin/fem/solving.py in _extract_bcs(bcs)
    491             cpp.dolfin_error("solving.py",
    492                              "solve variational problem",
--> 493                              "Unable to extract boundary condition arguments")
    494     return bcs

/usr/local/lib/python2.7/dist-packages/dolfin/cpp/common.py in dolfin_error(location, task, reason)
   2910 
   2911     """
-> 2912     return _common.dolfin_error(location, task, reason)
   2913 
   2914 def deprecation(feature, version_deprecated, message):

RuntimeError: 

*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
***     fenics-support@googlegroups.com
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error:   Unable to solve variational problem.
*** Reason:  Unable to extract boundary condition arguments.
*** Where:   This error was encountered inside solving.py.
*** Process: 0
*** 
*** DOLFIN version: 2016.2.0
*** Git changeset:  0f003bc07ee5fd583fb956245016d5972b80fea1
asked Jul 11, 2017 by pimenta.pvcl FEniCS Novice (320 points)

1 Answer

+1 vote
 
Best answer

Try:

bcs = []
problem=NonlinearVariationalProblem(F,u,bcs,J)

The empty list means no Dirichlet boundary conditions.

answered Jul 11, 2017 by nate FEniCS Expert (17,050 points)
selected Jul 11, 2017 by pimenta.pvcl

Thanks for all!

...