matplotlib.rcParams['figure.figsize'] = (figwidth, figwidth / ar) fig = pl.figure() grid = gridspec.GridSpec(nr, nc, wspace=0.0, hspace=0.0) ax = [[] for _ in range(nr * nc)] for i in range(nr * nc): ax[i] = pl.subplot(grid[i]) ax[i].axis('equal') #grid.tight_layout(fig) color = cycle(sns.color_palette('Set2', nr * nc)) pl.sca(ax[0]) levels = sf.contour() # freeze contour levels Mpoint = np.copy(sf.Mpoint) moviename = '../../Movies/{}'.format(filename) moviename += '.mp4' FFMpegWriter = manimation.writers['ffmpeg'] writer = FFMpegWriter(fps=10, bitrate=5000, codec='libx264', extra_args=['-pix_fmt', 'yuv420p']) with writer.saving(fig, moviename, 100): for p in perturb: print(p) for eig in range(nr * nc): c = next(color)
title = ['SN', 'X', 'SF-', 'SF+', 'SX', 'SXex'] for j, config in enumerate(['SN', 'X', 'SFm', 'SFp', 'SX', 'SXex']): print('') print(config) pl.sca(ax[0][j]) pl.title(title[j]) Color = cycle(sns.color_palette('Set2')) setup = Setup(config) sf = SF(setup.filename) rb = RB(setup, sf) pf = PF(sf.eqdsk) eq = EQ(sf, pf, sigma=0.1, boundary=rb.get_fw(expand=0.25), n=5e4) #eq = EQ(sf,pf,sigma=0.1,boundary=rb.get_fw(expand=0.25),n=5e3) sf.contour(Nlevel=21, lw=0.5) pl.plot([14, 14], [-14.5, 9.5], 'o', alpha=0) pf.plot(coils=pf.coil, label=False, plasma=False, current=False) rb.firstwall(calc=False, plot=True, debug=False) rb.vessel() tf = TF(nTF=16, shape={ 'vessel': rb.loop, 'pf': pf, 'fit': True, 'setup': setup, 'plot': False, 'config': config,
sf = SF(setup.filename) rb = RB(setup, sf) pf = PF(sf.eqdsk) tf = TF( Profile(config['TF'], family='S', part='TF', nTF=nTF, obj='L', load=True)) rb.firstwall(symetric=True, DN=True, plot=True) #pf.plot(coils=pf.coil,label=False,plasma=False,current=True) tf.fill() #sf.cpasma *= 1.1 eq = EQ(sf, pf, dCoil=1.5, sigma=0, boundary=sf.get_sep(expand=1.1), n=3e3) eq.gen_bal() #eq.gen_opp() sf.contour() inv = INV(sf, eq, tf) L = inv.grid_coils(offset=0.3) #pf.plot(coils=pf.coil,label=False,plasma=False,current=True) inv.fix_boundary_psi(N=25, alpha=1 - 1e-4, factor=1) # add boundary points inv.fix_boundary_feild(N=25, alpha=1 - 1e-4, factor=1) # add boundary points #inv.add_null(factor=1,point=sf.Xpoint) inv.add_null(factor=1, point=sf.Xpoint_array[:, 0]) inv.add_null(factor=1, point=sf.Xpoint_array[:, 1]) inv.set_swing() inv.update_limits(LCS=[-9.5, 9.5])
for j, z in enumerate(eq.z): points[i * eq.nz + j, :] = np.dot(TRT, np.array([r, z, 1])) # rotate psi grid sf.xo = np.dot(TRT, np.append(sf.xo, 1)) # rotate/translate X-point sead sf.xo[0] -= 0.5 dXpoint = np.dot(R, dXpoint) # rotate X-point deta eq.psi = griddata(points, values, (eq.r2d, eq.z2d), method='cubic', fill_value=0) eq.set_eq_psi() eq.plasma() # update core-b and plasma coils #eq.plotb() ''' sf.contour(boundary=False) pl.plot(sf.xo[0],sf.xo[1],'o') pl.plot(sf.Xpoint[0],sf.Xpoint[1],'d') inv.plot_fix(tails=True) ''' #pf.plot(coils=pf.coil,label=True,plasma=True,current=True) inv = INV(sf, eq, tf) Lpf = inv.grid_PF(nPF=nPF) Lcs = inv.grid_CS(nCS=nCS, Zbound=[-10.5, 7], gap=0.1) L = np.append(Lpf, Lcs) inv.update_coils() inv.update_coils() inv.fit_PF(offset=0.3)
Lcs = inv.grid_CS(nCS=config['nCS'], Zbound=[-8, 8], gap=0.1, fdr=1) L = np.append(Lpf, Lcs) inv.update_coils() inv.fit_PF(offset=0.3) inv.fix_boundary_psi(N=25, alpha=1 - 1e-4, factor=1) # add boundary points inv.fix_boundary_feild(N=25, alpha=1 - 1e-4, factor=1) # add boundary points inv.add_null(factor=1, point=sf.Xpoint) inv.set_swing() inv.update_limits(LCS=[-11.5, 10.5]) L = inv.optimize(L) #inv.plot_fix(tails=True) inv.fix_flux(inv.swing['flux'][1]) inv.solve_slsqp() eq.gen_opp() sf.contour(boundary=True, plot_vac=False) pf.plot(coils=pf.coil, label=True, plasma=False, current=True) rb.firstwall(mode='calc', plot=True, debug=False) rb.trim_sol() #loops.plot_variables(inv.Io,scale=1,postfix='MA') #loops.plot_variables(inv.Lo,scale=1) sf.eqwrite(pf, config=config['eq']) pkl = PKL(config['eq'], directory='../../Movies/') pkl.write(data={'sf': sf, 'eq': eq, 'inv': inv}) # pickle data
font='sans-serif', palette='Set2', font_scale=7 / 8, rc=rc) nPF, nTF = 3, 18 config = {'TF': 'SN_dtt', 'eq': 'SN_{:d}PF_{:d}TF'.format(nPF, nTF)} config = {'TF': 'SN_dtt', 'eq': 'DEMO_SNb'} setup = Setup(config['eq']) sf = SF(setup.filename) pf = PF(sf.eqdsk) pf.plot(coils=pf.coil, label=True, plasma=False, current=True) levels = sf.contour() rb = RB(setup, sf) rb.firstwall(plot=False, debug=False) profile = Profile(config['TF'], family='S', part='TF', nTF=18, obj='L', load=True) shp = Shape(profile, obj='L', eqconf=config['eq'], load=True) # ,nTF=18 rvv, zvv = geom.rzSLine(rb.segment['vessel']['r'], rb.segment['vessel']['z'], 31)
setup = Setup(config['eq']) sf = SF(setup.filename) tf = TF(profile,sf=sf) pf = PF(sf.eqdsk) rb = RB(setup,sf) cage = coil_cage(nTF=nTF,rc=tf.rc,plasma={'config':config['eq']},coil=tf.x['cl']) demo = DEMO() demo.fill_part('Vessel') demo.fill_part('Blanket') demo.fill_part('TF_Coil') demo.plot_ports() demo.plot_limiter() sf.contour(Nlevel=51,plot_vac=False,lw=0.5) pl.plot(sf.rbdry,sf.zbdry,color=0.75*np.ones(3),lw=1) r,z = demo.parts['Plasma']['out']['r'],demo.parts['Plasma']['out']['z'] rb.Rb,rb.Zb = geom.rzInterp(r,z) rb.trim_sol() tf.fill(alpha=0.8) #cage.plot_contours() pl.axis('equal') pl.axis('off') #pl.savefig('../../Figs/TF_ripple_{:d}.pdf'.format(nTF))
'savefig.pad_inches': 0.1, 'lines.linewidth': 1.5 } sns.set(context='talk', style='white', font='sans-serif', palette='Set2', font_scale=7 / 8, rc=rc) color = sns.color_palette('Set2', 5) config, setup = select(base={'TF': 'dtt', 'eq': 'DEMO_FW_SOF'}, nTF=18) sf = SF(setup.filename) pf = PF(sf.eqdsk) pf.plot(coils=pf.coil, label=True, plasma=False, current=True) levels = sf.contour(plot_vac=False) rb = RB(setup, sf) rb.firstwall(plot=True, debug=False, color=color[1]) rb.trim_sol() filename = trim_dir('../../Data/') + 'CATIA_FW.xlsx' wb = load_workbook(filename=filename, read_only=True, data_only=True) ws = wb[wb.get_sheet_names()[0]] FW = {} for col, var in zip([5, 6], ['r', 'z']): row = ws.columns[col] FW[var] = np.zeros(len(row) - 1) for i, r in enumerate(row[1:]): try: FW[var][i] = 1e-3 * float(r.value) # m
inv.add_null(factor=1,point=sf.Xpoint) inv.set_swing() inv.update_limits(LCS=[-9.5,9.5]) Lo = inv.optimize(Lo) inv.fix_flux(inv.swing['flux'][1]) inv.solve_slsqp() #eq = EQ(sf,pf,dCoil=2,sigma=0,boundary=tf.get_loop(expand=0),n=1e4) eq.get_Vcoil() eq.gen_opp() rb.firstwall(mode='calc',plot=True,debug=False) sf.contour() pf.plot(coils=pf.coil,label=True,plasma=True,current=True) sf.contour(boundary=False) inv.plot_fix(tails=True) tf.fill() demo = DEMO() demo.fill_part('Vessel') demo.fill_part('Blanket') pl.plot(demo.limiter['L3']['r'],demo.limiter['L3']['z']) pl.axis('equal') pl.tight_layout() loops.plot_variables(inv.Io,scale=1,postfix='MA') loops.plot_variables(inv.Lo,scale=1)
''' inv = INV(sf,eq,tf) L = inv.grid_coils(offset=0.3) inv.fix_boundary_psi(N=25,alpha=1-1e-4,factor=1) # add boundary points inv.fix_boundary_feild(N=25,alpha=1-1e-4,factor=1) # add boundary points inv.add_null(factor=1,point=sf.Xpoint) inv.set_swing(width=250) inv.initialize_log() inv.set_background() inv.get_weight() inv.set_Lo(L) # set position bounds Lnorm = loops.normalize_variables(inv.Lo) inv.update_position(Lnorm,update_area=True) inv.plot_fix(tails=True) eq.gen_opp() ''' pf.plot(coils=pf.coil, label=True, current=True) pf.plot(coils=eq.coil, label=False, plasma=True, current=False) sf.contour(boundary=True) ff = force_feild(eq.pf.index, eq.pf.coil, eq.coil, eq.plasma_coil, multi_filament=True) ff.plot(scale=1.5) #sf.eqwrite(pf,config=config['eq'])