diff --git a/sirepo/package_data/static/js/elegant.js b/sirepo/package_data/static/js/elegant.js index 1bfc67a8c9..40d511bec6 100644 --- a/sirepo/package_data/static/js/elegant.js +++ b/sirepo/package_data/static/js/elegant.js @@ -155,34 +155,33 @@ SIREPO.app.factory('elegantService', function(appState, commandService, requestS } function commandsChanged() { - let cmd = self.findFirstCommand('run_setup'); - if (cmd && cmd.use_beamline) { - appState.models.simulation.visualizationBeamlineId = cmd.use_beamline; + const rscmd = self.findFirstCommand('run_setup'); + if (rscmd && rscmd.use_beamline) { + appState.models.simulation.visualizationBeamlineId = rscmd.use_beamline; appState.saveQuietly('simulation'); } // update bunchSource, bunchFile, bunch models - cmd = self.findFirstCommand(['bunched_beam', 'sdds_beam']); - if (! cmd) { + const bcmd = self.findFirstCommand(['bunched_beam', 'sdds_beam']); + if (! bcmd) { return; } - appState.models.bunchSource.inputSource = cmd._type; + appState.models.bunchSource.inputSource = bcmd._type; appState.saveQuietly('bunchSource'); - cmd = self.findFirstCommand('run_setup'); const bunch = appState.models.bunch; - if (cmd) { - if (rpnService.getRpnValue(cmd.p_central_mev) !== 0) { - bunch.p_central_mev = cmd.p_central_mev; + if (rscmd) { + if (rpnService.getRpnValue(rscmd.p_central_mev) !== 0) { + bunch.p_central_mev = rscmd.p_central_mev; } else { - bunch.p_central_mev = rpnService.getRpnValue(cmd.p_central) * SIREPO.APP_SCHEMA.constants.ELEGANT_ME_EV; + bunch.p_central_mev = rpnService.getRpnValue(rscmd.p_central) * SIREPO.APP_SCHEMA.constants.ELEGANT_ME_EV; } } - if (cmd._type == 'bunched_beam') { - updateBunchFromCommand(bunch, cmd); + if (bcmd._type == 'bunched_beam') { + updateBunchFromCommand(bunch, bcmd); } else { - appState.models.bunchFile.sourceFile = cmd.input; + appState.models.bunchFile.sourceFile = bcmd.input; appState.saveQuietly('bunchFile'); } // need to update source reports. diff --git a/sirepo/package_data/static/js/sirepo-lattice.js b/sirepo/package_data/static/js/sirepo-lattice.js index d6b86ccbc4..8673e98529 100644 --- a/sirepo/package_data/static/js/sirepo-lattice.js +++ b/sirepo/package_data/static/js/sirepo-lattice.js @@ -1434,7 +1434,7 @@ SIREPO.app.directive('lattice', function(appState, latticeService, panelState, p currentLength = x; } var picType = getPicType(item.type); - var length = rpnValue(item.l || item.xmax || 0); + var length = rpnValue(item.l || (item.type == "ALPH" && item.xmax) || 0); if (picType == 'zeroLength') { length = 0; } diff --git a/sirepo/package_data/static/js/sirepo-plotting.js b/sirepo/package_data/static/js/sirepo-plotting.js index 5a22b9b577..cd136b75a3 100644 --- a/sirepo/package_data/static/js/sirepo-plotting.js +++ b/sirepo/package_data/static/js/sirepo-plotting.js @@ -181,21 +181,6 @@ class AbstractPlotShape2D extends AbstractPlotShape { } } -class PlotLine extends AbstractPlotShape { - constructor( - id, - name, - line - ) { - super( - id, - name, - 'line' - ); - this.line = line; - } -} - class PlotPolygon extends AbstractPlotShape2D { constructor( id, @@ -253,32 +238,6 @@ class PlotPolygon extends AbstractPlotShape2D { } } -class PlotRect extends AbstractPlotShape2D { - constructor( - id, - name, - center, - size=[1, 1] - ) { - super(id, name, 'rect', center); - this.size = { - x: size[0], - y: size[1], - }; - this.x = this.center.x + this.size.x / 2; - this.y = this.center.y - this.size.y / 2; - } - - getSizeCoords() { - return this.getCoords(this.size); - } - - setSize(coords) { - this.setCoords(this.size, coords); - } -} - - SIREPO.app.factory('plotting', function(appState, frameCache, panelState, utilities, requestQueue, simulationQueue, $interval, $rootScope, $window) { var INITIAL_HEIGHT = 400; @@ -2657,6 +2616,9 @@ SIREPO.app.directive('plot3d', function(appState, focusPointService, layoutServi function adjustZoomToCenter(scale) { // if the domain is almost centered on 0.0 (within 10%) adjust zoom and offset to center var domain = scale.domain(); + if (SIREPO.PLOTTING_SUMMED_LINEOUTS) { + return; + } if (domain[0] < 0 && domain[1] > 0) { var width = domain[1] - domain[0]; var diff = (domain[0] + domain[1]) / width; @@ -4144,8 +4106,6 @@ SIREPO.app.directive('particle', function(plotting, plot2dService) { SIREPO.PLOTTING = { HeatmapSelectCellEvent: 'heatmapSelectCell', - PlotLine: PlotLine, PlotPolygon: PlotPolygon, - PlotRect: PlotRect, Utils: PlottingUtils, }; diff --git a/sirepo/package_data/static/json/canvas-schema.json b/sirepo/package_data/static/json/canvas-schema.json index 771f1e7965..8df989b16e 100644 --- a/sirepo/package_data/static/json/canvas-schema.json +++ b/sirepo/package_data/static/json/canvas-schema.json @@ -124,7 +124,7 @@ "bunchAnimation": { "x": ["Horizontal Value to Plot", "PhaseSpaceCoordinate", "x"], "y": ["Vertical Value to Plot", "PhaseSpaceCoordinate", "px"], - "plotType": ["Plot Type", "PlotType", "heatmap"], + "plotType": ["Plot Type", "PlotType", "3d"], "histogramBins": ["Histogram Bins", "Integer", 60], "colorMap": ["Color Map", "ColorMap", "viridis"], "selectedFrame": ["", "FrameSlider", 0], @@ -134,7 +134,7 @@ "simCode": ["", "String", "elegant"], "x": ["Horizontal Value to Plot", "PhaseSpaceCoordinate", "x"], "y": ["Vertical Value to Plot", "PhaseSpaceCoordinate", "px"], - "plotType": ["Plot Type", "PlotType", "heatmap"], + "plotType": ["Plot Type", "PlotType", "3d"], "histogramBins": ["Histogram Bins", "Integer", 60], "colorMap": ["Color Map", "ColorMap", "viridis"], "notes": ["Notes", "Text", ""] @@ -143,7 +143,7 @@ "simCode": ["", "String", "madx"], "x": ["Horizontal Value to Plot", "PhaseSpaceCoordinate", "x"], "y": ["Vertical Value to Plot", "PhaseSpaceCoordinate", "px"], - "plotType": ["Plot Type", "PlotType", "heatmap"], + "plotType": ["Plot Type", "PlotType", "3d"], "histogramBins": ["Histogram Bins", "Integer", 60], "colorMap": ["Color Map", "ColorMap", "viridis"], "notes": ["Notes", "Text", ""] @@ -152,7 +152,7 @@ "simCode": ["", "String", "impactx"], "x": ["Horizontal Value to Plot", "PhaseSpaceCoordinate", "x"], "y": ["Vertical Value to Plot", "PhaseSpaceCoordinate", "px"], - "plotType": ["Plot Type", "PlotType", "heatmap"], + "plotType": ["Plot Type", "PlotType", "3d"], "histogramBins": ["Histogram Bins", "Integer", 60], "colorMap": ["Color Map", "ColorMap", "viridis"], "notes": ["Notes", "Text", ""] @@ -245,7 +245,7 @@ "_super": ["", "model", "_ELEMENT"], "volt": ["Voltage [V]", "RPNValue", 0], "freq": ["Frequency [Hz]", "RPNValue", 0], - "phase": ["Phase [rad]", "RPNValue", 0] + "phase": ["Phase [deg]", "RPNValue", 0, "RF synchronous phase (phase = 0 corresponds to maximum energy gain, phase = -90 corresponds to zero energy gain for bunching)"] }, "SBEND": { "_super": ["", "model", "_ELEMENT"], diff --git a/sirepo/package_data/static/json/impactx-schema.json b/sirepo/package_data/static/json/impactx-schema.json index 04bcd11fdf..cb19414607 100644 --- a/sirepo/package_data/static/json/impactx-schema.json +++ b/sirepo/package_data/static/json/impactx-schema.json @@ -395,7 +395,7 @@ "_super": ["_", "model", "_ELEMENT_WITH_ERROR"], "V": ["V","RPNValue",null,"Normalized RF voltage V = maximum energy gain/(m*c²)"], "freq": ["FREQ","RPNValue",null,"RF frequency in Hz"], - "phase": ["PHASE [deg]","RPNValue",-90.0,"RF synchronous phase (phase = 0 corresponds to maximum energy gain, phase = -90 corresponds go zero energy gain for bunching)"] + "phase": ["PHASE [deg]","RPNValue",-90.0,"RF synchronous phase (phase = 0 corresponds to maximum energy gain, phase = -90 corresponds to zero energy gain for bunching)"] }, "SOFTQUADRUPOLE": { "_super": ["_", "model", "_ELEMENT_WITH_LENGTH_AND_ERROR"], diff --git a/sirepo/package_data/template/canvas/examples/bessy-ii.json b/sirepo/package_data/template/canvas/examples/bessy-ii.json index d9efd6d1ed..d0d47084be 100644 --- a/sirepo/package_data/template/canvas/examples/bessy-ii.json +++ b/sirepo/package_data/template/canvas/examples/bessy-ii.json @@ -27,7 +27,7 @@ }, { "angle": 6.283185307179586, - "count": 49, + "count": 56, "distance": 7.385346623550245e-15, "id": 111, "items": [ @@ -45,10 +45,11 @@ }, { "angle": 0.7853981633974483, - "count": 6, + "count": 7, "distance": 11.642938286447297, "id": 109, "items": [ + 112, 103, 103, 105, @@ -69,18 +70,12 @@ } ], "bunchAnimation1": { - "histogramBins": 80, - "notes": "", "simCode": "elegant" }, "bunchAnimation2": { - "histogramBins": 80, - "notes": "", "simCode": "madx" }, "bunchAnimation3": { - "histogramBins": 80, - "notes": "", "simCode": "impactx" }, "bunchReport1": { @@ -132,7 +127,7 @@ "muypy": -0.6715875410129232, "normalize": 0, "normalize_halo": 0, - "particleCount": 10000, + "particleCount": 5000, "species": "electron" }, "elements": [ @@ -176,6 +171,16 @@ "psi": 0, "type": "DRIFT" }, + { + "_id": 112, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0, + "name": "M1", + "psi": 0, + "type": "MONITOR" + }, { "_id": 105, "_super": "_ELEMENT", @@ -231,22 +236,10 @@ } ], "rpnVariables": [ - { - "name": "pi", - "value": 3.141592653589793 - }, - { - "name": "ncell", - "value": 8 - }, { "name": "bendangle", "value": "pi/ncell" }, - { - "name": "lbend", - "value": 2.6193 - }, { "name": "bendradius", "value": "ncell*lbend/pi" @@ -268,40 +261,23 @@ "value": 2.1082 }, { - "name": "lquad", - "value": 0.3 - }, - { - "name": "twopi", - "value": "pi * 2" + "name": "lbend", + "value": 2.6193 }, { - "name": "raddeg", - "value": "pi / 180" + "name": "lquad", + "value": 0.3 }, { - "name": "degrad", - "value": "180 / pi" + "name": "ncell", + "value": 8 } ], - "sigmaAnimation": { - "includeLattice": "1", - "notes": "" - }, "simulation": { "activeBeamlineId": 111, "folder": "/Examples", "name": "BESSY-II-Booster", "visualizationBeamlineId": 111 - }, - "simulationSettings": { - "useElegant": "1", - "useImpactX": "1", - "useMadx": "1" - }, - "twissAnimation": { - "includeLattice": "1", - "notes": "" } }, "simulationType": "canvas" diff --git a/sirepo/package_data/template/canvas/examples/fodo-cell.json b/sirepo/package_data/template/canvas/examples/fodo-cell.json index b3e30c7115..5ab1614d77 100644 --- a/sirepo/package_data/template/canvas/examples/fodo-cell.json +++ b/sirepo/package_data/template/canvas/examples/fodo-cell.json @@ -19,18 +19,12 @@ } ], "bunchAnimation1": { - "histogramBins": 80, - "notes": "", "simCode": "elegant" }, "bunchAnimation2": { - "histogramBins": 80, - "notes": "", "simCode": "madx" }, "bunchAnimation3": { - "histogramBins": 80, - "notes": "", "simCode": "impactx" }, "bunchReport1": { @@ -123,28 +117,12 @@ "type": "QUADRUPOLE" } ], - "panelState": { - "hidden": [] - }, "rpnVariables": [], - "sigmaAnimation": { - "includeLattice": "1", - "notes": "" - }, "simulation": { "activeBeamlineId": 2, "folder": "/Examples", "name": "FODO Cell", "visualizationBeamlineId": 2 - }, - "simulationSettings": { - "useElegant": "1", - "useImpactX": "1", - "useMadx": "1" - }, - "twissAnimation": { - "includeLattice": "1", - "notes": "" } }, "simulationType": "canvas" diff --git a/sirepo/package_data/template/canvas/examples/iota-ring.json b/sirepo/package_data/template/canvas/examples/iota-ring.json index ca49920aab..aa242c4a11 100644 --- a/sirepo/package_data/template/canvas/examples/iota-ring.json +++ b/sirepo/package_data/template/canvas/examples/iota-ring.json @@ -869,25 +869,33 @@ }, { "angle": 6.2831853064, - "count": 48, + "count": 56, "distance": 3.2333211663797826e-09, "id": 376, "items": [ 367, + 377, 286, 369, + 377, 287, 371, + 377, 288, 373, + 377, 289, 375, + 377, 290, 374, + 377, 291, 372, + 377, 292, 370, + 377, 293, 368 ], @@ -1977,18 +1985,12 @@ } ], "bunchAnimation1": { - "histogramBins": 80, - "notes": "", "simCode": "elegant" }, "bunchAnimation2": { - "histogramBins": 80, - "notes": "", "simCode": "madx" }, "bunchAnimation3": { - "histogramBins": 80, - "notes": "", "simCode": "impactx" }, "bunchReport1": { @@ -2040,7 +2042,7 @@ "muypy": -3.972798701270233e-07, "normalize": 0, "normalize_halo": 0, - "particleCount": 10000, + "particleCount": 5000, "species": "electron" }, "elements": [ @@ -2844,6 +2846,16 @@ "psi": 0, "type": "DRIFT" }, + { + "_id": 377, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0, + "name": "M1", + "psi": 0, + "type": "MONITOR" + }, { "_id": 181, "_super": "_ELEMENT", @@ -3454,42 +3466,12 @@ "type": "SBEND" } ], - "rpnVariables": [ - { - "name": "pi", - "value": 3.141592653589793 - }, - { - "name": "twopi", - "value": "pi * 2" - }, - { - "name": "raddeg", - "value": "pi / 180" - }, - { - "name": "degrad", - "value": "180 / pi" - } - ], - "sigmaAnimation": { - "includeLattice": "1", - "notes": "" - }, + "rpnVariables": [], "simulation": { "activeBeamlineId": 376, "folder": "/Examples", "name": "IOTA Ring", "visualizationBeamlineId": 376 - }, - "simulationSettings": { - "useElegant": "1", - "useImpactX": "1", - "useMadx": "1" - }, - "twissAnimation": { - "includeLattice": "1", - "notes": "" } }, "simulationType": "canvas" diff --git a/sirepo/package_data/template/canvas/examples/pip-ii.json b/sirepo/package_data/template/canvas/examples/pip-ii.json new file mode 100644 index 0000000000..b96eb9948b --- /dev/null +++ b/sirepo/package_data/template/canvas/examples/pip-ii.json @@ -0,0 +1,1535 @@ +{ + "models": { + "beamlines": [ + { + "angle": 0, + "count": 131, + "distance": 12.575607800110301, + "id": 203, + "items": [ + 101, + 102, + 103, + 104, + 103, + 105, + 106, + 103, + 107, + 103, + 102, + 108, + 109, + 110, + 102, + 111, + 112, + 113, + 114, + 102, + 115, + 116, + 117, + 204, + 118, + 116, + 119, + 102, + 103, + 120, + 103, + 105, + 106, + 103, + 121, + 103, + 102, + 108, + 103, + 122, + 123, + 124, + 125, + 126, + 127, + 111, + 128, + 113, + 129, + 102, + 102, + 102, + 103, + 130, + 103, + 131, + 103, + 132, + 103, + 105, + 106, + 103, + 130, + 103, + 102, + 133, + 122, + 134, + 126, + 135, + 136, + 136, + 134, + 102, + 137, + 102, + 103, + 138, + 103, + 131, + 139, + 105, + 106, + 103, + 138, + 103, + 102, + 103, + 140, + 141, + 142, + 116, + 117, + 204, + 143, + 115, + 144, + 145, + 146, + 147, + 102, + 103, + 148, + 103, + 131, + 139, + 105, + 106, + 103, + 148, + 103, + 102, + 140, + 103, + 103, + 102, + 141, + 149, + 134, + 136, + 136, + 134, + 102, + 126, + 150, + 102, + 103, + 151, + 103, + 131, + 152, + 105, + 106, + 103, + 151, + 103, + 102, + 140, + 103, + 103, + 141, + 153, + 122, + 154, + 204, + 155, + 102, + 156, + 102, + 157, + 102, + 158, + 102, + 159, + 102, + 160, + 102, + 161, + 102, + 162, + 102, + 163, + 102, + 163, + 204, + 164, + 165, + 102, + 106, + 102, + 103, + 166, + 103, + 131, + 167, + 105, + 106, + 103, + 166, + 103, + 102, + 140, + 103, + 103, + 141, + 168, + 169, + 122, + 112, + 113, + 114, + 122, + 170, + 116, + 117, + 204, + 171, + 172, + 102, + 103, + 173, + 103, + 131, + 174, + 103, + 105, + 106, + 103, + 173, + 103, + 102, + 140, + 103, + 103, + 141, + 122, + 122, + 175, + 112, + 113, + 114, + 176, + 102, + 177, + 178, + 179, + 178, + 102, + 180, + 102, + 103, + 181, + 103, + 131, + 182, + 103, + 105, + 106, + 103, + 181, + 103, + 102, + 140, + 103, + 103, + 141, + 122, + 122, + 122, + 122, + 122, + 122, + 122, + 126, + 102, + 103, + 183, + 103, + 131, + 184, + 103, + 105, + 106, + 103, + 183, + 103, + 102, + 185, + 103, + 186, + 103, + 141, + 122, + 102, + 187, + 188, + 153, + 189, + 190, + 116, + 191, + 117, + 204, + 192, + 193, + 102, + 103, + 194, + 103, + 131, + 195, + 103, + 105, + 106, + 103, + 194, + 103, + 102, + 185, + 103, + 186, + 103, + 141, + 196, + 197, + 122, + 198, + 199, + 122, + 122, + 200, + 201, + 122, + 122, + 122, + 202 + ], + "length": 12.575607800110301, + "name": "BL1" + } + ], + "bunchAnimation1": { + "simCode": "elegant" + }, + "bunchAnimation2": { + "simCode": "madx" + }, + "bunchAnimation3": { + "simCode": "impactx" + }, + "bunchReport1": { + "colorMap": "viridis", + "histogramBins": 80, + "notes": "", + "x": "x", + "y": "px" + }, + "bunchReport2": { + "colorMap": "viridis", + "histogramBins": 80, + "notes": "", + "x": "y", + "y": "py" + }, + "bunchReport3": { + "colorMap": "viridis", + "histogramBins": 80, + "notes": "", + "x": "x", + "y": "y" + }, + "bunchReport4": { + "colorMap": "viridis", + "histogramBins": 60, + "notes": "", + "x": "t", + "y": "pt" + }, + "commands": [], + "distribution": { + "charge": 3.076923076923077e-11, + "distributionFile": "", + "distributionType": "Waterbag", + "energy": 0.9414169775, + "halo": 0, + "k": 6.283185307179586, + "kT": 3.6e-05, + "kT_halo": 3.6e-05, + "lambdapt": 0.00013805395453660597, + "lambdapx": 0.0031422987081054935, + "lambdapy": 0.005254746703749361, + "lambdat": 0.03659255945978034, + "lambdax": 0.0006270066814117068, + "lambday": 0.0005911029275613019, + "mutpt": 0, + "muxpx": 0.7754181925611844, + "muypy": -0.09496321527817456, + "normalize": 0.41604661, + "normalize_halo": 0, + "particleCount": 5000, + "species": "proton" + }, + "elements": [ + { + "_id": 103, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0, + "name": "AP01", + "psi": 0, + "shape": "elliptical", + "type": "APERTURE", + "xmax": 0.015, + "ymax": 0.015 + }, + { + "_id": 112, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0, + "name": "AP02", + "psi": 0, + "shape": "rectangular", + "type": "APERTURE", + "xmax": 0.0068, + "ymax": 0.015 + }, + { + "_id": 114, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0, + "name": "AP03", + "psi": 0, + "shape": "rectangular", + "type": "APERTURE", + "xmax": 0.015, + "ymax": 0.0052 + }, + { + "_id": 128, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0, + "name": "AP04", + "psi": 0, + "shape": "rectangular", + "type": "APERTURE", + "xmax": 0.0054800000000000005, + "ymax": 0.015 + }, + { + "_id": 129, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0, + "name": "AP05", + "psi": 0, + "shape": "rectangular", + "type": "APERTURE", + "xmax": 0.015, + "ymax": 0.0050999999999999995 + }, + { + "_id": 134, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0, + "name": "AP06", + "psi": 0, + "shape": "rectangular", + "type": "APERTURE", + "xmax": 0.02, + "ymax": 0.00646 + }, + { + "_id": 155, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0, + "name": "AP07", + "psi": 0, + "shape": "elliptical", + "type": "APERTURE", + "xmax": 0.0105, + "ymax": 0.009 + }, + { + "_id": 156, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0, + "name": "AP08", + "psi": 0, + "shape": "elliptical", + "type": "APERTURE", + "xmax": 0.01025, + "ymax": 0.0095 + }, + { + "_id": 157, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0, + "name": "AP09", + "psi": 0, + "shape": "elliptical", + "type": "APERTURE", + "xmax": 0.01, + "ymax": 0.01 + }, + { + "_id": 158, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0, + "name": "AP10", + "psi": 0, + "shape": "elliptical", + "type": "APERTURE", + "xmax": 0.00975, + "ymax": 0.0105 + }, + { + "_id": 159, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0, + "name": "AP11", + "psi": 0, + "shape": "elliptical", + "type": "APERTURE", + "xmax": 0.0095, + "ymax": 0.011 + }, + { + "_id": 160, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0, + "name": "AP12", + "psi": 0, + "shape": "elliptical", + "type": "APERTURE", + "xmax": 0.00925, + "ymax": 0.0115 + }, + { + "_id": 161, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0, + "name": "AP13", + "psi": 0, + "shape": "elliptical", + "type": "APERTURE", + "xmax": 0.009, + "ymax": 0.012 + }, + { + "_id": 162, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0, + "name": "AP14", + "psi": 0, + "shape": "elliptical", + "type": "APERTURE", + "xmax": 0.00875, + "ymax": 0.0125 + }, + { + "_id": 163, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0, + "name": "AP15", + "psi": 0, + "shape": "elliptical", + "type": "APERTURE", + "xmax": 0.00875, + "ymax": 0.013 + }, + { + "_id": 178, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0, + "name": "AP16", + "psi": 0, + "shape": "elliptical", + "type": "APERTURE", + "xmax": 0.005, + "ymax": 0.005 + }, + { + "_id": 101, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.25, + "name": "D01", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 102, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.05, + "name": "D02", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 105, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.035000000010000004, + "name": "D03", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 106, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.035, + "name": "D04", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 108, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.009, + "name": "D05", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 109, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.009, + "name": "D06", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 110, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.0404, + "name": "D07", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 111, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.05, + "name": "D08", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 113, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 1e-23, + "name": "D09", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 115, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.02, + "name": "D10", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 116, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.03, + "name": "D11", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 117, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.12, + "name": "D12", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 119, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.0016, + "name": "D13", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 122, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.1, + "name": "D14", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 123, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.075, + "name": "D15", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 124, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.1183, + "name": "D16", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 125, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.2317, + "name": "D17", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 126, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.025, + "name": "D18", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 127, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.026, + "name": "D19", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 131, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.07, + "name": "D20", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 133, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.0065000000001, + "name": "D21", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 135, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.018600000000100002, + "name": "D22", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 136, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.25, + "name": "D23", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 137, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.0349, + "name": "D24", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 140, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.0065, + "name": "D25", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 141, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.0035, + "name": "D26", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 142, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.0429, + "name": "D27", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 144, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.3173, + "name": "D28", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 145, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.0127, + "name": "D29", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 146, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.01, + "name": "D30", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 147, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.0518, + "name": "D31", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 149, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.0953, + "name": "D32", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 150, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.0047, + "name": "D33", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 153, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.04, + "name": "D34", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 154, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.04826, + "name": "D35", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 164, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.00174, + "name": "D36", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 165, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.0003, + "name": "D37", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 168, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.081, + "name": "D38", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 169, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.019, + "name": "D39", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 170, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.1389, + "name": "D40", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 172, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.0161, + "name": "D41", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 175, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.01291, + "name": "D42", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 176, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.01209, + "name": "D43", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 177, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.07823999999999999, + "name": "D44", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 179, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.2, + "name": "D45", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 180, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.12176000000000001, + "name": "D46", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 185, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.0065, + "name": "D47", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 186, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 2e-23, + "name": "D48", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 187, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.005, + "name": "D49", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 188, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.1, + "name": "D50", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 189, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.08585, + "name": "D51", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 190, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.02829, + "name": "D52", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 191, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.03, + "name": "D53", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 193, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.01586, + "name": "D54", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 196, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.16984, + "name": "D55", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 197, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.02016, + "name": "D56", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 198, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.01133, + "name": "D57", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 199, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.03867, + "name": "D58", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 200, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.0630500000001, + "name": "D59", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 201, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.036950000000000004, + "name": "D60", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 202, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0.010607799999999999, + "name": "D61", + "psi": 0, + "type": "DRIFT" + }, + { + "_id": 204, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0, + "name": "M1", + "psi": 0, + "type": "MONITOR" + }, + { + "_id": 104, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "k1": -57.88663154157264, + "k1s": 0, + "l": 0.1, + "name": "Q01", + "psi": 0, + "type": "QUADRUPOLE" + }, + { + "_id": 107, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "k1": 51.62348780100905, + "k1s": 0, + "l": 0.1, + "name": "Q02", + "psi": 0, + "type": "QUADRUPOLE" + }, + { + "_id": 120, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "k1": -36.77224544649082, + "k1s": 0, + "l": 0.1, + "name": "Q03", + "psi": 0, + "type": "QUADRUPOLE" + }, + { + "_id": 121, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "k1": 28.706075477583155, + "k1s": 0, + "l": 0.1, + "name": "Q04", + "psi": 0, + "type": "QUADRUPOLE" + }, + { + "_id": 130, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "k1": -50.76942274547764, + "k1s": 0, + "l": 0.05, + "name": "Q05", + "psi": 0, + "type": "QUADRUPOLE" + }, + { + "_id": 132, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "k1": 46.59399358510192, + "k1s": 0, + "l": 0.1, + "name": "Q06", + "psi": 0, + "type": "QUADRUPOLE" + }, + { + "_id": 138, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "k1": -61.207995646416975, + "k1s": 0, + "l": 0.05, + "name": "Q07", + "psi": 0, + "type": "QUADRUPOLE" + }, + { + "_id": 139, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "k1": 55.03974802313464, + "k1s": 0, + "l": 0.1, + "name": "Q08", + "psi": 0, + "type": "QUADRUPOLE" + }, + { + "_id": 148, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "k1": -63.105917992042315, + "k1s": 0, + "l": 0.05, + "name": "Q09", + "psi": 0, + "type": "QUADRUPOLE" + }, + { + "_id": 151, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "k1": -60.25903447360431, + "k1s": 0, + "l": 0.05, + "name": "Q10", + "psi": 0, + "type": "QUADRUPOLE" + }, + { + "_id": 152, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "k1": 52.61989703246235, + "k1s": 0, + "l": 0.1, + "name": "Q11", + "psi": 0, + "type": "QUADRUPOLE" + }, + { + "_id": 166, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "k1": -51.243903331883985, + "k1s": 0, + "l": 0.05, + "name": "Q12", + "psi": 0, + "type": "QUADRUPOLE" + }, + { + "_id": 167, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "k1": 47.21081834743015, + "k1s": 0, + "l": 0.1, + "name": "Q13", + "psi": 0, + "type": "QUADRUPOLE" + }, + { + "_id": 173, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "k1": -63.580398578448644, + "k1s": 0, + "l": 0.05, + "name": "Q14", + "psi": 0, + "type": "QUADRUPOLE" + }, + { + "_id": 174, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "k1": 57.41215095516631, + "k1s": 0, + "l": 0.1, + "name": "Q15", + "psi": 0, + "type": "QUADRUPOLE" + }, + { + "_id": 181, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "k1": -62.86867769883914, + "k1s": 0, + "l": 0.05, + "name": "Q16", + "psi": 0, + "type": "QUADRUPOLE" + }, + { + "_id": 182, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "k1": 55.988709195947315, + "k1s": 0, + "l": 0.1, + "name": "Q17", + "psi": 0, + "type": "QUADRUPOLE" + }, + { + "_id": 183, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "k1": -43.65221394938265, + "k1s": 0, + "l": 0.05, + "name": "Q18", + "psi": 0, + "type": "QUADRUPOLE" + }, + { + "_id": 184, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "k1": 41.99153189696048, + "k1s": 0, + "l": 0.1, + "name": "Q19", + "psi": 0, + "type": "QUADRUPOLE" + }, + { + "_id": 194, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "k1": -54.09078685032198, + "k1s": 0, + "l": 0.05, + "name": "Q20", + "psi": 0, + "type": "QUADRUPOLE" + }, + { + "_id": 195, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "k1": 49.67811739674308, + "k1s": 0, + "l": 0.1, + "name": "Q21", + "psi": 0, + "type": "QUADRUPOLE" + }, + { + "_id": 118, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "freq": 162500000, + "l": 0, + "name": "RF01", + "phase": -90, + "psi": 0, + "type": "RFCAVITY", + "volt": 69923.82005491722 + }, + { + "_id": 143, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "freq": 162500000, + "l": 0, + "name": "RF02", + "phase": -90, + "psi": 0, + "type": "RFCAVITY", + "volt": 46273.116212812856 + }, + { + "_id": 171, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "freq": 162500000, + "l": 0, + "name": "RF03", + "phase": -90, + "psi": 0, + "type": "RFCAVITY", + "volt": 29820.4526704794 + }, + { + "_id": 192, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "freq": 162500000, + "l": 0, + "name": "RF04", + "phase": -90, + "psi": 0, + "type": "RFCAVITY", + "volt": 60669.19681235465 + } + ], + "rpnVariables": [], + "simulation": { + "activeBeamlineId": 203, + "folder": "/Examples", + "name": "PIP-II Linac MEBT", + "visualizationBeamlineId": 203 + } + }, + "simulationType": "canvas" +} diff --git a/sirepo/package_data/template/canvas/examples/resr-storage-ring.json b/sirepo/package_data/template/canvas/examples/resr-storage-ring.json index f980d7fe0c..7789426042 100644 --- a/sirepo/package_data/template/canvas/examples/resr-storage-ring.json +++ b/sirepo/package_data/template/canvas/examples/resr-storage-ring.json @@ -98,13 +98,14 @@ }, { "angle": 3.141592632, - "count": 50, + "count": 51, "distance": 55.098448214820294, "id": 124, "items": [ 121, 122, 123, + 128, -123, -122, -121 @@ -114,7 +115,7 @@ }, { "angle": 6.283185263999996, - "count": 100, + "count": 102, "distance": 1.189564123649247e-06, "id": 125, "items": [ @@ -126,18 +127,12 @@ } ], "bunchAnimation1": { - "histogramBins": 80, - "notes": "", "simCode": "elegant" }, "bunchAnimation2": { - "histogramBins": 80, - "notes": "", "simCode": "madx" }, "bunchAnimation3": { - "histogramBins": 80, - "notes": "", "simCode": "impactx" }, "bunchReport1": { @@ -189,7 +184,7 @@ "muypy": -3.972798687837155e-07, "normalize": 0, "normalize_halo": 0, - "particleCount": 10000, + "particleCount": 5000, "species": "proton" }, "elements": [ @@ -253,6 +248,16 @@ "psi": 0, "type": "DRIFT" }, + { + "_id": 128, + "_super": "_ELEMENT", + "dx": 0, + "dy": 0, + "l": 0, + "name": "M1", + "psi": 0, + "type": "MONITOR" + }, { "_id": 107, "_super": "_ELEMENT", @@ -426,42 +431,12 @@ "type": "SEXTUPOLE" } ], - "rpnVariables": [ - { - "name": "pi", - "value": 3.141592653589793 - }, - { - "name": "twopi", - "value": "pi * 2" - }, - { - "name": "raddeg", - "value": "pi / 180" - }, - { - "name": "degrad", - "value": "180 / pi" - } - ], - "sigmaAnimation": { - "includeLattice": "1", - "notes": "" - }, + "rpnVariables": [], "simulation": { "activeBeamlineId": 125, "folder": "/Examples", "name": "RESR-Storage-Ring", "visualizationBeamlineId": 125 - }, - "simulationSettings": { - "useElegant": "1", - "useImpactX": "1", - "useMadx": "1" - }, - "twissAnimation": { - "includeLattice": "1", - "notes": "" } }, "simulationType": "canvas" diff --git a/sirepo/pkcli/canvas.py b/sirepo/pkcli/canvas.py index 90f825409c..739fca9b16 100644 --- a/sirepo/pkcli/canvas.py +++ b/sirepo/pkcli/canvas.py @@ -30,22 +30,25 @@ _MADX = sirepo.sim_data.get_class("madx") _MADX_INPUT_FILE = "in.madx" _MODEL_FIELD_MAP = PKDict( + APERTURE=PKDict( + _type="COLLIMATOR", + _fields=["name", "l", "_id"], + ), DRIFT=PKDict( - _fields=["name", "type", "l", "_id"], + _fields=["name", "l", "_id"], ), MONITOR=PKDict( - _fields=["name", "type", "_id"], + _fields=["name", "_id"], ), QUADRUPOLE=PKDict( - _fields=["name", "type", "l", "k1", "k1s", "_id"], + _fields=["name", "l", "k1", "k1s", "_id"], ), RFCAVITY=PKDict( - _fields=["name", "type", "l", "volt", "freq", "_id"], + _fields=["name", "l", "volt", "freq", "_id"], ), SBEND=PKDict( _fields=[ "name", - "type", "l", "angle", "fint", @@ -56,7 +59,7 @@ ], ), SEXTUPOLE=PKDict( - _fields=["name", "type", "l", "k2", "k2s", "_id"], + _fields=["name", "l", "k2", "k2s", "_id"], ), ) @@ -270,7 +273,11 @@ def _command(state, values): m._id = _next_id(state) return m + def _val(cv, var_value): + return cv.eval_var_with_assert(var_value) + util = LatticeUtil(data, _SCHEMA) + cv = sirepo.template.canvas.code_var(data.models.rpnVariables) state = PKDict( next_id=util.max_id + 1, util=util, @@ -312,15 +319,21 @@ def _command(state, values): for e in data.models.elements: assert e.type in _MODEL_FIELD_MAP, f"Missing type handler: {e.type}" if e.type in _MODEL_FIELD_MAP: - m = _MADX.model_defaults(e.type) + t = _MODEL_FIELD_MAP[e.type].get("_type", e.type) + m = _MADX.model_defaults(t).pkupdate(type=t) for f in _MODEL_FIELD_MAP[e.type]._fields: m[f] = e[f] res.models.elements.append(m) if e.type == "SBEND": - m.hgap = e.gap / 2 + m.hgap = _val(cv, e.gap) / 2 _add_dipedges(res, m, state) elif e.type == "RFCAVITY": - m.lag = e.phase + m.lag = -(_val(cv, e.phase) + 90) / 360 + m.volt = _val(cv, m.volt) * 1e-6 + m.freq = _val(cv, m.freq) * 1e-6 + elif e.type == "APERTURE": + m.apertype = "rectangle" if e.shape == "rectangular" else "ellipse" + m.aperture = f"{{{e.xmax},{e.ymax}}}" sirepo.template.madx.add_observers(LatticeUtil(res, _MADX.schema()), "MONITOR") return res diff --git a/sirepo/template/canvas.py b/sirepo/template/canvas.py index 0631e77135..5d5a7df3b9 100644 --- a/sirepo/template/canvas.py +++ b/sirepo/template/canvas.py @@ -43,6 +43,10 @@ class CanvasMadxConverter(MadxConverter): _FIELD_MAP = [ + [ + "COLLIMATOR", + ["APERTURE", "l"], + ], [ "DRIFT", ["DRIFT", "l"], @@ -87,12 +91,25 @@ def _fixup_element(self, element_in, element_out): if self.from_class.sim_type() == SIM_TYPE: pass else: + if element_in.type == "COLLIMATOR": + element_out.shape = ( + "rectangular" + if element_in.apertype == "rectangle" + else "elliptical" + ) + m = re.search(r"^\{?\s*(.*?),\s*(.*?)\s*\}?$", element_in.aperture) + if m: + element_out.xmax = float(m.group(1)) + element_out.ymax = float(m.group(2)) if element_in.type == "DIPEDGE": self.dipedges[element_out._id] = element_in elif element_in.type == "SBEND": element_out.gap = self.__val(element_in.hgap) * 2 if element_out.fintx == -1: element_out.fintx = element_out.fint + elif element_in.type == "RFCAVITY": + element_out.volt = self.__val(element_out.volt) * 1e6 + element_out.phase = self.__val(element_out.phase) * -180 def __merge_dipedges(self, data): # dipedge in: {'e1': 0.048345620280243, 'fint': 0.0, 'h': 0.096653578905433, 'hgap': 0.0, } @@ -237,7 +254,7 @@ def _to_elegant(field): if field == "t": v = -numpy.array(v) * scipy.constants.c if s is not None: - v += s + v -= v.mean() elif field == "pt": v = _elegant_p_to_pt(frame_args.run_dir, v) return v, s @@ -498,17 +515,16 @@ def _elegant_p_to_pt(run_dir, values): "elegant/run_setup.output.sdds", "pCentral" ), )() - return -( - ( - kinematic.Converter( - mass=mass, - mass_unit="SI", - betagamma=numpy.array(values), - )(silent=True)["gamma"] - - ref["gamma"] - ) - / ref["betagamma"] - ) + return ( + kinematic.Converter( + mass=mass, + mass_unit="SI", + betagamma=numpy.array(values), + )( + silent=True + )["gamma"] + - ref["gamma"] + ) / ref["betagamma"] def _generate_parameters_file(data): diff --git a/sirepo/template/elegant.py b/sirepo/template/elegant.py index 4a2aee787e..95595a879b 100644 --- a/sirepo/template/elegant.py +++ b/sirepo/template/elegant.py @@ -423,12 +423,8 @@ class ElegantMadxConverter(MadxConverter): ["RCOL", "l", "x_max=xsize", "y_max=ysize"], ], [ - "COLLIMATOR apertype=ELLIPSE", - ["ECOL", "l", "x_max=xsize", "y_max=ysize"], - ], - [ - "COLLIMATOR apertype=RECTANGLE", - ["RCOL", "l", "x_max=xsize", "y_max=ysize"], + "COLLIMATOR", + ["ECOL", "l"], ], [ "RFCAVITY", @@ -556,6 +552,17 @@ def _fixup_element(self, element_in, element_out): for f in scale: if f in element_out: element_out[f] = f"{element_out[f]} {op} {scale[f]}" + if element_in.type == "COLLIMATOR": + m = re.search(r"^\{?\s*(.*?),\s*(.*?)\s*\}?$", element_in.aperture) + if m: + element_out.x_max = float(m.group(1)) + element_out.y_max = float(m.group(2)) + if element_in.apertype == "rectangle": + element_out.type = "RCOL" + elif element_in.type == "RFCAVITY": + element_out.phase = self.__val(element_out.phase) * 360 + 180 + while element_out.phase >= 360: + element_out.phase -= 360 def __combine_dipedge(self, data): # DIPEDGE elements get converted into a CSBEND with no length @@ -634,6 +641,9 @@ def _var(v): ) # TODO(pjm): determine conversion from momentum_chirp to db_s_coupling + def __val(self, var_value): + return self.vars.eval_var_with_assert(var_value) + def background_percent_complete(report, run_dir, is_running): def _percent(data, last_element, step): @@ -732,7 +742,7 @@ def convert_to_sdds(openpmd_file): elegant_p = kinematic.Converter( mass=d.attrs["mass_ref"], mass_unit="SI", - gamma=-numpy.array(d["momentum/t"]) * ref["betagamma"] + ref["gamma"], + gamma=numpy.array(d["momentum/t"]) * ref["betagamma"] + ref["gamma"], )(silent=True)["betagamma"] s = writeSDDS() diff --git a/sirepo/template/impactx.py b/sirepo/template/impactx.py index 2b50430a27..9937e8835f 100644 --- a/sirepo/template/impactx.py +++ b/sirepo/template/impactx.py @@ -14,12 +14,12 @@ from sirepo.template.madx_converter import MadxConverter import numpy import pandas +import re import sirepo.lib import sirepo.sim_data import sirepo.template.lattice import sirepo.template.sdds_util - FINAL_DISTRIBUTION_OUTPUT_FILE = "diags/final_distribution.h5" # _DEFAULT_NSLICE = 12 _DEFAULT_NSLICE = 1 @@ -31,12 +31,14 @@ l="ds", ) _TYPE_TO_CLASS = PKDict( + APERTURE="Aperture", BEAMMONITOR="BeamMonitor", DIPEDGE="DipEdge", DRIFT="Drift", KICKER="Kicker", QUAD="Quad", SBEND="Sbend", + SHORTRF="ShortRF", SOL="Sol", ) @@ -69,6 +71,10 @@ def write_files(self, data, source_path, dest_dir): class ImpactxMadxConverter(MadxConverter): _FIELD_MAP = [ + [ + "COLLIMATOR", + ["APERTURE"], + ], [ "DRIFT", ["DRIFT", "l"], @@ -97,6 +103,10 @@ class ImpactxMadxConverter(MadxConverter): "MONITOR", ["BEAMMONITOR"], ], + [ + "RFCAVITY", + ["SHORTRF", "V=volt", "freq", "phase=lag"], + ], ] def __init__(self, qcall=None, nslice=1, **kwargs): @@ -110,6 +120,7 @@ def __init__(self, qcall=None, nslice=1, **kwargs): self.nslice = nslice def from_madx(self, madx): + self.beam = sirepo.template.lattice.LatticeUtil.find_first_command(madx, "beam") data = self.fill_in_missing_constants(super().from_madx(madx), PKDict()) self._remove_zero_drifts(data) return data @@ -130,6 +141,16 @@ def _fixup_element(self, element_in, element_out): element_out.rc = 0 if element_out.rc == 0: element_out.type = "DRIFT" + elif element_in.type == "COLLIMATOR": + m = re.search(r"^\{?\s*(.*?),\s*(.*?)\s*\}?$", element_in.aperture) + if m: + element_out.xmax = float(m.group(1)) + element_out.ymax = float(m.group(2)) + element_out.shape = ( + "rectangular" + if element_in.apertype == "rectangle" + else "elliptical" + ) elif element_in.type == "DIPEDGE": if self.__val(element_in.h) != 0: element_out.rc = 1.0 / self.__val(element_in.h) @@ -149,6 +170,21 @@ def _fixup_element(self, element_in, element_out): elif element_in.type == "MONITOR" and self.__val(element_in.l) > 0: # TODO(pjm) add drift pass + elif element_in.type == "RFCAVITY" and self.__val(element_in.freq) == 0: + if self.__val(element_in.l) > 0: + element_out.l = element_in.l + element_out.type = "DRIFT" + elif element_in.type == "RFCAVITY": + element_out.phase = -(self.__val(element_out.phase) * 360 + 90) + element_out.freq = self.__val(element_out.freq) * 1e6 + p = "electron" + if ( + self.beam + and self.beam.particle in SCHEMA.constants.particleMassAndCharge + ): + p = self.beam.particle + mc = SCHEMA.constants.particleMassAndCharge.get(p) + element_out.V = self.__val(element_out.V) / (mc[0] * 1e3) def __val(self, var_value): return self.vars.eval_var_with_assert(var_value) @@ -338,6 +374,8 @@ def _generate_elements(util): f[1] = cv.eval_var_with_assert(f[1]) if f[0] == "nslice": f[1] = int(f[1]) + elif f[2] in util.schema.enum: + f[1] = f'"{f[1]}"' fres.append(f"{f[0]}={f[1]}") res += ", ".join(fres) + "),\n" return res diff --git a/sirepo/template/zgoubi.py b/sirepo/template/zgoubi.py index 7990a2a6e1..abd56ad257 100644 --- a/sirepo/template/zgoubi.py +++ b/sirepo/template/zgoubi.py @@ -686,7 +686,7 @@ def _extract_animation(frame_args): it_filter = None if _particle_count(frame_args.sim_in) <= SCHEMA.constants.maxFilterPlotParticles: if frame_args.particleSelector != "all": - it_filter = frame_args.particleSelector + it_filter = str(frame_args.particleSelector) count = 0 el_names = [] @@ -800,7 +800,7 @@ def _extract_spin_3d(frame_args): it_idx = int(col_names.index("IT")) it_filter = None if frame_args.particleSelector != "all": - it_filter = frame_args.particleSelector + it_filter = str(frame_args.particleSelector) for row in all_rows: if it_filter and it_filter != row[it_idx]: continue