Hi all,

Please am having hard time applying the following boundary conditions on subdomains. Below is a sample of my code and the boundary conditions that I want to apply:

Am solving a system of nonlinear coupled pdes on the domain [-1,1]*[-1,1].

p1, p2 are scalar functions in 2d and U=(u1,u2), V=(v1,v2) are vector functions also in 2d.

Now I want to apply the following boundary conditions

Periodic condition on left and right

u1(-1,y)=u1(1,y)

u2(-1,y)=u2(1,y)

v1(-1,y)=v1(1,y)

v2(-1,y)=v2(1,y)

p1(-1,y)=p1(1,y)

p2(-1,y)=p1(1,y)

Dirichlet boundary condition for top and bottom for U=(u1,u2)

u1(x,-1) = -1 u1(x,1)= 1

u2(x,-1)= -1 u2(x,1)= 1

Periodic for V=(v1,v2) alone for top and bottom

v1(x,-1)= 0 v1(x,-1)= 0

v2(x,-1)= 0 v2(x,-1)=0

This is how my is code arranged.

from dolfin import *

mesh = RectangleMesh(Point(-1,-1),Point(1,1),200,200) #Domain[-1,1]*[-1,1]

V1= VectorFunctionSpace(mesh, 'CG', degree=2)

V2=VectorFunctionSpace(mesh, 'Lagrange', degree=2)

Q1 = FunctionSpace(mesh, 'CG', degree=1)

Q2 = FunctionSpace(mesh, 'CG', degree=1)

VQ = MixedFunctionSpace([V1,V2, Q1, Q2])

(U, V, p1,p2)= TrialFunctions(VQ)

(m,n, q, r) = TestFunctions(VQ)

H= Function(VQ)

## Need to define boundary conditions here and put them in a list like

## bcs=[ Boundary conditions]

## Am not sure how to proceed. whether to define on each subspace or on each each subdomain. And if that how to do them. Could someone help me with this please.

F = (All the terms of the system have been added here)

F1 = action(F,H)

J = derivative(F1,H)

problem = NonlinearVariationalProblem(F1,H,bcs, J)

solver = NonlinearVariationalSolver(problem)

solver.solve()

(U,V, p1,p2) = H.split(deepcopy=True)

Any help is greatly appreciated. Thank you.

Ok thank you hernan.

So I think I understand the periodic one and I did the following. For the Diritchlet am still not very sure since I have values for only some of the functions. Do I have to restrict it on the subspaces? Please help. Thanks.

## Periodic Boundary conditions

class PeriodicBoundary(SubDomain):

pbc = PeriodicBoundary()

mesh = RectangleMesh(Point(-1,-1),Point(1,1),200,200) #Domain[-1,1]*[-1,1]

V1= VectorFunctionSpace(mesh, 'CG', degree=2, constrained_domain = pbc)

V2= VectorFunctionSpace(mesh, 'CG', degree=2, constrained_domain= pbc)

Q1 = FunctionSpace(mesh, 'CG', degree=1, constrained_domain = pbc )

Q2 = FunctionSpace(mesh, 'CG', degree=1, constrained_domain = pbc)

VQ = MixedFunctionSpace([V1,V2, Q1, Q2])

Thank you