def extractEstimatorData(rendezvous_file, estimator_id, entity_id, is_adjoint):

    # Activate just-in-time initialization to prevent automatic loading of the
    # geometry and data tables
    Utility.activateJustInTimeInitialization()

    # Set the database path
    Collision.FilledGeometryModel.setDefaultDatabasePath(
        os.environ['DATABASE_PATH'])

    # Reload the simulation
    manager = Manager.ParticleSimulationManagerFactory(
        rendezvous_file).getManager()

    # Extract the estimator of interest
    estimator = manager.getEventHandler().getEstimator(estimator_id)

    if is_adjoint:
        energy_bins = list(estimator.getSourceEnergyDiscretization())
    else:
        energy_bins = list(estimator.getEnergyDiscretization())

    # Extract the estimator data
    entity_bin_data = estimator.getEntityBinProcessedData(entity_id)

    # Print out the extracted data
    print "#bin start (MeV), bin end (MeV), mean, re, vov, bin mid, mean/(bin width)"

    for i in range(0, len(energy_bins) - 1):
        print energy_bins[i], energy_bins[i + 1], entity_bin_data["mean"][
            i], entity_bin_data["re"][i], entity_bin_data["vov"][i], (
                energy_bins[i + 1] +
                energy_bins[i]) / 2, entity_bin_data["mean"][i] / (
                    energy_bins[i + 1] - energy_bins[i])
Esempio n. 2
0
def extractEstimatorData(rendezvous_file, estimator_id, entity_id):

    # Activate just-in-time initialization to prevent automatic loading of the
    # geometry and data tables
    Utility.activateJustInTimeInitialization()

    # Set the database path
    Collision.FilledGeometryModel.setDefaultDatabasePath(
        os.environ['DATABASE_PATH'])

    # Reload the simulation
    manager = Manager.ParticleSimulationManagerFactory(
        rendezvous_file).getManager()

    # Extract the estimator of interest
    estimator = manager.getEventHandler().getEstimator(estimator_id)

    # Extract the estimator data
    entity_bin_data = estimator.getEntityBinProcessedData(entity_id)
    energy_bins = list(estimator.getEnergyDiscretization())

    start_index = estimator.getNumberOfBins(Event.OBSERVER_ENERGY_DIMENSION)
    end_index = 2 * start_index

    # Print out the extracted data
    print "#bin start (MeV), bin end (MeV), mean, re, vov"

    for i in range(start_index, end_index):
        print energy_bins[i - start_index], energy_bins[
            i + 1 - start_index], entity_bin_data["mean"][i], entity_bin_data[
                "re"][i], entity_bin_data["vov"][i]
def extractEstimatorEnergyBins(rendezvous_file, estimator_id):

    # Activate just-in-time initialization to prevent automatic loading of the
    # geometry and data tables
    Utility.activateJustInTimeInitialization()

    # Set the database path
    Collision.FilledGeometryModel.setDefaultDatabasePath(
        os.environ['DATABASE_PATH'])

    # Reload the simulation
    manager = Manager.ParticleSimulationManagerFactory(
        rendezvous_file).getManager()

    # Extract the estimator of interest
    estimator = manager.getEventHandler().getEstimator(estimator_id)

    # Get the energy bins corresponding to the
    return list(estimator.getEnergyDiscretization())
def extractEstimatorTotalData(rendezvous_file, estimator_id, entity_id):

    # Activate just-in-time initialization to prevent automatic loading of the
    # geometry and data tables
    Utility.activateJustInTimeInitialization()

    # Set the database path
    Collision.FilledGeometryModel.setDefaultDatabasePath(
        os.environ['DATABASE_PATH'])

    # Reload the simulation
    manager = Manager.ParticleSimulationManagerFactory(
        rendezvous_file).getManager()

    # Extract the estimator of interest
    estimator = manager.getEventHandler().getEstimator(estimator_id)

    # Extract the estimator data
    entity_total_data = estimator.getEntityTotalProcessedData(entity_id)

    print entity_total_data["mean"][0], entity_total_data["re"][
        0], entity_total_data["mean"][0] * entity_total_data["re"][0]
