Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions include/openmc/random_ray/random_ray_simulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class RandomRaySimulation {

//----------------------------------------------------------------------------
// Methods
void compute_segment_correction_factors();
void apply_fixed_sources_and_mesh_domains();
void prepare_fixed_sources_adjoint();
void prepare_adjoint_simulation();
void simulate();
void output_simulation_results() const;
void instability_check(
Expand All @@ -34,9 +34,15 @@ class RandomRaySimulation {
// Accessors
FlatSourceDomain* domain() const { return domain_.get(); }

//----------------------------------------------------------------------------
// Public data members

// Flag for adjoint simulation;
bool adjoint_needed_;

private:
//----------------------------------------------------------------------------
// Data members
// Private data members

// Contains all flat source region data
unique_ptr<FlatSourceDomain> domain_;
Expand All @@ -51,6 +57,9 @@ class RandomRaySimulation {
// Number of energy groups
int negroups_;

// Toggle for first simulation
bool is_first_simulation_;

}; // class RandomRaySimulation

//============================================================================
Expand All @@ -60,6 +69,7 @@ class RandomRaySimulation {
void openmc_run_random_ray();
void validate_random_ray_inputs();
void openmc_reset_random_ray();
void print_adjoint_header();

} // namespace openmc

Expand Down
227 changes: 88 additions & 139 deletions openmc/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1179,8 +1179,8 @@ def plot(

# Convert ID map to RGB image
img = id_map_to_rgb(
id_map=id_map,
color_by=color_by,
id_map=id_map,
color_by=color_by,
colors=colors,
overlap_color=overlap_color
)
Expand Down Expand Up @@ -1217,7 +1217,7 @@ def plot(
extent=(x_min, x_max, y_min, y_max),
**contour_kwargs
)

# If only showing outline, set the axis limits and aspect explicitly
if outline == 'only':
axes.set_xlim(x_min, x_max)
Expand Down Expand Up @@ -1685,6 +1685,85 @@ def differentiate_mats(self, diff_volume_method: str = None, depletable_only: bo
self.geometry.get_all_materials().values()
)

def _auto_generate_mgxs_lib(
self,
model: openmc.model.model,
groups: openmc.mgxs.EnergyGroups,
correction: str | none,
directory: pathlike,
) -> openmc.mgxs.Library:
"""
Automatically generate a multi-group cross section libray from a model
with the specified group structure.

Parameters
----------
groups : openmc.mgxs.EnergyGroups
Energy group structure for the MGXS.
nparticles : int
Number of particles to simulate per batch when generating MGXS.
mgxs_path : str
Filename for the MGXS HDF5 file.
correction : str
Transport correction to apply to the MGXS. Options are None and
"P0".
directory : str
Directory to run the simulation in, so as to contain XML files.

Returns
-------
mgxs_lib : openmc.mgxs.Library
OpenMC MGXS Library object
"""

# Initialize MGXS library with a finished OpenMC geometry object
mgxs_lib = openmc.mgxs.Library(model.geometry)

# Pick energy group structure
mgxs_lib.energy_groups = groups

# Disable transport correction
mgxs_lib.correction = correction

# Specify needed cross sections for random ray
if correction == 'P0':
mgxs_lib.mgxs_types = [
'nu-transport', 'absorption', 'nu-fission', 'fission',
'consistent nu-scatter matrix', 'multiplicity matrix', 'chi'
]
elif correction is None:
mgxs_lib.mgxs_types = [
'total', 'absorption', 'nu-fission', 'fission',
'consistent nu-scatter matrix', 'multiplicity matrix', 'chi'
]

# Specify a "material" domain type for the cross section tally filters
mgxs_lib.domain_type = "material"

# Specify the domains over which to compute multi-group cross sections
mgxs_lib.domains = model.geometry.get_all_materials().values()

# Do not compute cross sections on a nuclide-by-nuclide basis
mgxs_lib.by_nuclide = False

# Check the library - if no errors are raised, then the library is satisfactory.
mgxs_lib.check_library_for_openmc_mgxs()

# Construct all tallies needed for the multi-group cross section library
mgxs_lib.build_library()

# Create a "tallies.xml" file for the MGXS Library
mgxs_lib.add_to_tallies(model.tallies, merge=True)

# Run
statepoint_filename = model.run(cwd=directory)

# Load MGXS
with openmc.StatePoint(statepoint_filename) as sp:
mgxs_lib.load_from_statepoint(sp)

return mgxs_lib

def _create_mgxs_sources(
self,
groups: openmc.mgxs.EnergyGroups,
Expand Down Expand Up @@ -1848,52 +1927,8 @@ def _generate_infinite_medium_mgxs(
model.geometry.root_universe = infinite_universe

# Add MGXS Tallies

# Initialize MGXS library with a finished OpenMC geometry object
mgxs_lib = openmc.mgxs.Library(model.geometry)

# Pick energy group structure
mgxs_lib.energy_groups = groups

# Disable transport correction
mgxs_lib.correction = correction

# Specify needed cross sections for random ray
if correction == 'P0':
mgxs_lib.mgxs_types = [
'nu-transport', 'absorption', 'nu-fission', 'fission',
'consistent nu-scatter matrix', 'multiplicity matrix', 'chi'
]
elif correction is None:
mgxs_lib.mgxs_types = [
'total', 'absorption', 'nu-fission', 'fission',
'consistent nu-scatter matrix', 'multiplicity matrix', 'chi'
]

# Specify a "cell" domain type for the cross section tally filters
mgxs_lib.domain_type = "material"

# Specify the cell domains over which to compute multi-group cross sections
mgxs_lib.domains = model.geometry.get_all_materials().values()

# Do not compute cross sections on a nuclide-by-nuclide basis
mgxs_lib.by_nuclide = False

# Check the library - if no errors are raised, then the library is satisfactory.
mgxs_lib.check_library_for_openmc_mgxs()

# Construct all tallies needed for the multi-group cross section library
mgxs_lib.build_library()

# Create a "tallies.xml" file for the MGXS Library
mgxs_lib.add_to_tallies(model.tallies, merge=True)

# Run
statepoint_filename = model.run(cwd=directory)

# Load MGXS
with openmc.StatePoint(statepoint_filename) as sp:
mgxs_lib.load_from_statepoint(sp)
mgxs_lib = self._auto_generate_mgxs_lib(
model, groups, correction, directory)

# Create a MGXS File which can then be written to disk
mgxs_set = mgxs_lib.get_xsdata(domain=material, xsdata_name=name)
Expand Down Expand Up @@ -2055,48 +2090,8 @@ def _generate_stochastic_slab_mgxs(
model.settings.output = {'summary': True, 'tallies': False}

# Add MGXS Tallies

# Initialize MGXS library with a finished OpenMC geometry object
mgxs_lib = openmc.mgxs.Library(model.geometry)

# Pick energy group structure
mgxs_lib.energy_groups = groups

# Disable transport correction
mgxs_lib.correction = correction

# Specify needed cross sections for random ray
if correction == 'P0':
mgxs_lib.mgxs_types = ['nu-transport', 'absorption', 'nu-fission', 'fission',
'consistent nu-scatter matrix', 'multiplicity matrix', 'chi']
elif correction is None:
mgxs_lib.mgxs_types = ['total', 'absorption', 'nu-fission', 'fission',
'consistent nu-scatter matrix', 'multiplicity matrix', 'chi']

# Specify a "cell" domain type for the cross section tally filters
mgxs_lib.domain_type = "material"

# Specify the cell domains over which to compute multi-group cross sections
mgxs_lib.domains = model.geometry.get_all_materials().values()

# Do not compute cross sections on a nuclide-by-nuclide basis
mgxs_lib.by_nuclide = False

# Check the library - if no errors are raised, then the library is satisfactory.
mgxs_lib.check_library_for_openmc_mgxs()

# Construct all tallies needed for the multi-group cross section library
mgxs_lib.build_library()

# Create a "tallies.xml" file for the MGXS Library
mgxs_lib.add_to_tallies(model.tallies, merge=True)

# Run
statepoint_filename = model.run(cwd=directory)

# Load MGXS
with openmc.StatePoint(statepoint_filename) as sp:
mgxs_lib.load_from_statepoint(sp)
mgxs_lib = self._auto_generate_mgxs_lib(
model, groups, correction, directory)

names = [mat.name for mat in mgxs_lib.domains]

Expand Down Expand Up @@ -2146,52 +2141,8 @@ def _generate_material_wise_mgxs(
model.settings.output = {'summary': True, 'tallies': False}

# Add MGXS Tallies

# Initialize MGXS library with a finished OpenMC geometry object
mgxs_lib = openmc.mgxs.Library(model.geometry)

# Pick energy group structure
mgxs_lib.energy_groups = groups

# Disable transport correction
mgxs_lib.correction = correction

# Specify needed cross sections for random ray
if correction == 'P0':
mgxs_lib.mgxs_types = [
'nu-transport', 'absorption', 'nu-fission', 'fission',
'consistent nu-scatter matrix', 'multiplicity matrix', 'chi'
]
elif correction is None:
mgxs_lib.mgxs_types = [
'total', 'absorption', 'nu-fission', 'fission',
'consistent nu-scatter matrix', 'multiplicity matrix', 'chi'
]

# Specify a "cell" domain type for the cross section tally filters
mgxs_lib.domain_type = "material"

# Specify the cell domains over which to compute multi-group cross sections
mgxs_lib.domains = model.geometry.get_all_materials().values()

# Do not compute cross sections on a nuclide-by-nuclide basis
mgxs_lib.by_nuclide = False

# Check the library - if no errors are raised, then the library is satisfactory.
mgxs_lib.check_library_for_openmc_mgxs()

# Construct all tallies needed for the multi-group cross section library
mgxs_lib.build_library()

# Create a "tallies.xml" file for the MGXS Library
mgxs_lib.add_to_tallies(model.tallies, merge=True)

# Run
statepoint_filename = model.run(cwd=directory)

# Load MGXS
with openmc.StatePoint(statepoint_filename) as sp:
mgxs_lib.load_from_statepoint(sp)
mgxs_lib = self._auto_generate_mgxs_lib(
model, groups, correction, directory)

names = [mat.name for mat in mgxs_lib.domains]

Expand Down Expand Up @@ -2617,5 +2568,3 @@ def function_calls(self) -> int:
def total_batches(self) -> int:
"""Total number of active batches used across all evaluations."""
return sum(self.batches)


Loading
Loading