In the blind
In the blind

Reputation: 113

FEM solution overestimation (Python, skfem)

I'm trying to solve the differential equation -y''(x) + y(x) = 2 + x - x^2, with inhomogenous boundary conditions: y'(0) = 1, y'(1)=-1, with the finite element method, using piecewise linear basis functions. I'm using the skfem package in python. My problem is that the FEM solution overestimates the solution outside the boundary. I'm not sure whether the problem is with my code, or if this is to be expected.

# nodes N
N = 6

mesh = MeshLine(np.linspace(0, 1, N))
e = ElementLineP1()
basis= Basis(mesh, e)

@fem.BilinearForm
def a(u,v, _):
 return dot( grad(u), grad(v) ) + dot(u, v)

@fem.LinearForm
def l(v, w):
 x = w.x
 f = 2 + x - x**2
 return dot(f,v)

A = a.assemble(basis)
b = l.assemble(basis)

D = basis.get_dofs()

z = fem.solve(*fem.condense(A, b, D=D))




Upvotes: 0

Views: 15

Answers (0)

Related Questions