In [1]:
import numpy
from matplotlib import pyplot
from matplotlib import colors
% matplotlib inline

In [2]:
import os, sys
sys.path.append(os.path.split(os.getcwd())[0])

In [3]:
import utils.poly as poly
import utils.quadrature as quad

The coordinates of solution points using Gauss-Legendre quadrature points.


In [4]:
xi = quad.GaussJacobi(4).nodes

The Lagrange basis using the Gauss-Legendre quadrature points.


In [5]:
Lk = poly.LagrangeBasis(xi)

The exact solution of $u(x)$.


In [6]:
def u_exact(x):
    '''exact solution of u'''
    return numpy.sin(x)

Define a function to calculate flux at a location given a known $u$.


In [7]:
def f(ui):
    '''flux at spificic location using known velocity at the same location'''
    return 0.5 * ui * ui

Calculate the $u$ at solution points.


In [8]:
ui = numpy.dot(Lk(xi), u_exact(xi))

Calculate the flux at solution points using $u$ at those locations.


In [9]:
fi = f(ui)

Use $u$ at solution points and Lagrange interpolation to calculate $u$ at left boundary.


In [10]:
uL = numpy.dot(Lk(-1), u_exact(xi))

Use $u$ at the left boundary to calculate flux at that boundary (that is, the $f(u_L)$ in the paper).


In [11]:
f(uL)


Out[11]:
0.35250512546198559

Use $f$ at the solution points and Lagrange interpolation to calculate the flux at that boundary (i.e., the $f_L$ in the paper).


In [12]:
fL = numpy.dot(Lk(-1), fi)
print(fL)


0.383561492566

We can now see that $$f_L \ne f(u_L)$$