Skip to content

Commit 903285e

Browse files
authored
add available problems and their runtime parameters to the docs (#269)
this adds a script to the build process to generate the problem definitions. This also fixes a bunch of docs errors and makes the solver pages more consistent
1 parent 075ce40 commit 903285e

14 files changed

Lines changed: 388 additions & 313 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ dist/
99
inputs.auto
1010
.noseids
1111

12+
*problems.inc
13+
1214
.ipynb_checkpoints/
1315

1416
*.pdf

docs/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ help:
1717
# Catch-all target: route all unknown targets to Sphinx using the new
1818
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
1919
%: Makefile
20+
./document_problems.py
2021
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/document_problems.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env python
2+
3+
import importlib
4+
from pathlib import Path
5+
6+
SOLVERS = ["advection",
7+
"advection_fv4",
8+
"advection_nonuniform",
9+
"advection_rk",
10+
"advection_weno",
11+
"burgers",
12+
"burgers_viscous",
13+
"compressible",
14+
"compressible_fv4",
15+
"compressible_react",
16+
"compressible_rk",
17+
"compressible_sdc",
18+
"diffusion",
19+
"incompressible",
20+
"incompressible_viscous",
21+
"lm_atm",
22+
"swe"]
23+
24+
MAX_LEN = 36
25+
26+
27+
def doit(pyro_home):
28+
29+
for s in SOLVERS:
30+
31+
# check it the problems/ directory is not a softlink to
32+
# a different solver
33+
34+
p = Path(f"{pyro_home}/pyro/{s}/problems").resolve()
35+
36+
with open(f"{pyro_home}/docs/source/{s}_problems.inc", "w") as finc:
37+
38+
finc.write("supported problems\n")
39+
finc.write("------------------\n")
40+
41+
if (parent_solver := p.parts[-2]) == s:
42+
43+
# find all the problems
44+
for prob in p.glob("*.py"):
45+
if prob.name == "__init__.py":
46+
continue
47+
48+
mprob = importlib.import_module(f"pyro.{s}.problems.{prob.stem}")
49+
50+
if "init_data" not in dir(mprob):
51+
# not a problem setup
52+
continue
53+
54+
finc.write(f"``{prob.stem}``\n")
55+
finc.write("^" * (len(prob.stem)+4) + "\n\n")
56+
57+
if mprob.__doc__:
58+
finc.write(mprob.__doc__)
59+
60+
finc.write("\n")
61+
62+
try:
63+
params = mprob.PROBLEM_PARAMS
64+
except AttributeError:
65+
params = {}
66+
67+
if params:
68+
finc.write("parameters: \n\n")
69+
70+
finc.write("="*MAX_LEN + " " + "="*MAX_LEN + "\n")
71+
finc.write(f"{'name':{MAX_LEN}} {'default':{MAX_LEN}}\n")
72+
finc.write("="*MAX_LEN + " " + "="*MAX_LEN + "\n")
73+
74+
for k, v in params.items():
75+
pname = "``" + k + "``"
76+
finc.write(f"{pname:{MAX_LEN}} {v:{MAX_LEN}}\n")
77+
78+
finc.write("="*MAX_LEN + " " + "="*MAX_LEN + "\n")
79+
80+
81+
finc.write("\n\n")
82+
83+
else:
84+
finc.write(f"``{s}`` uses the problems defined by ``{parent_solver}``.")
85+
86+
87+
if __name__ == "__main__":
88+
doit("..")

docs/source/advection_basics.rst

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
Advection solvers
2-
=================
1+
*********
2+
Advection
3+
*********
34

45
The linear advection equation:
56

@@ -14,7 +15,7 @@ pyro has several solvers for linear advection, which solve the equation
1415
with different spatial and temporal integration schemes.
1516

1617
``advection`` solver
17-
--------------------
18+
====================
1819

1920
:py:mod:`pyro.advection` implements the directionally unsplit corner
2021
transport upwind algorithm :cite:`colella:1990` with piecewise linear reconstruction.
@@ -29,9 +30,10 @@ The parameters for this solver are:
2930

3031
.. include:: advection_defaults.inc
3132

33+
.. include:: advection_problems.inc
3234

3335
``advection_fv4`` solver
34-
------------------------
36+
========================
3537

3638
:py:mod:`pyro.advection_fv4` uses a fourth-order accurate finite-volume
3739
method with RK4 time integration, following the ideas in
@@ -50,8 +52,10 @@ The parameters for this solver are:
5052

5153
.. include:: advection_fv4_defaults.inc
5254

55+
.. include:: advection_fv4_problems.inc
56+
5357
``advection_nonuniform`` solver
54-
-------------------------------
58+
===============================
5559

5660
:py:mod:`pyro.advection_nonuniform` models advection with a non-uniform
5761
velocity field. This is used to implement the slotted disk problem
@@ -62,8 +66,11 @@ The parameters for this solver are:
6266

6367
.. include:: advection_nonuniform_defaults.inc
6468

69+
.. include:: advection_nonuniform_problems.inc
70+
71+
6572
``advection_rk`` solver
66-
-----------------------
73+
=======================
6774

6875
:py:mod:`pyro.advection_rk` uses a method of lines time-integration
6976
approach with piecewise linear spatial reconstruction for linear
@@ -76,8 +83,10 @@ The parameter for this solver are:
7683

7784
.. include:: advection_rk_defaults.inc
7885

86+
.. include:: advection_rk_problems.inc
87+
7988
``advection_weno`` solver
80-
-------------------------
89+
=========================
8190

8291
:py:mod:`pyro.advection_weno` uses a WENO reconstruction and method of
8392
lines time-integration
@@ -87,9 +96,11 @@ The main parameters that affect this solver are:
8796

8897
.. include:: advection_weno_defaults.inc
8998

99+
.. include:: advection_weno_problems.inc
100+
90101

91102
General ideas
92-
-------------
103+
=============
93104

94105
The main use for the advection solver is to understand how Godunov
95106
techniques work for hyperbolic problems. These same ideas will be used
@@ -108,10 +119,10 @@ reconstruction, evolution, and averaging steps:
108119

109120

110121
Examples
111-
--------
122+
========
112123

113124
smooth
114-
^^^^^^
125+
------
115126

116127
The smooth problem initializes a Gaussian profile and advects it with
117128
:math:`u = v = 1` through periodic boundaries for a period. The result is that
@@ -147,22 +158,15 @@ with the ``advection_fv4`` solver. Departures from perfect scaling
147158
are likely due to the use of limiters.
148159

149160

150-
tophat
151-
^^^^^^
152-
153-
The tophat problem initializes a circle in the center of the domain
154-
with value 1, and 0 outside. This has very steep jumps, and the
155-
limiters will kick in strongly here.
156-
157161
Exercises
158-
---------
162+
=========
159163

160164
The best way to learn these methods is to play with them yourself. The
161165
exercises below are suggestions for explorations and features to add
162166
to the advection solver.
163167

164168
Explorations
165-
^^^^^^^^^^^^
169+
------------
166170

167171
* Test the convergence of the solver for a variety of initial
168172
conditions (tophat hat will differ from the smooth case because of
@@ -175,7 +179,7 @@ Explorations
175179
problem?)
176180

177181
Extensions
178-
^^^^^^^^^^
182+
----------
179183

180184
* Implement a dimensionally split version of the advection
181185
algorithm. How does the solution compare between the unsplit and

docs/source/burgers_basics.rst

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
*****************
12
Burgers' Equation
2-
==================
3+
*****************
34

4-
Burgers' Equation is a nonlinear hyperbolic equation. It has the same form as the advection equation, except that the quantity being advected is the velocity itself.
5+
Burgers' Equation is a nonlinear hyperbolic equation. It has the same
6+
form as the advection equation, except that the quantity being
7+
advected is the velocity itself.
58

69
``Inviscid Burgers``
7-
--------------------------------
10+
====================
811

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

@@ -29,14 +32,25 @@ The parameters for this solver are:
2932

3033
.. include:: burgers_defaults.inc
3134

35+
.. include:: burgers_problems.inc
36+
37+
Example
38+
-------
3239

3340
.. image:: burgers.png
3441
:align: center
3542

36-
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.
43+
The figure above is generated using ``burgers/problems/test.py``,
44+
which is used to test the validity of the solver. Bottom-left of the
45+
domain has a higher velocity than the top-right domain. With
46+
:math:`u_{i,j}=v_{i,j}`, the wave travels diagonally to the top-right
47+
with a constant velocity that is equal to the shock
48+
speed. ``burgers/problem/verify.py`` can be used to calculate the wave
49+
speed using outputs from ``test.py`` and compare to the theoretical
50+
shock speed.
3751

3852
``Viscous Burgers``
39-
--------------------------------
53+
===================
4054

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

@@ -60,6 +74,10 @@ The parameters for this solver are:
6074

6175
.. include:: burgers_viscous_defaults.inc
6276

77+
.. include:: burgers_problems.inc
78+
79+
Example
80+
-------
6381

6482
.. image:: viscous_burgers.png
6583
:align: center

0 commit comments

Comments
 (0)