Exemple #1
0
def run_gap_nogap_comparison():
    splopter_gap = spl.Splopter('bin/data/',
                                'benchmarking_sam/',
                                'prebprobe_fullgap/',
                                prepare=False)
    splopter_nogap = spl.Splopter('bin/data/',
                                  'benchmarking_sam/',
                                  'prebprobe_fullnogap/',
                                  prepare=False)

    splopter_gap.prepare(denormaliser_fl=False)
    splopter_nogap.prepare(denormaliser_fl=False)

    ivdata_g = splopter_gap.trim()
    ivdata_ng = splopter_nogap.trim()

    ivdata_g2 = splopter_gap.trim(trim_beg=0.05, trim_end=0.45)
    ivdata_ng2 = splopter_nogap.trim(trim_beg=0.05, trim_end=0.45)

    # ifit_g = splopter_gap.fit(ivdata_g, f.IonCurrentSEFitter(), print_fl=True)
    # ifit_ng = splopter_nogap.fit(ivdata_ng, f.IonCurrentSEFitter(), print_fl=True)

    ffit_g2 = splopter_gap.fit(ivdata_g2, print_fl=True)
    ffit_ng2 = splopter_nogap.fit(ivdata_ng2, print_fl=True)

    fig1 = plt.figure()
    splopter_gap.plot_iv(fig=fig1, plot_tot=True, label='Gap')
    splopter_nogap.plot_iv(fig=fig1,
                           plot_vf=True,
                           plot_tot=True,
                           label='No Gap')

    fig2 = plt.figure()
    splopter_gap.plot_f_fit(
        ffit_g2,
        fig=fig2,
        plot_vf=False,
        label=r'Gap - $T_e$ = {:.2g}, $I_{}$ = {:.3g}'.format(
            ffit_g2.get_temp(errors_fl=False), r'{sat}',
            ffit_g2.get_isat(errors_fl=False)))
    splopter_nogap.plot_f_fit(
        ffit_ng2,
        fig=fig2,
        label=r'No Gap - $T_e$ = {:.2g}, $I_{}$ = {:.3g}'.format(
            ffit_ng2.get_temp(errors_fl=False), '{sat}',
            ffit_ng2.get_isat(errors_fl=False)))

    # fig3 = plt.figure()
    # splopter_gap.plot_i_fit(ifit_g, fig=fig3, label='Gap ')
    # splopter_nogap.plot_i_fit(ifit_ng, fig=fig3, label='No Gap ')
    plt.legend()
    plt.show()
Exemple #2
0
def run_maxwellian_comparison():
    splopter_sheath = spl.Splopter('bin/data/',
                                   'benchmarking_sam/',
                                   'disttest_fullnogap/',
                                   prepare=False)
    splopter_whole = spl.Splopter('bin/data/',
                                  'benchmarking_sam/',
                                  'prebprobe_fullnogap/',
                                  prepare=False)

    fig = plt.figure()
    run_spice_df_analysis(splopter_sheath, fig=fig)
    run_spice_df_analysis(splopter_whole, fig=fig)
    plt.show()
Exemple #3
0
def test():
    flpt = spl.Splopter('bin/data_local/', 'benchmarking/', 'nogap/')

    vf = flpt.get_vf()
    phi = flpt.get_plasma_potential()

    mu = flpt.denormaliser.mu
    const = np.log(0.6 * np.sqrt((2 * np.pi) / mu))
    temperature = (vf - phi) / const
    print(temperature)
Exemple #4
0
def draw_potential(splopter=None, t_dict_label=sd.POT, plot_obj_fl=False):
    if not splopter:
        splopter = spl.Splopter('bin/data_local/',
                                'benchmarking/',
                                'disttest_fullnogap/',
                                prepare=False)
        # splopter = spl.Flopter('bin/data/', 'benchmarking_sam/', 'prebprobe_fullgap/', prepare=False)

    plasma_parameter = np.flip(splopter.tdata.t_dict[t_dict_label], 0)
    objects_raw = np.flip(splopter.tdata.objectsenum, 0)
    probe_obj_indices = splopter.parser.get_probe_obj_indices()
    objects = np.zeros(np.shape(plasma_parameter))

    wall_indices = np.where(plasma_parameter == 0)
    probe_objs = [
        np.where(objects_raw == index + 1) for index in probe_obj_indices
    ]

    if plot_obj_fl:
        plt.figure()
        plt.imshow(objects_raw, cmap='Greys')
        plt.colorbar()

    plasma_parameter[wall_indices] = np.NaN
    for probe_obj in probe_objs:
        plasma_parameter[probe_obj] = np.NaN
    objects[wall_indices] = 3.0
    for probe_obj in probe_objs:
        objects[probe_obj] = 1.5

    plt.figure()
    plt.imshow(
        objects,
        cmap='Greys',
        extent=[0,
                len(plasma_parameter[0]) / 2, 0,
                len(plasma_parameter) / 2])

    ax = plt.gca()
    im = ax.imshow(
        plasma_parameter,
        extent=[0,
                len(plasma_parameter[0]) / 2, 0,
                len(plasma_parameter) / 2],
        interpolation=None)
    plt.xlabel(r'y / $\lambda_D$', fontsize=15)
    plt.ylabel(r'z / $\lambda_D$', fontsize=15)
    # plt.title('Electrostatic potential for a flush mounted probe', fontsize=20)
    plt.quiver([200], [200], splopter.tdata.by, splopter.tdata.bz, scale=5)
    plt.colorbar(im, fraction=0.035, pad=0.04)
    plt.show()
