I am trying to solve the following PDE: $$ u_{xx} + u_{yy} = \begin{cases} - \cos(x) \quad -\pi/2 \leq x \leq \pi/2, \\ 0 \quad \text{otherwise} \end{cases} $$
The domain is $\Omega = [-\pi,\pi] \times [0,2]$. The boundary conditions are periodic at $x = \pm \pi$ - $u(-\pi,y) = u(\pi,y)$ - and $u(x,0) = 0$ (Dirchlet) and $u_y(x,2) = 0$ (Neumann).
I am able to solve the PDE if I choose all of conditions to be Dirichlet. I cannot, however, solve the PDE in the case where I have a combination of Neumann, Dirichlet, Periodic boundary conditions. I have no idea how to implement the Neumann boundary condition appropriately. Also my implementation of periodic boundary conditions gives errors.
Ω = Rectangle[{-Pi, 0}, {Pi, 2}];
op = Laplacian[u[x, y], {x, y}] -
Piecewise[{{-Cos[x], -Pi/2 < x < Pi/2}, {0, x < -Pi/2}, {0,
x > Pi/2}}, {x, -Pi, Pi}];
Subscript[Γ,
D] = {DirichletCondition[u[x, y] == 0, y == 0],
DirichletCondition[u[x, y] == 0, y == 2 ]};
mapping =
Last[FindGeometricTransform[{{-Pi, 0}, {-Pi, 2}}, {{Pi, 0}, {Pi,
2}}]];
Subscript[Γ, P] =
PeriodicBoundaryCondition[u[x, y], x == -Pi, mapping];
ufun = NDSolveValue[{op == 0, Subscript[Γ, D],
Subscript[Γ, P]},
u, {x, y} ∈ Ω];
ContourPlot[ufun[x, y], {x, y} ∈ Ω,
ColorFunction -> "Temperature", AspectRatio -> Automatic];