Hi there,
so I want to solve a simple Poisson equation in a unit cube with a neumann BC on one face and a Dirichlet BC on the opposite face.
However the solution looks quite off at the face with the neumann BC. I would expect to have a somewhat uniform distribution.
Here is the code:
from fenics import *
import numpy as np
mesh = BoxMesh(Point(-.5,-.5,0), Point(.5,.5,1),20,20,20)
V = FunctionSpace(mesh, 'CG', 1)
def top(x, on_boundary):
return x[2]>.99 and on_boundary
def bottom(x, on_boundary):
return x[2]<.01 and on_boundary
class Inflow(SubDomain):
def inside(self,x, on_boundary):
return bottom(x, on_boundary)
sub_domains = MeshFunction('size_t', mesh, 1)
sub_domains.set_all(0)
inflow_domain = Inflow()
inflow_domain.mark(sub_domains, 1)
ds = Measure('ds', domain=mesh, subdomain_data=sub_domains)
# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
a = inner(grad(u),grad(v))*dx
L = Constant(1)*v*ds(1)
bc = DirichletBC(V, Constant(1), top)
u = Function(V)
solve(a == L, u, bc)
vtkfile = File('solution.pvd')
vtkfile << u
subdomain_file = File("3d/subdomains.pvd")
subdomain_file << sub_domains
Any ideas on why that might happen?