Exemple #5
0
def test2():
    flpt = spl.Splopter('bin/data_local/', 'benchmarking/', 'nogap/')

    # plt.figure()

    print(flpt.tdata.diagnostics.keys())
    e_hist_before = flpt.tdata.diagnostics['eHistx1']
    i_hist_before = flpt.tdata.diagnostics['iHistx1']
    plt.plot(e_hist_before, label='eHistBefore')
    plt.plot(i_hist_before, label='iHistBefore')

    flpt.denormalise()

    e_hist_after = flpt.tdata.diagnostics['eHistx1']
    i_hist_after = flpt.tdata.diagnostics['iHistx1']
    # plt.plot(e_hist_after, label='eHistAfter')
    # plt.plot(i_hist_after, label='iHistAfter')
    plt.legend()

    plt.show()
from flopter.spice import splopter as spl
import matplotlib.pyplot as plt

if __name__ == '__main__':
    spl_t0_old = spl.Splopter('bin/data_local_m/',
                              'magnum/',
                              'fetail_T0_S1/',
                              reduce_fl=True)
    spl_t0 = spl.Splopter('bin/data_local_m/',
                          'magnum/',
                          'fetail_T0_S/',
                          reduce_fl=True)
    spl_t2 = spl.Splopter('bin/data_local_m/',
                          'magnum/',
                          'fetail_T2-5_S1/',
                          reduce_fl=True)
    spl_t10 = spl.Splopter('bin/data_local_m/',
                           'magnum/',
                           'fetail_T10_S1/',
                           reduce_fl=True)

    splopters = [spl_t0_old, spl_t0, spl_t2, spl_t10]
    for splopter in splopters:
        splopter.prepare(homogenise_fl=True, denormaliser_fl=False)
        plt.figure()
        splopter.plot_raw()

    plt.show()
Exemple #7
0
def homogenise_run(path):
    splopter = spl.Splopter(path, reduce=DESIRED_VARIABLES, ignore_tzero_fl=True, version=2.14,
                            store_dataframe_fl=True, ignore_a_file=True)
    splopter.parse_input()
    iv_data, raw_iv_data = splopter.homogenise(reduced_bin_fract=0.1)
    return splopter.iv_df, iv_data
