#!/usr/bin/env python
# coding: utf-8
# # Waves and Stability
#
# Copyright (C) 2010-2020 Luke Olson
# Copyright (C) 2020 Andreas Kloeckner
#
#
# MIT License
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# In[1]:
import numpy as np
import matplotlib.pyplot as plt
# ## Wavelength and Wavenumber
#
# Let $j$ be the wave number, then
# $$
# j = \frac{2\pi}{\tilde{\lambda}}
# $$
# where $\tilde{\lambda}$ is the wavelength.
#
# A sinusoidal wave is expressed as
# $$
# A \cos \left( \frac{2 \pi x}{\tilde{\lambda}} \right).
# $$
# In[2]:
kdx = np.linspace(0, np.pi, 20) / np.pi
plt.plot(kdx, np.cos(2*np.pi*kdx / 0.001))
plt.plot(kdx, np.cos(2*np.pi*kdx / 1.0))
# In[3]:
def ampFTBS(jhx, lmbda):
return np.sqrt(1 - 2 * lmbda * (1 - lmbda) * (1 - np.cos(np.pi*jhx)))
def ampBTCS(jhx, lmbda):
return 1 / np.sqrt(1 + lmbda**2 * np.sin(np.pi * jhx)**2)
# In[7]:
jhx = np.linspace(0, np.pi, 100) / np.pi
#lmbdas = [0.1, 0.2, 0.4, 0.8, 0.9, 1.0, 1.2, 1.4, 1.8, 2.0]
lmbdas = [0.1, 0.2, 0.5, 0.6, 0.75, 0.9, 1.1]
for lmbda in lmbdas:
plt.plot(jhx, ampFTBS(jhx, lmbda), label='%g'%lmbda, lw=4)
plt.legend()
plt.xlabel('$j h_x / \pi$', fontsize=24)
plt.ylabel('$|s(j)|$', fontsize=24)
# ## Dispersion
#
# In[5]:
def alphaoverj(jhx, lmbda):
return np.arctan((lmbda * np.sin(np.pi*jhx)) / (1 - lmbda + lmbda*np.cos(np.pi*jhx))) / (lmbda * np.pi * jhx)
# In[6]:
jhx = np.linspace(0, np.pi, 100) / np.pi
#lmbdas = [0.1, 0.2, 0.4, 0.8, 0.9, 1.0, 1.2, 1.4, 1.8, 2.0]
lmbdas = [0.25, .33, 0.88]
for lmbda in lmbdas:
plt.plot(jhx, alphaoverj(jhx, lmbda), label='%g' % lmbda)
plt.legend()
plt.xlabel('$j h_x / \pi$', fontsize=24)