How to set the boundary condations for PDEs with more than one function?

Hello, I have an 1D nonlinear problem

  1. with two PDE equations,
  2. with two functions, like phi(x), sigma(x),
  3. they are with different boundary condations,
     phi(0) = 0,  phi(1) = 2,
     sigma'(0) = 0, sigma(1) =0.

Assuming I had finished to set the boundary condations

     bc1= DirichletBC ( .... )
     bc2= DirichletBC ( .... )

and I had got the variational form
F= (.....) *dx + (...)* ds,
how can I to write the solver
solve ( F == 0, ?, ?,.... ).

Thanks!

I assume that you are solving this with a mixed finite element.
Then you add the BCs to the appropriate sub space, see for instance
https://bitbucket.org/fenics-project/dolfin/src/master/python/demo/documented/stokes-taylor-hood/demo_stokes-taylor-hood.py

Dokken, thank you for your reply!

My problem is 1D, the functions are m(x), phi(x) and sigma(x). They are satisfying the the following equations,

m' = N * phi'**2 + mu**2 * phi**2 + omega**2 *phi**2 /(N*sigma**2)
sigma' /(sigma*x) =  2.0*(phi**2+ omega**2*phi**2/(N**2*sigma**2))*sigma
phi'' = (2.0/x+N_x/N+sigma.dx(0)/sigma)*phi.dx(0) + (omega**2/N/sigma**2-mu**2)*phi/N

where

N(x) = (1-2 m / x) , and N_x= N' = dN(x)/dx

The boundary condations are

m(0) = 0, sigma(100)= 1, phi(100)=0, phi'(0) = 0

My codes are


from fenics import *


# parmeters
r_0     = 1.0E-6
r_b     = 100 # r的右边界值,the coordinate of right boundary
omega   = 0.9
mu      = 1.0

mesh=IntervalMesh(500,r_0,r_b)
# Define function space
P1 = FiniteElement( "Lagrange",mesh.ufl_cell(), 1)
element = MixedElement([P1, P1, P1])
V = FunctionSpace(mesh, element)

# Define functions 
u = Function(V)
# Split system functions to access components
m, phi, sigma = split(u)


# def the_boundary(x, on_boundary):
# 	tol = 1E-6 # tolerance for coordinate comparisons
# 	return on_boundary and (near(x[0], 0, tol) or near(x[0], r_b, tol))
def the_boundary_R(x, on_boundary): 
	tol = 1E-6 # tolerance for coordinate comparisons
	return on_boundary and near(x[0], r_b, tol)
def the_boundary_L(x, on_boundary): 
	tol = 1E-6 # tolerance for coordinate comparisons
	return on_boundary and near(x[0], r_0, tol)

m_boundary     = Expression ( "0.0", degree = 1 )
phi_boundary   = Expression ( "0.0", degree = 1 )
sigma_boundary = Expression ( "1.0", degree = 1 )

bc_m     = DirichletBC(V.sub(0), m_boundary, the_boundary_L)
bc_phi   = DirichletBC(V.sub(1), phi_boundary, the_boundary_R)
bc_sigma = DirichletBC(V.sub(2), sigma_boundary, the_boundary_R)


# Define test functions
v_1, v_2, v_3 = TestFunctions(V)

# Define variational problem
x    = Expression ("x[0]",degree = 1)
N    = (x-2.0*m)/x
N_x  = (2.0*m.dx(0)*x-2.0*m)/x**2
F1   = N*phi.dx(0)**2+ mu**2*phi**2+omega**2*phi**2/N/sigma**2 - m.dx(0)/x**2
F2   = 2.0*(phi.dx(0)**2+ omega**2*phi**2/(N**2*sigma**2))*sigma*x - sigma.dx(0)
F3   = (2.0/x+N_x/N+sigma.dx(0)/sigma)*phi.dx(0) + (omega**2/N/sigma**2-mu**2)*phi/N
F    = (F1*v_1+F2*v_2+F3*v_3 - phi.dx(0)*v_3.dx(0))*dx

#  Solve the system.
#
solve ( F == 0, u, [bc_m, bc_phi, bc_sigma] )

u_1_, u_2_, u_3_ = u.split()
plt.figure(1,dpi=300)  
plt.plot (u_1_)
plt.plot (u_2_)
plt.plot (u_3_)
filename = 'solutions.png'
plt.savefig ( filename )
print ( '  Graphics saved as "%s"' % ( filename ) )
plt.show()
plt.close ( )

I got the following error messages,

No Jacobian form specified for nonlinear variational problem.
Differentiating residual form F to obtain Jacobian J = F'.
Solving nonlinear variational problem.
  Newton iteration 0: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 1: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 2: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 3: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 4: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 5: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 6: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 7: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 8: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 9: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 10: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 11: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 12: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 13: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 14: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 15: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 16: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 17: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 18: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 19: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 20: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 21: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 22: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 23: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 24: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 25: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 26: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 27: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 28: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 29: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 30: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 31: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 32: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 33: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 34: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 35: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 36: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 37: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 38: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 39: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 40: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 41: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 42: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 43: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 44: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 45: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 46: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 47: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 48: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 49: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Newton iteration 50: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
Traceback (most recent call last):
  File "boson.py", line 56, in <module>
    solve ( F == 0, u, [bc_m, bc_phi, bc_sigma] )
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/fem/solving.py", line 233, in solve
    _solve_varproblem(*args, **kwargs)
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/fem/solving.py", line 314, in _solve_varproblem
    solver.solve()
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 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: 2019.2.0.dev0
*** Git changeset:  unknown
*** -------------------------------------------------------------------------

Can you help me to find out the bugs in my codes?

You divide by the unknown, thus you need to make sure that the initial guess is non zero, otherwise your problem is singular.

Thank you Dokken! I do not worry about the problem itself, because it had been solved by others. But I’m not sure whether the following expressions are meeting the requrements of fenics, because I cannot find a similar example from the books and documents about fenics and fenicsx.

And can you give me a clue to do the following?

The boundary conditions look fine.

You can for instance call

u.vector()[:] = 1

Dear Dokken, I had tried that but could not reach the covergence.