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 bins = list(Utility.doubleArrayFromString("{ 1e-4, 58i, 6e-3, 99i, 1e-2}")) ## ------------------------ Surface Flux Estimator ------------------------ ## # Setup a surface flux estimator estimator_id = 1 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.ELECTRON]) # Set the energy bins surface_flux_estimator.setEnergyDiscretization(bins) # Add the estimator to the event handler event_handler.addEstimator(surface_flux_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)
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()
# Set the energy bins energy_bins = numpy.logspace(numpy.log10(1.5e-5), numpy.log10(15.7), num=101) #[ 1.5e-5, 99l, 15.7 ] track_flux_estimator.setEnergyDiscretization( energy_bins ) # Add the estimator to the event handler event_handler.addEstimator( track_flux_estimator ) ##---------------------------------------------------------------------------## ## ----------------------- SIMULATION MANAGER SETUP ------------------------ ## ##---------------------------------------------------------------------------## data_directory = os.path.dirname(database_path) # Initialized database database = Data.ScatteringCenterPropertiesDatabase(database_path) scattering_center_definition_database = Collision.ScatteringCenterDefinitionDatabase() # Set element properties element_properties = database.getAtomProperties( Data.Au_ATOM ) element_definition = scattering_center_definition_database.createDefinition( element, Data.ZAID(zaid) ) version = 1 if file_type == Data.ElectroatomicDataProperties.ACE_EPR_FILE: version = 14 element_definition.setElectroatomicDataProperties( element_properties.getSharedElectroatomicDataProperties( file_type, version ) ) material_definition_database = Collision.MaterialDefinitionDatabase()
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) ## -------------------- Energy Deposition Calorimeter --------------------- ## number_of_subzones = 50 # Setup a cell pulse height estimator estimator_id = 1 cell_ids = range(1, number_of_subzones + 1) energy_deposition_estimator = Event.WeightAndEnergyMultipliedCellPulseHeightEstimator( estimator_id, 1.0, cell_ids) # Add the estimator to the event handler event_handler.addEstimator(energy_deposition_estimator) ##--------------------------------------------------------------------------## ## ----------------------- SIMULATION MANAGER SETUP ----------------------- ## ##--------------------------------------------------------------------------## # Initialized database database = Data.ScatteringCenterPropertiesDatabase(database_path) scattering_center_definition_database = Collision.ScatteringCenterDefinitionDatabase( ) # Set material properties version = 0 if file_type == Data.ElectroatomicDataProperties.ACE_EPR_FILE: version = 14 # Definition for Aluminum if material == "Al": al_properties = database.getAtomProperties(Data.Al_ATOM) al_definition = scattering_center_definition_database.createDefinition( material, Data.ZAID(13000)) al_definition.setElectroatomicDataProperties( al_properties.getSharedElectroatomicDataProperties( file_type, version)) definition = (("Al", 1.0), ) else: h_properties = database.getAtomProperties(Data.H_ATOM) h_definition = scattering_center_definition_database.createDefinition( "H", Data.ZAID(1000)) h_definition.setElectroatomicDataProperties( h_properties.getSharedElectroatomicDataProperties( file_type, version)) c_properties = database.getAtomProperties(Data.C_ATOM) c_definition = scattering_center_definition_database.createDefinition( "C", Data.ZAID(6000)) c_definition.setElectroatomicDataProperties( c_properties.getSharedElectroatomicDataProperties( file_type, version)) # Definition for polystyrene if material == "polystyrene": definition = (("H", -0.077418), ("C", -0.922582)) # Definition for polyethylene elif material == "polyethylene": definition = (("H", -0.14), ("C", -0.86)) else: print "ERROR: material ", material, " is currently not supported!" material_definition_database = Collision.MaterialDefinitionDatabase() material_definition_database.addDefinition(material, 1, definition) # 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 direction dimension distribution particle_distribution.setDirection(0.0, 0.0, 1.0) # Set the spatial dimension distribution particle_distribution.setPosition(0.0, 0.0, -0.01) 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" # 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(energy_deposition_estimator, name, title, subzone_width * density) print "Results will be in ", path.dirname(name)