Skip to content

Commit 2888ae3

Browse files
update tutorials
1 parent 9be5a27 commit 2888ae3

File tree

11 files changed

+386
-281
lines changed

11 files changed

+386
-281
lines changed

tutorials/tutorial1/tutorial.ipynb

Lines changed: 13 additions & 12 deletions
Large diffs are not rendered by default.

tutorials/tutorial12/tutorial.ipynb

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
},
3535
{
3636
"cell_type": "code",
37-
"execution_count": null,
37+
"execution_count": 1,
3838
"metadata": {},
3939
"outputs": [],
4040
"source": [
@@ -71,21 +71,18 @@
7171
"metadata": {},
7272
"outputs": [],
7373
"source": [
74-
"# define the burger equation\n",
75-
"def burger_equation(input_, output_):\n",
76-
" du = fast_grad(output_, input_, components=[\"u\"], d=[\"x\"])\n",
77-
" ddu = grad(du, input_, components=[\"dudx\"])\n",
74+
"# define the burgers equation\n",
75+
"def burgers_equation(input_, output_):\n",
76+
" du = grad(output_, input_)\n",
77+
" ddu = laplacian(output_, input_, components=\"x\")\n",
7878
" return (\n",
79-
" du.extract([\"dudt\"])\n",
80-
" + output_.extract([\"u\"]) * du.extract([\"dudx\"])\n",
81-
" - (0.01 / torch.pi) * ddu.extract([\"ddudxdx\"])\n",
79+
" du[\"dudt\"] + output_[\"u\"] * du[\"dudx\"] - (0.01 / torch.pi) * ddu\n",
8280
" )\n",
8381
"\n",
84-
"\n",
8582
"# define initial condition\n",
8683
"def initial_condition(input_, output_):\n",
87-
" u_expected = -torch.sin(torch.pi * input_.extract([\"x\"]))\n",
88-
" return output_.extract([\"u\"]) - u_expected"
84+
" u_expected = -torch.sin(torch.pi * input_[\"x\"])\n",
85+
" return output_[\"u\"] - u_expected"
8986
]
9087
},
9188
{
@@ -107,7 +104,7 @@
107104
},
108105
{
109106
"cell_type": "code",
110-
"execution_count": null,
107+
"execution_count": 3,
111108
"metadata": {},
112109
"outputs": [],
113110
"source": [
@@ -119,24 +116,18 @@
119116
" temporal_domain = CartesianDomain({\"t\": [0, 1]})\n",
120117
"\n",
121118
" domains = {\n",
122-
" \"bound_cond1\": CartesianDomain({\"x\": -1, \"t\": [0, 1]}),\n",
123-
" \"bound_cond2\": CartesianDomain({\"x\": 1, \"t\": [0, 1]}),\n",
124-
" \"time_cond\": CartesianDomain({\"x\": [-1, 1], \"t\": 0}),\n",
125-
" \"phys_cond\": CartesianDomain({\"x\": [-1, 1], \"t\": [0, 1]}),\n",
119+
" \"bound_cond\": spatial_domain.partial().update(temporal_domain),\n",
120+
" \"time_cond\": spatial_domain.update(CartesianDomain({\"t\": 0.0})),\n",
121+
" \"phys_cond\": spatial_domain.update(temporal_domain),\n",
126122
" }\n",
127123
" # problem condition statement\n",
128124
" conditions = {\n",
129-
" \"bound_cond1\": Condition(\n",
130-
" domain=\"bound_cond1\", equation=FixedValue(0.0)\n",
131-
" ),\n",
132-
" \"bound_cond2\": Condition(\n",
133-
" domain=\"bound_cond2\", equation=FixedValue(0.0)\n",
134-
" ),\n",
125+
" \"bound_cond\": Condition(domain=\"bound_cond\", equation=FixedValue(0.0)),\n",
135126
" \"time_cond\": Condition(\n",
136127
" domain=\"time_cond\", equation=Equation(initial_condition)\n",
137128
" ),\n",
138129
" \"phys_cond\": Condition(\n",
139-
" domain=\"phys_cond\", equation=Equation(burger_equation)\n",
130+
" domain=\"phys_cond\", equation=Equation(burgers_equation)\n",
140131
" ),\n",
141132
" }"
142133
]
@@ -145,7 +136,7 @@
145136
"cell_type": "markdown",
146137
"metadata": {},
147138
"source": [
148-
"The `Equation` class takes as input a function (in this case it happens twice, with `initial_condition` and `burger_equation`) which computes a residual of an equation, such as a PDE. In a problem class such as the one above, the `Equation` class with such a given input is passed as a parameter in the specified `Condition`. \n",
139+
"The `Equation` class takes as input a function (in this case it happens twice, with `initial_condition` and `burgers_equation`) which computes a residual of an equation, such as a PDE. In a problem class such as the one above, the `Equation` class with such a given input is passed as a parameter in the specified `Condition`. \n",
149140
"\n",
150141
"The `FixedValue` class takes as input a value of the same dimensions as the output functions. This class can be used to enforce a fixed value for a specific condition, such as Dirichlet boundary conditions, as demonstrated in our example.\n",
151142
"\n",
@@ -172,7 +163,7 @@
172163
},
173164
{
174165
"cell_type": "code",
175-
"execution_count": 3,
166+
"execution_count": 4,
176167
"metadata": {},
177168
"outputs": [],
178169
"source": [
@@ -206,7 +197,7 @@
206197
},
207198
{
208199
"cell_type": "code",
209-
"execution_count": 4,
200+
"execution_count": 5,
210201
"metadata": {},
211202
"outputs": [],
212203
"source": [
@@ -223,19 +214,13 @@
223214
" temporal_domain = CartesianDomain({\"t\": [0, 1]})\n",
224215
"\n",
225216
" domains = {\n",
226-
" \"bound_cond1\": CartesianDomain({\"x\": -1, \"t\": [0, 1]}),\n",
227-
" \"bound_cond2\": CartesianDomain({\"x\": 1, \"t\": [0, 1]}),\n",
228-
" \"time_cond\": CartesianDomain({\"x\": [-1, 1], \"t\": 0}),\n",
229-
" \"phys_cond\": CartesianDomain({\"x\": [-1, 1], \"t\": [0, 1]}),\n",
217+
" \"bound_cond\": spatial_domain.partial().update(temporal_domain),\n",
218+
" \"time_cond\": spatial_domain.update(CartesianDomain({\"t\": 0.0})),\n",
219+
" \"phys_cond\": spatial_domain.update(temporal_domain),\n",
230220
" }\n",
231221
" # problem condition statement\n",
232222
" conditions = {\n",
233-
" \"bound_cond1\": Condition(\n",
234-
" domain=\"bound_cond1\", equation=FixedValue(0.0)\n",
235-
" ),\n",
236-
" \"bound_cond2\": Condition(\n",
237-
" domain=\"bound_cond2\", equation=FixedValue(0.0)\n",
238-
" ),\n",
223+
" \"bound_cond\": Condition(domain=\"bound_cond\", equation=FixedValue(0.0)),\n",
239224
" \"time_cond\": Condition(\n",
240225
" domain=\"time_cond\", equation=Equation(initial_condition)\n",
241226
" ),\n",
@@ -266,7 +251,7 @@
266251
],
267252
"metadata": {
268253
"kernelspec": {
269-
"display_name": "pina",
254+
"display_name": "deep",
270255
"language": "python",
271256
"name": "python3"
272257
},
@@ -280,7 +265,7 @@
280265
"name": "python",
281266
"nbconvert_exporter": "python",
282267
"pygments_lexer": "ipython3",
283-
"version": "3.9.21"
268+
"version": "3.12.11"
284269
},
285270
"orig_nbformat": 4
286271
},

tutorials/tutorial13/tutorial.ipynb

Lines changed: 35 additions & 39 deletions
Large diffs are not rendered by default.

tutorials/tutorial14/tutorial.ipynb

Lines changed: 16 additions & 17 deletions
Large diffs are not rendered by default.

tutorials/tutorial16/tutorial.ipynb

Lines changed: 13 additions & 13 deletions
Large diffs are not rendered by default.

tutorials/tutorial17/tutorial.ipynb

Lines changed: 178 additions & 29 deletions
Large diffs are not rendered by default.

tutorials/tutorial24/tutorial.ipynb

Lines changed: 18 additions & 19 deletions
Large diffs are not rendered by default.

tutorials/tutorial3/tutorial.ipynb

Lines changed: 23 additions & 32 deletions
Large diffs are not rendered by default.

tutorials/tutorial6/tutorial.ipynb

Lines changed: 22 additions & 22 deletions
Large diffs are not rendered by default.

tutorials/tutorial7/tutorial.ipynb

Lines changed: 21 additions & 30 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)