Skip to content

Commit

Permalink
fix #7279 full support for PNNL material database (#7428)
Browse files Browse the repository at this point in the history
  • Loading branch information
moellep authored Jan 22, 2025
1 parent 2898e25 commit 3aed459
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 605 deletions.
143 changes: 104 additions & 39 deletions sirepo/package_data/static/js/openmc.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ SIREPO.app.config(() => {
<div data-ng-switch-when="SelectedTallyVolumes">
<div data-tally-volume-picker=""></div>
</div>
<div data-ng-switch-when="StandardMaterial" class="col-sm-7">
<div data-standard-material="" data-model-name="modelName" data-model="model" data-field="field"></div>
</div>
`;
SIREPO.FILE_UPLOAD_TYPE = {
'geometryInput-dagmcFile': '.h5m,.stp',
Expand All @@ -120,6 +123,7 @@ SIREPO.app.config(() => {

SIREPO.app.factory('openmcService', function(appState, panelState, requestSender, $rootScope) {
const self = {};
let standardMaterialNames;
appState.setAppService(self);

function findFilter(tallies, tally, type) {
Expand Down Expand Up @@ -230,6 +234,39 @@ SIREPO.app.factory('openmcService', function(appState, panelState, requestSender
return m[field] && (m[field][0] || m[field][1]);
};

self.loadStandardMaterial = (name, wantElements, callback) => {
requestSender.sendStatefulCompute(
appState,
(data) => {
callback(data.material);
},
{
method: 'get_standard_material',
args: {
name: name,
wantElements: wantElements,
},
}
);
};

self.loadStandardMaterialNames = (callback) => {
if (standardMaterialNames) {
callback(standardMaterialNames);
return;
}
requestSender.sendStatefulCompute(
appState,
(data) => {
standardMaterialNames = data.names;
callback(data.names);
},
{
method: 'get_standard_material_names',
}
);
};

self.selectVarianceReductionTab = () => {
$rootScope.$broadcast('sr.setActivePage', 'settings', 4);
};
Expand Down Expand Up @@ -321,12 +358,12 @@ SIREPO.app.controller('GeometryController', function (appState, openmcService, p
appState,
(data) => {
// don't initialize simulation until geometry is known
hasGeometry = data.animationDirExists;
hasGeometry = data.hasGeometry;
self.simState = persistentSimulation.initSimulationState(self);
self.simState.errorMessage = () => self.errorMessage;
},
{
method: 'check_animation_dir',
method: 'verify_geometry',
args: {
modelName: 'dagmcAnimation',
},
Expand Down Expand Up @@ -2978,43 +3015,6 @@ SIREPO.viewLogic('tallyView', function(appState, openmcService, panelState, vali
];
});

SIREPO.viewLogic('materialView', function(appState, panelState, $scope) {

let name = null;

$scope.whenSelected = () => {
$scope.appState = appState;
name = model().name;
};

function isStd() {
return model() && model().standardType !== 'None';
}

function model() {
return appState.models[$scope.modelName];
}

function updateMaterial() {
if (! model()) {
return;
}
if (isStd()) {
// don't change the name as it came from the loaded volume
appState.models[$scope.modelName] = appState.setModelDefaults({name: name}, model().standardType);
}
}

// only update when the user makes a change, not on the initial model load
$scope.$watch(`appState.models['${$scope.modelName}']['standardType']`, (newVal, oldVal) => {
if (oldVal === undefined || oldVal === newVal) {
return;
}
updateMaterial();
});

});

SIREPO.app.directive('simpleListEditor', function(panelState) {
return {
restrict: 'A',
Expand Down Expand Up @@ -3257,6 +3257,71 @@ SIREPO.app.directive('energyRangeSlider', function(appState, openmcService, pane
};
});

SIREPO.app.directive('standardMaterial', function(openmcService, panelState, utilities) {
const searchClass = 'sr-material-search';
return {
restrict: 'A',
scope: {
field: '<',
model: '=',
modelName: '<',
},
template: `
<div data-ng-if="list" class="input-group input-group-sm">
<span class="input-group-addon"><span class="glyphicon glyphicon-search"></span></span>
<input class="${searchClass} form-control" placeholder="Search Material Compendium" />
<span class="input-group-btn">
<button class="btn" data-ng-class="{'btn-primary': wantElement}" type="button" data-ng-disabled="! hasSelection()" data-ng-click="selectSearchType(true)">Element</button>
<button class="btn" data-ng-class="{'btn-primary': ! wantElement}" type="button" data-ng-disabled="! hasSelection()" data-ng-click="selectSearchType(false)">Nuclide</button>
</span>
</div>
`,
controller: function($scope, $element) {
let lastSelected = '';
$scope.wantElement = true;

$scope.hasSelection = () => lastSelected ? true : false;

$scope.onSelect = () => {
return (value) => {
if ($scope.model) {
lastSelected = value;
openmcService.loadStandardMaterial(value, $scope.wantElement, (m) => {
Object.assign($scope.model, m);
});
}
};
};

$scope.selectSearchType = (wantElement) => {
$scope.wantElement = wantElement;
if (lastSelected) {
$(`.${searchClass}`).val(lastSelected);
$scope.onSelect()(lastSelected);
}
};

openmcService.loadStandardMaterialNames((names) => {
$scope.list = [];
for (const n of names) {
$scope.list.push({
label: n,
value: n,
});
}
panelState.waitForUI(() => {
utilities.buildSearch($scope, $element, searchClass);
});
});

$scope.$on('cancelChanges', () => {
$(`.${searchClass}`).val('');
lastSelected = '';
});
},
};
});

SIREPO.app.directive('planePositionSlider', function(appState, panelState, tallyService) {
return {
restrict: 'A',
Expand Down
5 changes: 2 additions & 3 deletions sirepo/package_data/static/js/sirepo-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -698,9 +698,8 @@ SIREPO.app.directive('listSearch', function(panelState, utilities) {
</div>
`,
controller: function($scope, $element) {
let sel = null;
panelState.waitForUI(() => {
sel = utilities.buildSearch($scope, $element, searchClass);
utilities.buildSearch($scope, $element, searchClass);
});
},
};
Expand Down Expand Up @@ -5397,7 +5396,6 @@ SIREPO.app.service('utilities', function($window, $interval, $interpolate, $root
};

this.buildSearch = (scope, element, searchClass, supportsMulti) => {
const utilities = this;
function findToken(text, caretPos) {
let n = 0;
const tokens = text.split(/\s+/);
Expand All @@ -5419,6 +5417,7 @@ SIREPO.app.service('utilities', function($window, $interval, $interpolate, $root
'ui-autocomplete': 'sr-dropdown',
},
delay: 0,
minLength: supportsMulti ? 1 : 2,
select: (e, ui) => {
scope.$apply(() => {
// the jqueryui autocomplete wants to display the value instead of the
Expand Down
Loading

0 comments on commit 3aed459

Please sign in to comment.