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