Skip to content

Commit d063c13

Browse files
authored
show how to get the soruce listing for a problem setup (#266)
1 parent d6f2998 commit d063c13

1 file changed

Lines changed: 44 additions & 2 deletions

File tree

docs/source/adding_a_problem_jupyter.ipynb

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,50 @@
114114
"id": "6f682998-c452-4fdf-87dc-bac340e9e9df",
115115
"metadata": {},
116116
"source": [
117-
"Here's what the `smooth` setup looks like for the `advection` solver:\n",
118-
"https://github.com/python-hydro/pyro2/blob/main/pyro/advection/problems/smooth.py"
117+
"It often works best if you start with an existing problem. We can inspect the source of one of the build-in problems easily:"
118+
]
119+
},
120+
{
121+
"cell_type": "code",
122+
"execution_count": 4,
123+
"id": "d7f3180f-5284-451a-8684-839318bb6657",
124+
"metadata": {},
125+
"outputs": [
126+
{
127+
"data": {
128+
"text/plain": [
129+
"\u001b[0;31mSignature:\u001b[0m \u001b[0msmooth\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minit_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmy_data\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrp\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
130+
"\u001b[0;31mSource:\u001b[0m \n",
131+
"\u001b[0;32mdef\u001b[0m \u001b[0minit_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmy_data\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrp\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n",
132+
"\u001b[0;34m\u001b[0m \u001b[0;34m\"\"\" initialize the smooth advection problem \"\"\"\u001b[0m\u001b[0;34m\u001b[0m\n",
133+
"\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n",
134+
"\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mrp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_param\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"driver.verbose\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n",
135+
"\u001b[0;34m\u001b[0m \u001b[0mmsg\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbold\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"initializing the smooth advection problem...\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n",
136+
"\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n",
137+
"\u001b[0;34m\u001b[0m \u001b[0mdens\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmy_data\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_var\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"density\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n",
138+
"\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n",
139+
"\u001b[0;34m\u001b[0m \u001b[0mxmin\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmy_data\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgrid\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mxmin\u001b[0m\u001b[0;34m\u001b[0m\n",
140+
"\u001b[0;34m\u001b[0m \u001b[0mxmax\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmy_data\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgrid\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mxmax\u001b[0m\u001b[0;34m\u001b[0m\n",
141+
"\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n",
142+
"\u001b[0;34m\u001b[0m \u001b[0mymin\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmy_data\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgrid\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mymin\u001b[0m\u001b[0;34m\u001b[0m\n",
143+
"\u001b[0;34m\u001b[0m \u001b[0mymax\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmy_data\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgrid\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mymax\u001b[0m\u001b[0;34m\u001b[0m\n",
144+
"\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n",
145+
"\u001b[0;34m\u001b[0m \u001b[0mxctr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m0.5\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mxmin\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mxmax\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n",
146+
"\u001b[0;34m\u001b[0m \u001b[0myctr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m0.5\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mymin\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mymax\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n",
147+
"\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n",
148+
"\u001b[0;34m\u001b[0m \u001b[0mdens\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m:\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m1.0\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mnumpy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexp\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m60.0\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmy_data\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgrid\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mx2d\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0mxctr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0;36m2\u001b[0m \u001b[0;34m+\u001b[0m\u001b[0;34m\u001b[0m\n",
149+
"\u001b[0;34m\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mmy_data\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgrid\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0my2d\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0myctr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
150+
"\u001b[0;31mFile:\u001b[0m /raid/zingale/development/pyro2/pyro/advection/problems/smooth.py\n",
151+
"\u001b[0;31mType:\u001b[0m function"
152+
]
153+
},
154+
"metadata": {},
155+
"output_type": "display_data"
156+
}
157+
],
158+
"source": [
159+
"from pyro.advection.problems import smooth\n",
160+
"smooth.init_data??"
119161
]
120162
},
121163
{

0 commit comments

Comments
 (0)