Exemple #8
0
def compare_larmor_radii(files,
                         mount='bin/data/',
                         folder='benchmarking_mass/'):
    import gc
    splopters = {}
    for file in files:
        sp = spl.Splopter(mount, folder, file, prepare=True)
        print(sp.tdata.diagnostics.keys())

        print(len(sp.tdata.diagnostics['eTrackery']),
              np.size(sp.tdata.diagnostics['iTrackery']))

        print('Tracking Ions')
        i_splits = np.where(
            np.abs(np.diff(sp.tdata.diagnostics['iTrackery'], axis=0)) > 0.5
        )[0] + 1
        iy_tracks = np.split(sp.tdata.diagnostics['iTrackery'], i_splits)
        iz_tracks = np.split(sp.tdata.diagnostics['iTrackerz'], i_splits)

        iy_tracks.sort(key=len, reverse=True)
        iz_tracks.sort(key=len, reverse=True)

        # print(i_splits.shape, len(iy_tracks), iy_tracks[200])
        # for i, t in enumerate(iy_tracks):
        #     print('{}) {}'.format(i, len(t)))

        i_tracks = zip(iy_tracks[:200], iz_tracks[:200])

        print('Tracking Electrons')
        # Find positions within tracking array where target seems to change by selecting elements with a large jump
        e_splits = np.where(
            np.abs(np.diff(sp.tdata.diagnostics['eTrackery'], axis=0)) > 0.5
        )[0] + 1

        # Split tracking diagnostic array into different tracks using points found above
        ey_tracks = np.split(sp.tdata.diagnostics['eTrackery'], e_splits)
        ez_tracks = np.split(sp.tdata.diagnostics['eTrackerz'], e_splits)

        # Sort the tracks in descending order by length
        ey_tracks.sort(key=len, reverse=True)
        ez_tracks.sort(key=len, reverse=True)

        # Create a zip of the tracks individual components
        e_tracks = zip(ey_tracks[:200], ez_tracks[:200])

        # 'iTrackery', 'iTrackerz', 'iTrackerux', 'iTrackeruy', 'iTrackeruz',
        # 'eTrackery', 'eTrackerz', 'eTrackerux', 'eTrackeruy', 'eTrackeruz'

        print('Lengths. ion: {}, electron: {}'.format(len(i_splits),
                                                      len(e_splits)))

        print('Plotting 1')
        plt.figure()
        for y_track, z_track in i_tracks:
            plt.plot(y_track, z_track)
        plt.title(file + ' - Ions')
        plt.xlabel('Timestep')
        plt.ylabel(r'Z Position ($\lambda_D$)')

        plt.figure()
        print('Plotting 2')
        for y_track, z_track in e_tracks:
            plt.plot(y_track, z_track)
        plt.title(file + ' - Electrons')
        plt.xlabel('Timestep')
        plt.ylabel(r'Z Position ($\lambda_D$)')

        print('...finished plotting')

        # plt.figure()
        # # plt.plot(sp.tdata.diagnostics['iTrackery'], sp.tdata.diagnostics['iTrackerz'], 'x', label='Ion track')
        # plt.plot(sp.tdata.diagnostics['eTrackery'], sp.tdata.diagnostics['eTrackerz'], 'x', label='Electron track')
        # plt.legend()
        # plt.title(file)
        # plt.xlabel(r'Y Position ($\lambda_D$)')
        # plt.ylabel(r'Z Position ($\lambda_D$)')

        # deallocate the splopter object

        del sp
        gc.collect()

    plt.show()
Exemple #9
0
def injection_dist_function(gauss_fl=True, show_fl=True):
    splopter = spl.Splopter('bin/data_local/', 'tests/',
                            'injtestperp_halfnogap2/')
    # splopter = spl.Flopter('bin/data_local/', 'tests/', 'injtest_halfnogap1/')
    splopter.prepare(homogenise_fl=False)
    v_scale = 1000

    i_inj_path = splopter.afile_path.replace('.mat', '.i_inj')
    e_inj_path = splopter.afile_path.replace('.mat', '.e_inj')
    i_inj = -splopter.denormaliser(np.loadtxt(i_inj_path),
                                   c.CONV_VELOCITY) / v_scale
    e_inj = -splopter.denormaliser(np.loadtxt(e_inj_path),
                                   c.CONV_VELOCITY) / v_scale

    # runpath = 'data/'
    # i_inj_path = runpath + 'injtest_halfnogap.i_inj'
    # e_inj_path = runpath + 'injtest_halfnogap.e_inj'
    # i_inj = np.loadtxt(i_inj_path)
    # e_inj = np.loadtxt(e_inj_path)

    i_hist, i_gaps = np.histogram(i_inj, density=True, bins='auto')
    i_bins = (i_gaps[:-1] + i_gaps[1:]) / 2
    e_hist, e_gaps = np.histogram(e_inj, density=True, bins='auto')
    e_bins = (e_gaps[:-1] + e_gaps[1:]) / 2

    t_e_guess = splopter.denormaliser.temperature / (v_scale**2)
    guess = [t_e_guess, 1]

    if gauss_fl:
        i_fitter = f.GaussianVelIonEvFitter(mu=splopter.denormaliser.mu)
        i_fdata = get_histogram_fit(splopter,
                                    i_hist,
                                    i_bins,
                                    i_fitter,
                                    v_scale=v_scale)
    else:
        i_fitter = f.MaxwellianVelFitter(mu=splopter.denormaliser.mu)
        i_fdata = i_fitter.fit(i_bins, i_hist, initial_vals=guess)
    i_fdata.print_fit_params()

    if gauss_fl:
        e_fitter = f.GaussianVelElecEvFitter()
        e_fdata = get_histogram_fit(splopter,
                                    e_hist,
                                    e_bins,
                                    e_fitter,
                                    v_scale=v_scale)
    else:
        e_fitter = f.MaxwellianVelFitter(mu=1)
        e_fdata = e_fitter.fit(e_bins, e_hist, initial_vals=guess)
    e_fdata.print_fit_params()

    plt.figure()
    plt.plot(i_bins, i_hist)
    plt.plot(i_bins, i_fdata.fit_y)
    plt.title('Ion injection DF')

    plt.figure()
    plt.plot(e_bins, e_hist)
    plt.plot(e_bins, e_fdata.fit_y)
    plt.title('Electron injection DF')

    if show_fl:
        plt.show()
