Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

viscous burgers solver #171

Merged
merged 55 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
715f6ad
initial commit
zhichen3 Apr 20, 2023
fb29ed7
fix burgers
zhichen3 Apr 21, 2023
15fa38c
simplify incomp_interface.py
zhichen3 Apr 21, 2023
c354dc8
change visual plottings to output both u and v
zhichen3 Apr 21, 2023
af56db8
change plotting
zhichen3 Apr 21, 2023
28a97bf
change figure
zhichen3 Apr 21, 2023
51293a7
Merge branch 'burgers-fix' into incompressible_simplify
zhichen3 Apr 21, 2023
16b5b5d
fix pylint and flake8
zhichen3 Apr 21, 2023
034f4de
let incompressible inherit from burgers
zhichen3 Apr 21, 2023
0d48b7d
Merge branch 'burgers-fix' into incompressible_simplify
zhichen3 Apr 21, 2023
02492c1
fix pylint flake8
zhichen3 Apr 21, 2023
00b3cb9
change import
zhichen3 Apr 21, 2023
9702078
move riemann and upwind to burgers_interface to avoid circular import
zhichen3 Apr 21, 2023
5fef42e
move riemann and upwinds functions in incomp_interface to burgers_int…
zhichen3 Apr 21, 2023
0101c94
fix function call
zhichen3 Apr 21, 2023
2a20b56
Merge branch 'burgers-fix' into incompressible_simplify
zhichen3 Apr 21, 2023
272fef8
change import name
zhichen3 Apr 21, 2023
d5b2979
change readme and pyro_sim
zhichen3 Apr 22, 2023
58cfda2
change riemann to riemann_and_upwind
zhichen3 Apr 22, 2023
b98eecf
Merge branch 'burgers-fix' into viscous_burgers
zhichen3 Apr 23, 2023
47d7af1
change buf=1 to buf=2
zhichen3 Apr 23, 2023
116dfdf
Merge branch 'burgers-fix' into viscous_burgers
zhichen3 Apr 23, 2023
0053b53
split transverse correction to a separate function
zhichen3 Apr 23, 2023
78198f7
Merge branch 'burgers-fix' into incompressible_simplify
zhichen3 Apr 23, 2023
8e51e5c
apply gradp correction first instead of transverse correction
zhichen3 Apr 23, 2023
dbf9cb5
fix pylint and flake8
zhichen3 Apr 23, 2023
25d0603
Merge branch 'burgers-fix' into incompressible_simplify
zhichen3 Apr 23, 2023
f165466
fix pylint
zhichen3 Apr 24, 2023
be549b4
Merge branch 'burgers-fix' into incompressible_simplify
zhichen3 Apr 24, 2023
e2d97c0
fix pylint
zhichen3 Apr 24, 2023
c569a36
fix pylint
zhichen3 Apr 24, 2023
137db9d
Merge branch 'burgers-fix' into viscous_burgers
zhichen3 Apr 24, 2023
60514e7
viscous burger solver init commit
zhichen3 Apr 24, 2023
acff182
fix pylint and flake8
zhichen3 Apr 24, 2023
31da292
Merge branch 'main' into burgers-fix
zhichen3 Apr 24, 2023
fa58cc7
Merge branch 'burgers-fix' into viscous_burgers
zhichen3 Apr 24, 2023
31e3d6e
fix pylint
zhichen3 Apr 24, 2023
f299fc7
fix isort
zhichen3 Apr 24, 2023
8adaa3a
add description to _defaults
zhichen3 Apr 24, 2023
bf37342
update docs
zhichen3 Apr 24, 2023
949434b
add docs
zhichen3 Apr 24, 2023
de1f108
revert timestep calculation
zhichen3 Apr 24, 2023
b3c7c19
Merge branch 'burgers-fix' into viscous_burgers
zhichen3 Apr 24, 2023
da501fd
Merge branch 'burgers-fix' into incompressible_simplify
zhichen3 Apr 24, 2023
e721f4a
Merge branch 'main' into burgers-fix
zingale Apr 26, 2023
57b73da
Merge branch 'main' into incompressible_simplify
zhichen3 Apr 27, 2023
047ad09
revert to apply transverse terms first
zhichen3 Apr 27, 2023
8074edb
more revert
zhichen3 Apr 27, 2023
104363b
break up lines
zhichen3 Apr 27, 2023
10d00c6
Merge branch 'burgers-fix' of github.com:zhichen3/pyro2 into burgers-fix
zhichen3 Apr 27, 2023
b2d1d5b
Merge branch 'burgers-fix' into incompressible_simplify
zhichen3 Apr 27, 2023
d68599c
break up lines
zhichen3 Apr 27, 2023
bc17d46
Merge branch 'main' into incompressible_simplify
zhichen3 Aug 4, 2023
397498a
Merge branch 'incompressible_simplify' into viscous_burgers
zhichen3 Aug 4, 2023
2c48564
Merge branch 'main' into viscous_burgers
zingale Aug 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ pyro provides the following solvers (all in 2-d):

