Ejemplo n.º 1
0
def ne_avg_over_r(sim,
                  pluto_nframes,
                  average_ne,
                  z_lines=None,
                  ret_z_cell_borders=False):
    '''
    Compute max/integral-avg/axial electron density over the transverse section (r direction).
    return a vector of ne, the elements of ne correspond to different z positions
    Input:
        pluto_nframes : the frames of pluto which I want to see (it must be a list of integers)
    Returns:
        times, e
    '''

    times = []
    ne_avg_r_sims = []
    for ii in range(len(pluto_nframes)):
        pluto_dir = os.path.join(os.path.expandvars(sim), 'out')
        # Load the data
        q, r, z, theta, t, n = prf.pluto_read_vtk_frame(
            pluto_dir,
            # time=125.0,
            nframe=pluto_nframes[ii])
        times.append(t)
        # Convert r and z to cm
        r /= 1e3
        z /= 1e3
        ne_avg_r = []
        # If z_lines have not been provided, I take all z cell centers
        if z_lines is None:
            # idx_z_all = list(range(len(z)-1))  # I reduce by 1, since z are the cell borders, not the centers
            z_lines = 0.5 * (z[1:] + z[:-1])
        for z_line in z_lines:
            # Check that z-lines are inside the grid
            if z_line > z.max() or z_line < z.min():
                raise ValueError('z_lines outside z grid')
            # I find the grid cell where z_line is included,
            # note that ne is defined inside the cell (it's an average value)
            # so I may imagine that it is constant inside the cell
            idx_z = np.argmax(z[z <= z_line])
            if average_ne == 'integral' or average_ne == 'mean':
                # Build capillary shape (False where there is wall, True elsewere)
                cap = (q['interBound'] == 0e0)
                areas = []
                integ = np.sum(np.pi * q["ne"][idx_z, :] *
                               (r[1:]**2 - r[:-1]**2) * cap[idx_z, :])
                area_r = np.sum(np.pi * (r[1:]**2 - r[:-1]**2) * cap[idx_z, :])
                areas.append(area_r)
                ne_avg_r.append(integ / area_r)
            elif average_ne == 'max':
                ne_avg_r.append(q["ne"][idx_z, :].max())
            elif average_ne == 'axis':
                ne_avg_r.append(q["ne"][idx_z, 0])
            else:
                raise ValueError('Wrong choice for average_ne')
        ne_avg_r_sims.append(ne_avg_r)
    if ret_z_cell_borders:
        return z_lines, z, ne_avg_r_sims, times
    else:
        return z_lines, ne_avg_r_sims, times
Ejemplo n.º 2
0
    dz_cap = 1.e-3  # m
    rmax = 0.8e-3  # m
    zmax = 2.e-2  # m
    reverse_sign_B = True

#%% Load the data
if len(sim) != 2:
    raise ValueError('sim must be a list of two(2) simulation paths')
B = [[], []]
r = [[], []]
z = [[], []]
t = [[], []]
for ss in range(len(sim)):
    pluto_dir = os.path.join(os.path.expandvars(sim[ss]), 'out')
    q, r[ss], z[ss], theta, t[ss], n = prf.pluto_read_vtk_frame(
        pluto_dir,
        # time=125.0,
        nframe=pluto_nframe)
    B[ss] = q["bx3"]
    # Convert r and z to m
    r[ss] /= 1e5
    z[ss] /= 1e5

if reverse_sign_B:
    if np.mean(B[1]) < 0:
        B[1] = -B[1]
    else:
        B[0] = -B[0]

#%%
# Compute the cell centers
r_cc = [0.5 * (r[ss][1:] + r[ss][:-1]) for ss in (0, 1)]
Ejemplo n.º 3
0
# Capillary length, half of the real one (including electrodes)
l_cap = 0.6e-2  # m
r_cap = 0.5e-3  # m
dz_cap = 1.e-3  # m
rmax = 1e-3  # m
zmax = 1.2e-2  # m
# ---- For quiver plot ----
# This does not influence the physical correctness of the arrows plot, just the way it looks
quiv_scale = 8e4
# Lenght of the arrow appearing in the arrow legend ("arrow legend" is "quiver plot key" in matplolib)
# Also this parameterv does not influence the physical correctness of the arrows plot, just the way it looks
key_length = 1e4

