I need help trying to solve a periodic poisson problem on nonsquare mesh. I used my own mesher to create a symmetric mesh. The problem runs on fine on a square mesh and gives a periodic solution however when I use my own mesh the solution is not periodic.
Thanks!
MWE:
import matplotlib.pyplot as plt
from dolfin import *
# Source term
class Source(UserExpression):
def eval(self, values, x):
dx = x[0] - 0.5
dy = x[1] - 0.5
values[0] = x[0]*sin(5.0*DOLFIN_PI*x[1]) \
+ 1.0*exp(-(dx*dx + dy*dy)/0.02)
class PeriodicBoundary(SubDomain):
# Left boundary is "target domain" G
def inside(self, x, on_boundary):
# return True if on left or bottom boundary AND NOT on one of the two corners (0, 1) and (1, 0)
return bool((near(x[0], 0) or near(x[1], 0,)) and
(not ((near(x[0], 0) and near(x[1], 1)) or
(near(x[0], 1) and near(x[1], 0)))) and on_boundary)
def map(self, x, y):
if near(x[0], 1) and near(x[1], 1):
y[0] = x[0] - 1.
y[1] = x[1] - 1.
elif near(x[0], 1):
y[0] = x[0] - 1.
y[1] = x[1]
else: # near(x[1], 1)
y[0] = x[0]
y[1] = x[1] - 1.
# Create mesh and finite element
mesh = UnitSquareMesh(64,64)
#mesh = Mesh("wiggle_mesh.xml.gz")
W = FiniteElement("Lagrange",mesh.ufl_cell(),1)
R = FiniteElement("R",mesh.ufl_cell(),0)
TH = W * R
V = FunctionSpace(mesh, TH, constrained_domain=PeriodicBoundary())
# No Dirichlet Boundary Condtions
bcs= []
# Define variational problem
(u,c) = TrialFunction(V)
(v,d) = TestFunction(V)
f = Source(degree=1)
# Bilinear with integral constraints on the solution
a = dot(grad(u), grad(v))*dx+c*v*dx+u*d*dx
L = f*v*dx
# Compute solution
u = Function(V)
solve(a == L, u, bcs)
(ss,c) = u.split()
# Save solution to file
file = File("periodic.pvd")
file << ss
# Plot solution
plot(ss)
plt.show()