Skip to content

Commit

Permalink
fix #7170 Add MGXS generation and run mode (#7454)
Browse files Browse the repository at this point in the history
  • Loading branch information
moellep authored Feb 20, 2025
1 parent 631c54d commit 72ccef9
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 61 deletions.
7 changes: 6 additions & 1 deletion sirepo/package_data/static/html/openmc-visualization.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,16 @@
</table>
</div>
<div class="col-sm-12" data-ng-if="visualization.hasWeightWindowsFile">
<div class="col-sm-12"><a data-ng-attr-href="{{ visualization.weightWindowsFileURL() }}">
<div class="col-sm-12"><a data-ng-attr-href="{{ visualization.weightWindowsFileURL }}">
<span class="glyphicon glyphicon-cloud-download"></span> Computed Weight Windows</a>
<buttontype="button" class="btn btn-sm btn-default" data-ng-click="visualization.applyWeightWindows()">Apply Weight Windows</button>
</div>
</div>
<div class="col-sm-12" data-ng-if="visualization.hasMGXSFile">
<div class="col-sm-12"><a data-ng-attr-href="{{ visualization.mgxsFileURL }}">
<span class="glyphicon glyphicon-cloud-download"></span> Computed MGXS File</a>
</div>
</div>
</div>
</div>
</div>
Expand Down
33 changes: 20 additions & 13 deletions sirepo/package_data/static/js/openmc.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ SIREPO.app.config(() => {
SIREPO.FILE_UPLOAD_TYPE = {
'geometryInput-dagmcFile': '.h5m,.stp',
'geometryInput-materialsFile': '.xml',
'settings-mgxsFile': '.h5',
};
});

Expand Down Expand Up @@ -304,16 +305,6 @@ SIREPO.app.factory('openmcService', function(appState, panelState, requestSender
appState.saveQuietly('openmcAnimation');
};

self.weightWindowsFileURL = () => {
return requestSender.formatUrl('downloadDataFile', {
'<simulation_id>': appState.models.simulation.simulationId,
'<simulation_type>': SIREPO.APP_SCHEMA.simulationType,
'<model>': 'openmcAnimation',
'<frame>': SIREPO.nonDataFileFrame,
'<suffix>': 'h5',
});
};

return self;
});

