Example #1
0
    parser.add_option("--db_path",
                      type="string",
                      dest="db_path",
                      help="the database name (with extension)")
    parser.add_option("--sim_name",
                      type="string",
                      dest="sim_name",
                      default="sphere",
                      help="the simulation name")
    parser.add_option("--log_file",
                      type="string",
                      dest="log_file",
                      help="the file that will be used for logging")
    parser.add_option("--num_particles",
                      type="float",
                      dest="num_particles",
                      default=1e3,
                      help="the number of particles to run")
    options, args = parser.parse_args()

    if options.db_path is None:
        print "The database path must be specified!"
        sys.exit(1)

    # Run the simulation
    runBroomstickSimulation(
        options.sim_name, options.db_path, options.num_particles,
        MonteCarlo.DECOUPLED_HALF_PROFILE_DB_HYBRID_INCOHERENT_MODEL, 0.2,
        Utility.doubleArrayFromString("{1e-3, 998i, 0.2}"), options.threads,
        options.log_file)
Example #2
0
    
    # Parse the command line options
    parser = OptionParser()
    parser.add_option("--threads", type="int", dest="threads", default=1,
                      help="the number of threads to use")
    parser.add_option("--db_path", type="string", dest="db_path",
                      help="the database name (with extension)")
    parser.add_option("--sim_name", type="string", dest="sim_name", default="sphere",
                      help="the simulation name")
    parser.add_option("--log_file", type="string", dest="log_file",
                      help="the file that will be used for logging")
    parser.add_option("--num_particles", type="float", dest="num_particles", default=1e3,
                      help="the number of particles to run")
    options,args = parser.parse_args()

    if options.db_path is None:
        print "The database path must be specified!"
        sys.exit(1)

    # Run the simulation
    runBroomstickSimulation( options.sim_name,
                             options.db_path,
                             options.num_particles,
                             MonteCarlo.IMPULSE_INCOHERENT_MODEL,
                             1.0,
                             Utility.doubleArrayFromString( "{1e-3, 998i, 1.0}" ),
                             options.threads,
                             options.log_file )
    
    