#%% Load the data
pluto_dir = os.path.join(os.path.expandvars(sim), 'out')
q, r, z, theta, t, n = prf.pluto_read_vtk_frame(pluto_dir, nframe=pluto_nframe)
T = q["T"]
B = q["bx3"] * 1e-4  # Convert to Tesla
vr = q["vx1"] * 1e-2  # Converto to m/s
vz = q["vx2"] * 1e-2  # Converto to m/s
rho = q["rho"] * 1e-3  # Convert to g/cm3
# Convert r and z to m
r /= 1e5
z /= 1e5

#%%
# Compute the cell centers
r_cc = 0.5 * (r[1:] + r[:-1])
z_cc = 0.5 * (z[1:] + z[:-1])

#%% Plotting
Ejemplo n.º 4
0
def g_Dg_time_evol(sim, pluto_nframes, r_cap, l_cap, ret_full_g=False):
    '''
    Compute <B>/r and variation of <B>/r with respect to d<B>/dr(r=0).
    Input:
        pluto_nframes : the frames of pluto which I want to see (it must be a list of integers)
        r_cap : Capillary radius
        l_cap : Capillary length
    Returns:
        times, r_c, g, Dg
    '''

    # Load the data
    B = []
    r_sims = []
    z_sims = []
    cap = []
    times = []
    B_avg_z = []
    for ii in range(len(pluto_nframes)):
        pluto_dir = os.path.join(os.path.expandvars(sim), 'out')
        q, r, z, theta, t, n = prf.pluto_read_vtk_frame(
            pluto_dir,
            # time=125.0,
            nframe=pluto_nframes[ii])
        times.append(t)
        # Convert r and z to m
        r /= 1e5
        z /= 1e5
        r_sims.append(r)
        z_sims.append(z)
        B.append(q["bx3"] / 1e4)  # I convert B to Tesla

        # Averaging of B over z (I cannot use trapz, since I have cell-averaged B)
        # Beware: also the bcs on B (i.e. the first cells near the capillar wall that are in the internal boundary)
        # are useful for computing, because if I want to compute B at the cell edges, I need them
        B_integ_z = np.sum((B[ii].T * np.diff(z)).T, axis=0)

        B_avg_z.append(2 * B_integ_z / l_cap)

    # Build the focusing strenght g(r)=B/r (vertex centered)
    times = np.array(times)
    # Vertex centered averaged B
    B_avg_z_v = []
    B_v = []
    for ii in range(len(pluto_nframes)):
        B_avg_z_v.append(
            np.concatenate(
                (np.array([0]), 0.5 * (B_avg_z[ii][1:] + B_avg_z[ii][:-1]),
                 np.array([np.nan]))))
        B_v.append(
            np.concatenate((np.zeros((B[ii].shape[0] - 1, 1)), 0.25 *
                            (B[ii][1:, 1:] + B[ii][1:, :-1] + B[ii][-1:, 1:] +
                             B[ii][-1:, -1])),
                           axis=1))
    z_B_v = z[1:-1]
    r_B_v = r[:-1]

    # I radially restrict the B field to the capillary
    B_avg_z_v_c = np.transpose(
        np.array(
            [list(B_avg_z_v[ii][r <= r_cap]) for ii in range(len(B_avg_z_v))]))
    # B_v = np.transpose(np.array([list(B_v[ii][r<=r_cap]) for ii in range(len(B_v))]))
    r_c = r[r <= r_cap]

    # Build the longitudinal average of g (it is not really g, just B/R)
    g = np.zeros(B_avg_z_v_c.shape)
    for ii in range(B_avg_z_v_c.shape[1]):
        g[1:, ii] = B_avg_z_v_c[1:, ii] / r_c[1:]
    g[0, :] = g[1, :]
    # Build delta g
    Dg = np.zeros(g.shape)
    for ii in range(g.shape[1]):
        Dg[:, ii] = g[0, ii] - g[:, ii]

    # Build g as 2D matrix (to represent a function of (r,z))
    g_full = []
    for ii in range(len(pluto_nframes)):
        g_temp = B_v[ii][:, 1:] / r_B_v[1:]
        g_full.append(np.concatenate((g_temp[:, [0]], g_temp), axis=1))

    if ret_full_g:
        return times, r_c, g, Dg, B_v, g_full, z_B_v, r_B_v
    else:
        return times, r_c, g, Dg
