TITLE: On Schemes for Exponential Decay
AUTHOR: Hans Petter Langtangen at Center for Biomedical Computing, Simula Research Laboratory & Department of Informatics, University of Oslo
DATE: today

FIGURE: [../doc/src/slides/fig/CN_logo, width=300 frac=0.4]

## Comments start with a # and are visible as comments in the
## output. Lines starting with ## are also comments, but not visible
## in the output.

!split
===== Goal =====

The primary goal of this demo talk is to demonstrate how to write
talks with "DocOnce": "https://github.com/doconce/doconce"
and get them rendered in numerous HTML formats.
# #if FORMAT in ("html", "pdflatex", "latex")
!bnotice Layout
This version
utilizes ${SLIDE_TYPE} slides with the theme ${SLIDE_THEME}.
!enotice
# #endif

## Demonstrate use of Mako variables set on the command line
## (see last sentence too). We use Preprocess (run before Mako)
## to leave out the Mako test on SLIDE_THEME and SLIDE_TYPE.
## In that way, we do not need to specify these variables on
## the command line when compiling for LaTeX or other formats
## (e.g. for handouts).

# #if FORMAT == "html"
!bnotice
Speaker notes show up by
% if SLIDE_TYPE == 'reveal':
pressing "s".
% elif SLIDE_TYPE == 'deck':
pressing "n".
% elif SLIDE_TYPE == 'csss':
pressing "Ctrl-P".
% elif SLIDE_TYPE == 'html5slides':
pressing "p".
% elif SLIDE_TYPE == 'csss':
using the "onstage.html": "https://github.com/doconce/doconce/blob/main/bundled/dzslides/shells/onstage.html" embedding page.
% endif
!enotice
# #endif

## Add speaker notes (can also use preprocess or mako for this)

!bnotes
The talk investigates the accuracy of three finite difference
schemes for the ordinary differential equation $u'=-au$ with the
aid of numerical experiments. Numerical artifacts are in particular
demonstrated.
!enotes

!split
======= Methods =======

## New slide is indicated by !split at the beginning of a line:

!split
===== Mathematical problem =====

## Use !bslidecell XY and !eslidecell as begin and end for
## defining a cell XY in a table layout of the slide.
## X=0,1,..., Y=0,1,... XY=00 is the upper left cell.
## Here we define cell 00 and 01 (bullet list to the left
## and figure to the right).

!bslidecell 00

## latex blocks are surrounded by !bt and !et

!bt
\begin{align}
u'(t) &= -au(t),
label{ode}\\
u(0)  &= I,
label{initial:value}
\end{align}
!et

 * $t\in (0,T]$
 * $a$, $I$, and $T$ are prescribed parameters
 * $u(t)$ is the unknown function

!eslidecell

## Figures can have a width parameter specifying the pixel
## width in HTML. A caption can be added (after [...]).

!bslidecell 01
FIGURE: [../doc/src/slides/fig/teacher2, width=250 frac=0.5]
!eslidecell

!split
===== Numerical solution method =====

## !bpop and !epop surround elements that are to pop up
## as we progress in the slide show.
## They will often not work if there is code inside.

!bpop
 * Mesh in time: $0= t_0< t_1 \cdots < t_N=T$
 * Assume constant $\Delta t = t_{n}-t_{n-1}$
 * $u^n$: numerical approx to the exact solution at $t_n$
!epop

!bpop
Numerical scheme:
!bt
   \[
   u^{n+1} = \frac{1 - (1-\theta) a\Delta t}{1 + \theta a\Delta t}u^n,
   \quad n=0,1,\ldots,N-1
   \]
!et
!epop

# #if FORMAT == "html"

!split
## Next: embed YouTube video

===== Forward Euler explained =====

MOVIE: [https://youtu.be/PtJrPEIHNJw, width=640 height=480]

# #endif

!split
## Next: exemplify copying code directly from file (start
## with the line matching "def solver" and ending with
## "def verify_three", but not including this last line).

===== Implementation =====

The numerical method is implemented in a Python function:

@@@CODE ../doc/src/slides/src/solver.py  fromto: def solver@def exact_sol

!split
======= Selected results =======
# Short title: Results


!split
===== The Crank-Nicolson method =====

## Figure filenames do not need extension - the right version is picked

FIGURE: [../doc/src/slides/fig/CN, width=600]

!split
===== The artifacts can be explained by some theory =====

!bpop
Exact solution of the scheme:

!bt
\[ u^n = A^n,\quad A = \frac{1 - (1-\theta) a\Delta t}{1 + \theta a\Delta t}\thinspace .\]
!et
!epop

!bpop
 * Stability: $|A| < 1$
 * No oscillations: $A>0$
 * Always for Backward Euler ($\theta=1$)
 * $\Delta t < 1/a$ for Forward Euler ($\theta=0$)
 * $\Delta t < 2/a$ for Crank-Nicolson ($\theta=1/2$)
!epop

## The summary environment appears in a box in most formats
## (warning, notice, hint, question are other environments)
!bpop
!bsummary Concluding remarks:
Only the Backward Euler scheme is guaranteed to always give
qualitatively correct results.
!esummary
!epop
