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

Create incompressible_viscous solver and lid-driven cavity test problem #138

Merged
merged 44 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
fd36dc1
create incompressible_viscous solver and lid-driven cavity test problem
simonguichandut Mar 15, 2023
59c9ccd
Merge branch 'main' into dev_incompressible_viscous
zingale Mar 17, 2023
b0f306f
isort,flake8 fixes
simonguichandut Mar 17, 2023
85b6d70
another one
simonguichandut Mar 17, 2023
0932c4c
add regression test
simonguichandut Mar 17, 2023
0ccb018
add incompressible_viscous in setup.py benchmarks
simonguichandut Mar 23, 2023
3b267d0
Merge branch 'main' into dev_incompressible_viscous
zingale Mar 24, 2023
92fb3c6
[WIP] incompressible viscous docs
simonguichandut Mar 28, 2023
ba3dab3
[WIP] incompressible viscous converge test
simonguichandut Mar 28, 2023
60d0407
Merge branch 'main' into dev_incompressible_viscous
zingale Mar 31, 2023
d2883aa
gitignore adds
simonguichandut Apr 1, 2023
977d2c6
add viscosity as aux variable
simonguichandut Apr 4, 2023
45f37a2
docs fixes
simonguichandut Apr 4, 2023
b0a3811
add viscosity units
simonguichandut Apr 4, 2023
290446b
add incompressible_viscous converge problem
simonguichandut Apr 4, 2023
abe7bd1
add incompressible_viscous shear problem
simonguichandut Apr 4, 2023
76433f7
remove 0.5 factor
simonguichandut Apr 11, 2023
a7f5e61
add viscous term to interface calculation
simonguichandut Apr 12, 2023
b25cb2a
flake8
simonguichandut Apr 12, 2023
58a87c8
Merge branch 'main' into dev_incompressible_viscous
simonguichandut Apr 12, 2023
8c7bd09
factor in proj_type
simonguichandut Apr 18, 2023
9ef648b
Merge branch 'dev_incompressible_viscous' of https://github.com/simon…
simonguichandut Apr 18, 2023
2b6cf87
Merge branch 'python-hydro:main' into dev_incompressible_viscous
simonguichandut Apr 18, 2023
7b17330
check errors on zero viscosity test at the same time as incompressible
simonguichandut Apr 18, 2023
06f1003
fix converge problem solution
simonguichandut Apr 25, 2023
e2c4e8e
pylint fixes
simonguichandut Apr 26, 2023
5478a88
more
simonguichandut Apr 26, 2023
6b033d7
pylint arguments-differ ignore
simonguichandut Apr 26, 2023
991a71e
Eric's suggestion
simonguichandut Apr 26, 2023
8b9dc61
lower default viscosity on shear problem
simonguichandut Apr 26, 2023
808a2b6
update cavity benchmark file
simonguichandut Apr 26, 2023
6ffb4aa
remove time in cavity plot title
simonguichandut Apr 26, 2023
23bbcaf
incompressible viscous docs page
simonguichandut Apr 26, 2023
9ddd85b
docs update
simonguichandut Apr 26, 2023
e142d56
Merge branch 'main' into dev_incompressible_viscous
simonguichandut Apr 26, 2023
2a51706
api docs
simonguichandut Apr 26, 2023
47ebdf7
pyro.rst api file
simonguichandut Apr 26, 2023
4e8047e
redundant try except
simonguichandut Apr 27, 2023
aa3248c
Merge branch 'main' into dev_incompressible_viscous
simonguichandut May 3, 2023
affacbb
Merge branch 'main' into dev_incompressible_viscous
zingale May 3, 2023
02df7f4
merge from main, apply_other_source_terms() in incomp_interface
simonguichandut Aug 9, 2023
749cdd5
correct function description
simonguichandut Aug 9, 2023
a7cfc0d
re-import bnd
simonguichandut Aug 9, 2023
d299134
update description
simonguichandut Aug 9, 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ inputs.auto

