|
667 | 667 | "with the aid of a calculator\n",
|
668 | 668 | "and make a function for comparing these results with those from the `solver`\n",
|
669 | 669 | "function. The `test_three_steps` function in\n",
|
670 |
| - "the file [`vib_undamped.py`](${src_vib}/vib_undamped.py)\n", |
| 670 | + "the file [`vib_undamped.py`](https://github.com/devitocodes/devito_book/blob/master/fdm-devito-notebooks/01_vib/src-vib/vib_undamped.py)\n", |
671 | 671 | "shows the details of how we use the hand calculations to test the code:"
|
672 | 672 | ]
|
673 | 673 | },
|
|
908 | 908 | "cell_type": "markdown",
|
909 | 909 | "metadata": {},
|
910 | 910 | "source": [
|
911 |
| - "The complete code appears in the file [`vib_undamped.py`](src-vib/vib_undamped.py).\n", |
| 911 | + "The complete code appears in the file [`vib_undamped.py`](https://github.com/devitocodes/devito_book/blob/master/fdm-devito-notebooks/01_vib/src-vib/vib_undamped.py).\n", |
912 | 912 | "\n",
|
913 | 913 | "\n",
|
914 | 914 | "### Visualizing convergence rates with slope markers\n",
|
915 | 915 | "\n",
|
916 | 916 | "Tony S. Yu has written a script [`plotslopes.py`](http://goo.gl/A4Utm7)\n",
|
917 | 917 | "that is very useful to indicate the slope of a graph, especially\n",
|
918 | 918 | "a graph like $\\ln E = r\\ln \\Delta t + \\ln C$ arising from the model\n",
|
919 |
| - "$E=C\\Delta t^r$. A copy of the script resides in the [`src-vib`](src-vib)\n", |
| 919 | + "$E=C\\Delta t^r$. A copy of the script resides in the [`src-vib`](https://github.com/devitocodes/devito_book/tree/master/fdm-devito-notebooks/01_vib/src-vib)\n", |
920 | 920 | "directory. Let us use it to compare the original method for $u'' + \\omega^2u =0$\n",
|
921 | 921 | "with the same method applied to the equation with a modified\n",
|
922 | 922 | "$\\omega$. We make log-log plots of the error versus $\\Delta t$.\n",
|
|
1951 | 1951 | "cell_type": "markdown",
|
1952 | 1952 | "metadata": {},
|
1953 | 1953 | "source": [
|
1954 |
| - "The code segments are found in the file [`vib_empirical_analysis.py`](src-vib/vib_empirical_analysis.py).\n", |
| 1954 | + "The code segments are found in the file [`vib_empirical_analysis.py`](https://github.com/devitocodes/devito_book/blob/master/fdm-devito-notebooks/01_vib/src-vib/vib_empirical_analysis.py).\n", |
1955 | 1955 | "\n",
|
1956 | 1956 | "Since `a[i]` and `p[i]` correspond to\n",
|
1957 | 1957 | "the $i$-th amplitude estimate and the $i$-th period estimate, respectively,\n",
|
|
2367 | 2367 | "[Figure](#vib:ode1:tildeomega:plot) plots the discrete frequency\n",
|
2368 | 2368 | "([18](#vib:ode1:tildeomega)) and its approximation\n",
|
2369 | 2369 | "([19](#vib:ode1:tildeomega:series)) for $\\omega =1$ (based on the\n",
|
2370 |
| - "program [`vib_plot_freq.py`](src-vib/vib_plot_freq.py)).\n", |
| 2370 | + "program [`vib_plot_freq.py`](https://github.com/devitocodes/devito_book/blob/master/fdm-devito-notebooks/01_vib/src-vib/vib_plot_freq.py)).\n", |
2371 | 2371 | "Although $\\tilde\\omega$ is a function of $\\Delta t$ in\n",
|
2372 | 2372 | "([19](#vib:ode1:tildeomega:series)), it is misleading to think of\n",
|
2373 | 2373 | "$\\Delta t$ as the important discretization parameter. mathcal{I}_t is the\n",
|
|
3549 | 3549 | "metadata": {},
|
3550 | 3550 | "source": [
|
3551 | 3551 | "There is quite some more code dealing with plots also, and we refer\n",
|
3552 |
| - "to the source file [`vib_undamped_odespy.py`](src-vib/vib_undamped_odespy.py)\n", |
| 3552 | + "to the source file [`vib_undamped_odespy.py`](https://github.com/devitocodes/devito_book/blob/master/fdm-devito-notebooks/01_vib/src-vib/vib_undamped_odespy.py)\n", |
3553 | 3553 | "for details. Observe that keyword arguments in `f(u,t,w=1)` can\n",
|
3554 | 3554 | "be supplied through a solver parameter `f_kwargs` (dictionary of\n",
|
3555 | 3555 | "additional keyword arguments to `f`).\n",
|
|
4338 | 4338 | "verification. The value of `e_E_norm` is also useful for comparing\n",
|
4339 | 4339 | "schemes through their ability to preserve energy. Below is a table\n",
|
4340 | 4340 | "demonstrating the relative error in total energy for various schemes\n",
|
4341 |
| - "(computed by the [`vib_undamped_odespy.py`](src-vib/vib_undamped_odespy.py) program). The test problem is\n", |
| 4341 | + "(computed by the [`vib_undamped_odespy.py`](https://github.com/devitocodes/devito_book/blob/master/fdm-devito-notebooks/01_vib/src-vib/vib_undamped_odespy.py) program). The test problem is\n", |
4342 | 4342 | "$u^{\\prime\\prime} + 4\\pi^2 u =0$ with $u(0)=1$ and $u'(0)=0$, so the\n",
|
4343 | 4343 | "period is 1 and $E(t)\\approx 4.93$. We clearly see that the\n",
|
4344 | 4344 | "Crank-Nicolson and the Runge-Kutta schemes are superior to the Forward\n",
|
|
4802 | 4802 | "\n",
|
4803 | 4803 | "### Solver function\n",
|
4804 | 4804 | "\n",
|
4805 |
| - "The function below, found in [`vib_undamped_EulerCromer.py`](src-vib/vib_undamped_EulerCromer.py), implements the Euler-Cromer scheme\n", |
| 4805 | + "The function below, found in [`vib_undamped_EulerCromer.py`](https://github.com/devitocodes/devito_book/blob/master/fdm-devito-notebooks/01_vib/src-vib/vib_undamped_EulerCromer.py), implements the Euler-Cromer scheme\n", |
4806 | 4806 | "([54](#vib:model2x2:EulerCromer:veq1b))-([55](#vib:model2x2:EulerCromer:ueq1b)):"
|
4807 | 4807 | ]
|
4808 | 4808 | },
|
|
4914 | 4914 | "To verify the implementation of the Euler-Cromer method we can adjust\n",
|
4915 | 4915 | "`v[1]` so that the computer-generated values can be compared with the\n",
|
4916 | 4916 | "formula ([20](#vib:ode1:un:exact)) from in the section [Exact discrete solution](#vib:ode1:analysis:sol). This adjustment is done in an alternative\n",
|
4917 |
| - "solver function, `solver_ic_fix` in [`vib_undamped_EulerCromer.py`](src-vib/vib_undamped_EulerCromer.py). Since we now\n", |
| 4917 | + "solver function, `solver_ic_fix` in [`vib_undamped_EulerCromer.py`](https://github.com/devitocodes/devito_book/blob/master/fdm-devito-notebooks/01_vib/src-vib/vib_undamped_EulerCromer.py). Since we now\n", |
4918 | 4918 | "have an exact solution of the discrete equations available, we can\n",
|
4919 | 4919 | "write a test function `test_solver` for checking the equality of\n",
|
4920 | 4920 | "computed values with the formula ([20](#vib:ode1:un:exact)):"
|
|
4958 | 4958 | "### Convergence rates\n",
|
4959 | 4959 | "\n",
|
4960 | 4960 | "We may use the `convergence_rates` function in the file\n",
|
4961 |
| - "[`vib_undamped.py`](src-vib/vib_undamped.py) to investigate the convergence rate of the\n", |
| 4961 | + "[`vib_undamped.py`](https://github.com/devitocodes/devito_book/blob/master/fdm-devito-notebooks/01_vib/src-vib/vib_undamped.py) to investigate the convergence rate of the\n", |
4962 | 4962 | "Euler-Cromer method, see the `convergence_rate` function in the file\n",
|
4963 |
| - "[`vib_undamped_EulerCromer.py`](src-vib/vib_undamped_EulerCromer.py). Since we could eliminate $v$ to get a\n", |
| 4963 | + "[`vib_undamped_EulerCromer.py`](https://github.com/devitocodes/devito_book/blob/master/fdm-devito-notebooks/01_vib/src-vib/vib_undamped_EulerCromer.py). Since we could eliminate $v$ to get a\n", |
4964 | 4964 | "scheme for $u$ that is equivalent to the finite difference method for\n",
|
4965 | 4965 | "the second-order equation in $u$, we would expect the convergence\n",
|
4966 | 4966 | "rates to be the same, i.e., $r = 2$. However,\n",
|
|
5585 | 5585 | "`vib_undamped.py` (which solves $u''+\\omega^2u=0$ directly). The\n",
|
5586 | 5586 | "values should coincide to machine precision since the two numerical\n",
|
5587 | 5587 | "methods are mathematically equivalent. We refer to the file\n",
|
5588 |
| - "[`vib_undamped_staggered.py`](src-vib/vib_undamped_staggered.py)\n", |
| 5588 | + "[`vib_undamped_staggered.py`](https://github.com/devitocodes/devito_book/blob/master/fdm-devito-notebooks/01_vib/src-vib/vib_undamped_staggered.py)\n", |
5589 | 5589 | "for the details of a unit test (`test_staggered`) that checks this property.\n",
|
5590 | 5590 | "\n",
|
5591 | 5591 | "# Exercises and Problems\n",
|
|
8410 | 8410 | "## Problem 15: Minimize memory usage of a general vibration solver\n",
|
8411 | 8411 | "<div id=\"vib:exer:memsave\"></div>\n",
|
8412 | 8412 | "\n",
|
8413 |
| - "The program [`vib.py`](${src_vib}/vib.py) stores the complete\n", |
| 8413 | + "The program [`vib.py`](https://github.com/devitocodes/devito_book/blob/master/fdm-devito-notebooks/01_vib/src-vib/vib.py) stores the complete\n", |
8414 | 8414 | "solution $u^0,u^1,\\ldots,u^{N_t}$ in memory, which is convenient for\n",
|
8415 | 8415 | "later plotting. Make a memory minimizing version of this program\n",
|
8416 | 8416 | "where only the last three $u^{n+1}$, $u^n$, and $u^{n-1}$ values are\n",
|
|
9049 | 9049 | "name": "python",
|
9050 | 9050 | "nbconvert_exporter": "python",
|
9051 | 9051 | "pygments_lexer": "ipython3",
|
9052 |
| - "version": "3.8.3" |
| 9052 | + "version": "3.8.2" |
9053 | 9053 | }
|
9054 | 9054 | },
|
9055 | 9055 | "nbformat": 4,
|
|
0 commit comments