Solution not Correct

Asked by Pietro Maximoff

Hello

I am trying to solve the problem:

d/dx(x*du/dx) = 2/x^2 on the domain 1 < x < 2

subject to the following BCs:

u = 0 at x = 1
-x*du/dx = 0.5 at x = 2

The exact solution is: 0.5*ln(x) + 2/x

However, the solution I obtain is not correct. Below is the code I wrote to solve this:

# Create mesh and define function space
mesh = Interval(10, 1, 2)
V = FunctionSpace(mesh, 'CG', 2)

# Exact solution
u_exact = Expression('0.5*log(x[0]) + (2./x[0])')

# Dirichlet BC
class Boundary(SubDomain):
    def inside(self, x, on_boundary):
        return x[0] < 1 + DOLFIN_EPS

u_onboundary = Boundary()
bc = DirichletBC(V, u0, u_onboundary)

v = TestFunction(V)
u = TrialFunction(V)
f = Expression('2./(x[0]*x[0])')
g = Constant(0.5)
p = Expression('x[0]')

a = -p*dot(grad(u), grad(v))*dx
L = f*v*dx + p*v*g*ds

problem = VariationalProblem(a, L, bc)
u = problem.solve()

I can't see any problem wrong with the code yet the solution is quite different to the exact one.

Could someone please help me out here.

Best wishes

Pietro

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Pietro Maximoff
Solved:
Last query:
Last reply:
Revision history for this message
Pietro Maximoff (segment-x) said :
#1

L should be v*f*dx + v*g*ds