def plotBroomstickSimulationSpectrum(rendezvous_file,
                                     estimator_id,
                                     entity_id,
                                     mcnp_file,
                                     mcnp_file_start,
                                     mcnp_file_end,
                                     is_a_current,
                                     top_ylims=None,
                                     bottom_ylims=None,
                                     xlims=None,
                                     legend_pos=None):

    # Activate just-in-time initialization to prevent automatic loading of the
    # geometry and data tables
    Utility.activateJustInTimeInitialization()

    # Set the database path
    Collision.FilledGeometryModel.setDefaultDatabasePath(
        os.environ['DATABASE_PATH'])

    # Reload the simulation
    manager = Manager.ParticleSimulationManagerFactory(
        rendezvous_file).getManager()

    # Extract the estimator of interest
    estimator = manager.getEventHandler().getEstimator(estimator_id)

    full_entity_bin_data = estimator.getEntityBinProcessedData(entity_id)

    start_index = estimator.getNumberOfBins(Event.OBSERVER_ENERGY_DIMENSION)
    end_index = 2 * start_index

    entity_bin_data = {"mean": [], "re": [], "e_bins": []}

    for i in range(start_index, end_index):
        entity_bin_data["mean"].append(full_entity_bin_data["mean"][i])
        entity_bin_data["re"].append(full_entity_bin_data["re"][i])

    entity_bin_data["e_bins"] = list(estimator.getEnergyDiscretization())

    # Extract the mcnp data from the output file
    mcnp_file = open(mcnp_file, "r")
    mcnp_file_lines = mcnp_file.readlines()

    mcnp_bin_data = {"e_up": [], "mean": [], "re": []}

    for i in range(mcnp_file_start, mcnp_file_end + 1):
        split_line = mcnp_file_lines[i - 1].split()

        mean_value = float(split_line[1])

        mcnp_bin_data["e_up"].append(float(split_line[0]))
        mcnp_bin_data["mean"].append(mean_value)
        mcnp_bin_data["re"].append(float(split_line[2]))

    output_file_name = "pb_broomstick_"
    output_file_names = []

    if is_a_current:
        output_file_names.append(output_file_name + "current.eps")
        output_file_names.append(output_file_name + "current.png")
        data_type = "Current"
    else:
        output_file_names.append(output_file_name + "flux.eps")
        output_file_names.append(output_file_name + "flux.png")
        data_type = "Flux"

    # Plot the data
    plotSpectralDataWithErrors("FRENSIE",
                               entity_bin_data,
                               "MCNP6",
                               mcnp_bin_data,
                               data_type,
                               log_spacing=False,
                               per_lethargy=False,
                               top_ylims=top_ylims,
                               bottom_ylims=bottom_ylims,
                               xlims=xlims,
                               legend_pos=legend_pos,
                               output_plot_names=output_file_names)
def extractEstimatorRelaxData(rendezvous_file, estimator_id, entity_id,
                              mcnp_file, mcnp_file_start, mcnp_file_end,
                              relax_bins):

    # Activate just-in-time initialization to prevent automatic loading of the
    # geometry and data tables
    Utility.activateJustInTimeInitialization()

    # Set the database path
    Collision.FilledGeometryModel.setDefaultDatabasePath(
        os.environ['DATABASE_PATH'])

    # Reload the simulation
    manager = Manager.ParticleSimulationManagerFactory(
        rendezvous_file).getManager()

    # Extract the estimator of interest
    estimator = manager.getEventHandler().getEstimator(estimator_id)

    energy_bins = list(estimator.getEnergyDiscretization())

    # Extract the estimator data
    entity_bin_data = estimator.getEntityBinProcessedData(entity_id)

    # Only take the data at the second collision number bin
    start_index = estimator.getNumberOfBins(Event.OBSERVER_ENERGY_DIMENSION)
    end_index = 2 * start_index

    entity_bin_data["mean"] = entity_bin_data["mean"][start_index:end_index]
    entity_bin_data["re"] = entity_bin_data["re"][start_index:end_index]
    entity_bin_data["vov"] = entity_bin_data["vov"][start_index:end_index]
    entity_bin_data["fom"] = entity_bin_data["fom"][start_index:end_index]

    # Open the mcnp output file
    mcnp_file = open(mcnp_file, "r")
    mcnp_file_lines = mcnp_file.readlines()
    mcnp_file_lines = mcnp_file_lines[mcnp_file_start - 1:mcnp_file_end]

    # Extract and print the data
    print "#bin start (MeV), bin end (MeV), bin mid (MeV), FRENSIE mean/(bin width), MCNP mean/(bin width), F/M, F/M unc"

    for i in range(0, len(energy_bins) - 1):
        if i in relax_bins:
            mcnp_line = mcnp_file_lines[i].split()

            bin_width = energy_bins[i + 1] - energy_bins[i]
            frensie_mean = entity_bin_data["mean"][i] / bin_width
            mcnp_mean = float(mcnp_line[1]) / bin_width
            f_over_m = frensie_mean / mcnp_mean

            sigma_f = frensie_mean * entity_bin_data["re"][i]
            sigma_m = mcnp_mean * float(mcnp_line[2])

            f_squared = frensie_mean * frensie_mean
            m_squared = mcnp_mean * mcnp_mean

            f_over_m_unc = m.sqrt(sigma_f * sigma_f + (f_squared / m_squared) *
                                  sigma_m * sigma_m) / mcnp_mean

            print energy_bins[i], energy_bins[
                i + 1], (energy_bins[i] + energy_bins[i + 1]
                         ) / 2, frensie_mean, mcnp_mean, f_over_m, f_over_m_unc
