creating DG-representation of a step function
Hi all,
I was trying to define a step function over a rectangular region. It was supposed to be 0 on the left side and 1 on the right; these values coincide with my choice of mesh function indicating the two subdomains. However, when the result comes out, it's 1 on the left and 0 on the right... I couldn't solve it for a quite a while. Please take a look at the code below:
###### beginning of code
from dolfin import *
# a simple mesh consisting of 4 triangles
mesh = RectangleMesh(-1, 0, 1, 1, 2, 1)
class LeftRegion(
def inside(self, x, on_boundary):
return x[0]<= DOLFIN_EPS
class RightRegion(
def inside(self, x, on_boundary):
return x[0]>= -DOLFIN_EPS
# mark the left side as "0" and right side as "1"
marker = CellFunction(
RightRegion(
# DG-representation of marker
Vdg = FunctionSpace(mesh, 'DG', 0)
dx = Measure(
u = TrialFunction(Vdg)
v = TestFunction(Vdg)
a = u * v * dx(0) + u*v*dx(1)
L = Constant(0)*v*dx(0) + Constant(1)*v*dx(1)
u = Function(Vdg)
solve(a==L, u)mesh, subdomains, domain markers
print "marker is", marker.array()
print "u is", u.vector().array()
########### end of code
Results of the code reads:
marker is [0 0 1 1]
u is [ 1. 1. 0. 0.] (u is also supposed to be [0 0 1 1]!!!!)
Thank you!
Question information
- Language:
- English Edit question
- Status:
- Answered
- For:
- DOLFIN Edit question
- Assignee:
- No assignee Edit question
- Last query:
- Last reply:
Can you help with this problem?
Provide an answer of your own, or ask Xiaoxian Liu for more information if necessary.