r_sims = []
z_sims = []
cap = []
times = []
B_avg_z = []
for ss in range(len(sims)):
    B.append([])
    r_sims.append([])
    z_sims.append([])
    cap.append([])
    times.append([])
    B_avg_z.append([])
    for ii in range(len(pluto_nframes)):
        pluto_dir = os.path.join(os.path.expandvars(sims[ss]), 'out')
        q, r, z, theta, t, n = prf.pluto_read_vtk_frame(
            pluto_dir,
            # time=125.0,
            nframe=pluto_nframes[ii])
        times[ss].append(t)
        # Convert r and z to m
        r /= 1e5
        z /= 1e5
        r_sims[ss].append(r)
        z_sims[ss].append(z)
        B[ss].append(q["bx3"] * 1e-4)  # Convert to Tesla

        # Build capillary shape (False where there is wall, True elsewere)
        # u_cap = cap_shape(r, z, r_cap, l_cap)
        cap[ss].append(q['interBound'] == 0e0)

        # Averaging of B over z (I cannot use trapz, since I have cell-averaged B)
        # B_integ_z = np.sum(((B[ss][ii]*cap[ss][ii].astype(int)).T*np.diff(z)).T, axis=0)
Ejemplo n.º 6
0
r_pos = 0.00001e-2  # meters
rmax = 0.6e-3  # meters
zmax = 0.8e-2  # meters
name = ('(a)', '(b)')

# <codecell> Load the data
Tr = [[] for ii in range(len(sim))]
Tz = [[] for ii in range(len(sim))]
r_cc = [[] for ii in range(len(sim))]
z_cc = [[] for ii in range(len(sim))]
times = np.zeros((len(sim), len(pluto_nframes)))
for ss in range(len(sim)):
    for ff in range(len(pluto_nframes)):
        pluto_dir = os.path.join(os.path.expandvars(sim[ss]), 'out')
        q, r_temp, z_temp, theta, t, n = prf.pluto_read_vtk_frame(
            pluto_dir,
            # time=125.0,
            nframe=pluto_nframes[ff])
        times[ss, ff] = t
        # Convert r and z to m, and compute coordinates of grid centers
        r_cc[ss].append(0.5 * (r_temp[1:] + r_temp[:-1]) / 1e5)
        z_cc[ss].append(0.5 * (z_temp[1:] + z_temp[:-1]) / 1e5)
        Tr[ss].append(q["T"][np.argmin(np.abs(z_cc[ss][ff] - z_pos)), :])
        Tz[ss].append(q["T"][:, np.argmin(np.abs(r_cc[ss][ff] - r_pos))])

# <codecell>
# Plots
fig, ax = plt.subplots(ncols=len(sim), nrows=2, figsize=(5.5, 4.5))

for ss in range(len(sim)):
    for ff in range(len(pluto_nframes)):
        ax[ss, 0].plot(r_cc[ss][ff][r_cc[ss][ff] <= r_cap[ss]] * 1e6,
Ejemplo n.º 7
0
import pluto_read_frm as prf

importlib.reload(prf)
importlib.reload(cu)

plt.close("all")

# <codecell>
sim = '/home/ema/simulazioni/sims_pluto/I90/newtransp-rho20'
pluto_nframe = 25
quantities = ['bx3']
ordering = 'F'

# <codecell>
# Load data
pluto_dir = os.path.join(sim, 'out')
q, x, y, z, t, n = prf.pluto_read_vtk_frame(
    pluto_dir,
    # time=125.0,
    nframe=pluto_nframe)

# x,y = np.meshgrid(x,y)

# <codecell>
# Plotting
fig, ax = plt.subplots()

ax.pcolormesh(x, y, q["bx3"])

plt.show()
Ejemplo n.º 8
0
# Load the data
ne_sims = []
ne_avg_sims = []
r_sims = []
z_sims = []
cap = []
times = []
try:
    Nframes = len(pluto_nframes)
except NameError:
    Nframes = len(time)
for ii in range(Nframes):
    pluto_dir = os.path.join(os.path.expandvars(sim),'out')
    q, r, z, theta, t, n = prf.pluto_read_vtk_frame(pluto_dir,
                                                    time = time[ii],
                                                    # nframe = pluto_nframes[ii],
                                                    )
    times.append(t)
    # Convert r and z to cm
    r /= 1e3
    z /= 1e3
    r_sims.append(r)
    z_sims.append(z)
    ne_sims.append(q["ne"])

    ne_avg_r = []
    if average_ne == 'integral':
        # Build capillary shape (False where there is wall, True elsewere)
        cap.append(q['interBound']==0e0)
        areas = []
        for jj in range(len(z_lines)):