codex/past-exam-of-the-condensed-matter-physics-major-option-course-of-the-university-of-oxford/2018-magnetic-and-superconducting-response.py

past-exam-of-the-condensed-matter-physics-major-option-course-of-the-university-of-oxford/2018-magnetic-and-superconducting-response.py
"""Original normalized magnetic and superconducting model responses."""
from pathlib import Path
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
plt.rcParams.update({'font.size':11,'axes.spines.top':False,'axes.spines.right':False})
fig,axes=plt.subplots(2,2,figsize=(11,7.8),layout='constrained',facecolor='white')
a=axes[0,0];r=np.linspace(0,.5,400);a.plot(r,-3+6*r,lw=2,label='type I');a.plot(r,-1-2*r,lw=2,label='type II');a.axvline(.25,color='#777',ls=':');a.text(.26,-2.8,'crossing 1/4');a.set(xlabel='J₂ / J₁',ylabel='energy per spin / (J₁ S²)',title='A  Competing classical spin orders');a.legend(frameon=False)
a=axes[0,1];t=np.linspace(.02,2.5,600);para=np.empty_like(t);perp=np.where(t<1,1,2/(t+1))
for i,z in enumerate(t):
 if z>=1:para[i]=2/(z+1);continue
 lo,hi=1e-14,1.
 for _ in range(70):
  m=(lo+hi)/2
  if np.tanh(m/z)>m:lo=m
  else:hi=m
 m=(lo+hi)/2;v=(1-m*m)/z;para[i]=2*v/(1+v)
a.plot(t,perp,lw=2,label='perpendicular');a.plot(t,para,lw=2,label='parallel');a.axvline(1,color='#777',ls=':');a.set(xlabel='T / Tₙ',ylabel='χ / χ(Tₙ)',title='B  Fixed-axis spin-½ mean-field response');a.legend(frameon=False)
a=axes[1,0];t=np.linspace(0,1,400);upper=1-t*t;lower=.13*upper
a.fill_between(t,0,lower,color='#d6e8f4');a.fill_between(t,lower,upper,color='#e4edcf');a.fill_between(t,upper,1.15,color='#f5eee4');a.plot(t,upper,color='#355a9b',label='Hc₂');a.plot(t,lower,color='#269572',label='Hc₁');a.text(.13,.04,'Meissner');a.text(.2,.45,'mixed');a.text(.7,.95,'normal');a.set(xlabel='T / Tc',ylabel='normalized applied field',xlim=(0,1.05),ylim=(0,1.15),title='C  Type-II phase diagram (illustrative)');a.legend(frameon=False,fontsize=9)
a=axes[1,1];x=np.linspace(-12,12,1200);distance=np.minimum.reduce([abs(x-v) for v in [-8,0,8]]);amplitude=np.tanh(distance/np.sqrt(2));a.plot(x,amplitude,color='#8b5292',lw=2)
for v in [-8,0,8]:a.axvline(v,color='#777',ls=':',lw=.7)
a.annotate('core: ψ = 0',xy=(0,0),xytext=(1,.3),arrowprops={'arrowstyle':'->'});a.set(xlabel='distance along cut / ξ',ylabel='|ψ| / bulk amplitude',ylim=(-.03,1.1),title='D  Order parameter recovers between vortices')
fig.savefig(Path.cwd()/Path(__file__).with_suffix('.png').name,dpi=110,facecolor='white')