|
34 | 34 | }, |
35 | 35 | { |
36 | 36 | "cell_type": "code", |
37 | | - "execution_count": null, |
| 37 | + "execution_count": 1, |
38 | 38 | "metadata": {}, |
39 | 39 | "outputs": [], |
40 | 40 | "source": [ |
|
71 | 71 | "metadata": {}, |
72 | 72 | "outputs": [], |
73 | 73 | "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", |
78 | 78 | " 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", |
82 | 80 | " )\n", |
83 | 81 | "\n", |
84 | | - "\n", |
85 | 82 | "# define initial condition\n", |
86 | 83 | "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" |
89 | 86 | ] |
90 | 87 | }, |
91 | 88 | { |
|
107 | 104 | }, |
108 | 105 | { |
109 | 106 | "cell_type": "code", |
110 | | - "execution_count": null, |
| 107 | + "execution_count": 3, |
111 | 108 | "metadata": {}, |
112 | 109 | "outputs": [], |
113 | 110 | "source": [ |
|
119 | 116 | " temporal_domain = CartesianDomain({\"t\": [0, 1]})\n", |
120 | 117 | "\n", |
121 | 118 | " 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", |
126 | 122 | " }\n", |
127 | 123 | " # problem condition statement\n", |
128 | 124 | " 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", |
135 | 126 | " \"time_cond\": Condition(\n", |
136 | 127 | " domain=\"time_cond\", equation=Equation(initial_condition)\n", |
137 | 128 | " ),\n", |
138 | 129 | " \"phys_cond\": Condition(\n", |
139 | | - " domain=\"phys_cond\", equation=Equation(burger_equation)\n", |
| 130 | + " domain=\"phys_cond\", equation=Equation(burgers_equation)\n", |
140 | 131 | " ),\n", |
141 | 132 | " }" |
142 | 133 | ] |
|
145 | 136 | "cell_type": "markdown", |
146 | 137 | "metadata": {}, |
147 | 138 | "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", |
149 | 140 | "\n", |
150 | 141 | "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", |
151 | 142 | "\n", |
|
172 | 163 | }, |
173 | 164 | { |
174 | 165 | "cell_type": "code", |
175 | | - "execution_count": 3, |
| 166 | + "execution_count": 4, |
176 | 167 | "metadata": {}, |
177 | 168 | "outputs": [], |
178 | 169 | "source": [ |
|
206 | 197 | }, |
207 | 198 | { |
208 | 199 | "cell_type": "code", |
209 | | - "execution_count": 4, |
| 200 | + "execution_count": 5, |
210 | 201 | "metadata": {}, |
211 | 202 | "outputs": [], |
212 | 203 | "source": [ |
|
223 | 214 | " temporal_domain = CartesianDomain({\"t\": [0, 1]})\n", |
224 | 215 | "\n", |
225 | 216 | " 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", |
230 | 220 | " }\n", |
231 | 221 | " # problem condition statement\n", |
232 | 222 | " 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", |
239 | 224 | " \"time_cond\": Condition(\n", |
240 | 225 | " domain=\"time_cond\", equation=Equation(initial_condition)\n", |
241 | 226 | " ),\n", |
|
266 | 251 | ], |
267 | 252 | "metadata": { |
268 | 253 | "kernelspec": { |
269 | | - "display_name": "pina", |
| 254 | + "display_name": "deep", |
270 | 255 | "language": "python", |
271 | 256 | "name": "python3" |
272 | 257 | }, |
|
280 | 265 | "name": "python", |
281 | 266 | "nbconvert_exporter": "python", |
282 | 267 | "pygments_lexer": "ipython3", |
283 | | - "version": "3.9.21" |
| 268 | + "version": "3.12.11" |
284 | 269 | }, |
285 | 270 | "orig_nbformat": 4 |
286 | 271 | }, |
|
0 commit comments