How to define the periodic and Neumann boundary condition?

I tried to write the code of Poisson equation.
- \Delta u = f on [0,1] \times [0,1]
\frac{\partial u}{\partial n} = 0 on y=0 and y=1
u(0,y) = u(1 , y)

The minimal example of the code is:

 # Create mesh and define the function space
    mesh = RectangleMesh(Point(0, 0),Point(1, 1), nx, ny)
    V = FunctionSpace(mesh, "CG", 1, constrained_domain=PeriodicBoundary()  )
    dof_coordinates = V.tabulate_dof_coordinates()

    # Define Boundary Condition
    class PeriodicBoundary(Subdomain):
        def inside(self, x, on_boundary):
            return bool( x[0] <DOLFIN_EPS or x[0] > -DOLFIN_EPS and on_boundary)

The following error occurred:

File "AN.py", line 126, in <module>
    - f_1*v_1*dx - f_2*v_2*dx - M1 * dot(grad( vel(u_1)), grad( u_1))*v_1* dx \
  File "AN.py", line 105, in vel
    class PeriodicBoundary(Subdomain):
NameError: name 'Subdomain' is not defined

I am not sure what the mistake I am making here. Can anyone please help me to fix this?

That is because it is written as SubDomain, not Subdomain

1 Like

[quote=“kapchaw, post:1, topic:5835”]
I tried to write the code of Poisson equation.

  • \Delta u = f−Δu=f- \Delta u = f on [0,1] \times [0,1][0,1]×[0,1][0,1] \times [0,1]
    \frac{\partial u}{\partial n} = 0 ∂u∂n=0\frac{\partial u}{\partial n} = 0 on y=0y=0y=0 and y=1y=1y=1
    u(0,y) = u(1 , y)u(0,y)=u(1,y)u(0,y) = u(1 , y)

How would you do this with dolfinX_mpc?