Skip to content

Commit

Permalink
for #7332 2d plot axes now matches 3d view
Browse files Browse the repository at this point in the history
  • Loading branch information
moellep committed Oct 31, 2024
1 parent 20eebcd commit eaf4dc9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 23 deletions.
51 changes: 31 additions & 20 deletions sirepo/package_data/static/js/openmc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ SIREPO.app.directive('geometry2d', function(appState, frameCache, openmcService,
o.axis = appState.models.tallyReport.axis;
appState.saveQuietly('outlineAnimation');

const n = tallyReportAxisIndices()[0];
const n = SIREPO.GEOMETRY.GeometryUtils.BASIS().indexOf(appState.models.tallyReport.axis);
const range = tallyService.getMeshRanges()[n];
frameCache.getFrame(
'outlineAnimation',
Expand All @@ -1021,9 +1021,13 @@ SIREPO.app.directive('geometry2d', function(appState, frameCache, openmcService,

function buildTallyReportsWithOutlines() {
const [z, x, y] = tallyReportAxes();
const [n, m, l] = tallyReportAxisIndices();
const [zi, xi, yi] = tallyReportAxisIndices();
const ranges = tallyService.getMeshRanges();
const pos = appState.models.tallyReport.planePos;
if (z === 'z' || z === 'x') {
const [xl, xh] = ranges[xi];
ranges[xi][0] = xh;
ranges[xi][1] = xl;
}
const outlines = [];
for (const volId of openmcService.getNonGraveyardVolumes()) {
const v = openmcService.getVolumeById(volId);
Expand All @@ -1047,7 +1051,7 @@ SIREPO.app.directive('geometry2d', function(appState, frameCache, openmcService,
arRange[0],
Math.min(
arRange[1],
Math.abs(ranges[m][1] - ranges[m][0]) / Math.abs(ranges[l][1] - ranges[l][0])
Math.abs(ranges[yi][1] - ranges[yi][0]) / Math.abs(ranges[xi][1] - ranges[xi][0])
)
);
const r = {
Expand All @@ -1056,13 +1060,13 @@ SIREPO.app.directive('geometry2d', function(appState, frameCache, openmcService,
global_min: appState.models.openmcAnimation.colorRange[0],
global_max: appState.models.openmcAnimation.colorRange[1],
threshold: appState.models.openmcAnimation.thresholds,
title: `Score at ${z} = ${SIREPO.UTILS.roundToPlaces(pos, 6)}m${energySumLabel()}`,
title: `Score at ${z} = ${SIREPO.UTILS.roundToPlaces(appState.models.tallyReport.planePos, 6)}m${energySumLabel()}`,
x_label: `${x} [m]`,
x_range: ranges[l],
x_range: ranges[xi],
y_label: `${y} [m]`,
y_range: ranges[m],
y_range: ranges[yi],
z_matrix: sliceFieldData(),
z_range: ranges[n],
z_range: ranges[zi],
overlayData: outlines.concat(getSourceOutlines()),
selectedCoords: $scope.energyFilter ? tallyService.getEnergyReportCoords() : null,
};
Expand All @@ -1084,6 +1088,9 @@ SIREPO.app.directive('geometry2d', function(appState, frameCache, openmcService,
}

function getSourceOutlines() {
if (appState.models.openmcAnimation.showSources === '0') {
return [];
}
//TODO(pjm): rework this method
const [n, m, l] = tallyReportAxisIndices();
const dimIndex = n;
Expand Down Expand Up @@ -1201,12 +1208,12 @@ SIREPO.app.directive('geometry2d', function(appState, frameCache, openmcService,

if (a === 'x') {
const x = slice;
for (let y = 0; y < ny; y++) {
for (let z = 0; z < nz; z++) {
const r = [];
for (let z = 0; z < nz; z++) {
r[z] = f[z * nx * ny + y * nx + x];
for (let y = 0; y < ny; y++) {
r[y] = f[z * nx * ny + y * nx + x];
}
v.push(r);
v.push(r.reverse());
}
}
else if (a === 'y') {
Expand All @@ -1221,10 +1228,10 @@ SIREPO.app.directive('geometry2d', function(appState, frameCache, openmcService,
}
else if (a === 'z') {
const z = slice * nx * ny;
for (let x = 0; x < nx; x++) {
for (let y = 0; y < ny; y++) {
const r = [];
for (let y = 0; y < ny; y++) {
r[y] = f[z + y * nx + x];
for (let x = 0; x < nx; x++) {
r[nx - x - 1] = f[z + y * nx + x];
}
v.push(r);
}
Expand All @@ -1248,14 +1255,18 @@ SIREPO.app.directive('geometry2d', function(appState, frameCache, openmcService,
}

function tallyReportAxes() {
return [
appState.models.tallyReport.axis,
...SIREPO.GEOMETRY.GeometryUtils.nextAxes(appState.models.tallyReport.axis).reverse()
];
const a = appState.models.tallyReport.axis;
if (a === 'x') {
return ['x', 'y', 'z'];
}
if (a === 'y') {
return ['y', 'x', 'z'];
}
return ['z', 'x', 'y'];
}

function tallyReportAxisIndices() {
return SIREPO.GEOMETRY.GeometryUtils.axisIndices(appState.models.tallyReport.axis);
return tallyReportAxes().map((a) => SIREPO.GEOMETRY.GeometryUtils.BASIS().indexOf(a));
}

function updateDisplay() {
Expand Down
6 changes: 5 additions & 1 deletion sirepo/package_data/static/js/sirepo-plotting-vtk.js
Original file line number Diff line number Diff line change
Expand Up @@ -728,9 +728,13 @@ class VTKScene {
* @param {[number]} viewUp
*/
setCam(position = [1, 0, 0], viewUp = [0, 0, 1]) {
// set focal point outside of the origin initially to avoid a VTK warning:
// "resetting view-up since view plane normal is parallel"
// this happens because the camera is recalculated on each modification
this.cam.setFocalPoint(10, 10, 10);
this.cam.setViewUp(...viewUp);
this.cam.setPosition(...position);
this.cam.setFocalPoint(0, 0, 0);
this.cam.setViewUp(...viewUp);
this.renderer.resetCamera();
this.cam.yaw(0.6);
if (this.marker) {
Expand Down
4 changes: 2 additions & 2 deletions sirepo/template/openmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,9 @@ def _is_skip_dimension(tally_range, dim):
basis_vects = numpy.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
rots = numpy.array(
[
[[1, 0], [0, 1]],
[[0, 1], [1, 0]],
[[0, -1], [1, 0]],
[[0, 1], [-1, 0]],
[[-1, 0], [0, 1]],
]
)
scale = SCHEMA.constants.geometryScale
Expand Down

0 comments on commit eaf4dc9

Please sign in to comment.