示例#1
0
文件: output.py 项目: vsemionov/npamp
def plot_beam(dirname, input_beam, Rho, Phi, ref_output_fluence):
    filename = lambda name: os.path.join(dirname, name)
    
    if len(Rho) > 1:
        vfluence = np.vectorize(input_beam.fluence)
        ref_input_fluence = vfluence(*np.meshgrid(Rho, Phi)).T
        norm_input_fluence = ref_input_fluence / input_beam.ref_fluence
        norm_output_fluence = ref_output_fluence / input_beam.ref_fluence
        max_output_fluence = np.amax(norm_output_fluence)
        
        n_ref = -1
        for n, phi in enumerate(Phi):
            if n_ref < 0 or abs(phi - input_beam.phi_ref) < abs(Phi[n_ref] - input_beam.phi_ref):
                n_ref = n
        rholim = (Rho[0], Rho[-1])
        plot.plot_data(filename("fluences"), "Input and Output Fluence", ((Rho,)*2, None, rholim, rho_label), ((norm_input_fluence[:, n_ref], norm_output_fluence[:, n_ref]), None, None, fluence_rel_label), ("input beam", "output beam"))
        plot.plot_data(filename("fluences_norm"), "Normalized Input and Output Fluence", ((Rho,)*2, None, rholim, rho_label), ((norm_input_fluence[:, n_ref], norm_output_fluence[:, n_ref] / max_output_fluence), None, None, fluence_norm_rel_label), ("input beam", "output beam"))
        
        if len(Phi) > 1:
            FR, RF = np.meshgrid(Phi, Rho)
            XY, YX = RF * np.cos(FR), RF * np.sin(FR)
            stride_rho = max(len(Rho) // params.out_count_rho, 1)
            stride_phi = max(len(Phi) // params.out_count_phi, 1)
            plot.plot_projection(filename("fluence_in"), "Input Fluence", (XY, None, x_label), (YX, None, y_label), (norm_input_fluence, None, fluence_rel_label), (30, -60), (stride_rho, stride_phi))
            plot.plot_projection(filename("fluence_out"), "Output Fluence", (XY, None, x_label), (YX, None, y_label), (norm_output_fluence, None, fluence_rel_label), (30, -60), (stride_rho, stride_phi))
示例#2
0
文件: output.py 项目: vsemionov/npamp
def plot_output(dirname, input_beam, input_pulse, fwhm, amp, fluences, exact_density_out=None, exact_population_final=None):
    filename = lambda name: os.path.join(dirname, name)
    
    density = amp.density
    population = amp.population
    upper = population[0]
    lower = population[1]
    inversion = upper - lower
    
    Z = amp.Z
    T = amp.T
    
    if params.output_rel_time:
        T = T / fwhm
    
    TZ, ZT = np.meshgrid(T, Z)
    
    zlim = (Z[0], Z[-1])
    tlim = (T[0], T[-1])
    
    ref_density = input_pulse.ref_density
    ref_inversion = amp.active_medium.initial_inversion.ref_inversion
    
    out_t_label = norm_t_label if params.output_rel_time else t_amp_label
    
    stride_z = max(len(amp.Z) // params.out_count_z, 1)
    stride_t = max(len(amp.T) // params.out_count_t, 1)
    
    plot.plot_data(filename("density_in"), "Input Photon Density", (T, None, tlim, out_t_label), (density[0]/ref_density, None, None, density_rel_label))
    plot.plot_data(filename("density_out"), "Output Photon Density", (T, None, tlim, out_t_label), (density[-1]/ref_density, None, None, density_rel_label))
    plot.plot_data(filename("densities"), "Input and Output Photon Density", ((T, ) * 2, None, tlim, out_t_label), ((density[0]/ref_density, density[-1]/ref_density), None, None, density_rel_label), ("input pulse", "output pulse"))
    plot.plot_data(filename("densities_norm"), "Normalized Input and Output Photon Density", ((T, ) * 2, None, tlim, out_t_label), ((density[0]/ref_density, density[-1]/np.amax(density[-1])), None, None, density_norm_rel_label), ("input pulse", "output pulse"))
    
    plot.plot_data(filename("upper_init"), "Initial Upper State Population", (Z, None, zlim, z_label), (upper.T[0]/ref_inversion, None, None, upper_rel_label))
    plot.plot_data(filename("upper_final"), "Final Upper State Population", (Z, None, zlim, z_label), (upper.T[-1]/ref_inversion, None, None, upper_rel_label))
    plot.plot_data(filename("lower_init"), "Initial Lower State Population", (Z, None, zlim, z_label), (lower.T[0]/ref_inversion, None, None, lower_rel_label))
    plot.plot_data(filename("lower_final"), "Final Lower State Population", (Z, None, zlim, z_label), (lower.T[-1]/ref_inversion, None, None, lower_rel_label))
    plot.plot_data(filename("inversion_init"), "Initial Population Inversion", (Z, None, zlim, z_label), (inversion.T[0]/ref_inversion, None, None, inversion_rel_label))
    plot.plot_data(filename("inversion_final"), "Final Population Inversion", (Z, None, zlim, z_label), (inversion.T[-1]/ref_inversion, None, None, inversion_rel_label))
    
    plot.plot_projection(filename("density_evo"), "Photon Density Evolution", (ZT, None, z_label), (TZ, None, out_t_label), (density/ref_density, None, density_rel_label), (30, -30), (stride_z, stride_t))
    plot.plot_projection(filename("upper_evo"), "Upper State Population Evolution", (ZT, None, z_label), (TZ, None, out_t_label), (upper/ref_inversion, None, upper_rel_label), (30, 30), (stride_z, stride_t))
    plot.plot_projection(filename("lower_evo"), "Lower State Population Evolution", (ZT, None, z_label), (TZ, None, out_t_label), (lower/ref_inversion, None, lower_rel_label), (30, 30), (stride_z, stride_t))
    plot.plot_projection(filename("inversion_evo"), "Population Inversion Evolution", (ZT, None, z_label), (TZ, None, out_t_label), (inversion/ref_inversion, None, inversion_rel_label), (30, 30), (stride_z, stride_t))
    
    if exact_density_out is not None:
        plot.plot_error(filename("density_err"), "Photon Density Relative Error", (T, None, tlim, out_t_label), ((exact_density_out, density[-1]), None, None, error_label))
    if exact_population_final is not None:
        plot.plot_error(filename("inversion_err"), "Population Inversion Relative Error", (Z, None, zlim, z_label), ((exact_population_final[0] - exact_population_final[1], inversion.T[-1]), None, None, error_label))
        if amp.active_medium.doping_agent.lower_lifetime != 0.0:
            plot.plot_error(filename("upper_err"), "Upper State Population Relative Error", (Z, None, zlim, z_label), ((exact_population_final[0], upper.T[-1]), None, None, error_label))
            plot.plot_error(filename("lower_err"), "Lower State Population Relative Error", (Z, None, zlim, z_label), ((exact_population_final[1], lower.T[-1]), None, None, error_label))
    
    norm_fluences = fluences / input_beam.ref_fluence
    plot.plot_data(filename("fluence"), "Fluence Evolution", (Z, None, zlim, z_label), (norm_fluences, None, None, fluence_rel_label))