-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create incompressible_viscous solver and lid-driven cavity test probl…
…em (#138) Needed to change a few things in incompressible/simulation.py as well: Neumann BC's on phi in the case of dirichlet BC's on v (and apply phi-specific BC's in the multigrid solves) Allow user-defined BC's Allow another method for the velocity update in the evolve loop The latter two are then redefined in incompressible_viscous/simulation.py. The rest of the methods are inherited from the base class. For the lid-driven cavity problem, the only free parameter is the viscosity. Since the velocity and length scales are =1, the Reynolds number is just 1/viscosity.
- Loading branch information
1 parent
70445dc
commit 113a50d
Showing
43 changed files
with
1,306 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,10 @@ inputs.auto | |
|
||
__pycache__/ | ||
|
||
.DS_Store | ||
|
||
|
||
pyro/_version.py | ||
pyro.egg-info/ | ||
pyro_hydro.egg-info/ | ||
.eggs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`` | | | ||
+----------------------------------+----------------+----------------------------------------------------+ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Oops, something went wrong.