def get_cross_section(self, reaction_id, E): # There is no switch statement in python :( if reaction_id == 1: return self._da_np(E) # 1. d + a -> n + p if reaction_id == 2: return self._ta_nd(E) # 2. t + a -> n + d if reaction_id == 3: return self._ta_npn(E) # 3. t + a -> 2n + p if reaction_id == 4: return self._He3a_pd(E) # 4. He3 + a -> p + d if reaction_id == 5: return self._He3a_npp(E) # 5. He3 + a -> n + 2p if reaction_id == 6: return self._He4a_pt(E) # 6. He4 + a -> p + t if reaction_id == 7: return self._He4a_nHe3(E) # 7. He4 + a -> n + He3 if reaction_id == 8: return self._He4a_dd(E) # 8. He4 + a -> 2d if reaction_id == 9: return self._He4a_npd(E) # 9. He4 + a -> n + p + d if reaction_id == 10: return self._Li6a_npHe4(E) # 10. Li6 + a -> n + p + He4 if reaction_id == 11: return self._Li6a_XA3(E) # 11. Li7 + a -> X + A3 if reaction_id == 12: return self._Li7a_tHe4(E) # 12. Li7 + a -> t + He4 if reaction_id == 13: return self._Li7a_nLi6(E) # 13. Li7 + a -> n + Li6 if reaction_id == 14: return self._Li7a_nnpHe4(E) # 14. Li7 + a -> 2n + p + He4 if reaction_id == 15: return self._Be7a_He3He4(E) # 15. Be7 + a -> He3 + He4 if reaction_id == 16: return self._Be7a_pLi6(E) # 16. Be7 + a -> p + Li6 if reaction_id == 17: return self._Be7a_ppnHe4(E) # 17. Be7 + a -> 2p + n + He4 # If no match is found, return 0. print_error( "Reaction with reaction_id" + str(reaction_id) + "does not exist.", "acropolis.nucl.NuclearReactor.get_cross_section" )
def _parse_arguments(self, **kwargs): # Loop over the different parameters for key in kwargs.keys(): param = kwargs[key] # Extract the fixed values if type(param) in [int, float]: self._sFixed[key] = float(param) # Extract the scan parameters elif isinstance(param, ScanParameter): self._sNp += 1 # Save the 'is_fast' status of all parameters self._sFastf[key] = param.is_fast() # Save the relevant range of all paremeters self._sScanp[key] = param.get_range() else: print_error( "All parameters must either be 'int', 'float' or an instance of 'ScanParameter'", "BufferedScanner._parse_arguments") if list(self._sFastf.values()).count(True) > 1: print_error( "Using more than one 'fast' parameter is not yet supported", "BufferedScanner._parse_arguments")
def _parse_arguments(self, **kwargs): # Loop over the different parameters for key in kwargs.keys(): param = kwargs[key] # Extract the fixed values if type(param) in [int, float]: self._sFixed[key] = float(param) # Extract the scan parameters elif isinstance(param, ScanParameter): self._sNP += 1 # Save the relevant range of all paremeters self._sScanp[key] = param.get_range() # Save the 'is_fast' status of all parameters self._sFastf[key] = param.is_fast() else: print_error( "All parameters must either be 'int', 'float' or an instance of 'ScanParameter'", "acropolis.scans.BufferedScanner._parse_arguments" ) # Get the number of 'fast' parameters (Np_fast <= Np - 1) self._sNP_fast = list( self._sFastf.values() ).count(True) # ERRORS for not-yet-implemented features (TODO) ################################ if self._sNP_fast > 1 or self._sNP != 2: print_error( "Currently only exactly 2 scan parameters with <= 1 fast parameter are supported!", "acropolis.scans.BufferedScanner._parse_arguments" )
def __init__(self, model, **kwargs): # Store the requested model # self._sModel(...) afterwards creates # a new instance of the requested model if not issubclass(model, AbstractModel): print_error( model.__name__ + " is not a subclass of AbstractModel", "acropolis.scans.BufferedScanner.__init__" ) self._sModel = model ####################################################################### # Initialize the various sets self._sFixed = {} # Fixed parameter self._sScanp = {} # Scan parameters... self._sFastf = {} # ...w/o fast scanning # Initialize the number of scan parameters... self._sNP = 0 # (all) self._sNP_fast = 0 # (only fast) # Parse the keyword arguments and build up the # sets 'self._sFixed' and 'self._sScanp' self._parse_arguments(**kwargs) ####################################################################### # Generate the keys for the scan parameters self._sScanp_id = list( self._sScanp.keys() ) # Determine the parameter for the parallelisation # In case there is a 'fast' parameter, this whould be # one of the 'non-fast' parameters # # Sort the keys in order for the fast parameters # to be at he beginning of the array list.sort( self._sScanp_id, key=lambda id: self._sFastf[id], reverse=True ) # Choose the last parameter, which in any case is not the # 'fast' parameter and therefore can be calculated in parallel self._sId_pp = self._sScanp_id[-1] ####################################################################### # Extract the dimension of parallel/sequential jobs self._sDp, self._sDs = 0, 0 for id in self._sScanp_id: if id == self._sId_pp: self._sDp += len( self._sScanp[id] ) else: self._sDs += len( self._sScanp[id] )
def total_kernel_x(self, E, Ep, T, X): if X == 0: return self._kernel_compton(E, Ep, T) + self._kernel_bethe_heitler( E, Ep, T) + self._kernel_pair_creation(E, Ep, T) # Photon -> Positron if X == 1: return 0. # Electron -> Positron if X == 2: return self._kernel_inverse_compton(E, Ep, T) # Positron -> Positron print_error( "Particle with identifier X =" + str(X) + "does not exist.", "acropolis.cascade._PositronReactionWrapper.total_kernel_x")
def __init__(self, model, **kwargs): # Store the requested model # self._sWrapper(...) creates # a new instance of this class if not issubclass(model, AbstractModel): print_error(str(model) + " is not a subclass of 'AbstractModel'") self._sModel = model # Define the various sets self._sFixed = {} # Fixed parameter self._sScanp = {} # Scan parameters... self._sFastf = {} # ...that allow for fast scanning # Define the number of scan parameters self._sNp = 0 # Parse the keyword arguments and build up the # sets 'self._sFixed' and 'self._sScanp' self._parse_arguments(**kwargs) ####################################################################### # Generate the keys for the scan parameters self._sScanp_id = list(self._sScanp.keys()) # Determine the parameter for the parallelisation # In case there is a 'fast' parameter, this whould be # one of the 'non-fast' parameters # # Sort the keys in order for the fast parameter # to be at position 0 list.sort(self._sScanp_id, key=lambda id: self._sFastf[id], reverse=True) # Choose the last parameter, which in any case is not the # 'fast' parameter and therefore can be calculated in parallel self._sPP_id = self._sScanp_id[-1] # Determine the 'fast' parameter self._sFP_id = self._sScanp_id[0]
def _check_data(self): # Check if param_file.dat includes the required parameters req_param = ("eta" in self._sParamData) if not req_param: print_error( "The mandatory variable 'eta' could not be found in 'param_file.dat'", "acropolis.input.InputInterface::_check_data") # Check if abundance_file.dat has the correct dimensions abund_shape = (self._sAbundData.shape[0] == NY) if not abund_shape: print_error( "The content of 'abundance_file.dat' does not have the required shape.", "acropolis.input.InputInterface::_check_data") # Check if cosmo_file.dat has the correct number of columns cosmo_shape = (self._sCosmoDataShp[1] >= NC) if not cosmo_shape: print_error( "The content of 'cosmo_file.dat' does not have the required shape.", "acropolis.input.InputInterface::_check_data")