Skip to content

Commit

Permalink
Fix #6706 - let user hide sources (#6714)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeilman authored Feb 6, 2024
1 parent 66ff0ea commit 3281765
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 21 deletions.
61 changes: 40 additions & 21 deletions sirepo/package_data/static/js/cloudmc.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ SIREPO.app.factory('cloudmcService', function(appState, panelState, $rootScope)
};


self.getSources = builders => {
self.getSourceVisualizations = builders => {
const sources = [];
const noop = () => {};
for (const s of appState.models.settings.sources.filter(x => x.space)) {
for (const s of appState.models.settings.sources.filter(x => x.space && x.space.only_fissionable !== '1')) {
let b = null;
const space = s.space;
b = (builders[space._type] || noop)(space);
Expand Down Expand Up @@ -760,7 +760,7 @@ SIREPO.app.directive('geometry2d', function(appState, cloudmcService, frameCache
controller: function($scope) {
$scope.modelName = 'tallyReport';
const displayRanges = {};
const sources = cloudmcService.getSources(
const sources = cloudmcService.getSourceVisualizations(
{
box: space => {
const d = cloudmcService.boxDimensions(space);
Expand Down Expand Up @@ -884,7 +884,7 @@ SIREPO.app.directive('geometry2d', function(appState, cloudmcService, frameCache
.attr('orient', 'auto')
.attr('markerUnits', 'strokeWidth')
.select('path')
.attr('fill', d => d);
.attr('fill', d => sourceColor(d));
}

const outlines = [];
Expand All @@ -910,7 +910,7 @@ SIREPO.app.directive('geometry2d', function(appState, cloudmcService, frameCache
}
outlines.push({
name: `source-${s.particle}-${s.space._type}-${i}`,
color: '#ff0000',
color: sourceColor('#ff0000'),
data: view.shapePoints(dim).map(p => p.toReversed()),
doClose: true,
});
Expand All @@ -925,7 +925,7 @@ SIREPO.app.directive('geometry2d', function(appState, cloudmcService, frameCache
const p2 = [p1[0] + r * p.direction[j] / d, p1[1] + r * p.direction[k] / d];
outlines.push({
name: `${p.type}-${p.energy}eV-${n}`,
color: particleColor(p),
color: sourceColor(particleColor(p)),
dashes: p.type === 'PHOTON' ? '6 2' : '',
data: [p1, p2].map(p => p.toReversed()),
marker: particleId(p),
Expand Down Expand Up @@ -962,6 +962,10 @@ SIREPO.app.directive('geometry2d', function(appState, cloudmcService, frameCache
return ff;
}

function sourceColor(color) {
return appState.models.openmcAnimation.showSources === '1' ? color : 'none';
}

function tallyReportAxes() {
return [
appState.models.tallyReport.axis,
Expand All @@ -988,6 +992,7 @@ SIREPO.app.directive('geometry2d', function(appState, cloudmcService, frameCache
buildTallyReport();
// save quietly but immediately
appState.saveQuietly('tallyReport');
appState.saveQuietly('openmcAnimation');
appState.autoSave();
}

Expand Down Expand Up @@ -1049,7 +1054,7 @@ SIREPO.app.directive('geometry2d', function(appState, cloudmcService, frameCache

$scope.$on('tallyReport.summaryData', updateSliceAxis);
appState.watchModelFields($scope, ['tallyReport.axis'], updateSliceAxis);
appState.watchModelFields($scope, ['tallyReport.planePos'], updateSlice, true);
appState.watchModelFields($scope, ['tallyReport.planePos', 'openmcAnimation.showSources'], updateSlice, true);
$scope.$on('openmcAnimation.summaryData', updateDisplayRange);
if (frameCache.hasFrames('openmcAnimation')) {
panelState.waitForUI(updateDisplayRange);
Expand Down Expand Up @@ -1103,7 +1108,7 @@ SIREPO.app.directive('geometry3d', function(appState, cloudmcService, plotting,
edgeVisibility: true,
lighting: false,
};
const sourceBundles = cloudmcService.getSources(
const sourceBundles = cloudmcService.getSourceVisualizations(
{
box: space => {
const d = cloudmcService.boxDimensions(space);
Expand Down Expand Up @@ -1164,6 +1169,9 @@ SIREPO.app.directive('geometry3d', function(appState, cloudmcService, plotting,
function addSources() {
sourceBundles.forEach(b => {
vtkScene.removeActor(b.actor);
if (appState.models.openmcAnimation.showSources !== '1') {
return;
}
if (b.source.setRadius) {
b.source.setRadius(0.25 * vectorScaleFactor());
}
Expand All @@ -1173,19 +1181,20 @@ SIREPO.app.directive('geometry3d', function(appState, cloudmcService, plotting,
if (particleBundle) {
vtkScene.removeActor(particleBundle.actor);
}
const particles = tallyService.getSourceParticles();
if (particles.length) {
particleBundle = coordMapper.buildVectorField(
particles.map(p => p.direction.map(x => p.energy * x)),
particles.map(p => p.position),
vectorScaleFactor(),
true,
appState.models.openmcAnimation.sourceColorMap,
{edgeVisibility: false, lighting: false}
);
vtkScene.addActor(particleBundle.actor);
if (appState.models.openmcAnimation.showSources === '1') {
const particles = tallyService.getSourceParticles();
if (particles.length) {
particleBundle = coordMapper.buildVectorField(
particles.map(p => p.direction.map(x => p.energy * x)),
particles.map(p => p.position),
vectorScaleFactor(),
true,
appState.models.openmcAnimation.sourceColorMap,
{edgeVisibility: false, lighting: false}
);
vtkScene.addActor(particleBundle.actor);
}
}

vtkScene.render();
}

Expand Down Expand Up @@ -1577,6 +1586,12 @@ SIREPO.app.directive('geometry3d', function(appState, cloudmcService, plotting,
vtkScene.render();
}

function showSources() {
addSources();
appState.saveQuietly($scope.modelName);
appState.autoSave();
}

function vectorScaleFactor() {
return 3.5 * tallyService.getMaxMeshExtent();
}
Expand All @@ -1592,6 +1607,7 @@ SIREPO.app.directive('geometry3d', function(appState, cloudmcService, plotting,
$scope.$on($scope.modelName + '.changed', setGlobalProperties);

if (hasTallies) {
appState.watchModelFields($scope, [`${$scope.modelName}.showSources`], showSources, true);
$scope.$on('openmcAnimation.summaryData', () => {
if (vtkScene) {
$rootScope.$broadcast('vtk.showLoader');
Expand Down Expand Up @@ -2799,6 +2815,7 @@ SIREPO.viewLogic('tallySettingsView', function(appState, cloudmcService, panelSt

function showFields() {
const is2D = appState.models.tallyReport.selectedGeometry === '2D';
const showSources = appState.models.openmcAnimation.showSources === '1';
panelState.showFields('openmcAnimation', [
'opacity', ! is2D,
]);
Expand All @@ -2807,7 +2824,8 @@ SIREPO.viewLogic('tallySettingsView', function(appState, cloudmcService, panelSt
]);
panelState.showField('openmcAnimation', 'energyRangeSum', ! ! $scope.energyFilter);
panelState.showField('openmcAnimation', 'sourceNormalization', cloudmcService.canNormalizeScore(appState.models.openmcAnimation.score));
panelState.showField('openmcAnimation', 'sourceColorMap', appState.models.openmcAnimation.numSampleSourceParticles);
panelState.showField('openmcAnimation', 'numSampleSourceParticles', showSources);
panelState.showField('openmcAnimation', 'sourceColorMap', showSources && appState.models.openmcAnimation.numSampleSourceParticles);
}

function updateEnergyRange() {
Expand Down Expand Up @@ -2852,6 +2870,7 @@ SIREPO.viewLogic('tallySettingsView', function(appState, cloudmcService, panelSt
[
'tallyReport.selectedGeometry',
'openmcAnimation.score',
'openmcAnimation.showSources',
'openmcAnimation.numSampleSourceParticles',
], showFields,
];
Expand Down
2 changes: 2 additions & 0 deletions sirepo/package_data/static/json/cloudmc-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,7 @@
"opacity": ["Global alpha", "Range", 1.0, "", 0.0, 1.0],
"showEdges": ["Show edges", "Boolean", "0"],
"showMarker": ["Show axis marker", "Boolean", "1"],
"showSources": ["Show Sources", "Boolean", "1"],
"sourceColorMap": ["Source Energy Color Map", "ColorMap", "jet"],
"tally": ["Tally", "TallyList"],
"threshold": ["Threshold", "Float", 0.0, "Tally cells with a value below this will not be displayed"],
Expand Down Expand Up @@ -1207,6 +1208,7 @@
"score",
"aspect",
"energyRangeSum",
"showSources",
"numSampleSourceParticles",
"sourceColorMap",
"colorMap",
Expand Down

0 comments on commit 3281765

Please sign in to comment.