Higher-Order Reconstruction¶

Copyright (C) 2022 Andreas Kloeckner

MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
In [2]:
import sympy as sp
In [4]:
x, h, a, b, c, d = sp.symbols("x, h, a, b, c, d")

ubarj, ubarjm1, ubarjp1 = sp.symbols("ubarj, ubarjm1, ubarjp1")

Set u to a generic polynomial in terms of unknown coefficients a, b, c, ... of the right degree for our reconstruction:

In [6]:
u = a * x + b
u
Out[6]:
$\displaystyle a x + b$

For simplicity, assume that cell $j$ is the interval $(-h/2, h/2)$, cell $j+1$ is the interval $(h/2,3h/2)$ and so on. Compute the (symbolic) cell averages for cells $j$, $j+1$ and $j-1$, assigning the symbolic values to uavgj, uavgjm1 and uavgjp1.

To compute integrals: sp.integrate(u, (x, left, right))

In [8]:
uavgj = sp.integrate(u, (x, -h/2, h/2))/h
uavgjp1 = sp.integrate(u, (x, h/2, 3*h/2))/h
uavgjm1 = sp.integrate(u, (x, -3*h/2, -h/2))/h

uavgj
Out[8]:
$\displaystyle b$

Centered Reconstruction¶

Find the coefficients for centered reconstruction, i.e. finding the coefficients in u from $\bar u_j$ and $\bar u_{j+1}$:

Use sp.solve([f1, f2], [unknown1, unknown2]).

In [10]:
sol = sp.solve([ubarjp1 - uavgjp1, ubarj - uavgj], [a,b])
sol
Out[10]:
{a: (-ubarj + ubarjp1)/h, b: ubarj}

Find the reconstructed u in terms of the cell averages:

Use u.subs({var: value}).

In [11]:
ureconstructed = u.subs(sol)
ureconstructed
Out[11]:
$\displaystyle ubarj + \frac{x \left(- ubarj + ubarjp_{1}\right)}{h}$

Evaluate the reconstructed u at the cell interface:

In [12]:
ureconstructed.subs({x: h/2})
Out[12]:
$\displaystyle \frac{ubarj}{2} + \frac{ubarjp_{1}}{2}$

Upwind Reconstructions¶

Perform the same process for upwind reconstruction, i.e. finding the coefficients in u from $\bar u_j$ and $\bar u_{j-1}$:

In [13]:
sol = sp.solve([ubarjm1 - uavgjm1, ubarj - uavgj], [a,b])
ureconstructed = u.subs(sol)
ureconstructed.subs({x: h/2})
Out[13]:
$\displaystyle \frac{3 ubarj}{2} - \frac{ubarjm_{1}}{2}$
In [ ]: