Processing math: 50%
This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Zero Dirichlet Boundary Condition doesn't work

0 votes

I have just reinstalled the newest version of FEniCS, and try to rerun some previous code. However, I keep getting some different results and finally I find the problem is from the boundary condition.

Here is my code:

V = FunctionSpace(mesh, "Lagrange", 1)

def boundary(x, on_boundary):
    return on_boundary
u0 = Constant(0.0)
bc = DirichletBC(V, u0, boundary)

u = TrialFunction(V)
v = TestFunction(V)    
res = Function(V)

a = 0.5*inner(nabla_grad(u), nabla_grad(v))*dx-u*r*v*dx
b = v*dx

problem = LinearVariationalProblem(a, b, res, bc)
solver = LinearVariationalSolver(problem)
solver.parameters["linear_solver"] = "gmres"
solver.parameters["preconditioner"] = "amg"
solver.solve()

The mesh I used is adaptive. And I find the calculated result res doesn't satisfy zero boundary condition.

asked Sep 9, 2014 by vincehouhou FEniCS Novice (540 points)
edited Sep 9, 2014 by vincehouhou

bc is not defined in your code

I am sorry I forget to post the code of setting bc

u0 = Constant(0.0)
bc = DirichletBC(V, u0, boundary)

3 Answers

0 votes

Hi,

What is your space V?

For instance, if V = DG1, your solution may not be equal to 0 on the boundary even if you use 0 dirichlet BC (because of the discontinuity of the solution, it will be 0 on the outside facet of the boundary but res will only contain the value on the inside of the boundary)

answered Sep 9, 2014 by V_L FEniCS User (4,440 points)

Here is the V:

V = FunctionSpace(mesh, "Lagrange", 1)
0 votes

My initial mesh is

mesh = BoxMesh(-50,-50,-50,50,50,50,2,2,2)

Then I create an adaptive mesh from the initial mesh based on some conditions, and conduct the calculation in the original post. Here is an example that the calculated result res doesn't satisfy zero boundary condition.

res[-50,25,-25]=0.0188,

where it should be zero because it is on the boundary.

answered Sep 9, 2014 by vincehouhou FEniCS Novice (540 points)
0 votes

I did another test on the same problem with a rougher mesh, and here are results on boundary:

[-50. -50. -50.] 0.0
[  0. -50. -50.] 0.0
[ 50. -50. -50.] 0.0
[-50.   0. -50.] 0.0
[  0.   0. -50.] 0.0
[ 50.   0. -50.] 0.0
[-50.  50. -50.] 0.0
[  0.  50. -50.] -0.000258264961087
[ 50.  50. -50.] 0.0
[-50. -50.   0.] 0.0
[  0. -50.   0.] -0.000138253282976
[ 50. -50.   0.] 0.0
[-50.   0.   0.] -0.00013825329051
[ 50.   0.   0.] 0.0
[-50.  50.   0.] -0.000258009737271
[  0.  50.   0.] 0.00651775683023
[ 50.  50.   0.] -0.000261577716232
[-50. -50.  50.] 0.0
[  0. -50.  50.] -0.000138253291081
[ 50. -50.  50.] 0.0
[-50.   0.  50.] 0.0
[  0.   0.  50.] -0.000138253339378
[ 50.   0.  50.] 0.0
[-50.  50.  50.] 0.0
[  0.  50.  50.] 0.0
[ 50.  50.  50.] 0.0

where all the boundary values should be zero??

I tested the same problem on FEniCS 1.1, and the results are zero at these boundary points.

answered Sep 9, 2014 by vincehouhou FEniCS Novice (540 points)
...