Example #3
0
def runSimulation(threads, histories, time):

    ##--------------------------------------------------------------------------##
    ## ------------------------------ MPI Session ----------------------------- ##
    ##--------------------------------------------------------------------------##
    session = MPI.GlobalMPISession(len(sys.argv), sys.argv)
    Utility.removeAllLogs()
    session.initializeLogs(0, True)

    if session.rank() == 0:
        print "The PyFrensie path is set to: ", pyfrensie_path

    properties = setSimulationProperties(histories, time)

    ##--------------------------------------------------------------------------##
    ## ---------------------------- GEOMETRY SETUP ---------------------------- ##
    ##--------------------------------------------------------------------------##

    # Set geometry path and type
    model_properties = DagMC.DagMCModelProperties(geometry_path)
    model_properties.useFastIdLookup()

    # Construct model
    geom_model = DagMC.DagMCModel(model_properties)

    ##--------------------------------------------------------------------------##
    ## -------------------------- EVENT HANDLER SETUP ------------------------- ##
    ##--------------------------------------------------------------------------##

    # Set event handler
    event_handler = Event.EventHandler(properties)

    # Set the energy bins
    bins = list(Utility.doubleArrayFromString("{ 1e-4, 58i, 6e-3, 99i, 1e-2}"))

    ## ------------------------ Surface Flux Estimator ------------------------ ##

    # Setup an adjoint surface flux estimator
    estimator_id = 2
    surface_ids = [1, 16, 18]
    surface_flux_estimator = Event.WeightMultipliedSurfaceFluxEstimator(
        estimator_id, 1.0, surface_ids, geom_model)

    # Set the particle type
    surface_flux_estimator.setParticleTypes([MonteCarlo.ADJOINT_ELECTRON])

    # Set the energy bins
    surface_flux_estimator.setSourceEnergyDiscretization(bins)

    # Create response function
    delta_energy = Distribution.DeltaDistribution(energy)
    particle_response_function = ActiveRegion.EnergyParticleResponseFunction(
        delta_energy)
    response_function = ActiveRegion.StandardParticleResponse(
        particle_response_function)

    # Set the response function
    surface_flux_estimator.setResponseFunctions([response_function])

    # Add the estimator to the event handler
    event_handler.addEstimator(surface_flux_estimator)

    ## -------------------------- Particle Tracker ---------------------------- ##

    # particle_tracker = Event.ParticleTracker( 0, 1000 )

    # # Add the particle tracker to the event handler
    # event_handler.addParticleTracker( particle_tracker )

    ##--------------------------------------------------------------------------##
    ## ----------------------- SIMULATION MANAGER SETUP ----------------------- ##
    ##--------------------------------------------------------------------------##

    # Initialized database
    database = Data.ScatteringCenterPropertiesDatabase(database_path)
    scattering_center_definition_database = Collision.ScatteringCenterDefinitionDatabase(
    )

    # Set element properties
    element_properties = database.getAtomProperties(atom)

    element_definition = scattering_center_definition_database.createDefinition(
        element, Data.ZAID(zaid))

    # version = 0
    if "debug" in pyfrensie_path:
        version = 1
    else:
        version = 0
    file_type = Data.AdjointElectroatomicDataProperties.Native_EPR_FILE

    element_definition.setAdjointElectroatomicDataProperties(
        element_properties.getSharedAdjointElectroatomicDataProperties(
            file_type, version))

    material_definition_database = Collision.MaterialDefinitionDatabase()
    material_definition_database.addDefinition(element, 1, (element, ),
                                               (1.0, ))

    # Fill model
    model = Collision.FilledGeometryModel(
        database_path, scattering_center_definition_database,
        material_definition_database, properties, geom_model, True)

    # Set particle distribution
    particle_distribution = ActiveRegion.StandardParticleDistribution(
        "source distribution")

    # Set the energy dimension distribution
    uniform_energy = Distribution.UniformDistribution(energy_cutoff, energy)
    energy_dimension_dist = ActiveRegion.IndependentEnergyDimensionDistribution(
        uniform_energy)
    particle_distribution.setDimensionDistribution(energy_dimension_dist)

    # Set the spatial dimension distribution
    particle_distribution.setPosition(0.0, 0.0, 0.0)

    particle_distribution.constructDimensionDistributionDependencyTree()

    # Set source components
    source_component = [
        ActiveRegion.StandardAdjointElectronSourceComponent(
            0, 1.0, model, particle_distribution)
    ]

    # Set source
    source = ActiveRegion.StandardParticleSource(source_component)

    # Set the archive type
    archive_type = "xml"

    # Set the simulation name and title
    name, title = setSimulationName(properties)

    factory = Manager.ParticleSimulationManagerFactory(model, source,
                                                       event_handler,
                                                       properties, name,
                                                       archive_type, threads)

    manager = factory.getManager()

    Utility.removeAllLogs()
    session.initializeLogs(0, False)

    manager.runSimulation()

    if session.rank() == 0:

        print "Processing the results:"
        processData(event_handler, name, title)
        print "Results will be in ", path.dirname(name)
