n=2 bern = bernstein(psi_flux,n=n) # set up bezier curves bPprime = bern.fit(sf.Pprime(psi_flux))[1] bFFprime = bern.fit(sf.FFprime(psi_flux))[1] b_norm = np.append(bPprime,bFFprime) bo = np.ones(len(b_norm)) opp = op.minimize(flux_fit,bo,options={'disp':True},method='L-BFGS-B') ''' opp = op.minimize(flux_fit, [1e-2, 1e-2], options={'disp': True}, method='SLSQP', tol=1e-12) print('fun:{:1.8f}'.format(opp.fun)) #eq.coreBC() eq.psi = eq.solve() eq.set_eq_psi() eq.plotb() sf.contour(levels=levels, color=next(color), Xnorm=False) eq.sf.Bquiver() fig, ax = pl.subplots(2, sharex=True) ax[0].plot(psi_flux, sf.Pprime(psi_flux)) ax[0].plot(sf.eq['pnorm'], sf.eq['pprime'], '.') ax[1].plot(psi_flux, sf.FFprime(psi_flux)) ax[1].plot(sf.eq['pnorm'], sf.eq['ffprim'], '.') fig.subplots_adjust(hspace=0.1) sns.despine()
f.write('{:1.6f}\t{:1.6f}\n'.format(R[i],Z[i])) pl.plot(rb,zb,'r') pl.plot(R,Z,'bo') pl.axis('off') pl.savefig('../Figs/SN_bdry_image.png',dpi=200) nf = 100 psi_ff = np.linspace(0,1,nf) pl.figure(figsize=(12,9)) ax1 = pl.subplot(211) ax2 = pl.subplot(212,sharex=ax1) FFprime = sf.FFprime(psi_ff) Pprime = sf.Pprime(psi_ff) ff=np.polyfit(psi_ff,FFprime,4) FFfit = np.zeros(np.shape(psi_ff)) for i in range(len(ff)): FFfit += ff[-i-1]*psi_ff**i p=np.polyfit(psi_ff,Pprime,4) Pfit = np.zeros(np.shape(psi_ff)) for i in range(len(p)): Pfit += p[-i-1]*psi_ff**i C = next(Color) ax1.plot(psi_ff,FFprime,color=C) ax1.plot(psi_ff,FFfit,'k--') C = next(Color)