Exemple #10
0
def run_current_comparison():
    splopter_prep = spl.Splopter('bin/data/',
                                 'benchmarking_sam/',
                                 'disttest_fullnogap/',
                                 prepare=False)
    splopter_top = spl.Splopter('bin/data/',
                                'bms_distruns/',
                                'disttest_fullnogap_top/',
                                prepare=False)
    splopter_bottom = spl.Splopter('bin/data/',
                                   'bms_distruns/',
                                   'disttest_fullnogap_bottom/',
                                   prepare=False)
    splopters = {
        'prep': splopter_prep,
        'top': splopter_top,
        'bottom': splopter_bottom
    }

    currents = {}
    times = {}
    diagnostics = {}
    for name, sp in splopters.items():
        currents[name] = sp.tdata.objectscurrente[0]
        times[name] = sp.tdata.t[1:]
        diagnostics[name] = [
            diag for diag_name, diag in sp.tdata.diagnostics.items()
            if 'eHist' in diag_name
        ]

    print(np.shape(diagnostics.items()))

    for name in splopters.keys():
        plt.figure(1)
        plt.plot(times[name], currents[name], label=name)
        plt.legend()

        plt.figure(2)
        for i, diag in enumerate(diagnostics[name]):
            plt.plot(diag, label=name.join(str(i)))
        plt.legend()

    # current_prep = splopter_prep.tdata.objectscurrente
    # time_prep = splopter_prep.tdata.t[1:]
    # print(np.shape(time_prep), np.shape(current_prep))
    # current_top = splopter_top.tdata.objectscurrente
    # time_top = splopter_top.tdata.t[1:]

    # for i in range(len(current_prep)):
    #     plt.figure()
    #     # current_combo = np.concatenate((current_prep[i], current_run0[i]))
    #     plt.plot(time_prep, current_prep[i], label='prep')
    #     plt.plot(time_top, current_top[i], label='top')
    #     # plt.plot(current_combo)
    #     plt.legend()

    plt.figure()
    plt.imshow(splopter_prep.tdata.pot)
    plt.colorbar()

    plt.figure()
    plt.imshow(splopter_top.tdata.pot)
    plt.colorbar()

    plt.figure()
    plt.imshow(splopter_bottom.tdata.pot)
    plt.colorbar()

    print(splopter_prep.tdata.diagnostics.keys())
    print(splopter_top.tdata.diagnostics.keys())

    plt.show()
Exemple #11
0
def run_multihistogram_extr(z_high=370.0,
                            z_low=70.0,
                            num_samples=11,
                            fig=None,
                            show=None):
    splopter = spl.Splopter('bin/data_local/',
                            'benchmarking/',
                            'disttest_fullnogap/',
                            prepare=False)
    # path = 'bin/data_local/benchmarking/disttest_fullnogap/'
    nproc = int(np.squeeze(splopter.tdata.nproc))

    u_pars = {}
    assert isinstance(num_samples, int)
    if num_samples <= 1:
        num_samples = 2
    z_vals = np.linspace(z_low, z_high, num_samples)
    for z in z_vals[:-1]:
        u_pars[z] = np.array([], dtype=np.float64)

    ralpha = (-splopter.tdata.alphayz / 180.0) * np.pi
    rbeta = ((90.0 - splopter.tdata.alphaxz) / 180) * np.pi

    for i in range(nproc):
        num = str(i).zfill(2)
        filename = splopter.tfile_path.replace('.mat', '{}.mat'.format(num))
        p_file = loadmat(filename)

        # [print(key+': ', str(np.shape(array))) for key, array in p_file.items() if '__' not in key]
        for j in range(len(z_vals) - 1):
            print('int(j)', int(j))
            print('z_vals[int(j)]', z_vals[int(j)])
            print('z_vals[int(j+1)]', z_vals[int(j + 1)])
            indices = np.where((p_file['z'] > z_vals[int(j)])
                               & (p_file['z'] <= z_vals[int(j + 1)])
                               & (p_file['stype'] == 2))
            u_pars[z_vals[int(j)]] = np.append(
                u_pars[z_vals[int(j)]],
                (p_file['uy'][indices] * np.cos(ralpha) * np.cos(rbeta)) -
                (p_file['uz'][indices] * np.sin(ralpha)))

    # u_par = (u_pars['uy'] * np.cos(ralpha) * np.cos(rbeta)) - (u_pars['uz'] * np.sin(ralpha))
    # u_par = (u_pars['ux'] * np.sin(rbeta) * np.cos(ralpha)) + \
    #         (u_pars['uy'] * np.cos(ralpha) * np.cos(rbeta)) - \
    #         (u_pars['uz'] * np.sin(ralpha))

    # sp.io.savemat('test.mat', u_par)
    print('Finished compiling ')

    if not fig:
        fig = plt.figure()

    # plt.hist(u_pars['u_par'], bins=500)
    # plt.title('z_high = {}, z_low = {}'.format(z_high, z_low))
    # run_spice_df_analysis(splopter, fig=fig)

    for z_val, u_par in u_pars.items():
        print(u_par)
        hist, gaps = np.histogram(u_par, bins='auto', density=True)
        plt.plot(gaps[:-1], hist, label='z_low = {}'.format(z_val))

    plt.legend()

    if show:
        plt.show()
