dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #17130
[Question #96080]: Solution not Correct
New question #96080 on DOLFIN:
https://answers.launchpad.net/dolfin/+question/96080
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
--
You received this question notification because you are a member of
DOLFIN Team, which is an answer contact for DOLFIN.