__pycache__/

.DS_Store


pyro/_version.py
pyro.egg-info/
pyro_hydro.egg-info/
.eggs/
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ pyro provides the following solvers (all in 2-d):
projection method for the incompressible equations of
hydrodynamics.

- `incompressible_viscous`: an extension of the incompressible solver
including a diffusion term for viscosity.

- `lm_atm`: a solver for the equations of low Mach number
hydrodynamics for atmospheric flows.

Expand Down
Binary file added docs/source/cavity_Re100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/cavity_Re1000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/cavity_Re400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/incomp_viscous_converge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
115 changes: 115 additions & 0 deletions docs/source/incompressible_viscous_basics.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
Incompressible viscous hydrodynamics solver
===========================================

pyro's incompressible viscous solver solves:

.. math::

\frac{\partial U}{\partial t} + U \cdot \nabla U + \nabla p &= \nu \nabla^2 U \\
\nabla \cdot U &= 0

This solver is based on pyro's incompressible solver, but modifies the
velocity update step to take viscosity into account.

The main parameters that affect this solver are:

.. include:: incompressible_viscous_defaults.inc

Examples
--------

shear
^^^^^

The same shear problem as in incompressible solver, here with viscosity
added.

.. prompt:: bash

pyro_sim.py incompressible_viscous shear inputs.shear

.. image:: shear_viscous.png
:align: center

Compare this with the inviscid result. Notice how the velocities have
diffused in all directions.

cavity
^^^^^^

The lid-driven cavity is a well-known benchmark problem for hydro codes
(see e.g. :cite:t:`ghia1982`, :cite:t:`Kuhlmann2019`). In a unit square box
with initially static fluid, motion is initiated by a "lid" at the top
boundary, moving to the right with unit velocity. The basic command is:

.. prompt:: bash

pyro_sim.py incompressible_viscous cavity inputs.cavity

It is interesting to observe what happens when varying the viscosity, or,
equivalently the Reynolds number (in this case :math:`\rm{Re}=1/\nu` since
the characteristic length and velocity scales are 1 by default).

|pic1| |pic2| |pic3|

.. |pic1| image:: cavity_Re100.png
:width: 32%

.. |pic2| image:: cavity_Re400.png
:width: 32%

.. |pic3| image:: cavity_Re1000.png
:width: 32%

These plots were made by allowing the code to run for longer and approach a
steady-state with the option ``driver.max_steps=1000``, then running
(e.g. for the Re=100 case):

.. prompt:: bash

python incompressible_viscous/problems/plot_cavity.py cavity_n64_Re100_0406.h5 -Re 100 -o cavity_Re100.png

convergence
^^^^^^^^^^^

This is the same test as in the incompressible solver. With viscosity,
an exponential term is added to the solution. Limiting can again be
disabled by adding ``incompressible.limiter=0`` to the run command.
The basic set of tests shown below are run as:

.. prompt:: bash

pyro_sim.py incompressible_viscous converge inputs.converge.32 vis.dovis=0
pyro_sim.py incompressible_viscous converge inputs.converge.64 vis.dovis=0
pyro_sim.py incompressible_viscous converge inputs.converge.128 vis.dovis=0

The error is measured by comparing with the analytic solution using
the routine ``incomp_viscous_converge_error.py`` in ``analysis/``. To
generate the plot below, run

.. prompt:: bash

python incompressible_viscous/tests/convergence_errors.py convergence_errors.txt

or ``convergence_errors_no_limiter.txt`` after running with that option. Then:

.. prompt:: bash

python incompressible_viscous/tests/convergence_plot.py

.. image:: incomp_viscous_converge.png
:align: center

The solver is converging but below second-order, unlike the inviscid case. Limiting
does not seem to make a difference here.

Exercises
---------

Explorations
^^^^^^^^^^^^

