Skip to content

Commit f916f7f

Browse files
committed
Update testing_pde_to_ode.ipynb
1 parent 7afd5fc commit f916f7f

File tree

1 file changed

+99
-13
lines changed

1 file changed

+99
-13
lines changed

test/testing_pde_to_ode.ipynb

Lines changed: 99 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 8,
5+
"execution_count": 2,
66
"metadata": {},
77
"outputs": [],
88
"source": [
@@ -28,7 +28,7 @@
2828
},
2929
{
3030
"cell_type": "code",
31-
"execution_count": 9,
31+
"execution_count": 3,
3232
"metadata": {},
3333
"outputs": [],
3434
"source": [
@@ -38,7 +38,7 @@
3838
},
3939
{
4040
"cell_type": "code",
41-
"execution_count": 10,
41+
"execution_count": 4,
4242
"metadata": {},
4343
"outputs": [],
4444
"source": [
@@ -49,28 +49,114 @@
4949
},
5050
{
5151
"cell_type": "code",
52-
"execution_count": 13,
52+
"execution_count": 5,
53+
"metadata": {},
54+
"outputs": [
55+
{
56+
"data": {
57+
"text/plain": [
58+
"LinearPDESystemOperator(2, immutabledict({DerivativeIdentifier(mi=(2, 0), vec_idx=0): 1, DerivativeIdentifier(mi=(0, 2), vec_idx=0): 1}))"
59+
]
60+
},
61+
"execution_count": 5,
62+
"metadata": {},
63+
"output_type": "execute_result"
64+
}
65+
],
66+
"source": [
67+
"from collections import namedtuple\n",
68+
"DerivativeIdentifier = namedtuple(\"DerivativeIdentifier\", [\"mi\", \"vec_idx\"])\n",
69+
"partial_1 = DerivativeIdentifier((2,0), 0)\n",
70+
"partial_2 = DerivativeIdentifier((0,2), 0)\n",
71+
"list_pde = {partial_1: 1, partial_2: 1}\n",
72+
"list_pde = immutabledict(list_pde)\n",
73+
"pde_op = LinearPDESystemOperator(2,(list_pde))\n",
74+
"pde_op"
75+
]
76+
},
77+
{
78+
"cell_type": "code",
79+
"execution_count": 6,
80+
"metadata": {},
81+
"outputs": [
82+
{
83+
"data": {
84+
"text/plain": [
85+
"LinearPDESystemOperator(2, (immutabledict({DerivativeIdentifier(mi=(2, 0), vec_idx=0): 1, DerivativeIdentifier(mi=(0, 2), vec_idx=0): 1}),))"
86+
]
87+
},
88+
"execution_count": 6,
89+
"metadata": {},
90+
"output_type": "execute_result"
91+
}
92+
],
93+
"source": [
94+
"w = make_identity_diff_op(2)\n",
95+
"laplace2d = laplacian(w)\n",
96+
"laplace2d"
97+
]
98+
},
99+
{
100+
"cell_type": "code",
101+
"execution_count": 67,
102+
"metadata": {},
103+
"outputs": [
104+
{
105+
"data": {
106+
"text/plain": [
107+
"LinearPDESystemOperator(2, immutabledict({DerivativeIdentifier(mi=(2, 0), vec_idx=0): 1, DerivativeIdentifier(mi=(0, 2), vec_idx=0): 1}))"
108+
]
109+
},
110+
"execution_count": 67,
111+
"metadata": {},
112+
"output_type": "execute_result"
113+
}
114+
],
115+
"source": [
116+
"pde_op"
117+
]
118+
},
119+
{
120+
"cell_type": "code",
121+
"execution_count": 62,
53122
"metadata": {},
54123
"outputs": [
55124
{
56125
"data": {
57-
"text/latex": [
58-
"$\\displaystyle \\frac{f_{r1}}{\\sqrt{x_{0}^{2} + x_{1}^{2}}} + f_{r2}$"
59-
],
60126
"text/plain": [
61-
"f_r1/sqrt(x0**2 + x1**2) + f_r2"
127+
"LinearPDESystemOperator(2, (immutabledict({DerivativeIdentifier(mi=(2, 0), vec_idx=0): 1, DerivativeIdentifier(mi=(0, 2), vec_idx=0): 1}),))"
62128
]
63129
},
64-
"execution_count": 13,
130+
"execution_count": 62,
65131
"metadata": {},
66132
"output_type": "execute_result"
67133
}
68134
],
69135
"source": [
70-
"ode_in_r, var, ode_order = pde_to_ode_in_r(laplace2d)\n",
71-
"ode_in_x = ode_in_r_to_x(ode_in_r, var, ode_order).simplify()\n",
72-
"ode_in_x_cleared = (ode_in_x * var[0]**(ode_order+1)).simplify()\n",
73-
"ode_in_r.simplify()"
136+
"laplace2d"
137+
]
138+
},
139+
{
140+
"cell_type": "code",
141+
"execution_count": 63,
142+
"metadata": {},
143+
"outputs": [
144+
{
145+
"ename": "ValueError",
146+
"evalue": "PDE must be scalar",
147+
"output_type": "error",
148+
"traceback": [
149+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
150+
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
151+
"Cell \u001b[0;32mIn[63], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m ode_in_r, var, ode_order \u001b[38;5;241m=\u001b[39m \u001b[43mpde_to_ode_in_r\u001b[49m\u001b[43m(\u001b[49m\u001b[43mpde_op\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 2\u001b[0m ode_in_r\n",
152+
"File \u001b[0;32m~/Desktop/sumpy/sumpy/recurrence.py:98\u001b[0m, in \u001b[0;36mpde_to_ode_in_r\u001b[0;34m(pde)\u001b[0m\n\u001b[1;32m 83\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124mr\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 84\u001b[0m \u001b[38;5;124;03mReturns an ODE satisfied by the radial derivatives of a function\u001b[39;00m\n\u001b[1;32m 85\u001b[0m \u001b[38;5;124;03m:math:`f:\\mathbb R^n \\to \\mathbb R` satisfying\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 95\u001b[0m \u001b[38;5;124;03m- *ode_order* the order of ODE that is returned\u001b[39;00m\n\u001b[1;32m 96\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 97\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(pde\u001b[38;5;241m.\u001b[39meqs) \u001b[38;5;241m!=\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[0;32m---> 98\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mPDE must be scalar\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 100\u001b[0m dim \u001b[38;5;241m=\u001b[39m pde\u001b[38;5;241m.\u001b[39mdim\n\u001b[1;32m 101\u001b[0m ode_order \u001b[38;5;241m=\u001b[39m pde\u001b[38;5;241m.\u001b[39morder\n",
153+
"\u001b[0;31mValueError\u001b[0m: PDE must be scalar"
154+
]
155+
}
156+
],
157+
"source": [
158+
"ode_in_r, var, ode_order = pde_to_ode_in_r(pde_op)\n",
159+
"ode_in_r"
74160
]
75161
},
76162
{

0 commit comments

Comments
 (0)