- `burgers`: a second-order unsplit solver for invsicid Burgers' equation.

- `viscous_burgers`: a second-order unsplit solver for viscous Burgers' equation
with constant-coefficient diffusion. It uses Crank-Nicolson time-discretized
solver for solving diffusion.

- `compressible`: a second-order unsplit solver for the Euler
equations of compressible hydrodynamics. This uses characteristic
tracing and corner coupling for the prediction of the interface
Expand Down
29 changes: 28 additions & 1 deletion docs/source/burgers_basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Burgers' Equation is a nonlinear hyperbolic equation. It has the same form as th
``Inviscid Burgers``
--------------------------------

A 2D Burgers' Equation has the following form:
A 2D inviscid Burgers' Equation has the following form:

.. math::

Expand Down Expand Up @@ -34,3 +34,30 @@ The parameters for this solver are:
:align: center

The figure above is generated using ``burgers/problems/test.py``, which is used to test the validity of the solver. Bottom-left of the domain has a higher velocity than the top-right domain. With :math:`u_{i,j}=v_{i,j}`, the wave travels diagonally to the top-right with a constant velocity that is equal to the shock speed. ``burgers/problem/verify.py`` can be used to calculate the wave speed using outputs from ``test.py`` and compare to the theoretical shock speed.

``Viscous Burgers``
--------------------------------

A 2D viscous Burgers' Equation has the following form:

.. math::

u_t + u u_x + v u_y = \epsilon \left( u_{xx} + u_{yy}\right) \\
v_t + u v_x + v v_y = \epsilon \left( v_{xx} + v_{yy}\right)

The viscous Burgers' equation has an additional velocity diffusion term on the RHS compared to the inviscid Burgers' equation. Here :math:`\epsilon` represents the constant viscosity.

:py:mod:`pyro.viscous_burgers` is inherited from :py:mod:`pyro.burgers`, where we added an additional diffusion term when constructing the interface states. We then solve for diffusion along with the extra advective source to the Helmholtz equation by using the Crank-Nicolson discretization and multigrid solvers.


The parameters for this solver are:

.. include:: viscous_burgers_defaults.inc


.. image:: viscous_burgers.png
:align: center

The figure above is generated using ``viscous_burgers/problems/test.py``, which has the identical setup as in ``burgers/problems/test.py``. With diffusion added to the system, we see the shock (discontinuity) is smeared out as system evolves.


1 change: 1 addition & 0 deletions docs/source/pyro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Subpackages
pyro.advection_rk
pyro.advection_weno
pyro.burgers
pyro.viscous_burgers
pyro.compressible
pyro.compressible_fv4
pyro.compressible_react
Expand Down
26 changes: 26 additions & 0 deletions docs/source/pyro.viscous_burgers.problems.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
pyro.viscous\_burgers.problems package
=======================================

.. automodule:: pyro.viscous_burgers.problems
:members:
:undoc-members:
:show-inheritance:

Submodules
----------

pyro.viscous\_burgers.problems.converge module
-----------------------------------------------

.. automodule:: pyro.viscous_burgers.problems.converge
:members:
:undoc-members:
:show-inheritance:

pyro.viscous\_burgers.problems.tophat module
--------------------------------------------

.. automodule:: pyro.viscous_burgers.problems.tophat
:members:
:undoc-members:
:show-inheritance:
34 changes: 34 additions & 0 deletions docs/source/pyro.viscous_burgers.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
pyro.viscous\_burgers package
==============================