Expand Down Expand Up @@ -414,11 +405,23 @@ SIREPO.app.controller('GeometryController', function (appState, openmcService, p
SIREPO.app.controller('VisualizationController', function(appState, errorService, openmcService, frameCache, panelState, persistentSimulation, requestSender, tallyService, $scope) {
const self = this;
self.eigenvalue = null;
self.mgxsFileURL = fileURL('mgxs');
self.results = null;
self.simScope = $scope;
self.simComputeModel = 'openmcAnimation';
self.simScope = $scope;
self.weightWindowsFileURL = fileURL('ww');
let errorMessage, isRunning, statusMessage;

function fileURL(suffix) {
return requestSender.formatUrl('downloadDataFile', {
'<simulation_id>': appState.models.simulation.simulationId,
'<simulation_type>': SIREPO.APP_SCHEMA.simulationType,
'<model>': 'openmcAnimation',
'<frame>': SIREPO.nonDataFileFrame,
'<suffix>': suffix,
});
}

function validateSelectedTally(tallies) {
appState.models.openmcAnimation.tallies = tallies;
appState.saveQuietly('openmcAnimation');
Expand Down Expand Up @@ -459,6 +462,7 @@ SIREPO.app.controller('VisualizationController', function(appState, errorService
validateSelectedTally(data.tallies);
}
self.hasWeightWindowsFile = data.hasWeightWindowsFile;
self.hasMGXSFile = data.hasMGXSFile;
};
self.simState = persistentSimulation.initSimulationState(self);
self.simState.errorMessage = () => errorMessage;
Expand Down Expand Up @@ -501,8 +505,6 @@ SIREPO.app.controller('VisualizationController', function(appState, errorService
return `Tally Results - ${a.tally} - ${a.score} - ${a.aspect}`;
};

self.weightWindowsFileURL = openmcService.weightWindowsFileURL;

const sortTallies = () => {
for (const t of appState.models.settings.tallies) {
// sort and unique scores
Expand Down Expand Up @@ -2900,6 +2902,9 @@ SIREPO.viewLogic('settingsView', function(appState, panelState, validationServic
panelState.showFields('settings', [
['max_splits'], ['weight_windows_tally', 'weight_windows_mesh'].includes(m.varianceReduction),
['weightWindowsFile'], m.varianceReduction === 'weight_windows_file',
['materialLibrary', 'generateMGXS', 'photon_transport'], m.materialDefinition === 'library',
['mgxsFile'], m.materialDefinition == 'mgxs',
['energyGroup'], m.generateMGXS == '1',
]);
validationService.validateField(
$scope.modelName,
Expand All @@ -2918,6 +2923,8 @@ SIREPO.viewLogic('settingsView', function(appState, panelState, validationServic
`${$scope.modelName}.batches`,
`${$scope.modelName}.inactive`,
`${$scope.modelName}.varianceReduction`,
`${$scope.modelName}.materialDefinition`,
`${$scope.modelName}.generateMGXS`,
'reflectivePlanes.useReflectivePlanes'
], updateEditor,
];
Expand Down
7 changes: 5 additions & 2 deletions sirepo/package_data/static/js/sirepo-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -4955,8 +4955,11 @@ SIREPO.app.directive('simStatusPanel', function(appState) {
<div data-pending-link-to-simulations="" data-sim-state="simState"></div>
<div data-ng-show="simState.isStateRunning()">
<div class="col-sm-12">
<div data-ng-show="simState.isInitializing()">{{ initMessage() }} {{ simState.dots }}</div>
<div data-ng-show="simState.getFrameCount() > 0">{{ runningMessage(); }}</div>
<div>
<div data-ng-show="simState.isInitializing()">{{ initMessage() }} {{ simState.dots }}</div>
<div data-ng-show="simState.getFrameCount() > 0">{{ runningMessage(); }}</div>
<div data-simulation-status-timer="simState"></div>
</div>
<div data-sim-state-progress-bar="" data-sim-state="simState"></div>
</div>
</div>
Expand Down
42 changes: 38 additions & 4 deletions sirepo/package_data/static/json/openmc-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,28 @@
["sum", "sum"],
["macro", "macro"]
],
"EnergyGroup": [
["CASMO-2", "CASMO-2"],
["CASMO-4", "CASMO-4"],
["CASMO-8", "CASMO-8"],
["CASMO-16", "CASMO-16"],
["CASMO-25", "CASMO-25"],
["CASMO-40", "CASMO-40"],
["CASMO-70", "CASMO-70"],
["CCFE-709", "CCFE-709"],
["ECCO-1968", "ECCO-1968"],
["MPACT-51", "MPACT-51"],
["MPACT-60", "MPACT-60"],
["MPACT-69", "MPACT-69"],
["SCALE-44", "SCALE-44"],
["SCALE-252", "SCALE-252"],
["SHEM-361", "SHEM-361"],
["TRIPOLI-315", "TRIPOLI-315"],
["UKAEA-1102", "UKAEA-1102"],
["VITAMIN-J-42", "VITAMIN-J-42"],
["VITAMIN-J-175", "VITAMIN-J-175"],
["XMAS-172", "XMAS-172"]
],
"Estimator": [
["default", "Default"],
["analog", "Analog"],
Expand Down Expand Up @@ -82,6 +104,10 @@
["add_nuclide", "Nuclide"],
["add_s_alpha_beta", "S alpha beta"]
],
"MaterialDefinition": [
["library", "Material Data Library"],
["mgxs", "Multi-Group Cross Section File"]
],
"MaterialLibrary": [
["ENDFB-7.1-NNDC", "ENDFB-7.1-NNDC"],
["ENDFB-8.0-NNDC", "ENDFB-8.0-NNDC"],
Expand Down Expand Up @@ -333,7 +359,7 @@
},
"geometryInput": {
"dagmcFile": ["Model file", "InputFile", "", "A DAGMC (.h5m) or Step (.stp) file"],
"materialsFile": ["Materials XML file (optional)", "InputFile", "", "An OpenMC materials.xml mapping from names to volume properties", false],
"materialsFile": ["Materials XML file (optional)", "InputFile", "", "An OpenMC materials.xml (or model.xml) mapping from names to volume properties", false],
"exampleURL": ["", "String", ""]
},
"geometry3DReport": {
Expand Down Expand Up @@ -487,9 +513,13 @@
"run_mode": ["Run mode", "RunMode", "fixed source", "The type of calculation to perform"],
"materialLibrary": ["Material data library", "MaterialLibrary", "ENDFB-8.0-NNDC"],
"varianceReduction": ["Technique", "VarianceReduction", "None"],
"max_splits": ["Maximum splits", "Integer", 1000, "Maximum number of particle splits for weight windows"],
"max_splits": ["Maximum history splits", "Integer", 1e7, "Maximum number of particle splits for weight windows"],
"outputInterval": ["Output interval", "Integer", 1, "Output interval for active batches", 1],
"weightWindowsFile": ["File", "InputFile", ""]
"weightWindowsFile": ["File", "InputFile", ""],
"materialDefinition": ["Material definition", "MaterialDefinition", "library"],
"mgxsFile": ["MGXS material file", "InputFile", ""],
"generateMGXS": ["Generate MGXS data file", "Boolean", "0", "Create a multi-group cross section file during simulation"],
"energyGroup": ["MGXS Energy Group", "EnergyGroup", "CASMO-2"]
},
"source": {
"angle": ["Angular distribution", "UnitSphere", {"_type": "None"}],
Expand Down Expand Up @@ -806,8 +836,12 @@
"particles",
"run_mode",
"outputInterval",
"materialDefinition",
"materialLibrary",
"photon_transport"
"mgxsFile",
"photon_transport",
"generateMGXS",
"energyGroup"
]],
["Sources", [
"sources"
Expand Down
2 changes: 2 additions & 0 deletions sirepo/package_data/template/openmc/extract_dagmc.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def _name(material_name):

def add_materials(volumes):
e = xml.etree.ElementTree.parse("{{ materialsFile }}").getroot()
if e.find("materials"):
e = e.find("materials")
for child in e:
n = _name(child.attrib.get("name"))
if not n or n not in volumes:
Expand Down
84 changes: 67 additions & 17 deletions sirepo/package_data/template/openmc/parameters.py.jinja
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- python -*-
import os
{{ weightWindowsThreadLimit }}
import numpy
Expand All @@ -8,9 +7,33 @@ import openmc.lib
import openmc_data_downloader


{% if generateMGXS %}
def create_mgxs_library(geometry, materials):
mgxs_lib = openmc.mgxs.Library(geometry)
mgxs_lib.energy_groups = openmc.mgxs.EnergyGroups(
openmc.mgxs.GROUP_STRUCTURES["{{ settings_energyGroup }}"]
)
mgxs_lib.correction = None
mgxs_lib.mgxs_types = [
"total",
"absorption",
"nu-fission",
"fission",
"nu-scatter matrix",
"multiplicity matrix",
"chi",
]
mgxs_lib.domain_type = "material"
mgxs_lib._domains = materials
mgxs_lib.by_nuclide = False
mgxs_lib.check_library_for_openmc_mgxs()
mgxs_lib.build_library()
return mgxs_lib
{% endif %}

def create_geometry():
univ = openmc.DAGMCUniverse(
filename='{{ dagmcFilename }}',
filename="{{ dagmcFilename }}",
auto_geom_ids=True,
)
{% if reflectivePlanes_useReflectivePlanes == '1' %}
Expand All @@ -19,27 +42,38 @@ def create_geometry():
region={{ region }},
fill=univ.bounded_universe(),
)
openmc.Geometry([univ]).export_to_xml()
g = openmc.Geometry([univ])
{% elif hasGraveyard %}
openmc.Geometry(univ).export_to_xml()
g = openmc.Geometry(univ)
{% else %}
openmc.Geometry(univ.bounded_universe()).export_to_xml()
g = openmc.Geometry(univ.bounded_universe())
{% endif %}
g.export_to_xml()
return g


def create_materials():
{% filter indent(width=4) %}
{{ materials }}
{% endfilter %}
materials.export_to_xml()
{% if settings_materialDefinition == 'library' %}
materials.download_cross_section_data(
libraries=['{{ settings_materialLibrary }}'],
destination='{{ materialDirectory }}',
libraries=["{{ settings_materialLibrary }}"],
destination="{{ materialDirectory }}",
)
{% endif %}
{% if settings_materialDefinition == 'mgxs' %}
materials.cross_sections = "{{ mgxsFile }}"
{% endif %}
materials.export_to_xml()
return materials


def create_settings():
settings = openmc.Settings()
{% if settings_materialDefinition == 'mgxs' %}
settings.energy_mode = "multi-group"
{% endif %}
settings.batches = {{ settings_batches }}
settings.statepoint = dict(
batches={{ batchSequence }},
Expand All @@ -49,15 +83,15 @@ def create_settings():
{% endif %}
settings.particles = {{ settings_particles }}
settings.temperature = dict(
method='interpolation',
method="interpolation",
)
{% if settings_varianceReduction == "weight_windows_mesh" or settings_varianceReduction == "weight_windows_tally" %}
settings.max_splits = {{ settings_max_splits }}
settings.max_history_splits = {{ settings_max_splits }}
{% elif settings_varianceReduction == "weight_windows_file" %}
settings.weight_windows = openmc.hdf5_to_wws("{{ weightWindowsFile }}")
{% endif %}
settings.output = dict(
summary=False,
summary={{ generateMGXS }},
tallies=False,
)
settings.source = [
Expand All @@ -66,7 +100,7 @@ def create_settings():
{% endfilter %}
]
settings.run_mode = "{{ settings_run_mode }}"
settings.photon_transport = "{{ settings_photon_transport }}" == "1"
settings.photon_transport = {{ settings_photon_transport == '1' and settings_materialDefinition == 'library' }}
{% if settings_varianceReduction == "survival_biasing" %}
settings.survival_biasing = True
settings.cutoff = {
Expand All @@ -85,21 +119,37 @@ def create_settings():
p = openmc.lib.sample_external_source(n_samples={{ maxSampleSourceParticles }})
openmc.source.write_source_file(p, "{{ sourceFile }}")
openmc.lib.finalize()
return settings


def create_tallies():
def create_tallies(geometry, materials):
{% filter indent(width=4) %}
{{ tallies }}
{% endfilter %}
{% if generateMGXS %}
mgxs_lib = create_mgxs_library(geometry, materials)
mgxs_lib.add_to_tallies_file(tallies, merge=True)
{% else %}
mgxs_lib = None
{% endif %}
tallies.export_to_xml()
return mgxs_lib


create_geometry()
create_materials()
create_settings()
create_tallies()
g = create_geometry()
m = create_materials()
s = create_settings()
mgxs_lib = create_tallies(g, m)
{% if not isPythonSource %}
import sirepo.template
sirepo.template.import_module('openmc').write_volume_outlines()
{% endif %}
{{ runCommand }}
{{ saveWeightWindowsFile }}

{% if generateMGXS %}
mgxs_lib.load_from_statepoint(openmc.StatePoint(f"statepoint.{s.batches}.h5"))
mgxs_lib.create_mg_library(
xs_type="macro", xsdata_names=[m.name for m in mgxs_lib.domains]
).export_to_hdf5("{{ mgxsFile }}")
{% endif %}
8 changes: 8 additions & 0 deletions sirepo/sim_data/openmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ def _lib_file_basenames(cls, data):
data.models.settings.weightWindowsFile,
)
)
if data.models.settings.materialDefinition == "mgxs":
r.append(
cls.lib_file_name_with_model_field(
"settings",
"mgxsFile",
data.models.settings.mgxsFile,
)
)
return r

@classmethod
Expand Down
Loading

0 comments on commit 72ccef9

Please sign in to comment.