Example #4
0
def runSimulation(threads, histories, time):

    ##--------------------------------------------------------------------------##
    ## ------------------------------ MPI Session ----------------------------- ##
    ##--------------------------------------------------------------------------##
    session = MPI.GlobalMPISession(len(sys.argv), sys.argv)
    Utility.removeAllLogs()
    session.initializeLogs(0, True)

    if session.rank() == 0:
        print "The PyFrensie path is set to: ", pyfrensie_path

    properties = setSimulationProperties(histories, time)

    ##--------------------------------------------------------------------------##
    ## ---------------------------- GEOMETRY SETUP ---------------------------- ##
    ##--------------------------------------------------------------------------##

    # Set element zaid and name
    atom = Data.H_ATOM
    zaid = 1000
    element = "H"

    # Set geometry path and type
    model_properties = DagMC.DagMCModelProperties(geometry_path)
    model_properties.useFastIdLookup()

    # Set model
    geom_model = DagMC.DagMCModel(model_properties)

    ##--------------------------------------------------------------------------##
    ## -------------------------- EVENT HANDLER SETUP ------------------------- ##
    ##--------------------------------------------------------------------------##

    # Set event handler
    event_handler = Event.EventHandler(properties)

    # Set the energy bins
    if energy == 0.1:
        bins = list(Utility.doubleArrayFromString("{ 1e-4, 5e-4, 198i, 1e-1}"))
    elif energy == 0.01:
        bins = list(
            Utility.doubleArrayFromString("{ 1e-4, 58i, 6e-3, 99i, 1e-2}"))
    elif energy == 0.001:
        bins = list(Utility.doubleArrayFromString("{ 1e-4, 197i, 1e-3}"))
    else:
        print "ERROR: energy ", energy, " not supported!"

    ## -------------------------- Track Length Flux --------------------------- ##

    # Setup a track length flux estimator
    estimator_id = 1
    cell_ids = [1]
    track_flux_estimator = Event.WeightMultipliedCellTrackLengthFluxEstimator(
        estimator_id, 1.0, cell_ids, geom_model)

    # Set the particle type
    track_flux_estimator.setParticleTypes([MonteCarlo.ELECTRON])

    # Set the energy bins
    track_flux_estimator.setEnergyDiscretization(bins)

    # Add the estimator to the event handler
    event_handler.addEstimator(track_flux_estimator)

    ## ------------------------ Surface Flux Estimator ------------------------ ##

    # Setup a surface flux estimator
    estimator_id = 2
    surface_ids = [1]
    surface_flux_estimator = Event.WeightMultipliedSurfaceFluxEstimator(
        estimator_id, 1.0, surface_ids, geom_model)

    # Set the particle type
    surface_flux_estimator.setParticleTypes([MonteCarlo.ELECTRON])

    # Set the energy bins
    surface_flux_estimator.setEnergyDiscretization(bins)

    # Add the estimator to the event handler
    event_handler.addEstimator(surface_flux_estimator)

    ## ---------------------- Surface Current Estimator ----------------------- ##

    # Setup a surface current estimator
    estimator_id = 3
    surface_ids = [1]
    surface_current_estimator = Event.WeightMultipliedSurfaceCurrentEstimator(
        estimator_id, 1.0, surface_ids)

    # Set the particle type
    surface_current_estimator.setParticleTypes([MonteCarlo.ELECTRON])

    # Set the energy bins
    surface_current_estimator.setEnergyDiscretization(bins)

    # Add the estimator to the event handler
    event_handler.addEstimator(surface_current_estimator)

    ##--------------------------------------------------------------------------##
    ## ----------------------- SIMULATION MANAGER SETUP ----------------------- ##
    ##--------------------------------------------------------------------------##

    # Initialized database
    database = Data.ScatteringCenterPropertiesDatabase(database_path)
    scattering_center_definition_database = Collision.ScatteringCenterDefinitionDatabase(
    )

    # Set element properties
    element_properties = database.getAtomProperties(atom)

    element_definition = scattering_center_definition_database.createDefinition(
        element, Data.ZAID(zaid))

    version = 0
    if file_type == Data.ElectroatomicDataProperties.ACE_EPR_FILE:
        version = 14

    element_definition.setElectroatomicDataProperties(
        element_properties.getSharedElectroatomicDataProperties(
            file_type, version))

    material_definition_database = Collision.MaterialDefinitionDatabase()
    material_definition_database.addDefinition(element, 1, (element, ),
                                               (1.0, ))

    # Fill model
    model = Collision.FilledGeometryModel(
        database_path, scattering_center_definition_database,
        material_definition_database, properties, geom_model, True)

    # Set particle distribution
    particle_distribution = ActiveRegion.StandardParticleDistribution(
        "source distribution")

    # Set the energy dimension distribution
    delta_energy = Distribution.DeltaDistribution(energy)
    energy_dimension_dist = ActiveRegion.IndependentEnergyDimensionDistribution(
        delta_energy)
    particle_distribution.setDimensionDistribution(energy_dimension_dist)

    # Set the spatial dimension distribution
    particle_distribution.setPosition(0.0, 0.0, 0.0)

    particle_distribution.constructDimensionDistributionDependencyTree()

    # Set source components
    source_component = [
        ActiveRegion.StandardElectronSourceComponent(0, 1.0, geom_model,
                                                     particle_distribution)
    ]

    # Set source
    source = ActiveRegion.StandardParticleSource(source_component)

    # Set the archive type
    archive_type = "xml"

    name, title = setSimulationName(properties)

    factory = Manager.ParticleSimulationManagerFactory(model, source,
                                                       event_handler,
                                                       properties, name,
                                                       archive_type, threads)

    manager = factory.getManager()

    Utility.removeAllLogs()
    session.initializeLogs(0, False)

    manager.runSimulation()

    if session.rank() == 0:

        print "Processing the results:"
        processData(event_handler, name, title)

        print "Results will be in ", path.dirname(name)
Example #5
0
    "KO4": 8.82612e-2,
    "KO5": 8.8264e-2,
    "KP2": 8.8283e-2,
    "KP3": 8.82847e-2
}

sorted_x_ray_line_names = [
    "KL2", "KL3", "KM2", "KM3", "KM4", "KM5", "KN2", "KN3", "KN4", "KN5",
    "KO2", "KO3", "KO4", "KO5", "KP2", "KP3"
]

