2

The equation I'm trying to solve is

$$ \frac{d^2}{dx^2}u = - \frac{1}{1+x^2} $$

on the domain $0 < x < 1$, with boundary conditions $u(0) = 0$ and $\frac{du}{dx}(1)=0$.

I got the weak form equation as:

$$\int_0^1 \frac{du}{dx} \frac{d\psi}{dx} \ dx =\int_0^1\left( \frac 1 {1+x^2} \right)(\psi) \, dx$$

I assumed a linear element.My element stiffness matrix is:

$$ k^e_{ij} = \frac{1}{h} \left[ \begin{matrix} 1 & -1 \\ -1 & 1 \end{matrix} \right] $$

and

$$ f_i^e = \left( \begin{matrix} \arctan h - \frac 1 {2h}\ln(1+h^2) \\ \frac 1 {2h} \ln(1+h^2) \end{matrix} \right) $$

Here are the results for a 10 element model of a python program that I did:

Exact   FEM
0.07355 0.09468
0.13721 0.17939
0.19127 0.25413
0.23617 0.31891
0.27245 0.37372
0.30073 0.41856
0.32166 0.45343
0.33587 0.47834
0.34399 0.49329
0.34657 0.49826

Are these results to be expected? Or is there a mistake in the model/matrices above?

Leir
  • 23
  • Why are you using FEM to solve an ODE? – copper.hat Apr 08 '17 at 04:54
  • 2
    It's a problem in an introductory course I'm taking. I want to understand the method - hence the need to start at basic problems like this. – Leir Apr 08 '17 at 06:36
  • If you want to check the results, double the number of nodes and look how the error behaves. There are standard estimates which give convergence order and which you can check – VorKir Apr 08 '17 at 21:54

1 Answers1

1

Your finite element solution is not correct. For this kind of problem (1 -dimensional problem, constant material parameter) the finite element solution should be exact at the vertices. So the floating point numbers in your lists should be equal.

It's hard to say where the error is without seeing your full code. Some possible errors:

  • Wrong load vector. I don't know how you evaluated yours, I usually do it using numerical quadrature so I don't use any analytical expressions.

  • Error in the boundary condition.

Edit: I added the following test I made to confirm my claim that the finite element solution should be exact at vertices. The following code uses sp.fem python library to compute the solution with linear elements. The solution is compared to the exact solution as given by Mathematica.

import numpy as np
import matplotlib.pyplot as plt 
from spfem.mesh import MeshLine
from spfem.asm import *
from spfem.element import *
from spfem.utils import direct

N = 11
m = MeshLine(np.array([np.linspace(0,1,N)]), np.array([range(N-1),range(1,N)]))

e = ElementLineP1()
a = AssemblerElement(m, e)

A = a.iasm(lambda du,dv: du*dv)
f = a.iasm(lambda v,x: 1.0/(1.0+x**2)*v)

x = direct(A,f,I=np.setdiff1d(np.arange(A.shape[0]),[0]))

exact = lambda x: 1./4.*(np.pi*x-4.0*x*np.arctan(x)+2.0*np.log(1.0+x**2))
y = np.linspace(0,1,30)

m.plot(x)
plt.plot(y,exact(y),'b-')
plt.legend(['finite element','exact'])
m.show()

The following plot is outputted:

comparing the exact and finite element solutions

knl
  • 1,295
  • 9
  • 15
  • Now I'm confused. I thought linear elements would only yield exact solutions at the nodes if the exact solution is at most quadratic in nature. BTW, I'm travelling right now. I'll upload and comment a link of the ipython notebook where I coded this problem when I get home. Please do have a look. Thanks! – Leir Apr 11 '17 at 09:14
  • I added an example which I used to verify that the solution should be exact (although I was 99% sure even without the example). If my memory serves me right, the exactness property should hold whenever $a(x)$ is constant in the following left hand side: $(a(x)u')'$. – knl Apr 11 '17 at 11:07
  • Thank you! I'll go check where I made a mistake (Please help me find it). I did try increasing the nodes but is still not giving correct results. Anyway, here is a link of my code. I avoided using packages like sp.fem because I want to understand things more. – Leir Apr 11 '17 at 14:19
  • I think the problem is in the load vector. More precisely, the local load vector should depend on global $x$ since the loading is not constant. You integrate as if the coordinate ran only from 0 to $h$ in every element. – knl Apr 11 '17 at 21:09
  • Yes you're right. Thank you! I'll go fix things now. – Leir Apr 14 '17 at 06:16