Datasets:
Formats:
json
Languages:
English
Size:
1K - 10K
Tags:
mathematics
fluid-dynamics
navier-stokes
helicity
nonlinear-observability
experimental-mathematics
Download research/src/make_figures.py from PureOne/Chisael-Nexythra: direct link, hf CLI and curl.
- Browser
- Download file 7.5 kB
-
https://huggingface.co/datasets/PureOne/Chisael-Nexythra/resolve/main/research/src/make_figures.py
- Command line
-
hf download hf://datasets/PureOne/Chisael-Nexythra/research/src/make_figures.py
-
curl -L -o make_figures.py https://huggingface.co/datasets/PureOne/Chisael-Nexythra/resolve/main/research/src/make_figures.py
7.5 kB
| """Rebuild numerical figures and their CSV data (no external data required).""" | |
| from pathlib import Path | |
| import sys,json | |
| import numpy as np | |
| import matplotlib | |
| matplotlib.use('Agg') | |
| import matplotlib.pyplot as plt | |
| import mpmath as mp | |
| from event_calculus import Event,compile_score,observation_matrix | |
| ROOT=Path(__file__).resolve().parents[1]; F=ROOT/'figures';D=ROOT/'data' | |
| F.mkdir(exist_ok=True) | |
| def save(name,fig,data=None,header=''): | |
| fig.tight_layout() | |
| fig.savefig(F/(name+'.pdf'),bbox_inches='tight') | |
| fig.savefig(F/(name+'.png'),dpi=170,bbox_inches='tight') | |
| plt.close(fig) | |
| if data is not None:np.savetxt(D/(name+'.csv'),data,delimiter=',',header=header,comments='') | |
| def axes(xlabel,ylabel): | |
| fig,ax=plt.subplots(figsize=(6.7,4.0));ax.set_xlabel(xlabel);ax.set_ylabel(ylabel);ax.grid(True,alpha=.22) | |
| return fig,ax | |
| s=compile_score([Event('0',2),Event('.18',1),Event('.33',2)],'.5',precision=100) | |
| t=np.linspace(0,.8,901);h=np.array([float(s.helicity(str(x))) for x in t]);e=np.array([float(s.energy(str(x))) for x in t]) | |
| fig,ax=axes('Operational time','Normalized helicity') | |
| ax.plot(t,h);ax.set_yscale('symlog',linthresh=.05) | |
| for x in [0,.18,.33]:ax.axvline(x,ls=':',lw=.8) | |
| ax.set_title('Two contacts and one crossing, compiled exactly') | |
| save('01_event_divisor',fig,np.c_[t,h,e],'time,helicity,energy') | |
| fig,ax=axes('Carrier wavenumber','Signed helicity coefficient') | |
| cs=np.array(list(map(float,s.coefficients)));ax.stem(s.wavenumbers,cs);ax.set_title('Every carrier is present; handedness alternates') | |
| save('02_scissor_carriers',fig,np.c_[s.wavenumbers,cs],'wavenumber,coefficient') | |
| fig,ax=axes('Time','Third-order response coefficient') | |
| data=[t] | |
| for nu in [.2,1,3]: | |
| c=np.exp(-6*nu*t)*(np.expm1(4*nu*t)-4*nu*t)/(8*nu) | |
| ax.plot(t,c,label=f'viscosity {nu:g}');data.append(c) | |
| ax.legend();ax.set_title('The closed triad creates a positive response kernel') | |
| save('03_triad_kernel',fig,np.array(data).T,'time,nu_0p2,nu_1,nu_3') | |
| phi=np.linspace(-np.pi,np.pi,501); val=np.cos(phi) | |
| fig,ax=axes('Closed-loop phase (radians)','Initial helicity acceleration / (2 nu a b c)') | |
| ax.plot(phi,val);ax.axhline(0,ls=':',lw=.8);ax.set_title('Phase reversal and exact quadrature extinction') | |
| save('04_phase_gate',fig,np.c_[phi,val],'phase,normalized_acceleration') | |
| nd=json.loads((D/'nonlinear_demo.json').read_text());rs=nd['results'] | |
| eps=np.array([r['epsilon'] for r in rs]);corr=np.array([r['amplitude_correction_norm'] for r in rs]) | |
| fig,ax=axes('Transverse perturbation amplitude','Norm of axial amplitude correction') | |
| ax.loglog(eps,corr,'o-',label='Galerkin continuation') | |
| ax.loglog(eps,corr[0]*(eps/eps[0])**2,'--',label='Quadratic reference') | |
| ax.legend();ax.set_title('Retuning begins at second order') | |
| save('05_quadratic_retuning',fig,np.c_[eps,corr],'epsilon,amplitude_correction_norm') | |
| fig,ax=axes('Transverse perturbation amplitude','Relative diagnostic (normalized at first point)') | |
| nl=np.array([r['nonlinear_l2'] for r in rs]);st=np.array([r['stretching_l2'] for r in rs]) | |
| ax.loglog(eps,nl/nl[0],'o-',label='Projected advection') | |
| ax.loglog(eps,corr/corr[0],'s-',label='Axial retuning') | |
| ax.legend();ax.set_title('First-order interaction; second-order scalar correction') | |
| save('06_interaction_orders',fig,np.c_[eps,nl,st,corr],'epsilon,advection,stretching,retuning') | |
| base=compile_score([Event('0',1),Event('.12',1)],'.25');tt=np.array(rs[-1]['times']) | |
| fig,ax=axes('Time','Helicity') | |
| ax.plot(tt,[.01*float(base.helicity(str(x))) for x in tt],ls='--',label='Exact shear scaffold') | |
| ax.plot(tt,rs[-1]['helicity'],label='Nonlinear retuned flow, K=3') | |
| for x in [0,.12,.25]:ax.axvline(x,ls=':',lw=.7) | |
| ax.legend();ax.set_title('Zeros retained; the intermediate curve is not prescribed') | |
| save('07_nonlinear_calendar',fig,np.c_[tt,rs[-1]['helicity']],'time,helicity') | |
| fig,ax=axes('Time','Kinetic energy') | |
| for r in rs:ax.plot(r['times'],r['energy'],label=f"epsilon={r['epsilon']:g}") | |
| ax.legend();ax.set_title('Energy decreases throughout every demonstrated run') | |
| save('08_energy_decay',fig) | |
| fig,ax=axes('Kinetic energy','Helicity') | |
| ax.plot(rs[-1]['energy'],rs[-1]['helicity']);ax.invert_xaxis();ax.set_title('An event curve without timestamps') | |
| save('09_energy_clock',fig,np.c_[rs[-1]['energy'],rs[-1]['helicity']],'energy,helicity') | |
| lab=np.linspace(0,1.1,1101) | |
| # A precisely specified, externally imposed common clock. | |
| T=lab-np.clip(lab-.15,0,.18)-np.clip(lab-.65,0,.2) | |
| H=np.array([float(base.helicity(str(x))) for x in T]); E=np.array([float(base.energy(str(x))) for x in T]) | |
| fig,ax=axes('Laboratory time','Helicity / anchor helicity') | |
| ax.plot(lab,H,label='Common-gated equation') | |
| ax.plot(lab,[float(base.helicity(str(x))) for x in lab],ls='--',label='Ungated equation') | |
| ax.legend();ax.set_title('Pauses are clock control, not ordinary fixed-viscosity dynamics') | |
| save('10_common_clock',fig,np.c_[lab,T,E,H],'laboratory_time,operational_time,energy,helicity') | |
| fig,ax=axes('Energy','Helicity') | |
| ss=np.linspace(0,.72,700) | |
| ax.plot([float(base.energy(str(x))) for x in ss],[float(base.helicity(str(x))) for x in ss],label='Ungated geometric curve') | |
| ax.plot(E[::40],H[::40],'o',ms=3,label='Samples under the paused clock') | |
| ax.invert_xaxis();ax.legend();ax.set_title('The energy-coordinate event multiplicity survives retiming') | |
| save('11_clock_quotient',fig) | |
| lp=json.loads((D/'optimal_score.json').read_text()) | |
| fig,ax=axes('Wavenumber in the finite library','Signed helicity coefficient') | |
| ax.stem(lp['wavenumbers'],lp['coefficients']);ax.set_title('Energy optimum uses the minimum three carriers') | |
| save('12_energy_optimizer',fig,np.c_[lp['wavenumbers'],lp['coefficients']],'wavenumber,coefficient') | |
| ks=np.array(lp['wavenumbers']);A=np.array(observation_matrix([Event(0,1),Event(.12,1)],.25,1,ks).tolist(),dtype=float) | |
| q=np.abs(A.T@np.array(lp['dual']));w=1/(2*ks) | |
| fig,ax=axes('Wavenumber','Dual magnitude / energy weight') | |
| ax.plot(ks,q,'o-',label='Absolute dual evaluation');ax.plot(ks,w,'s--',label='Allowed envelope 1/(2k)') | |
| ax.legend();ax.set_title('A dual certificate supports the spectral energy optimum') | |
| save('13_dual_certificate',fig,np.c_[ks,q,w],'wavenumber,dual_absolute,weight') | |
| orders=np.arange(1,11);conds=[] | |
| for N in orders: | |
| A=np.array(observation_matrix([Event(0,int(N))],.2,1,list(range(1,int(N)+2))).tolist(),dtype=float) | |
| A=A/np.max(np.abs(A),axis=1)[:,None] | |
| conds.append(np.linalg.cond(A)) | |
| fig,ax=axes('Initial vanishing order','Row-scaled observation condition number') | |
| ax.semilogy(orders,conds,'o-');ax.set_title('Exact solvability is not numerical robustness') | |
| save('14_conditioning',fig,np.c_[orders,conds],'order,row_scaled_condition_number') | |
| eta=np.logspace(-12,-2,250) | |
| fig,ax=axes('Uniform observation error','Characteristic root displacement') | |
| for m in [1,2,4,8]:ax.loglog(eta,eta**(1/m),label=f'order {m}') | |
| ax.legend();ax.set_title('High-order silence has a sharp noise penalty') | |
| save('15_root_sensitivity',fig,np.c_[eta,*[eta**(1/m) for m in [1,2,4,8]]],'noise,order1,order2,order4,order8') | |
| # The exact rational four-carrier example, with coefficient c0=1. | |
| r=np.array([1,4,9,16]); cc=np.array([27141,-227464,331779,-131456])/27141 | |
| te=np.linspace(0,2.2,701);he=np.sum(cc[None,:]*np.exp(-te[:,None]*r),axis=1) | |
| fig,ax=axes('Time (2 nu = 1)','Helicity with first coefficient normalized to 1') | |
| ax.plot(te,he);ax.axvline(np.log(2),ls=':',lw=.8);ax.axhline(0,ls=':',lw=.8) | |
| ax.set_title('An exact double zero at 0 and a simple zero at log(2)') | |
| save('16_exact_example',fig,np.c_[te,he],'time,helicity') | |
| print('Built',len(list(F.glob('*.pdf'))),'figures.') | |