.. automodule:: pyro.viscous_burgers
:members:
:undoc-members:
:show-inheritance:

Subpackages
-----------

.. toctree::
:maxdepth: 4

pyro.viscous_burgers.problems

Submodules
----------

pyro.viscous\_burgers.interface module
---------------------------------------

.. automodule:: pyro.viscous_burgers.interface
:members:
:undoc-members:
:show-inheritance:

pyro.viscous_burgers.simulation module
---------------------------------------

.. automodule:: pyro.viscous_burgers.simulation
:members:
:undoc-members:
:show-inheritance:
34 changes: 34 additions & 0 deletions docs/source/viscous_burgers_defaults.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
* section: [advection]

+----------------------------------+----------------+----------------------------------------------------+
| option | value | description |
+==================================+================+====================================================+
| limiter | ``2`` | limiter (0 = none, 1 = 2nd order, 2 = 4th order) |
+----------------------------------+----------------+----------------------------------------------------+

* section: [diffusion]

+----------------------------------+----------------+----------------------------------------------------+
| option | value | description |
+==================================+================+====================================================+
| eps | ``0.005`` | Viscosity for diffusion |
+----------------------------------+----------------+----------------------------------------------------+

* section: [driver]

+----------------------------------+----------------+----------------------------------------------------+
| option | value | description |
+==================================+================+====================================================+
| cfl | ``0.8`` | advective CFL number |
+----------------------------------+----------------+----------------------------------------------------+

* section: [particles]

+----------------------------------+----------------+----------------------------------------------------+
| option | value | description |
+==================================+================+====================================================+
| do_particles | ``0`` | |
+----------------------------------+----------------+----------------------------------------------------+
| particle_generator | ``grid`` | |
+----------------------------------+----------------+----------------------------------------------------+

1 change: 1 addition & 0 deletions pyro/pyro_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"advection_fv4",
"advection_weno",
"burgers",
"viscous_burgers",
"compressible",
"compressible_rk",
"compressible_fv4",
Expand Down
7 changes: 7 additions & 0 deletions pyro/viscous_burgers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
The pyro viscous burgers solver. This implements a second-order,
unsplit method for viscous burgers equations.
"""

__all__ = ['simulation']
from .simulation import Simulation
14 changes: 14 additions & 0 deletions pyro/viscous_burgers/_defaults
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[driver]
cfl = 0.8 ; advective CFL number


[advection]
limiter = 2 ; limiter (0 = none, 1 = 2nd order, 2 = 4th order)


[particles]
do_particles = 0
particle_generator = grid

[diffusion]
eps = 0.005 ; Viscosity for diffusion
171 changes: 171 additions & 0 deletions pyro/viscous_burgers/interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
from pyro.multigrid import MG


def get_lap(grid, a):
r"""
Parameters
----------
grid: grid object
a: ndarray
the variable that we want to find the laplacian of

Returns
-------
out : ndarray (laplacian of state a)
"""

lap = grid.scratch_array()

lap.v(buf=2)[:, :] = (a.ip(1, buf=2) - 2.0*a.v(buf=2) + a.ip(-1, buf=2)) / grid.dx**2 \
+ (a.jp(1, buf=2) - 2.0*a.v(buf=2) + a.jp(-1, buf=2)) / grid.dy**2

return lap


def diffuse(my_data, rp, dt, scalar_name, A):
r"""
A routine to solve the Helmhotlz equation with constant coefficient
and update the state.

(a + b \lap) phi = f

using Crank-Nicolson discretization with multigrid V-cycle.

Parameters
----------
my_data : CellCenterData2d object
The data object containing the grid and advective scalar that
we are advecting.
rp : RuntimeParameters object
The runtime parameters for the simulation
dt : float
The timestep we are advancing through.
scalar_name : str
The name of the variable contained in my_data that we are
advecting
A: ndarray
The advective source term for diffusion

Returns
-------
out : ndarray (solution of the Helmholtz equation)