* In the lid-driven cavity problem, when does the solution reach a steady-state?

* :cite:`ghia1982` give benchmark velocities at different Reynolds number for the
lid-driven cavity problem (see their Table I). Do we agree with their results?
36 changes: 36 additions & 0 deletions docs/source/incompressible_viscous_defaults.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
* section: [driver]

+----------------------------------+----------------+----------------------------------------------------+
| option | value | description |
+==================================+================+====================================================+
| cfl | ``0.8`` | |
+----------------------------------+----------------+----------------------------------------------------+

* section: [incompressible]

+----------------------------------+----------------+----------------------------------------------------+
| option | value | description |
+==================================+================+====================================================+
| limiter | ``2`` | limiter (0 = none, 1 = 2nd order, 2 = 4th order) |
+----------------------------------+----------------+----------------------------------------------------+
| proj_type | ``2`` | what are we projecting? 1 includes -Gp term in U* |
+----------------------------------+----------------+----------------------------------------------------+

* section: [incompressible_viscous]

+----------------------------------+----------------+----------------------------------------------------+
| option | value | description |
+==================================+================+====================================================+
| viscosity | ``0.1`` | kinematic viscosity of the fluid (units L^2/T) |
+----------------------------------+----------------+----------------------------------------------------+

* section: [particles]

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

1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pyro: a python hydro code
multigrid
diffusion_basics
incompressible_basics
incompressible_viscous_basics
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think incompressible_viscous_basics is really an extension of incompressible solver, so it might be better to just add subsections in incompressible_basics.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might make the page a little cumbersome. An alternative is to combine the solvers into a single one, since incompressible_viscous perfectly reproduces incompressible when viscosity=0. But that would be another PR.

Thoughts @zhichen3 @zingale ?

lowmach_basics
swe_basics
particles_basics
Expand Down
42 changes: 42 additions & 0 deletions docs/source/pyro.incompressible_viscous.problems.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
pyro.incompressible\_viscous.problems package
=============================================

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

Submodules
----------

pyro.incompressible\_viscous.problems.cavity module
---------------------------------------------------

.. automodule:: pyro.incompressible_viscous.problems.cavity
:members:
:undoc-members:
:show-inheritance:

pyro.incompressible\_viscous.problems.converge module
-----------------------------------------------------

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

pyro.incompressible\_viscous.problems.plot\_cavity module
---------------------------------------------------------

.. automodule:: pyro.incompressible_viscous.problems.plot_cavity
:members:
:undoc-members:
:show-inheritance:

pyro.incompressible\_viscous.problems.shear module
--------------------------------------------------

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

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

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

.. toctree::
:maxdepth: 4

pyro.incompressible_viscous.problems

Submodules
----------

pyro.incompressible\_viscous.BC module
--------------------------------------

.. automodule:: pyro.incompressible_viscous.BC
:members:
:undoc-members:
:show-inheritance:

pyro.incompressible\_viscous.simulation module
----------------------------------------------

.. automodule:: pyro.incompressible_viscous.simulation
:members:
:undoc-members:
:show-inheritance:
1 change: 1 addition & 0 deletions docs/source/pyro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Subpackages
pyro.compressible_sr
pyro.diffusion
pyro.incompressible
pyro.incompressible_viscous
pyro.lm_atm
pyro.mesh
pyro.multigrid
Expand Down
30 changes: 29 additions & 1 deletion docs/source/refs.bib
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ @article{ZALESAK1979335
abstract = "The theory of flux-corrected transport (FCT) developed by Boris and Book [J. Comput. Phys. 11 (1973) 38; 18 (1975) 248; 20 (1976) 397] is placed in a simple, generalized format, and a new algorithm for implementing the critical flux limiting stage' in multidimensions without resort to time splitting is presented. The new flux limiting algorithm allows the use of FCT techniques in multidimensional fluid problems for which time splitting would produce unacceptable numerical results, such as those involving incompressible or nearly incompressible flow fields. The “clipping” problem associated with the original one dimensional flux limiter is also eliminated or alleviated. Test results and applications to a two dimensional fluid plasma problem are presented."
}


