Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 30 19:47:31 2021
gravfront.py
@author: David Nolte
Introduction to Modern Dynamics, 2nd edition (Oxford University Press, 2019)
Gravitational Lensing
"""
import numpy as np
from matplotlib import pyplot as plt
plt.close('all')
def refindex(x):
n = n0/(1 + abs(x)**expon)**(1/expon);
return n
delt = 0.001
Ly = 10
Lx = 5
n0 = 1
expon = 2 # adjust this from 1 to 10
delx = 0.01
rng = np.int(Lx/delx)
x = delx*np.linspace(-rng,rng)
n = refindex(x)
dndx = np.diff(n)/np.diff(x)
plt.figure(1)
lines = plt.plot(x,n)
plt.figure(2)
lines2 = plt.plot(dndx)
plt.figure(3)
plt.xlim(-Lx, Lx)
plt.ylim(-Ly, 2)
Nloop = 160;
xd = np.zeros((Nloop,3))
yd = np.zeros((Nloop,3))
for loop in range(0,Nloop):
xp = -Lx + 2*Lx*(loop/Nloop)
plt.plot([xp, xp],[2, 0],'b',linewidth = 0.25)
thet = (refindex(xp+delt) - refindex(xp-delt))/(2*delt)
xb = xp + np.tan(thet)*Ly
plt.plot([xp, xb],[0, -Ly],'b',linewidth = 0.25)
for sloop in range(0,3):
delay = n0/(1 + abs(xp)**expon)**(1/expon) - n0
dis = 0.75*(sloop+1)**2 - delay
xfront = xp + np.sin(thet)*dis
yfront = -dis*np.cos(thet)
xd[loop,sloop] = xfront
yd[loop,sloop] = yfront
for sloop in range(0,3):
plt.plot(xd[:,sloop],yd[:,sloop],'r',linewidth = 0.5)