Esempio n. 7
0
def plotContSoilSimulationSpectrum(rendezvous_file,
                                   estimator_id,
                                   entity_id,
                                   mcnp_file,
                                   mcnp_file_start,
                                   mcnp_file_end,
                                   is_a_current,
                                   is_forward,
                                   col_bin=None,
                                   top_ylims=None,
                                   bottom_ylims=None,
                                   xlims=None,
                                   legend_pos=None):

    # Activate just-in-time initialization to prevent automatic loading of the
    # geometry and data tables
    Utility.activateJustInTimeInitialization()

    # Set the database path
    Collision.FilledGeometryModel.setDefaultDatabasePath(
        os.environ['DATABASE_PATH'])

    # Reload the simulation
    manager = Manager.ParticleSimulationManagerFactory(
        rendezvous_file).getManager()

    # Print the leakage current
    # estimator = manager.getEventHandler().getEstimator( 2 )
    # print estimator.getEntityTotalProcessedData( 20 )
    # print estimator.getEntityTotalProcessedData( 21 )
    # print estimator.getEntityTotalProcessedData( 22 )
    # print estimator.getEntityTotalProcessedData( 23 )
    # print estimator.getEntityTotalProcessedData( 24 )
    # print estimator.getEntityTotalProcessedData( 25 )

    # Extract the estimator of interest
    estimator = manager.getEventHandler().getEstimator(estimator_id)

    full_entity_bin_data = estimator.getEntityBinProcessedData(entity_id)

    num_energy_bins = 0

    if is_forward:
        num_energy_bins = estimator.getNumberOfBins(
            Event.OBSERVER_ENERGY_DIMENSION)
    else:
        num_energy_bins = estimator.getNumberOfBins(
            Event.OBSERVER_SOURCE_ENERGY_DIMENSION)

    start_index = 0
    end_index = num_energy_bins

    if not col_bin is None:
        num_col_bins = estimator.getNumberOfBins(
            Event.OBSERVER_COLLISION_NUMBER_DIMENSION)

        if col_bin >= num_col_bins:
            print "There are only", num_col_bins, "collision number bins!"
            sys.exit(1)

        start_index = col_bin * num_energy_bins
        end_index = start_index + num_energy_bins

    entity_bin_data = {
        "mean": [],
        "re": [],
        "e_bins": [],
        "vov": [],
        "fom": []
    }

    for i in range(start_index, end_index):
        entity_bin_data["mean"].append(full_entity_bin_data["mean"][i])
        entity_bin_data["re"].append(full_entity_bin_data["re"][i])
        #entity_bin_data["vov"].append( full_entity_bin_data["vov"][i] )
        entity_bin_data["fom"].append(full_entity_bin_data["fom"][i])

    if is_forward:
        entity_bin_data["e_bins"] = list(estimator.getEnergyDiscretization())
    else:
        entity_bin_data["e_bins"] = list(
            estimator.getSourceEnergyDiscretization())

    # Extract the mcnp data from the output file
    mcnp_file = open(mcnp_file, "r")
    mcnp_file_lines = mcnp_file.readlines()

    mcnp_bin_data = {"e_up": [], "mean": [], "re": []}

    mcnp_first_nonzero_index = 0
    first_nonzero_value_found = False

    for i in range(mcnp_file_start, mcnp_file_end + 1):
        split_line = mcnp_file_lines[i - 1].split()

        mean_value = float(split_line[1])

        mcnp_bin_data["e_up"].append(float(split_line[0]))
        mcnp_bin_data["mean"].append(mean_value)
        mcnp_bin_data["re"].append(float(split_line[2]))

    for i in range(0, len(mcnp_bin_data["e_up"])):
        print i, mcnp_bin_data["e_up"][i], entity_bin_data["e_bins"][
            i + 1], mcnp_bin_data["mean"][i], entity_bin_data["mean"][
                i], entity_bin_data["re"][i]
        #print i, entity_bin_data["e_bins"][i], entity_bin_data["e_bins"][i+1], entity_bin_data["mean"][i], entity_bin_data["re"][i], entity_bin_data["vov"][i], entity_bin_data["fom"][i]

    output_file_name = "h_infinite_medium_"
    output_file_names = []

    if is_a_current:
        output_file_names.append(output_file_name + "current.eps")
        output_file_names.append(output_file_name + "current.png")
        data_type = "Current"
    else:
        output_file_names.append(output_file_name + "flux.eps")
        output_file_names.append(output_file_name + "flux.png")
        data_type = "Flux"

    # Plot the data
    plotSpectralDataWithErrors("FRENSIE",
                               entity_bin_data,
                               "MCNP6",
                               mcnp_bin_data,
                               data_type,
                               log_spacing=False,
                               per_lethargy=False,
                               top_ylims=top_ylims,
                               bottom_ylims=bottom_ylims,
                               xlims=xlims,
                               legend_pos=legend_pos,
                               output_plot_names=output_file_names)