Skip to content

Commit 910d27e

Browse files
committed
examples: Add note on legacy SubDomain API to tutorial notebook
1 parent 58850b3 commit 910d27e

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

examples/userapi/03_subdomains.ipynb

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
"source": [
1414
"This tutorial is designed to introduce users to the concept of subdomains in Devito and how to utilize them within simulations for a variety of purposes.\n",
1515
"\n",
16+
"It is worth noting that Devito has two `SubDomain` APIs, the current and legacy APIs. Backward compatibility is retained for the latter API (outlined in the appendix at the end of this notebook). However, use of the current API outlined in this notebook is encouraged.\n",
17+
"\n",
1618
"We will begin by exploring the subdomains created internally (and by default) when creating a `Grid` and then explore in detail how users can define and utilize their own subdomains.\n",
1719
"\n",
1820
"Consider the construction of the following `Grid`:"
@@ -912,6 +914,65 @@
912914
"assert np.isclose(norm(v[0]), 0.10301, rtol=1e-4)"
913915
]
914916
},
917+
{
918+
"cell_type": "markdown",
919+
"metadata": {},
920+
"source": [
921+
"## Legacy API\n",
922+
"\n",
923+
"The legacy `SubDomain` API required `SubDomain`s to be created prior to the `Grid`, and passed to the `Grid` on instantiation. This interface can still be used to avoid breaking backward compatibility with existing codes. We can use the `Middle`, `Left`, and `Right` classes from earlier to illustrate this API."
924+
]
925+
},
926+
{
927+
"cell_type": "code",
928+
"execution_count": 33,
929+
"metadata": {},
930+
"outputs": [
931+
{
932+
"name": "stderr",
933+
"output_type": "stream",
934+
"text": [
935+
"Operator `Kernel` ran in 0.01 s\n"
936+
]
937+
},
938+
{
939+
"data": {
940+
"text/plain": [
941+
"Data([[2., 2., 2., 2., 2., 2., 2., 2., 5., 5.],\n",
942+
" [2., 2., 2., 2., 2., 2., 2., 2., 5., 5.],\n",
943+
" [0., 0., 0., 0., 0., 0., 0., 0., 3., 3.],\n",
944+
" [0., 0., 0., 0., 1., 1., 1., 0., 3., 3.],\n",
945+
" [0., 0., 0., 0., 1., 1., 1., 0., 3., 3.],\n",
946+
" [0., 0., 0., 0., 1., 1., 1., 0., 3., 3.],\n",
947+
" [0., 0., 0., 0., 0., 0., 0., 0., 3., 3.],\n",
948+
" [0., 0., 0., 0., 0., 0., 0., 0., 3., 3.],\n",
949+
" [0., 0., 0., 0., 0., 0., 0., 0., 3., 3.],\n",
950+
" [0., 0., 0., 0., 0., 0., 0., 0., 3., 3.]], dtype=float32)"
951+
]
952+
},
953+
"execution_count": 33,
954+
"metadata": {},
955+
"output_type": "execute_result"
956+
}
957+
],
958+
"source": [
959+
"left = Left()\n",
960+
"right = Right()\n",
961+
"mid = Middle()\n",
962+
"\n",
963+
"new_grid = Grid(shape=(10, 10), subdomains=(left, right, mid))\n",
964+
"\n",
965+
"g = Function(name='g', grid=new_grid)\n",
966+
"\n",
967+
"eq1 = Eq(g, g+1, subdomain=new_grid.subdomains['middle'])\n",
968+
"eq2 = Eq(g, g+2, subdomain=new_grid.subdomains['left'])\n",
969+
"eq3 = Eq(g, g+3, subdomain=new_grid.subdomains['right'])\n",
970+
"\n",
971+
"Operator([eq1, eq2, eq3])()\n",
972+
"\n",
973+
"g.data"
974+
]
975+
},
915976
{
916977
"cell_type": "markdown",
917978
"metadata": {},

0 commit comments

Comments
 (0)