Exemple #12
0
    # splopter = spl.Flopter('bin/data/', 'benchmarking_sam/', 'prebprobe2_fullgap/', prepare=True)
    # splopter = spl.Flopter('bin/data/', 'benchmarking_sam/', 'prebprobe2_fullnogap/', prepare=True)
    # splopter = spl.Flopter('bin/data/', 'angledtip/', 'angledtiptest/', prepare=False)
    # splopter = spl.Flopter('bin/data/', 'angledtip/', 'angledtiptest1/', prepare=False)
    # splopter = spl.Flopter('bin/data/', 'test/', 'floatingpottest/', prepare=False)

    # Radii comparison files
    # comparison_files = ['benchmark_ms_g_hg/', 'massrationtest_ms_g_hg/', 'ionmasstest_ms_g_hg/',
    #                     'speciesmasstest_ms_g_hg/']
    # compare_larmor_radii(comparison_files)

    # splopter = spl.Splopter('bin/data/', 'benchmarking_mass/', 'benchmark_ms_g_hg/', prepare=True)
    # splopter = spl.Splopter('bin/data/', 'benchmarking_mass/', 'massrationtest_ms_g_hg/', prepare=True)
    # splopter = spl.Splopter('bin/data/', 'benchmarking_mass/', 'ionmasstest_ms_g_hg/', prepare=True)
    # splopter = spl.Splopter('bin/data/', 'benchmarking_mass/', 'speciesmasstest_ms_g_hg/', prepare=True)
    splopter = spl.Splopter('bin/data/', 'magnum/', 'sprobe_1e19_nopadding1/')
    # splopter = spl.Splopter('bin/data/', 'magnum/', 'sprobe_1e19_nopadding1/')

    # splopter.plot_2d_variable(show_fl=False)

    # splopter.analyse_iv(show_fl=True)
    # splopter.plot_1d_variable(variable_label=c.DIAG_WALL_POT, time_dep_fl=True, diagnostic_fl=True)
    # splopter.plot_1d_variable(variable_label=sd.NZ)

    # extract_density(splopter)
    splopter.prepare(homogenise_fl=True, denormaliser_fl=False)
    regions = splopter.parser.get_hist_diag_regions(2)
    # run_multi_hist_analysis(regions=regions, splopter=splopter, show_fl=True, species=2)
    # run_gap_nogap_comparison()

    # run_multi_hist_analysis(splopter=splopter, fitter=f.GaussianVelElecEvFitter(), show_fl=False)
Exemple #13
0
# angles_search_str = '/*[!.{yml, inp}]/backup*'
angles_search_str = '/*[!.{yml, inp}]'

desired_variables = td.DEFAULT_REDUCED_DATASET | {'ProbePot'}

all_run_dirs = {}
scans = glob.glob(scans_searchstr)
scans = list(set(scans) - skippable_scans)
for scan in scans:
    if scan in skippable_scans:
        print(f'Skipping {scan}...\n\n')
        continue
    all_run_dirs[scan] = glob.glob(scan + angles_search_str)

    print(f'{scan}: {all_run_dirs[scan]}\n')

# For adding a new run to the list of splopters
angle_dir = all_run_dirs[scans[6]][0]
print(angle_dir)

splopters = {}

if angle_dir in splopters:
    print(f'Removing {angle_dir} from existing list of splopters')
    splopters.pop(angle_dir)
splopter = spl.Splopter(lowdens_dir / angle_dir, reduce=desired_variables)
splopter.prepare(denormaliser_fl=True, homogenise_fl=True, find_se_temp_fl=False)
splopter.denormalise()
splopters[angle_dir] = splopter

print('Created splopter')