# AdaptiveNonlinearSolver with periodic boundary conditions

Hello, I have a question
Do Fenics’s meshes within the AdaptiveNonlinearVariationalSolver can handle meshes that have periodic boundary conditions using CG-FE?

Here is a min working example of my question adapted from the auto adaptive poisson example without periodic it runs line 34, with periodic it does not line 33. Thanks for any help…

``````1. from dolfin import *

2. # Form compiler options
3. parameters["form_compiler"]["optimize"]     = True
4. parameters["form_compiler"]["cpp_optimize"] = True

5. # Create mesh and define function space
6. mesh = UnitSquareMesh(8, 8)

7. class left(SubDomain):
8.     def inside(self, x, on_boundary):
9.         return x[0] < DOLFIN_EPS

10. class right(SubDomain):
11.     def inside(self, x, on_boundary):
12.         return x[0] > (1.0 - DOLFIN_EPS)

13. class bottom(SubDomain):
14.     def inside(self, x, on_boundary):
15.         return x[1] < DOLFIN_EPS

16. class top(SubDomain):
17.     def inside(self, x, on_boundary):
18.         return x[1] > 1.0 - DOLFIN_EPS

19. left = left()
20. right = right()
21. top = top()
22. bottom = bottom()

23. class PeriodicBoundary(SubDomain):

24. # Left boundary is "target domain" G
25.     def inside(self, x, on_boundary):
26.         return bool(x[0] < DOLFIN_EPS and x[0] > -DOLFIN_EPS and on_boundary)

27. # Map right boundary (H) to left boundary (G)
28.     def map(self, x, y):
29.         y[0] = x[0] - 1.0
30.         y[1] = x[1]

31. # Define function space for system of concentrations
32. P = FiniteElement("Lagrange", mesh.ufl_cell(), 1)

33. #V = FunctionSpace(mesh, P, constrained_domain=PeriodicBoundary()) #This implements periodic let and right and gives error
34. V = FunctionSpace(mesh, P) #This implements Neumann left and right and works

35. # Define boundary condition
36. u0 = Function(V)
37. u1 = Function(V)
38. u0 = Constant(1)
39. u1 = Constant(0)
40. bc0 = DirichletBC(V,u0, top)
41. bc1 = DirichletBC(V,u1, bottom)

42. bc = [bc0, bc1]

43. # Define variational problem
44. # Define function for the solution
45. u = Function(V)
46. v = TestFunction(V)
47. f = Expression("10*exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)",
48.                degree=1)

50. L = (1.0 - 0.5/(u + 0.5))*v*dx() #made it nonlinear here...

51. F = a-L

52. # Define goal functional (quantity of interest)
53. M = u*dx()

54. # Define error tolerance
55. tol = 1.e-9

57. du = TrialFunction(V)

58. J = derivative(F, u, du)

59. # Solve equation F = 0 with respect to u and the given boundary
60. # conditions, such that the estimated error (measured in M) is less
61. # than tol

62. problem = NonlinearVariationalProblem(F, u, bc, J)
64. solver.parameters["error_control"]["dual_variational_solver"]["linear_solver"] = "default"
65. parameters["refinement_algorithm"] = "plaza_with_parent_facets"
66. solver.solve(tol)

67. solver.summary()
68. ######

69. # Output file
70. soln_init_mesh = File("init_u.pvd", "compressed")
71. soln_final_mesh = File("refined_u.pvd", "compressed")

72. soln_init_mesh << u.root_node()
73. soln_final_mesh << u.leaf_node()
``````

the error I am getting when periodic are used is:

``````*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***