{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# \n",
"\n",
"# Substitutions\n",
"\n",
"`Substitutions(self, *args)`\n",
"\n",
"Devito class to convert Coefficient objects into replacent rules to be\n",
"applied when constructing a Devito Eq.\n",
"\n",
"## Examples\n",
"\n",
"``` python\n",
">>> from devito import Grid, TimeFunction, Coefficient\n",
">>> grid = Grid(shape=(4, 4))\n",
">>> u = TimeFunction(name='u', grid=grid, space_order=2, coefficients='symbolic')\n",
">>> x, y = grid.dimensions\n",
"```\n",
"\n",
"Now define some partial d/dx FD coefficients of the Function u:\n",
"\n",
"``` python\n",
">>> u_x_coeffs = Coefficient(1, u, x, np.array([-0.6, 0.1, 0.6]))\n",
"```\n",
"\n",
"And now create our Substitutions object to pass to equation:\n",
"\n",
"``` python\n",
">>> from devito import Substitutions\n",
">>> subs = Substitutions(u_x_coeffs)\n",
"```\n",
"\n",
"Now create a Devito equation and pass to it ‘subs’\n",
"\n",
"``` python\n",
">>> from devito import Eq\n",
">>> eq = Eq(u.dt+u.dx, coefficients=subs)\n",
"```\n",
"\n",
"When evaluated, the derivatives will use the custom coefficients. We can\n",
"check that by\n",
"\n",
"``` python\n",
">>> eq.evaluate\n",
"Eq(-u(t, x, y)/dt + u(t + dt, x, y)/dt + 0.1*u(t, x, y) - 0.6*u(t, x - h_x, y) + 0.6*u(t, x + h_x, y), 0)\n",
"```\n",
"\n",
"## Notes\n",
"\n",
"If a Function is declared with ‘symbolic’ coefficients and no\n",
"replacement rules for any derivative appearing in a Devito equation, the\n",
"coefficients will revert to those of the ‘default’ Taylor expansion.\n",
"\n",
"## Attributes\n",
"\n",
"| Name | Description |\n",
"|------------------------------------|------------------------------------|\n",
"| [coefficients](#devito.Substitutions.coefficients) | The Coefficient objects passed. |"
],
"id": "ef5163da-2763-4b01-bd1a-2af449206b85"
}
],
"nbformat": 4,
"nbformat_minor": 5,
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
}
}
}