#energy_bins = list(Utility.doubleArrayFromString( "{1e-3, 499i, 0.1}" ))
#energy_bins = list(Utility.doubleArrayFromString( "{1e-3, 499i, 0.2}" ))
#energy_bins = list(Utility.doubleArrayFromString( "{1e-3, 499i, 0.5}" ))
#energy_bins = list(Utility.doubleArrayFromString( "{1e-3, 499i, 1.0}" ))
energy_bins = list(Utility.doubleArrayFromString("{1e-3, 499i, 10.0}"))

x_ray_line_indices = set()

# Loop through each x-ray line and determine the bin that it falls in
for i in range(0, len(sorted_x_ray_line_names)):
    name = sorted_x_ray_line_names[i]
    x_ray_energy = x_ray_lines[name]

    for j in range(0, len(energy_bins) - 1):
        if x_ray_energy > energy_bins[j] and x_ray_energy <= energy_bins[j +
                                                                         1]:
            #print name, "in bin", j, "->", x_ray_energy, energy_bins[j], energy_bins[j+1]
            index = 0

            if j in x_ray_line_indices:
Example #6
0
    parser.add_option("--sim_name",
                      type="string",
                      dest="sim_name",
                      default="sphere",
                      help="the simulation name")
    parser.add_option("--log_file",
                      type="string",
                      dest="log_file",
                      help="the file that will be used for logging")
    parser.add_option("--num_particles",
                      type="float",
                      dest="num_particles",
                      default=1e3,
                      help="the number of particles to run")
    parser.add_option("--source_energy",
                      type="float",
                      dest="source_energy",
                      default=1.0,
                      help="the source energy in MeV")
    options, args = parser.parse_args()

    if options.db_path is None:
        print "The database path must be specified!"
        sys.exit(1)

    # Run the simulation
    sphereSimulation(options.sim_name, options.db_path, options.num_particles,
                     options.source_energy,
                     Utility.doubleArrayFromString("{1e-9,100l,1.0}"),
                     options.threads, options.log_file)
Example #7
0
    parser.add_option("--db_path",
                      type="string",
                      dest="db_path",
                      help="the database name (with extension)")
    parser.add_option("--sim_name",
                      type="string",
                      dest="sim_name",
                      default="sphere",
                      help="the simulation name")
    parser.add_option("--log_file",
                      type="string",
                      dest="log_file",
                      help="the file that will be used for logging")
    parser.add_option("--num_particles",
                      type="float",
                      dest="num_particles",
                      default=1e3,
                      help="the number of particles to run")
    options, args = parser.parse_args()

    if options.db_path is None:
        print "The database path must be specified!"
        sys.exit(1)

    # Run the simulation
    runBroomstickSimulation(
        options.sim_name, options.db_path, options.num_particles,
        MonteCarlo.DECOUPLED_HALF_PROFILE_DB_HYBRID_INCOHERENT_MODEL, 0.1,
        Utility.doubleArrayFromString("{1e-3, 988i, 0.0999, 9i, 0.1}"),
        options.threads, options.log_file)
Example #8
0
    1.238122,
    1.280976,
    1.377669,
    1.401515,
    1.407988,
    1.50921,
    1.661274,
    1.729595,
    1.764491,
    1.847429,
    2.118514,
    2.204059,
    2.44770
]

energy_bins = list(Utility.doubleArrayFromString("{1e-3, 998i, 2.44770}"))

gamma_line_indices = set()

# Loop through each gamma line and determine the bin that it falls in
for i in range(0, len(gamma_lines)):
    gamma_energy = gamma_lines[i]

    for j in range(0, len(energy_bins) - 1):
        if gamma_energy > energy_bins[j] and gamma_energy <= energy_bins[j +
                                                                         1]:
            #print name, "in bin", j, "->", gamma_energy, energy_bins[j], energy_bins[j+1]
            index = 0

            if j in gamma_line_indices:
                print "Error: x-ray line energy bin width too large!"
def sphereSimulation( sim_name,
                      db_path,
                      num_particles,
                      temp,
                      threads,
                      log_file = None ):
    
##---------------------------------------------------------------------------##
## Initialize the MPI Session
##---------------------------------------------------------------------------##
    
    session = MPI.GlobalMPISession( len(sys.argv), sys.argv )
    
    # Suppress logging on all procs except for the master (proc=0)
    Utility.removeAllLogs()
    session.initializeLogs( 0, True )
    
    if not log_file is None:
        session.initializeLogs( log_file, 0, True )
    
