def setAdjointSimulationProperties(histories, time, elastic_mode, elastic_sampling_method): properties = MonteCarlo.SimulationProperties() ## -------------------------- GENERAL PROPERTIES -------------------------- ## # Set the particle mode properties.setParticleMode(MonteCarlo.ADJOINT_ELECTRON_MODE) # Set the number of histories properties.setNumberOfHistories(histories) # Set the minimum number of rendezvous if histories > 100: properties.setMinNumberOfRendezvous(10) # Change time from minutes to seconds time_sec = time * 60 # Set the wall time properties.setSimulationWallTime(time_sec) ## ---------------------- ADJOINT NEUTRON PROPERTIES ---------------------- ## ## ---------------------- ADJOINT PHOTON PROPERTIES ----------------------- ## ## --------------------- ADJOINT ELECTRON PROPERTIES ---------------------- ## # Set the min electron energy in MeV (Default is 100 eV) properties.setMinAdjointElectronEnergy(1e-4) # Set the max electron energy in MeV (Default is 20 MeV) properties.setMaxAdjointElectronEnergy(20.0) # Set the electron evaluation tolerance (Default is 1e-6) properties.setAdjointElectronEvaluationTolerance(1e-6) ## --- Adjoint Elastic Properties --- # Set the elastic distribution mode ( DECOUPLED, COUPLED, HYBRID ) properties.setAdjointElasticElectronDistributionMode(elastic_mode) # Set the elastic coupled sampling method # ( TWO_D_UNION, ONE_D_UNION, MODIFIED_TWO_D_UNION ) properties.setAdjointCoupledElasticSamplingMode(elastic_sampling_method) # Set the elastic cutoff angle cosine ( -1.0 < mu < 1.0 ) properties.setAdjointElasticCutoffAngleCosine(1.0) return properties
def restartBroomstickSimulation( rendezvous_file_name, db_path, num_particles, threads, log_file = None, num_rendezvous = 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 database path Collision.FilledGeometryModel.setDefaultDatabasePath( db_path ) if not num_rendevous is None: new_simulation_properties = MonteCarlo.SimulationGeneralProperties() new_simulation_properties.setNumberOfHistories( int(num_particles) ) new_simulation_properties.setMinNumberOfRendezvous( int(num_rendezvous) ) factory = Manager.ParticleSimulationManagerFactory( rendezvous_file_name, new_simulation_properties, threads ) else: factory = Manger.ParticleSimulationManagerFactory( rendezvous_file_name, int(num_particles), threads ) manager = factory.getManager() # Allow logging on all procs session.restoreOutputStreams() ## Run the simulation if session.size() == 1: manager.runInterruptibleSimulation() else: manager.runSimulation()
def runBroomstickSimulation(sim_name, db_path, num_particles, incoherent_model_type, source_energy, energy_bins, 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 photons only simulation_properties.setParticleMode(MonteCarlo.PHOTON_MODE) simulation_properties.setIncoherentModelType(incoherent_model_type) simulation_properties.setNumberOfPhotonHashGridBins(100) # Set the number of histories to run and the number of rendezvous simulation_properties.setNumberOfHistories(num_particles) simulation_properties.setMinNumberOfRendezvous(100) simulation_properties.setNumberOfSnapshotsPerBatch(1) ## Set up the materials database = Data.ScatteringCenterPropertiesDatabase(db_path) # Extract the properties for H from the database atom_properties = database.getAtomProperties(Data.ZAID(82000)) # Set the definition for H for this simulation scattering_center_definitions = Collision.ScatteringCenterDefinitionDatabase( ) atom_definition = scattering_center_definitions.createDefinition( "Pb", Data.ZAID(82000)) if incoherent_model_type == MonteCarlo.IMPULSE_INCOHERENT_MODEL or incoherent_model_type == MonteCarlo.FULL_PROFILE_DB_IMPULSE_INCOHERENT_MODEL: atom_definition.setPhotoatomicDataProperties( atom_properties.getSharedPhotoatomicDataProperties( Data.PhotoatomicDataProperties.Native_EPR_FILE, 0)) else: atom_definition.setPhotoatomicDataProperties( atom_properties.getSharedPhotoatomicDataProperties( Data.PhotoatomicDataProperties.ACE_EPR_FILE, 12)) # Set the definition for material 1 material_definitions = Collision.MaterialDefinitionDatabase() material_definitions.addDefinition("Pb", 1, ["Pb"], [1.0]) ## Set up the geometry model_properties = DagMC.DagMCModelProperties("broomstick.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 material filled_model = Collision.FilledGeometryModel( db_path, scattering_center_definitions, material_definitions, simulation_properties, model, True) ## Set up the source particle_distribution = ActiveRegion.StandardParticleDistribution( "mono-directional mono-energetic dist") particle_distribution.setEnergy(source_energy) particle_distribution.setPosition(0.0, 0.0, -500.1) particle_distribution.setDirection(0.0, 0.0, 1.0) particle_distribution.constructDimensionDistributionDependencyTree() # The generic distribution will be used to generate photons photon_distribution = ActiveRegion.StandardPhotonSourceComponent( 0, 1.0, model, particle_distribution) # Assign the photon source component to the source source = ActiveRegion.StandardParticleSource([photon_distribution]) ## Set up the event handler event_handler = Event.EventHandler(model, simulation_properties) # Set the energy and collision number bins in estimator 1 event_handler.getEstimator(1).setEnergyDiscretization(energy_bins) event_handler.getEstimator(1).setCollisionNumberDiscretization([0, 1, 10]) # Set the energy and collision number bins in estimator 2 event_handler.getEstimator(2).setEnergyDiscretization(energy_bins) event_handler.getEstimator(2).setCollisionNumberDiscretization([0, 1, 10]) ## Set up the simulation manager factory = Manager.ParticleSimulationManagerFactory(filled_model, source, event_handler, simulation_properties, sim_name, "xml", threads) # Create the simulation manager manager = factory.getManager() manager.useSingleRendezvousFile() # Allow logging on all procs session.restoreOutputStreams() ## Run the simulation if session.size() == 1: manager.runInterruptibleSimulation() else: manager.runSimulation()
def sphereSimulation(sim_name, db_path, num_particles, source_energy, energy_bins, 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) # 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) # Set the definition of H1 for this simulation scattering_center_definitions = Collision.ScatteringCenterDefinitionDatabase( ) # Extract the properties for H1 from the database nuclide_properties = database.getNuclideProperties(Data.ZAID(82204)) nuclide_definition = scattering_center_definitions.createDefinition( "Pb204", Data.ZAID(82204)) nuclide_definition.setNuclearDataProperties( nuclide_properties.getSharedNuclearDataProperties( Data.NuclearDataProperties.ACE_FILE, 8, 293.6, False)) nuclide_properties = database.getNuclideProperties(Data.ZAID(82206)) nuclide_definition = scattering_center_definitions.createDefinition( "Pb206", Data.ZAID(82206)) nuclide_definition.setNuclearDataProperties( nuclide_properties.getSharedNuclearDataProperties( Data.NuclearDataProperties.ACE_FILE, 8, 293.6, False)) nuclide_properties = database.getNuclideProperties(Data.ZAID(82207)) nuclide_definition = scattering_center_definitions.createDefinition( "Pb207", Data.ZAID(82207)) nuclide_definition.setNuclearDataProperties( nuclide_properties.getSharedNuclearDataProperties( Data.NuclearDataProperties.ACE_FILE, 8, 293.6, False)) nuclide_properties = database.getNuclideProperties(Data.ZAID(82208)) nuclide_definition = scattering_center_definitions.createDefinition( "Pb208", Data.ZAID(82208)) nuclide_definition.setNuclearDataProperties( nuclide_properties.getSharedNuclearDataProperties( Data.NuclearDataProperties.ACE_FILE, 8, 293.6, False)) material_definitions = Collision.MaterialDefinitionDatabase() material_definitions.addDefinition("Pb_nat", 1, ["Pb204", "Pb206", "Pb207", "Pb208"], [0.014, 0.241, 0.221, 0.524]) ##---------------------------------------------------------------------------## ## 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(source_energy) 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(energy_bins) # Set the energy and collision number bins in estimator 2 event_handler.getEstimator(2).setEnergyDiscretization(energy_bins) ##---------------------------------------------------------------------------## ## 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()
##---------------------------------------------------------------------------## 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) # 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
coupled_react = Electron.createCoupledElasticReaction_LinLinCorrelated( native_data, method, 1e-15) # Coupled Distribution coupled_dist = Electron.createCoupledElasticDistribution_LinLinCorrelated( native_data, method, 1e-15) # Decoupled Reaction decoupled_react = Electron.createDecoupledElasticReaction_LinLinCorrelated( native_data, 1e-15) # Cutoff Distribution cutoff_dist = Electron.createCutoffElasticDistribution_LinLinCorrelated( native_data, 0.999999, 1e-15) print "\n----- ", method, " -----\n" n = 100 electron = MonteCarlo.ElectronState(0) bank = MonteCarlo.ParticleBank() for energy in energies: fig, ax = plt.subplots() print "\t -- React 256 keV--" energy0 = 0.256 electron.setEnergy(energy0) sampling_ratio = decoupled_react.getSamplingRatio(energy0) print "sampling_ratio = ", sampling_ratio random_numbers = [0.0] * 2 * n if sampling_ratio > 0.5: cdf1 = numpy.linspace(0.5, sampling_ratio - 1e-15, n / 2) cdf2 = numpy.linspace(sampling_ratio + 1e-15, 1.0 - 1e-15, n / 2)
def runAdjointSimulation( sim_name, db_path, geom_name, num_particles, incoherent_model_type, threads, use_energy_bins = False, 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 photons only simulation_properties.setParticleMode( MonteCarlo.ADJOINT_PHOTON_MODE ) simulation_properties.setIncoherentAdjointModelType( incoherent_model_type ) simulation_properties.setMinAdjointPhotonEnergy( 1e-3 ) if incoherent_model_type == MonteCarlo.DB_IMPULSE_INCOHERENT_ADJOINT_MODEL: simulation_properties.setMaxAdjointPhotonEnergy( energy_bins[-1]*1.5 ) else: simulation_properties.setMaxAdjointPhotonEnergy( energy_bins[-1] ) simulation_properties.setCriticalAdjointPhotonLineEnergies( [0.186211, 0.241995, 0.2656, 0.2952228, 0.3046, 0.3519321, 0.60932, 0.6496, 0.665447, 0.76836, 0.78596, 0.80618, 0.934056, 1.120294, 1.15521, 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] ) simulation_properties.setAdjointPhotonRouletteThresholdWeight( 0.0025 ) simulation_properties.setAdjointPhotonRouletteSurvivalWeight( 0.005 ) simulation_properties.setNumberOfAdjointPhotonHashGridBins( 100 ) # Set the number of histories to run and the number of rendezvous simulation_properties.setNumberOfHistories( num_particles ) simulation_properties.setMinNumberOfRendezvous( 100 ) simulation_properties.setNumberOfSnapshotsPerBatch( 1 ) ## Set up the materials database = Data.ScatteringCenterPropertiesDatabase( db_path ) # Extract the properties from the database c_atom_properties = database.getAtomProperties( Data.ZAID(6000) ) n_atom_properties = database.getAtomProperties( Data.ZAID(7000) ) o_atom_properties = database.getAtomProperties( Data.ZAID(8000) ) na_atom_properties = database.getAtomProperties( Data.ZAID(11000) ) mg_atom_properties = database.getAtomProperties( Data.ZAID(12000) ) al_atom_properties = database.getAtomProperties( Data.ZAID(13000) ) si_atom_properties = database.getAtomProperties( Data.ZAID(14000) ) ar_atom_properties = database.getAtomProperties( Data.ZAID(18000) ) k_atom_properties = database.getAtomProperties( Data.ZAID(19000) ) ca_atom_properties = database.getAtomProperties( Data.ZAID(20000) ) ti_atom_properties = database.getAtomProperties( Data.ZAID(22000) ) mn_atom_properties = database.getAtomProperties( Data.ZAID(25000) ) fe_atom_properties = database.getAtomProperties( Data.ZAID(26000) ) # Set the atom definitions scattering_center_definitions = Collision.ScatteringCenterDefinitionDatabase() c_atom_definition = scattering_center_definitions.createDefinition( "C", Data.ZAID(6000) ) n_atom_definition = scattering_center_definitions.createDefinition( "N", Data.ZAID(7000) ) o_atom_definition = scattering_center_definitions.createDefinition( "O", Data.ZAID(8000) ) na_atom_definition = scattering_center_definitions.createDefinition( "Na", Data.ZAID(11000) ) mg_atom_definition = scattering_center_definitions.createDefinition( "Mg", Data.ZAID(12000) ) al_atom_definition = scattering_center_definitions.createDefinition( "Al", Data.ZAID(13000) ) si_atom_definition = scattering_center_definitions.createDefinition( "Si", Data.ZAID(14000) ) ar_atom_definition = scattering_center_definitions.createDefinition( "Ar", Data.ZAID(18000) ) k_atom_definition = scattering_center_definitions.createDefinition( "K", Data.ZAID(19000) ) ca_atom_definition = scattering_center_definitions.createDefinition( "Ca", Data.ZAID(20000) ) ti_atom_definition = scattering_center_definitions.createDefinition( "Ti", Data.ZAID(22000) ) mn_atom_definition = scattering_center_definitions.createDefinition( "Mn", Data.ZAID(25000) ) fe_atom_definition = scattering_center_definitions.createDefinition( "Fe", Data.ZAID(26000) ) data_file_type = Data.AdjointPhotoatomicDataProperties.Native_EPR_FILE file_version = 0 c_atom_definition.setAdjointPhotoatomicDataProperties( c_atom_properties.getSharedAdjointPhotoatomicDataProperties( data_file_type, file_version ) ) n_atom_definition.setAdjointPhotoatomicDataProperties( n_atom_properties.getSharedAdjointPhotoatomicDataProperties( data_file_type, file_version ) ) o_atom_definition.setAdjointPhotoatomicDataProperties( o_atom_properties.getSharedAdjointPhotoatomicDataProperties( data_file_type, file_version ) ) na_atom_definition.setAdjointPhotoatomicDataProperties( na_atom_properties.getSharedAdjointPhotoatomicDataProperties( data_file_type, file_version ) ) mg_atom_definition.setAdjointPhotoatomicDataProperties( mg_atom_properties.getSharedAdjointPhotoatomicDataProperties( data_file_type, file_version ) ) al_atom_definition.setAdjointPhotoatomicDataProperties( al_atom_properties.getSharedAdjointPhotoatomicDataProperties( data_file_type, file_version ) ) si_atom_definition.setAdjointPhotoatomicDataProperties( si_atom_properties.getSharedAdjointPhotoatomicDataProperties( data_file_type, file_version ) ) ar_atom_definition.setAdjointPhotoatomicDataProperties( ar_atom_properties.getSharedAdjointPhotoatomicDataProperties( data_file_type, file_version ) ) k_atom_definition.setAdjointPhotoatomicDataProperties( k_atom_properties.getSharedAdjointPhotoatomicDataProperties( data_file_type, file_version ) ) ca_atom_definition.setAdjointPhotoatomicDataProperties( ca_atom_properties.getSharedAdjointPhotoatomicDataProperties( data_file_type, file_version ) ) ti_atom_definition.setAdjointPhotoatomicDataProperties( ti_atom_properties.getSharedAdjointPhotoatomicDataProperties( data_file_type, file_version ) ) mn_atom_definition.setAdjointPhotoatomicDataProperties( mn_atom_properties.getSharedAdjointPhotoatomicDataProperties( data_file_type, file_version ) ) fe_atom_definition.setAdjointPhotoatomicDataProperties( fe_atom_properties.getSharedAdjointPhotoatomicDataProperties( data_file_type, file_version ) ) # Set the definition for material 1 (ave soil US from PNNL-15870 Rev1) material_definitions = Collision.MaterialDefinitionDatabase() material_definitions.addDefinition( "Soil", 1, ["O", "Na", "Mg", "Al", "Si", "K", "Ca", "Ti", "Mn", "Fe"], [0.670604, 0.005578, 0.011432, 0.053073, 0.201665, 0.007653, 0.026664, 0.002009, 0.000272, 0.021050] ) material_definitions.addDefinition( "Air", 2, ["C", "N", "O", "Ar"], [0.000150, 0.784431, 0.231781, 0.004671] ) # Set up the geometry model_properties = DagMC.DagMCModelProperties( geom_name ) model_properties.setMaterialPropertyName( "mat" ) model_properties.setDensityPropertyName( "rho" ) model_properties.setTerminationCellPropertyName( "termination.cell" ) model_properties.setReflectingSurfacePropertyName( "reflecting.surface" ) model_properties.setSurfaceFluxName( "surface.flux" ) model_properties.useFastIdLookup() # Load the model model = DagMC.DagMCModel( model_properties ) # Fill the model with the defined material filled_model = Collision.FilledGeometryModel( db_path, scattering_center_definitions, material_definitions, simulation_properties, model, True ) # Set up the source particle_distribution = ActiveRegion.StandardParticleDistribution( "isotropic point source" ) uniform_energy = Distribution.UniformDistribution( 1e-3, energy_bins[-1] ) energy_dimension_dist = ActiveRegion.IndependentEnergyDimensionDistribution( uniform_energy ) particle_distribution.setDimensionDistribution( energy_dimension_dist ) particle_distribution.setPosition( 0.0, 0.0, 5200.0 ) particle_distribution.constructDimensionDistributionDependencyTree() # The generic distribution will be used to generate photons adjoint_photon_distribution = ActiveRegion.StandardAdjointPhotonSourceComponent( 0, 1.0, filled_model, particle_distribution ) # Assign the photon source component to the source source = ActiveRegion.StandardParticleSource( [adjoint_photon_distribution] ) ## Set up the event handler event_handler = Event.EventHandler( model, simulation_properties ) # Create the discrete forward source line energy response function discrete_energy_response_function = ActiveRegion.EnergyParticleResponseFunction( Distribution.DiscreteDistribution( [0.186211, 0.241995, 0.2656, 0.2952228, 0.3046, 0.3519321, 0.60932, 0.6496, 0.665447, 0.76836, 0.78596, 0.80618, 0.934056, 1.120294, 1.15521, 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], [0.013622652525055947, 0.02713677292834634, 0.1908668348290806, 0.068936609755915, 0.10478963480812267, 0.13323253568461313, 0.17024573169362503, 0.012724455655272039, 0.0057297475318298504, 0.01831573116967687, 0.00396703617487893, 0.004730503514195252, 0.011627906976744184, 0.05583790540489965, 0.006111481201488011, 0.021833668909663845, 0.005366726296958854, 0.014925037986242614, 0.004977507653385827, 0.00895951377609449, 0.007971497219332189, 0.003918383844432301, 0.010770877463492038, 0.057260050448724176, 0.007578536088801728, 0.004341284870622224, 0.01842800577839986, 0.005793369810106211] ) ) # Create the flux-to-effective dose from ICRP-116 table A.1, ISO values) flux_to_dose_response_function = ActiveRegion.SourceEnergyParticleResponseFunction( Distribution.TabularDistribution_LinLin( [0.01, 0.015, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.1, 0.15, 0.2, 0.3, 0.4, 0.5, 0.511, 0.6, 0.662, 0.8, 1.0, 1.117, 1.33, 1.5, 2.0, 3.0], [0.0288, 0.0560, 0.0812, 0.127, 0.158, 0.180, 0.199, 0.218, 0.239, 0.287, 0.429, 0.589, 0.932, 1.28, 1.63, 1.67, 1.97, 2.17, 2.62, 3.25, 3.60, 4.20, 4.66, 5.90, 8.08] ) ) # Create the complete response function response = ActiveRegion.StandardParticleResponse( discrete_energy_response_function*flux_to_dose_response_function/1000.0 ) source_norm = 1462129.344*(energy_bins[-1] - 1e-3) # Create the cell track-length flux estimator cell_flux_estimator = Event.WeightMultipliedCellTrackLengthFluxEstimator( 1, source_norm, [2], model ) cell_flux_estimator.setParticleTypes( [MonteCarlo.ADJOINT_PHOTON] ) cell_flux_estimator.setResponseFunctions( [response] ) event_handler.addEstimator( cell_flux_estimator ) # Create the second estimator if use_energy_bins: cell_flux_estimator_2 = Event.WeightMultipliedCellTrackLengthFluxEstimator( 2, source_norm, [2], model ) cell_flux_estimator_2.setSourceEnergyDiscretization( energy_bins ) cell_flux_estimator_2.setParticleTypes( [MonteCarlo.ADJOINT_PHOTON] ) cell_flux_estimator_2.setResponseFunctions( [response] ) event_handler.addEstimator( cell_flux_estimator_2 ) # Set up the simulation manager factory = Manager.ParticleSimulationManagerFactory( filled_model, source, event_handler, simulation_properties, sim_name, "xml", threads ) # Create the simulation manager manager = factory.getManager() manager.useSingleRendezvousFile() # Allow logging on all procs session.restoreOutputStreams() ## Run the simulation if session.size() == 1: manager.runInterruptibleSimulation() else: manager.runSimulation()
def runForwardSimulation( sim_name, db_path, geom_name, num_particles, incoherent_model_type, threads, use_energy_bins = False, use_native = False, log_file = None, enable_relax = True ): ## 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 photons only simulation_properties.setParticleMode( MonteCarlo.PHOTON_MODE ) simulation_properties.setIncoherentModelType( incoherent_model_type ) simulation_properties.setNumberOfPhotonHashGridBins( 100 ) # Enable atomic relaxation if enable_relax: simulation_properties.setAtomicRelaxationModeOn( MonteCarlo.PHOTON ) else: simulation_properties.setAtomicRelaxationModeOff( MonteCarlo.PHOTON ) # Set the number of histories to run and the number of rendezvous simulation_properties.setNumberOfHistories( num_particles ) simulation_properties.setMinNumberOfRendezvous( 10 ) simulation_properties.setNumberOfSnapshotsPerBatch( 10 ) ## Set up the materials database = Data.ScatteringCenterPropertiesDatabase( db_path ) # Extract the properties from the database c_atom_properties = database.getAtomProperties( Data.ZAID(6000) ) n_atom_properties = database.getAtomProperties( Data.ZAID(7000) ) o_atom_properties = database.getAtomProperties( Data.ZAID(8000) ) na_atom_properties = database.getAtomProperties( Data.ZAID(11000) ) mg_atom_properties = database.getAtomProperties( Data.ZAID(12000) ) al_atom_properties = database.getAtomProperties( Data.ZAID(13000) ) si_atom_properties = database.getAtomProperties( Data.ZAID(14000) ) ar_atom_properties = database.getAtomProperties( Data.ZAID(18000) ) k_atom_properties = database.getAtomProperties( Data.ZAID(19000) ) ca_atom_properties = database.getAtomProperties( Data.ZAID(20000) ) ti_atom_properties = database.getAtomProperties( Data.ZAID(22000) ) mn_atom_properties = database.getAtomProperties( Data.ZAID(25000) ) fe_atom_properties = database.getAtomProperties( Data.ZAID(26000) ) # Set the atom definitions scattering_center_definitions = Collision.ScatteringCenterDefinitionDatabase() c_atom_definition = scattering_center_definitions.createDefinition( "C", Data.ZAID(6000) ) n_atom_definition = scattering_center_definitions.createDefinition( "N", Data.ZAID(7000) ) o_atom_definition = scattering_center_definitions.createDefinition( "O", Data.ZAID(8000) ) na_atom_definition = scattering_center_definitions.createDefinition( "Na", Data.ZAID(11000) ) mg_atom_definition = scattering_center_definitions.createDefinition( "Mg", Data.ZAID(12000) ) al_atom_definition = scattering_center_definitions.createDefinition( "Al", Data.ZAID(13000) ) si_atom_definition = scattering_center_definitions.createDefinition( "Si", Data.ZAID(14000) ) ar_atom_definition = scattering_center_definitions.createDefinition( "Ar", Data.ZAID(18000) ) k_atom_definition = scattering_center_definitions.createDefinition( "K", Data.ZAID(19000) ) ca_atom_definition = scattering_center_definitions.createDefinition( "Ca", Data.ZAID(20000) ) ti_atom_definition = scattering_center_definitions.createDefinition( "Ti", Data.ZAID(22000) ) mn_atom_definition = scattering_center_definitions.createDefinition( "Mn", Data.ZAID(25000) ) fe_atom_definition = scattering_center_definitions.createDefinition( "Fe", Data.ZAID(26000) ) if use_native: data_file_type = Data.PhotoatomicDataProperties.Native_EPR_FILE file_version = 0 else: data_file_type = Data.PhotoatomicDataProperties.ACE_EPR_FILE file_version = 12 c_atom_definition.setPhotoatomicDataProperties( c_atom_properties.getSharedPhotoatomicDataProperties( data_file_type, file_version ) ) n_atom_definition.setPhotoatomicDataProperties( n_atom_properties.getSharedPhotoatomicDataProperties( data_file_type, file_version ) ) o_atom_definition.setPhotoatomicDataProperties( o_atom_properties.getSharedPhotoatomicDataProperties( data_file_type, file_version ) ) na_atom_definition.setPhotoatomicDataProperties( na_atom_properties.getSharedPhotoatomicDataProperties( data_file_type, file_version ) ) mg_atom_definition.setPhotoatomicDataProperties( mg_atom_properties.getSharedPhotoatomicDataProperties( data_file_type, file_version ) ) al_atom_definition.setPhotoatomicDataProperties( al_atom_properties.getSharedPhotoatomicDataProperties( data_file_type, file_version ) ) si_atom_definition.setPhotoatomicDataProperties( si_atom_properties.getSharedPhotoatomicDataProperties( data_file_type, file_version ) ) ar_atom_definition.setPhotoatomicDataProperties( ar_atom_properties.getSharedPhotoatomicDataProperties( data_file_type, file_version ) ) k_atom_definition.setPhotoatomicDataProperties( k_atom_properties.getSharedPhotoatomicDataProperties( data_file_type, file_version ) ) ca_atom_definition.setPhotoatomicDataProperties( ca_atom_properties.getSharedPhotoatomicDataProperties( data_file_type, file_version ) ) ti_atom_definition.setPhotoatomicDataProperties( ti_atom_properties.getSharedPhotoatomicDataProperties( data_file_type, file_version ) ) mn_atom_definition.setPhotoatomicDataProperties( mn_atom_properties.getSharedPhotoatomicDataProperties( data_file_type, file_version ) ) fe_atom_definition.setPhotoatomicDataProperties( fe_atom_properties.getSharedPhotoatomicDataProperties( data_file_type, file_version ) ) # Set the definition for material 1 (ave soil US from PNNL-15870 Rev1) material_definitions = Collision.MaterialDefinitionDatabase() material_definitions.addDefinition( "Soil", 1, ["O", "Na", "Mg", "Al", "Si", "K", "Ca", "Ti", "Mn", "Fe"], [0.670604, 0.005578, 0.011432, 0.053073, 0.201665, 0.007653, 0.026664, 0.002009, 0.000272, 0.021050] ) material_definitions.addDefinition( "Air", 2, ["C", "N", "O", "Ar"], [0.000150, 0.784431, 0.231781, 0.004671] ) # Set up the geometry model_properties = DagMC.DagMCModelProperties( geom_name ) model_properties.setMaterialPropertyName( "mat" ) model_properties.setDensityPropertyName( "rho" ) model_properties.setTerminationCellPropertyName( "termination.cell" ) model_properties.setReflectingSurfacePropertyName( "reflecting.surface" ) model_properties.setSurfaceFluxName( "surface.flux" ) model_properties.useFastIdLookup() # Load the model model = DagMC.DagMCModel( model_properties ) # Fill the model with the defined material filled_model = Collision.FilledGeometryModel( db_path, scattering_center_definitions, material_definitions, simulation_properties, model, True ) # Set up the source particle_distribution = ActiveRegion.StandardParticleDistribution( "contaminated soil dist" ) decay_energy_dist = Distribution.DiscreteDistribution( [0.186211, 0.241995, 0.2656, 0.2952228, 0.3046, 0.3519321, 0.60932, 0.6496, 0.665447, 0.76836, 0.78596, 0.80618, 0.934056, 1.120294, 1.15521, 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], [3.64, 7.251, 51.0, 18.42, 28.0, 35.60, 45.49, 3.4, 1.531, 4.894, 1.06, 1.264, 3.107, 14.92, 1.633, 5.834, 1.434, 3.988, 1.330, 2.394, 2.130, 1.047, 2.878, 15.30, 2.025, 1.160, 4.924, 1.548] ) energy_dimension_dist = ActiveRegion.IndependentEnergyDimensionDistribution( decay_energy_dist ) particle_distribution.setDimensionDistribution( energy_dimension_dist ) uniform_xy_position_dist = Distribution.UniformDistribution( -5.0, 5.0 ) uniform_z_position_dist = Distribution.UniformDistribution( 5000, 5100 ) x_position_dimension_dist = ActiveRegion.IndependentPrimarySpatialDimensionDistribution( uniform_xy_position_dist ) y_position_dimension_dist = ActiveRegion.IndependentSecondarySpatialDimensionDistribution( uniform_xy_position_dist ) z_position_dimension_dist = ActiveRegion.IndependentTertiarySpatialDimensionDistribution( uniform_z_position_dist ) particle_distribution.setDimensionDistribution( x_position_dimension_dist ) particle_distribution.setDimensionDistribution( y_position_dimension_dist ) particle_distribution.setDimensionDistribution( z_position_dimension_dist ) particle_distribution.constructDimensionDistributionDependencyTree() # The generic distribution will be used to generate photons photon_distribution = ActiveRegion.StandardPhotonSourceComponent( 0, 1.0, model, particle_distribution ) # Assign the photon source component to the source source = ActiveRegion.StandardParticleSource( [photon_distribution] ) # Set up the event handler event_handler = Event.EventHandler( model, simulation_properties ) # Create the estimator response functions (flux-to-effective dose from # ICRP-116 table A.1, ISO values) flux_to_dose_dist = Distribution.TabularDistribution_LinLin( [0.01, 0.015, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.1, 0.15, 0.2, 0.3, 0.4, 0.5, 0.511, 0.6, 0.662, 0.8, 1.0, 1.117, 1.33, 1.5, 2.0, 3.0], [0.0288, 0.0560, 0.0812, 0.127, 0.158, 0.180, 0.199, 0.218, 0.239, 0.287, 0.429, 0.589, 0.932, 1.28, 1.63, 1.67, 1.97, 2.17, 2.62, 3.25, 3.60, 4.20, 4.66, 5.90, 8.08] ) partial_response_function = ActiveRegion.EnergyParticleResponseFunction( flux_to_dose_dist ) # convert from pSv to nSv response_function = partial_response_function / 1000.0 response = ActiveRegion.StandardParticleResponse( response_function ) source_norm = 1462129.344 # Create the surface flux estimator surface_flux_estimator = Event.WeightMultipliedSurfaceFluxEstimator( 1, source_norm, [13], model ) surface_flux_estimator.setParticleTypes( [MonteCarlo.PHOTON] ) surface_flux_estimator.setCosineCutoffValue( 0.1 ) surface_flux_estimator.setResponseFunctions( [response] ) event_handler.addEstimator( surface_flux_estimator ) # Create the second surface flux estimator if use_energy_bins: surface_flux_estimator_2 = Event.WeightMultipliedSurfaceFluxEstimator( 2, source_norm, [13], model ) surface_flux_estimator_2.setEnergyDiscretization( energy_bins ) surface_flux_estimator_2.setParticleTypes( [MonteCarlo.PHOTON] ) surface_flux_estimator_2.setCosineCutoffValue( 0.1 ) surface_flux_estimator_2.setResponseFunctions( [response] ) event_handler.addEstimator( surface_flux_estimator_2 ) # Set up the simulation manager factory = Manager.ParticleSimulationManagerFactory( filled_model, source, event_handler, simulation_properties, sim_name, "xml", threads ) # Create the simulation manager manager = factory.getManager() manager.useSingleRendezvousFile() # Allow logging on all procs session.restoreOutputStreams() ## Run the simulation if session.size() == 1: manager.runInterruptibleSimulation() else: manager.runSimulation()
def setSimulationProperties(histories, time, interpolation, grid_policy, elastic_mode, elastic_sampling_method): properties = MonteCarlo.SimulationProperties() ## -------------------------- GENERAL PROPERTIES -------------------------- ## # Set the particle mode properties.setParticleMode(MonteCarlo.ELECTRON_MODE) # Set the number of histories properties.setNumberOfHistories(histories) # Set the minimum number of rendezvous if histories > 100: properties.setMinNumberOfRendezvous(10) # Change time from minutes to seconds time_sec = time * 60 # Set the wall time properties.setSimulationWallTime(time_sec) ## -------------------------- NEUTRON PROPERTIES -------------------------- ## ## -------------------------- PHOTON PROPERTIES --------------------------- ## ## ------------------------- ELECTRON PROPERTIES -------------------------- ## # Set the min electron energy in MeV (Default is 100 eV) properties.setMinElectronEnergy(1e-4) # Set the max electron energy in MeV (Default is 20 MeV) properties.setMaxElectronEnergy(20.0) # Set the bivariate interpolation (LOGLOGLOG, LINLINLIN, LINLINLOG) properties.setElectronTwoDInterpPolicy(interpolation) # Set the bivariate Grid Policy (UNIT_BASE_CORRELATED, CORRELATED, UNIT_BASE) properties.setElectronTwoDGridPolicy(grid_policy) # Set the electron evaluation tolerance (Default is 1e-8) properties.setElectronEvaluationTolerance(1e-8) ## --- Elastic Properties --- # Turn elastic electron scattering off # properties.setElasticModeOff() # Set the elastic distribution mode ( DECOUPLED, COUPLED, HYBRID ) properties.setElasticElectronDistributionMode(elastic_mode) # Set the elastic coupled sampling method # ( TWO_D_UNION, ONE_D_UNION, MODIFIED_TWO_D_UNION ) properties.setCoupledElasticSamplingMode(elastic_sampling_method) # Set the elastic cutoff angle cosine ( -1.0 < mu < 1.0 ) properties.setElasticCutoffAngleCosine(1.0) ## --- Electroionization Properties --- # Turn the electro-ionization reaction off # properties.setElectroionizationModeOff() ## --- Bremsstrahlung Properties --- # Turn electron bremsstrahlung reaction off # properties.setBremsstrahlungModeOff() # Set the bremsstrahlung angular distribution function # ( DIPOLE, TABULAR, ??? ) properties.setBremsstrahlungAngularDistributionFunction( MonteCarlo.DIPOLE_DISTRIBUTION) ## --- Atomic Excitation Properties --- # Turn electron atomic excitation reaction off # properties.setAtomicExcitationModeOff() return properties