From 328176527d2531b8bbd08da9617e140fef1e2887 Mon Sep 17 00:00:00 2001 From: Michael Keilman <30352290+mkeilman@users.noreply.github.com> Date: Mon, 5 Feb 2024 18:50:48 -0700 Subject: [PATCH] Fix #6706 - let user hide sources (#6714) --- sirepo/package_data/static/js/cloudmc.js | 61 ++++++++++++------- .../static/json/cloudmc-schema.json | 2 + 2 files changed, 42 insertions(+), 21 deletions(-) diff --git a/sirepo/package_data/static/js/cloudmc.js b/sirepo/package_data/static/js/cloudmc.js index a807c1fc53..fde4f447db 100644 --- a/sirepo/package_data/static/js/cloudmc.js +++ b/sirepo/package_data/static/js/cloudmc.js @@ -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); @@ -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); @@ -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 = []; @@ -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, }); @@ -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), @@ -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, @@ -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(); } @@ -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); @@ -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); @@ -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()); } @@ -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(); } @@ -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(); } @@ -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'); @@ -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, ]); @@ -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() { @@ -2852,6 +2870,7 @@ SIREPO.viewLogic('tallySettingsView', function(appState, cloudmcService, panelSt [ 'tallyReport.selectedGeometry', 'openmcAnimation.score', + 'openmcAnimation.showSources', 'openmcAnimation.numSampleSourceParticles', ], showFields, ]; diff --git a/sirepo/package_data/static/json/cloudmc-schema.json b/sirepo/package_data/static/json/cloudmc-schema.json index 1c27977990..b110b010fd 100644 --- a/sirepo/package_data/static/json/cloudmc-schema.json +++ b/sirepo/package_data/static/json/cloudmc-schema.json @@ -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"], @@ -1207,6 +1208,7 @@ "score", "aspect", "energyRangeSum", + "showSources", "numSampleSourceParticles", "sourceColorMap", "colorMap",