##---------------------------------------------------------------------------##
## Set the simulation properties
##---------------------------------------------------------------------------##
    
    simulation_properties = MonteCarlo.SimulationProperties()
    
    # Simulate neutrons only
    simulation_properties.setParticleMode( MonteCarlo.NEUTRON_MODE )
    simulation_properties.setUnresolvedResonanceProbabilityTableModeOff()
    simulation_properties.setNumberOfNeutronHashGridBins( 100 )
    simulation_properties.setSurfaceFluxEstimatorAngleCosineCutoff( 0.1 )
    
    # Set the number of histories to run and the number of rendezvous
    simulation_properties.setNumberOfHistories( num_particles )
    simulation_properties.setMinNumberOfRendezvous( 10 )
    
##---------------------------------------------------------------------------##
## Set up the materials
##---------------------------------------------------------------------------##
    
    # Load the database
    database = Data.ScatteringCenterPropertiesDatabase( db_path )
    
    # Extract the properties for H1 from the database
    nuclide_properties = database.getNuclideProperties( Data.ZAID(1001) )
    
    # Set the definition of H1 for this simulation
    scattering_center_definitions = Collision.ScatteringCenterDefinitionDatabase()
    nuclide_definition = scattering_center_definitions.createDefinition( "H1", Data.ZAID(1001) )
    
    nuclide_definition.setNuclearDataProperties( nuclide_properties.getSharedNuclearDataProperties( Data.NuclearDataProperties.ACE_FILE, 8, temp, False ) )
    
    # Set the definition for material 1
    material_definitions = Collision.MaterialDefinitionDatabase()
    material_definitions.addDefinition( "H1", 1, ["H1"], [1.0] )
    
##---------------------------------------------------------------------------##
## Set up the geometry
##---------------------------------------------------------------------------##
    
    # Set the model properties before loading the model
    model_properties = DagMC.DagMCModelProperties( "sphere.h5m" )
    model_properties.setMaterialPropertyName( "mat" )
    model_properties.setDensityPropertyName( "rho" )
    model_properties.setTerminationCellPropertyName( "termination.cell" )
    model_properties.setSurfaceFluxName( "surface.flux" )
    model_properties.setSurfaceCurrentName( "surface.current" )
    model_properties.useFastIdLookup()
    
    # Load the model
    model = DagMC.DagMCModel( model_properties )
    
    # Fill the model with the defined materials
    filled_model = Collision.FilledGeometryModel( db_path, scattering_center_definitions, material_definitions, simulation_properties, model, True )
    
##---------------------------------------------------------------------------##
## Set up the source
##---------------------------------------------------------------------------##
    
    # Define the generic particle distribution
    particle_distribution = ActiveRegion.StandardParticleDistribution( "source distribution" )
    
    particle_distribution.setEnergy( 1.0 );
    particle_distribution.setPosition( 0.0, 0.0, 0.0 )
    particle_distribution.constructDimensionDistributionDependencyTree()
    
    # The generic distribution will be used to generate neutrons
    neutron_distribution = ActiveRegion.StandardNeutronSourceComponent( 0, 1.0, model, particle_distribution )
    
    # Assign the neutron source component to the source
    source = ActiveRegion.StandardParticleSource( [neutron_distribution] )
    
##---------------------------------------------------------------------------##
## Set up the event handler
##---------------------------------------------------------------------------##
    
    # The model must be passed to the event handler so that the estimators
    # defined in the model can be constructed
    event_handler = Event.EventHandler( model, simulation_properties )
    
    # Set the energy and collision number bins in estimator 1
    event_handler.getEstimator( 1 ).setEnergyDiscretization( Utility.doubleArrayFromString( "{1e-9, 100l, 1.0}" ) )
    
    # Set the energy and collision number bins in estimator 2
    event_handler.getEstimator( 2 ).setEnergyDiscretization( Utility.doubleArrayFromString( "{1e-9, 100l, 1.0}" ) )
        
##---------------------------------------------------------------------------##
## Set up the simulation manager
##---------------------------------------------------------------------------##
    
    # The factory will use the simulation properties and the MPI session
    # properties to determine the appropriate simulation manager to construct
    factory = Manager.ParticleSimulationManagerFactory( filled_model,
                                                        source,
                                                        event_handler,
                                                        simulation_properties,
                                                        sim_name,
                                                        "xml",
                                                        threads )
    
    # Create the simulation manager
    manager = factory.getManager()
    
    # Allow logging on all procs
    session.restoreOutputStreams()
    
##---------------------------------------------------------------------------##
## Run the simulation
##---------------------------------------------------------------------------##
    
    if session.size() == 1:
        manager.runInterruptibleSimulation()
    else:
        manager.runSimulation()