@article{stoker:1958,
author = {Stoker,J. J. and Lindsay,R. Bruce },
title = {Water Waves},
Expand Down Expand Up @@ -101,3 +100,32 @@ @ARTICLE{minion:1996
adsurl = {https://ui.adsabs.harvard.edu/abs/1996JCoPh.127..158M},
adsnote = {Provided by the SAO/NASA Astrophysics Data System}
}

@ARTICLE{ghia1982,
author = {{Ghia}, U. and {Ghia}, K.~N. and {Shin}, C.~T.},
title = "{High-Re Solutions for Incompressible Flow Using the Navier-Stokes Equations and a Multigrid Method}",
journal = {Journal of Computational Physics},
keywords = {Computational Fluid Dynamics, Computational Grids, High Reynolds Number, Incompressible Flow, Navier-Stokes Equation, Algorithms, Computer Programs, Partial Differential Equations, Velocity Distribution, Fluid Mechanics and Heat Transfer},
year = 1982,
month = dec,
volume = {48},
number = {3},
pages = {387-411},
doi = {10.1016/0021-9991(82)90058-4},
adsurl = {https://ui.adsabs.harvard.edu/abs/1982JCoPh..48..387G},
adsnote = {Provided by the SAO/NASA Astrophysics Data System}
}

@Inbook{Kuhlmann2019,
author="Kuhlmann, Hendrik C.
and Roman{\`o}, Francesco",
editor="Gelfgat, Alexander",
title="The Lid-Driven Cavity",
bookTitle="Computational Modelling of Bifurcations and Instabilities in Fluid Dynamics",
year="2019",
publisher="Springer International Publishing",
address="Cham",
pages="233--309",
isbn="978-3-319-91494-7",
doi="10.1007/978-3-319-91494-7_8",
}
Binary file added docs/source/shear_viscous.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 1 addition & 6 deletions pyro/analysis/incomp_converge_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,7 @@ def main():
print(usage)
sys.exit(2)

try:
file = sys.argv[1]
except IndexError:
print(usage)
sys.exit(2)

file = sys.argv[1]
errors = get_errors(file)
print("errors: ", errors[0], errors[1])

Expand Down
57 changes: 57 additions & 0 deletions pyro/analysis/incomp_viscous_converge_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python3


import math
import sys

import numpy as np

import pyro.util.io_pyro as io

usage = """
compare the output in file from the incompressible viscous converge problem to
the analytic solution.

usage: ./incomp_viscous_converge_error.py file
"""


def get_errors(file):

sim = io.read(file)
myd = sim.cc_data
myg = myd.grid

# numerical solution
u = myd.get_var("x-velocity")
v = myd.get_var("y-velocity")
nu = myd.get_aux("viscosity")

t = myd.t

# analytic solution
u_exact = myg.scratch_array()
u_exact[:, :] = 1.0 - 2.0*np.cos(2.0*math.pi*(myg.x2d-t))*np.sin(2.0*math.pi*(myg.y2d-t))*np.exp(-8*math.pi**2*nu*t)

v_exact = myg.scratch_array()
v_exact[:, :] = 1.0 + 2.0*np.sin(2.0*math.pi*(myg.x2d-t))*np.cos(2.0*math.pi*(myg.y2d-t))*np.exp(-8*math.pi**2*nu*t)

# error
udiff = u_exact - u
vdiff = v_exact - v

return udiff.norm(), vdiff.norm()


def main():
if len(sys.argv) != 2:
print(usage)
sys.exit(2)

file = sys.argv[1]
errors = get_errors(file)
print("errors: ", errors[0], errors[1])


if __name__ == "__main__":
main()
Loading