Hi,
I try to solve Poisson equation with Dirichlet boundary conditions and discontinuous Galerkin element (DG=0)
The BC are:x[0]=0 c=500 and x[0]=1 c=100.
There is no source term.
I have used the demo_dg-poisson.py to start
https://github.com/FEniCS/dolfin/blob/master/demo/undocumented/dg-poisson/python/demo_dg-poisson.py
Here is my code (FEniCS 2016.1)
When i plot the solution field at the end, the concentrations show a non-linear gradient i do not understand.
I guess the BC or the variational formulation are ill-posed.
If someone can help.
Thanks.
from dolfin import *
tolerance_boundary_location = DOLFIN_EPS*1000;
class DirichletBoundary(SubDomain):
def inside(self, x, on_boundary):
return ( abs(x[0]) < tolerance_boundary_location or abs(x[0]-1) < tolerance_boundary_location)
# Create mesh and define function space
mesh = UnitCubeMesh(10, 10, 10)
V = FunctionSpace(mesh, 'DG', 0)
# Define test and trial functions
u = TrialFunction(V)
v = TestFunction(V)
# Define normal vector and mesh size
n = FacetNormal(mesh)
h = CellSize(mesh)
h_avg = (h('+') + h('-'))/2
# Define the source term f, Dirichlet term u0 and Neumann term g
u0 = Expression('-400*x[0] + 500', degree=2)
f = Constant(0)
# Mark facets of the mesh
boundaries = FacetFunction('size_t', mesh, 0)
DirichletBoundary().mark(boundaries, 1)
# Define outer surface measure aware of Dirichlet and Neumann boundaries
ds = Measure('ds', domain=mesh, subdomain_data=boundaries)
# Define parameters
alpha = 4.0
gamma = 8.0
plot(boundaries, title='Dirichlet BC are applied here', interactive=True)
# Define variational problem
a = dot(grad(v), grad(u))*dx \
- dot(avg(grad(v)), jump(u, n))*dS \
- dot(jump(v, n), avg(grad(u)))*dS \
+ alpha/h_avg*dot(jump(v, n), jump(u, n))*dS \
- dot(grad(v), u*n)*ds(1) \
- dot(v*n, grad(u))*ds(1) \
+ (gamma/h)*v*u*ds(1)
L = v*f*dx - u0*dot(grad(v), n)*ds(1) + (gamma/h)*u0*v*ds(1)
# Compute solution
u = Function(V)
solve(a == L, u)
# Plot solution
plot(u, interactive=True)