def get_subdomain_avg_library(self): """Construct a subdomain-averaged version of this library. This routine averages each multi-group cross section across distribcell instances. The method performs spatial homogenization to compute the scalar flux-weighted average cross section across the subdomains. NOTE: This method is only relevant for distribcell domain types and simplys returns a deep copy of the library for all other domains types. Returns ------- openmc.mgxs.Library A new multi-group cross section library averaged across subdomains Raises ------ ValueError When this method is called before a statepoint has been loaded See also -------- MGXS.get_subdomain_avg_xs(subdomains) """ if self.sp_filename is None: msg = 'Unable to get a subdomain-averaged cross section ' \ 'library since the statepoint has not yet been loaded' raise ValueError(msg) # Clone this Library to initialize the subdomain-averaged version subdomain_avg_library = copy.deepcopy(self) if subdomain_avg_library.domain_type == 'distribcell': subdomain_avg_library.domain_type = 'cell' else: return subdomain_avg_library # Subdomain average the MGXS for each domain and mgxs type for domain in self.domains: for mgxs_type in self.mgxs_types: mgxs = subdomain_avg_library.get_mgxs(domain, mgxs_type) if mgxs.domain_type == 'distribcell': avg_mgxs = mgxs.get_subdomain_avg_xs() subdomain_avg_library.all_mgxs[domain.id][mgxs_type] = avg_mgxs return subdomain_avg_library
def build_hdf5_store(self, filename='mgxs.h5', directory='mgxs', subdomains='all', nuclides='all', xs_type='macro'): """Export the multi-group cross section library to an HDF5 binary file. This method constructs an HDF5 file which stores the library's multi-group cross section data. The data is stored in a hierarchy of HDF5 groups from the domain type, domain id, subdomain id (for distribcell domains), nuclides and cross section types. Two datasets for the mean and standard deviation are stored for each subdomain entry in the HDF5 file. The number of groups is stored as a file attribute. NOTE: This requires the h5py Python package. Parameters ---------- filename : str Filename for the HDF5 file. Defaults to 'mgxs.h5'. directory : str Directory for the HDF5 file. Defaults to 'mgxs'. subdomains : {'all', 'avg'} Report all subdomains or the average of all subdomain cross sections in the report. Defaults to 'all'. nuclides : {'all', 'sum'} The nuclides of the cross-sections to include in the report. This may be a list of nuclide name strings (e.g., ['U-235', 'U-238']). The special string 'all' will report the cross sections for all nuclides in the spatial domain. The special string 'sum' will report the cross sections summed over all nuclides. Defaults to 'all'. xs_type: {'macro', 'micro'} Store the macro or micro cross section in units of cm^-1 or barns. Defaults to 'macro'. Raises ------ ValueError When this method is called before a statepoint has been loaded See also -------- MGXS.build_hdf5_store(filename, directory, xs_type) """ if self.sp_filename is None: msg = 'Unable to export multi-group cross section library ' \ 'since a statepoint has not yet been loaded' raise ValueError(msg) cv.check_type('filename', filename, basestring) cv.check_type('directory', directory, basestring) import h5py # Make directory if it does not exist if not os.path.exists(directory): os.makedirs(directory) # Add an attribute for the number of energy groups to the HDF5 file full_filename = os.path.join(directory, filename) full_filename = full_filename.replace(' ', '-') f = h5py.File(full_filename, 'w') f.attrs["# groups"] = self.num_groups f.close() # Export MGXS for each domain and mgxs type to an HDF5 file for domain in self.domains: for mgxs_type in self.mgxs_types: mgxs = self.all_mgxs[domain.id][mgxs_type] if subdomains == 'avg': mgxs = mgxs.get_subdomain_avg_xs() mgxs.build_hdf5_store(filename, directory, xs_type=xs_type, nuclides=nuclides)
def build_hdf5_store(self, filename='mgxs.h5', directory='mgxs', subdomains='all', nuclides='all', xs_type='macro', row_column='inout'): """Export the multi-group cross section library to an HDF5 binary file. This method constructs an HDF5 file which stores the library's multi-group cross section data. The data is stored in a hierarchy of HDF5 groups from the domain type, domain id, subdomain id (for distribcell domains), nuclides and cross section types. Two datasets for the mean and standard deviation are stored for each subdomain entry in the HDF5 file. The number of groups is stored as a file attribute. NOTE: This requires the h5py Python package. Parameters ---------- filename : str Filename for the HDF5 file. Defaults to 'mgxs.h5'. directory : str Directory for the HDF5 file. Defaults to 'mgxs'. subdomains : {'all', 'avg'} Report all subdomains or the average of all subdomain cross sections in the report. Defaults to 'all'. nuclides : {'all', 'sum'} The nuclides of the cross-sections to include in the report. This may be a list of nuclide name strings (e.g., ['U-235', 'U-238']). The special string 'all' will report the cross sections for all nuclides in the spatial domain. The special string 'sum' will report the cross sections summed over all nuclides. Defaults to 'all'. xs_type: {'macro', 'micro'} Store the macro or micro cross section in units of cm^-1 or barns. Defaults to 'macro'. row_column: {'inout', 'outin'} Store scattering matrices indexed first by incoming group and second by outgoing group ('inout'), or vice versa ('outin'). Defaults to 'inout'. Raises ------ ValueError When this method is called before a statepoint has been loaded See also -------- MGXS.build_hdf5_store(filename, directory, xs_type) """ if self.sp_filename is None: msg = 'Unable to export multi-group cross section library ' \ 'since a statepoint has not yet been loaded' raise ValueError(msg) cv.check_type('filename', filename, basestring) cv.check_type('directory', directory, basestring) import h5py # Make directory if it does not exist if not os.path.exists(directory): os.makedirs(directory) # Add an attribute for the number of energy groups to the HDF5 file full_filename = os.path.join(directory, filename) full_filename = full_filename.replace(' ', '-') f = h5py.File(full_filename, 'w') f.attrs['# groups'] = self.num_groups f.close() # Export MGXS for each domain and mgxs type to an HDF5 file for domain in self.domains: for mgxs_type in self.mgxs_types: mgxs = self.all_mgxs[domain.id][mgxs_type] if subdomains == 'avg': mgxs = mgxs.get_subdomain_avg_xs() mgxs.build_hdf5_store(filename, directory, xs_type=xs_type, nuclides=nuclides, row_column=row_column)