"""

myg = my_data.grid

a = my_data.get_var(scalar_name)
eps = rp.get_param("diffusion.eps")

# Create the multigrid with a constant diffusion coefficient
# the equation has form:
# (alpha - beta L) phi = f
#
# with alpha = 1
# beta = (dt/2) k
# f = phi + (dt/2) k L phi - A
#
# Same as Crank-Nicolson discretization except with an extra
# advection source term)

mg = MG.CellCenterMG2d(myg.nx, myg.ny,
xmin=myg.xmin, xmax=myg.xmax,
ymin=myg.ymin, ymax=myg.ymax,
xl_BC_type=my_data.BCs[scalar_name].xlb,
xr_BC_type=my_data.BCs[scalar_name].xrb,
yl_BC_type=my_data.BCs[scalar_name].ylb,
yr_BC_type=my_data.BCs[scalar_name].yrb,
alpha=1.0, beta=0.5*dt*eps,
verbose=0)

# Compute the RHS: f

f = mg.soln_grid.scratch_array()

lap = get_lap(myg, a)

f.v()[:, :] = a.v() + 0.5*dt*eps * lap.v() - dt*A.v()

mg.init_RHS(f)

# initial guess is zeros

mg.init_zeros()
mg.solve(rtol=1.e-12)

# perform the diffusion update

a.v()[:, :] = mg.get_solution().v()


def apply_diffusion_corrections(grid, dt, eps,
u, v,
u_xl, u_xr,
u_yl, u_yr,
v_xl, v_xr,
v_yl, v_yr):
r"""
Apply diffusion correction term to the interface state

.. math::

u_t + u u_x + v u_y = eps (u_xx + u_yy)
v_t + u v_x + v v_y = eps (v_xx + v_yy)

We use a second-order (piecewise linear) unsplit Godunov method
(following Colella 1990).

Our convection is that the fluxes are going to be defined on the
left edge of the computational zones::

| | | |
| | | |
-+------+------+------+------+------+------+--
| i-1 | i | i+1 |

a_l,i a_r,i a_l,i+1


a_r,i and a_l,i+1 are computed using the information in
zone i,j.

Parameters
----------
grid : Grid2d
The grid object
dt : float
The timestep
eps : float
The viscosity
u_xl, u_xr : ndarray ndarray
left and right states of x-velocity in x-interface.
u_yl, u_yr : ndarray ndarray
left and right states of x-velocity in y-interface.
v_xl, v_xr : ndarray ndarray
left and right states of y-velocity in x-interface.
v_yl, u_yr : ndarray ndarray
left and right states of y-velocity in y-interface.

Returns
-------
out : ndarray, ndarray, ndarray, ndarray, ndarray, ndarray, ndarray, ndarray
unsplit predictions of the left and right states of u and v on both the x- and
y-interfaces along with diffusion correction terms.
"""

#apply diffusion correction to the interface

lap_u = get_lap(grid, u)
lap_v = get_lap(grid, v)

u_xl.ip(1, buf=2)[:, :] += 0.5 * eps * dt * lap_u.v(buf=2)
u_yl.jp(1, buf=2)[:, :] += 0.5 * eps * dt * lap_u.v(buf=2)
u_xr.v(buf=2)[:, :] += 0.5 * eps * dt * lap_u.v(buf=2)
u_yr.v(buf=2)[:, :] += 0.5 * eps * dt * lap_u.v(buf=2)

v_xl.ip(1, buf=2)[:, :] += 0.5 * eps * dt * lap_v.v(buf=2)
v_yl.jp(1, buf=2)[:, :] += 0.5 * eps * dt * lap_v.v(buf=2)
v_xr.v(buf=2)[:, :] += 0.5 * eps * dt * lap_v.v(buf=2)
v_yr.v(buf=2)[:, :] += 0.5 * eps * dt * lap_v.v(buf=2)

return u_xl, u_xr, u_yl, u_yr, v_xl, v_xr, v_yl, v_yr
1 change: 1 addition & 0 deletions pyro/viscous_burgers/problems/__init__.py
1 change: 1 addition & 0 deletions pyro/viscous_burgers/problems/_converge.defaults
1 change: 1 addition & 0 deletions pyro/viscous_burgers/problems/_test.defaults
1 change: 1 addition & 0 deletions pyro/viscous_burgers/problems/_tophat.defaults
1 change: 1 addition & 0 deletions pyro/viscous_burgers/problems/converge.py
Loading