Ejemplo n.º 1
0
 def sim(self):
     d = self.data
     self.jinja_env = template_common.flatten_data(d.models, PKDict())
     self._code_var = code_var(d.models.rpnVariables)
     if 'bunchReport' in d.get('report', ''):
         return self._bunch_simulation()
     return self._full_simulation()
Ejemplo n.º 2
0
def generate_parameters_file(data, is_parallel=False):
    _validate_data(data, _SCHEMA)
    v = template_common.flatten_data(data["models"], {})
    longitudinal_method = int(data["models"]["bunch"]["longitudinalMethod"])

    # sigma s, sigma dp, dp s coupling
    if longitudinal_method == 1:
        v["bunch_emit_z"] = 0
        v["bunch_beta_z"] = 0
        v["bunch_alpha_z"] = 0
    # sigma s, sigma dp, alpha z
    elif longitudinal_method == 2:
        v["bunch_emit_z"] = 0
        v["bunch_beta_z"] = 0
        v["bunch_dp_s_coupling"] = 0
    # emit z, beta z, alpha z
    elif longitudinal_method == 3:
        v["bunch_sigma_dp"] = 0
        v["bunch_sigma_s"] = 0
        v["bunch_dp_s_coupling"] = 0
    if data["models"]["bunchSource"]["inputSource"] == "sdds_beam":
        v["bunch_beta_x"] = 5
        v["bunch_beta_y"] = 5
        v["bunch_alpha_x"] = 0
        v["bunch_alpha_x"] = 0
    v["rpn_variables"] = _generate_variables(data)

    if is_parallel:
        filename_map = _build_filename_map(data)
        beamline_map = _build_beamline_map(data)
        v["commands"] = _generate_commands(data, filename_map, beamline_map, v)
        v["lattice"] = generate_lattice(data, filename_map, beamline_map, v)
        return pkjinja.render_resource("elegant.py", v)

    return pkjinja.render_resource("elegant_bunch.py", v)
Ejemplo n.º 3
0
def _generate_parameters_file(data):
    v = None
    template_common.validate_models(data, _SCHEMA)
    v = template_common.flatten_data(data['models'], {})
    v['particlePeriod'] = _PARTICLE_PERIOD
    v['particleFile'] = _PARTICLE_FILE
    v['densityFile'] = _DENSITY_FILE
    v['egunCurrentFile'] = _EGUN_CURRENT_FILE
    v['conductors'] = _prepare_conductors(data)
    v['maxConductorVoltage'] = _max_conductor_voltage(data)
    v['is3D'] = _is_3D(data)
    if not v['is3D']:
        v['simulationGrid_num_y'] = v['simulationGrid_num_x']
        v['simulationGrid_channel_height'] = v['simulationGrid_channel_width']
    if 'report' not in data:
        data['report'] = 'animation'
    v['isOptimize'] = data['report'] == 'optimizerAnimation'
    if v['isOptimize']:
        _replace_optimize_variables(data, v)
    res = _render_jinja('base', v)
    if data['report'] == 'animation':
        if data['models']['simulation']['egun_mode'] == '1':
            v['egunStatusFile'] = _EGUN_STATUS_FILE
            res += _render_jinja('egun', v)
        else:
            res += _render_jinja('visualization', v)
        res += _render_jinja('impact-density', v)
    elif data['report'] == 'optimizerAnimation':
        res += _render_jinja('parameters-optimize', v)
    else:
        res += _render_jinja('source-field', v)
    return res, v
Ejemplo n.º 4
0
def _generate_parameters_file(data, run_dir=None, is_parallel=False):
    _validate_data(data, simulation_db.get_schema(SIM_TYPE))
    _convert_meters_to_centimeters(data['models'])
    _convert_meters_to_centimeters(data['models']['beamline'])
    v = template_common.flatten_data(data['models'], {})
    r = data['report']
    report_model = data['models'][r]
    beamline = data['models']['beamline']
    v['shadowOutputFile'] = _SHADOW_OUTPUT_FILE

    if r == 'initialIntensityReport':
        v['distanceFromSource'] = beamline[0]['position'] if len(
            beamline) else template_common.DEFAULT_INTENSITY_DISTANCE
    elif _SIM_DATA.is_watchpoint(r):
        v['beamlineOptics'] = _generate_beamline_optics(
            data['models'], _SIM_DATA.watchpoint_id(r))
    else:
        v['distanceFromSource'] = report_model['distanceFromSource']

    if v['simulation_sourceType'] == 'bendingMagnet':
        v['bendingMagnetSettings'] = _generate_bending_magnet(data)
    elif v['simulation_sourceType'] == 'geometricSource':
        v['geometricSourceSettings'] = _generate_geometric_source(data)
    elif v['simulation_sourceType'] == 'wiggler':
        v['wigglerSettings'] = _generate_wiggler(data)
        v['wigglerTrajectoryFilename'] = _WIGGLER_TRAJECTOR_FILENAME
        v['wigglerTrajectoryInput'] = ''
        if data['models']['wiggler']['b_from'] in ('1', '2'):
            v['wigglerTrajectoryInput'] = _SIM_DATA.shadow_wiggler_file(
                data.models.wiggler.trajFile)
    return template_common.render_jinja(SIM_TYPE, v)
Ejemplo n.º 5
0
def _generate_parameters_file(data, run_dir=None, is_parallel=False):
    v = None
    template_common.validate_models(data, _SCHEMA)
    v = template_common.flatten_data(data['models'], {})
    v['outputDir'] = '"{}"'.format(run_dir) if run_dir else None
    v['particlePeriod'] = _PARTICLE_PERIOD
    v['particleFile'] = _PARTICLE_FILE
    v['impactDensityCalculation'] = _generate_impact_density()
    v['egunCurrentFile'] = _EGUN_CURRENT_FILE
    v['conductorLatticeAndParticleScraper'] = _generate_lattice(data)
    v['maxConductorVoltage'] = _max_conductor_voltage(data)
    v['is3D'] = data.models.simulationGrid.simulation_mode == '3d'
    if not v['is3D']:
        v['simulationGrid_num_y'] = v['simulationGrid_num_x']
        v['simulationGrid_channel_height'] = v['simulationGrid_channel_width']
    template_name = ''
    if 'report' not in data:
        template_name = 'visualization'
    elif data['report'] == 'animation':
        if data['models']['simulation']['egun_mode'] == '1':
            v['egunStatusFile'] = _EGUN_STATUS_FILE
            template_name = 'egun'
        else:
            template_name = 'visualization'
    else:
        template_name = 'source-field'
    return template_common.render_jinja(SIM_TYPE, v, 'base.py') \
        + template_common.render_jinja(SIM_TYPE, v, '{}.py'.format(template_name))
Ejemplo n.º 6
0
def generate_parameters_file(data, schema, run_dir=None, run_async=False):
    if 'report' in data and (re.search('watchpointReport', data['report']) or data['report'] == 'sourceIntensityReport'):
        # render the watchpoint report settings in the initialIntensityReport template slot
        data['models']['initialIntensityReport'] = data['models'][data['report']].copy()
    _validate_data(data, schema)
    last_id = None
    if 'report' in data:
        m = re.search('watchpointReport(\d+)', data['report'])
        if m:
            last_id = int(m.group(1))
    if int(data['models']['simulation']['samplingMethod']) == 2:
        data['models']['simulation']['sampleFactor'] = 0
    v = template_common.flatten_data(data['models'], {})
    v['beamlineOptics'] = _generate_beamline_optics(data['models'], last_id)

    if 'report' in data and 'distanceFromSource' in data['models'][data['report']]:
        position = data['models'][data['report']]['distanceFromSource']
    else:
        position = _get_first_element_position(data)
    v['beamlineFirstElementPosition'] = position
    # initial drift = 1/2 undulator length + 2 periods
    source_type = data['models']['simulation']['sourceType']
    drift = 0
    if source_type == 'u':
        drift = -0.5 * data['models']['undulator']['length'] - 2 * data['models']['undulator']['period']
    else:
        #TODO(pjm): allow this to be set in UI?
        drift = 0
    v['electronBeamInitialDrift'] = drift
    # 1: auto-undulator 2: auto-wiggler
    v['energyCalculationMethod'] = 1 if source_type == 'u' else 2
    v['userDefinedElectronBeam'] = 1
    if 'isReadOnly' in data['models']['electronBeam'] and data['models']['electronBeam']['isReadOnly']:
        v['userDefinedElectronBeam'] = 0
    return pkjinja.render_resource('srw.py', v)
Ejemplo n.º 7
0
def _generate_parameters_file(data, run_dir=None, is_parallel=False):
    _validate_data(data, _SCHEMA)
    _scale_units(data)
    v = template_common.flatten_data(data.models, PKDict())
    r = data.report
    report_model = data.models[r]
    beamline = data.models.beamline
    v.shadowOutputFile = _SHADOW_OUTPUT_FILE

    if r == 'initialIntensityReport':
        v.distanceFromSource = beamline[
            0].position if beamline else template_common.DEFAULT_INTENSITY_DISTANCE
    elif _SIM_DATA.is_watchpoint(r):
        v.beamlineOptics = _generate_beamline_optics(
            data.models, _SIM_DATA.watchpoint_id(r))
    else:
        v.distanceFromSource = report_model.distanceFromSource

    if v.simulation_sourceType == 'bendingMagnet':
        v.bendingMagnetSettings = _generate_bending_magnet(data)
    elif v.simulation_sourceType == 'geometricSource':
        v.geometricSourceSettings = _generate_geometric_source(data)
    elif v.simulation_sourceType == 'wiggler':
        v.wigglerSettings = _generate_wiggler(data)
        v.wigglerTrajectoryFilename = _WIGGLER_TRAJECTORY_FILENAME
        v.wigglerTrajectoryInput = ''
        if data.models.wiggler.b_from in ('1', '2'):
            v.wigglerTrajectoryInput = _SIM_DATA.shadow_wiggler_file(
                data.models.wiggler.trajFile)
    return template_common.render_jinja(SIM_TYPE, v)
Ejemplo n.º 8
0
def _generate_parameters_file(data, run_dir=None, is_parallel=False):
    _validate_data(data, simulation_db.get_schema(SIM_TYPE))
    _convert_meters_to_centimeters(data['models'])
    _convert_meters_to_centimeters(data['models']['beamline'])
    v = template_common.flatten_data(data['models'], {})
    r = data['report']
    report_model = data['models'][r]
    beamline = data['models']['beamline']
    v['shadowOutputFile'] = _SHADOW_OUTPUT_FILE

    if r == 'initialIntensityReport':
        v['distanceFromSource'] = beamline[0]['position'] if len(beamline) else template_common.DEFAULT_INTENSITY_DISTANCE
    elif template_common.is_watchpoint(r):
        v['beamlineOptics'] = _generate_beamline_optics(data['models'], template_common.watchpoint_id(r))
    else:
        v['distanceFromSource'] = report_model['distanceFromSource']

    if v['simulation_sourceType'] == 'bendingMagnet':
        v['bendingMagnetSettings'] = _generate_bending_magnet(data)
    elif v['simulation_sourceType'] == 'geometricSource':
        v['geometricSourceSettings'] = _generate_geometric_source(data)
    elif v['simulation_sourceType'] == 'wiggler':
        v['wigglerSettings'] = _generate_wiggler(data)
        v['wigglerTrajectoryFilename'] = _WIGGLER_TRAJECTOR_FILENAME
        v['wigglerTrajectoryInput'] = ''
        if data['models']['wiggler']['b_from'] in ('1', '2'):
            v['wigglerTrajectoryInput'] = _wiggler_file(data['models']['wiggler']['trajFile'])
    return template_common.render_jinja(SIM_TYPE, v)
Ejemplo n.º 9
0
def _generate_parameters_file(run_dir, data):
    report = data['report'] if 'report' in data else None
    if report and report != 'epicsServerAnimation':
        return ''
    #template_common.validate_models(data, simulation_db.get_schema(SIM_TYPE))

    # copy model values into beamline elements
    kicker_values = []
    count = 0
    for idx in range(len(data.models.elements)):
        el = data.models.elements[idx]
        key = '{}{}'.format(el.type, el._id)
        if key in data.models:
            data.models.elements[idx] = data.models[key]
            el = data.models.elements[idx]
        if el.type == 'KICKER':
            kicker_values += [el.hkick, el.vkick]
            count += 1
            el.hkick = '{' + 'vagrant_corrector{}_HCurrent'.format(count) + '}'
            el.vkick = '{' + 'vagrant_corrector{}_VCurrent'.format(count) + '}'
    if run_dir:
        np.save(str(run_dir.join(CURRENT_FILE)),
                np.array([CURRENT_FIELDS, kicker_values]))
    v = template_common.flatten_data(data['models'], {})
    from sirepo.template import elegant
    #TODO(pjm): calling private template.elegant._build_beamline_map()
    data.models.commands = []
    v['currentFile'] = CURRENT_FILE
    v['fodoLattice'] = elegant.generate_lattice(
        data, elegant._build_filename_map(data),
        elegant._build_beamline_map(data), v)
    v['BPM_FIELDS'] = BPM_FIELDS
    v['CURRENT_FIELDS'] = CURRENT_FIELDS
    return template_common.render_jinja(SIM_TYPE, v)
Ejemplo n.º 10
0
def _generate_parameters_file(data, run_dir=None, is_parallel=False):
    _validate_data(data, _SCHEMA)
    _scale_units(data)
    v = template_common.flatten_data(data.models, PKDict())
    r = data.report
    report_model = data.models[r]
    beamline = data.models.beamline
    v.shadowOutputFile = _SHADOW_OUTPUT_FILE
    if _has_zone_plate(beamline):
        v.zonePlateMethods = template_common.render_jinja(
            SIM_TYPE, v, 'zone_plate.py')

    if v.simulation_sourceType == 'bendingMagnet':
        v.bendingMagnetSettings = _generate_bending_magnet(data)
    elif v.simulation_sourceType == 'geometricSource':
        v.geometricSourceSettings = _generate_geometric_source(data)
    elif v.simulation_sourceType == 'wiggler':
        v.wigglerSettings = _generate_wiggler(data)
        v.wigglerTrajectoryFilename = _WIGGLER_TRAJECTORY_FILENAME
        v.wigglerTrajectoryInput = ''
        if data.models.wiggler.b_from in ('1', '2'):
            v.wigglerTrajectoryInput = _SIM_DATA.shadow_wiggler_file(
                data.models.wiggler.trajFile)
    elif v.simulation_sourceType == 'undulator':
        v.undulatorSettings = template_common.render_jinja(
            SIM_TYPE, v, 'undulator.py')

    if r == 'initialIntensityReport':
        v.distanceFromSource = beamline[
            0].position if beamline else template_common.DEFAULT_INTENSITY_DISTANCE
    elif r == 'beamStatisticsReport':
        v.simulation_npoint = 10000
        v.beamlineOptics = _generate_beamline_optics(data.models,
                                                     calc_beam_stats=True)
        v.beamStatsFile = BEAM_STATS_FILE
        assert v.simulation_sourceType in ('bendingMagnet', 'geometricSource',
                                           'undulator')
        if v.simulation_sourceType == 'geometricSource':
            if v.geometricSource_f_color == '1':
                v.photonEnergy = v.geometricSource_singleEnergyValue
            else:
                v.photonEnergy = (v.geometricSource_ph1 +
                                  v.geometricSource_ph2) / 2
        elif v.simulation_sourceType == 'undulator':
            if v.undulator_select_energy == 'range':
                v.photonEnergy = (v.undulator_emin + v.undulator_emax) / 2
            else:
                v.photonEnergy = v.undulator_photon_energy
        elif v.simulation_sourceType == 'bendingMagnet':
            v.photonEnergy = v.bendingMagnet_ph1
        return template_common.render_jinja(SIM_TYPE, v, 'beam_statistics.py')
    elif _SIM_DATA.is_watchpoint(r):
        v.beamlineOptics = _generate_beamline_optics(
            data.models, last_id=_SIM_DATA.watchpoint_id(r))
    else:
        v.distanceFromSource = report_model.distanceFromSource
    return template_common.render_jinja(SIM_TYPE, v)
Ejemplo n.º 11
0
def generate_parameters_file(data, is_parallel=False):
    _validate_data(data, _SCHEMA)
    v = template_common.flatten_data(data['models'], {})
    v['rpn_variables'] = _generate_variables(data)

    if is_parallel:
        return _generate_full_simulation(data, v)

    if 'report' in data and data['report'] == 'twissReport':
        return _generate_twiss_simulation(data, v)

    return _generate_bunch_simulation(data, v)
Ejemplo n.º 12
0
def generate_parameters_file(data, is_parallel=False):
    _validate_data(data, _SCHEMA)
    v = template_common.flatten_data(data['models'], {})
    v['rpn_variables'] = _generate_variables(data)

    if is_parallel:
        return _generate_full_simulation(data, v)

    if 'report' in data and data['report'] == 'twissReport':
        return _generate_twiss_simulation(data, v)

    return _generate_bunch_simulation(data, v)
Ejemplo n.º 13
0
def _generate_parameters_file(data, run_dir=None, is_parallel=False):
    template_common.validate_models(data, _SCHEMA)
    v = template_common.flatten_data(data['models'], {})
    v['optionsCommand'] = _generate_options(data['models'])
    v['solenoidCommand'] = _generate_solenoid(data['models'])
    v['beamCommand'] = _generate_beam(data['models'])
    v['currentCommand'] = _generate_current(data['models'])
    v['chargeCommand'] = _generate_charge(data['models'])
    if is_parallel:
        v['latticeCommands'] = _generate_lattice(data['models'])
    else:
        v['latticeCommands'] = _DEFAULT_DRIFT_ELEMENT
    return template_common.render_jinja(SIM_TYPE, v)
Ejemplo n.º 14
0
def _generate_parameters_file(data):
    v = template_common.flatten_data(data.models, {})
    report = data.report if 'report' in data else ''
    v['particleDef'] = _generate_particle(data.models.particle)
    v['beamlineElements'] = _generate_beamline_elements(report, data)
    v['bunchCoordinates'] = data.models.bunch.coordinates
    res = template_common.render_jinja(SIM_TYPE, v, 'base.py')
    if 'twissReport' in report or 'opticsReport' in report or report == 'twissSummaryReport':
        return res + template_common.render_jinja(SIM_TYPE, v, 'twiss.py')
    v['outputFile'] = _ZGOUBI_DATA_FILE
    res += template_common.render_jinja(SIM_TYPE, v, 'bunch.py')
    if 'bunchReport' in report:
        return res + template_common.render_jinja(SIM_TYPE, v,
                                                  'bunch-report.py')
    return res + template_common.render_jinja(SIM_TYPE, v)
Ejemplo n.º 15
0
def generate_parameters_file(data, is_parallel=False):
    template_common.validate_models(data, _SCHEMA)
    v = template_common.flatten_data(data['models'], {})
    v['isAnimationView'] = is_parallel
    v['incSteps'] = 50
    v['diagnosticPeriod'] = 50
    if data['models']['simulation']['sourceType'] == 'electronBeam':
        v['useBeam'] = 1
        v['useLaser'] = 0
    else:
        v['useBeam'] = 0
        v['useLaser'] = 1
    if data['models']['electronBeam']['beamRadiusMethod'] == 'a':
        v['electronBeam_transverseEmittance'] = 0
    return template_common.render_jinja(SIM_TYPE, v)
Ejemplo n.º 16
0
def _generate_parameters_file(data):
    _validate_data(data, _SCHEMA)
    v = template_common.flatten_data(data['models'], {})
    beamline_map = _build_beamline_map(data)
    v['lattice'] = _generate_lattice(data, beamline_map, v)
    v['diagnosticFilename'] = _BEAM_EVOLUTION_OUTPUT_FILENAME
    res = template_common.render_jinja(SIM_TYPE, v, 'base.py')
    report = data['report'] if 'report' in data else ''
    if report == 'bunchReport' or report == 'twissReport' or report == 'twissReport2':
        res += template_common.render_jinja(SIM_TYPE, v, 'twiss.py')
        if report == 'bunchReport':
            res += template_common.render_jinja(SIM_TYPE, v, 'bunch.py')
    else:
        res += template_common.render_jinja(SIM_TYPE, v, 'parameters.py')
    return res
Ejemplo n.º 17
0
def _generate_parameters_file(data):
    v = template_common.flatten_data(data.models, {})
    report = data.report if 'report' in data else ''
    v['particleDef'] = _generate_particle(data.models.particle)
    v['beamlineElements'] = _generate_beamline_elements(report, data)
    res = template_common.render_jinja(SIM_TYPE, v, 'base.py')
    if 'twissReport' in report:
        return res + template_common.render_jinja(SIM_TYPE, v, 'twiss.py')
    if 'opticsReport' in report:
        return res + template_common.render_jinja(SIM_TYPE, v, 'optics.py')
    v['outputFile'] = _ZGOUBI_DATA_FILE
    res += template_common.render_jinja(SIM_TYPE, v, 'bunch.py')
    if 'bunchReport' in report:
        return res + template_common.render_jinja(SIM_TYPE, v, 'bunch-report.py')
    return res + template_common.render_jinja(SIM_TYPE, v)
Ejemplo n.º 18
0
def generate_parameters_file(data, run_dir=None, is_parallel=False):
    _validate_data(data, simulation_db.get_schema(_SIMULATION_TYPE))
    v = template_common.flatten_data(data['models'], {})
    v['outputDir'] = '"{}"'.format(run_dir) if run_dir else None
    v['isAnimationView'] = is_parallel
    v['incSteps'] = 50
    v['diagnosticPeriod'] = 50
    if data['models']['simulation']['sourceType'] == 'electronBeam':
        v['useBeam'] = 1
        v['useLaser'] = 0
    else:
        v['useBeam'] = 0
        v['useLaser'] = 1
    if data['models']['electronBeam']['beamRadiusMethod'] == 'a':
        v['electronBeam_transverseEmittance'] = 0
    return pkjinja.render_resource('warp.py', v)
Ejemplo n.º 19
0
def generate_parameters_file(data, run_dir=None, is_parallel=False):
    template_common.validate_models(data, _SCHEMA)
    v = template_common.flatten_data(data['models'], {})
    v['outputDir'] = '"{}"'.format(run_dir) if run_dir else None
    v['isAnimationView'] = is_parallel
    v['incSteps'] = 50
    v['diagnosticPeriod'] = 50
    if data['models']['simulation']['sourceType'] == 'electronBeam':
        v['useBeam'] = 1
        v['useLaser'] = 0
    else:
        v['useBeam'] = 0
        v['useLaser'] = 1
    if data['models']['electronBeam']['beamRadiusMethod'] == 'a':
        v['electronBeam_transverseEmittance'] = 0
    return template_common.render_jinja(SIM_TYPE, v)
Ejemplo n.º 20
0
def _generate_parameters_file(data):
    report = data['report'] if 'report' in data else None
    template_common.validate_models(data, simulation_db.get_schema(SIM_TYPE))
    v = template_common.flatten_data(data['models'], {})
    v['beamEvolutionOutputFilename'] = _BEAM_EVOLUTION_OUTPUT_FILENAME
    v['runSimulation'] = report is None or report == 'animation'
    v['runRateCalculation'] = report is None or report == 'rateCalculationReport'
    if data['models']['ring']['latticeSource'] == 'madx':
        v['latticeFilename'] = template_common.lib_file_name('ring', 'lattice', v['ring_lattice'])
    else:
        v['latticeFilename'] = JSPEC_TWISS_FILENAME
    if v['ionBeam_beam_type'] == 'continuous':
        v['ionBeam_rms_bunch_length'] = 0
    v['simulationSettings_ibs'] = 'on' if v['simulationSettings_ibs'] == '1' else 'off'
    v['simulationSettings_e_cool'] = 'on' if v['simulationSettings_e_cool'] == '1' else 'off'
    return template_common.render_jinja(SIM_TYPE, v)
Ejemplo n.º 21
0
def generate_parameters_file(data, schema, run_dir=None, run_async=False):
    if 'report' in data and (re.search('watchpointReport', data['report'])
                             or data['report'] == 'sourceIntensityReport'):
        # render the watchpoint report settings in the initialIntensityReport template slot
        data['models']['initialIntensityReport'] = data['models'][
            data['report']].copy()
    _validate_data(data, schema)
    last_id = None
    if 'report' in data:
        m = re.search('watchpointReport(\d+)', data['report'])
        if m:
            last_id = int(m.group(1))
    if int(data['models']['simulation']['samplingMethod']) == 2:
        data['models']['simulation']['sampleFactor'] = 0
    v = template_common.flatten_data(data['models'], {})
    v['beamlineOptics'] = _generate_beamline_optics(data['models'], last_id)
    # und_g and und_ph API units are mm rather than m
    v['tabulatedUndulator_gap'] *= 1000
    v['tabulatedUndulator_phase'] *= 1000

    if 'report' in data and 'distanceFromSource' in data['models'][
            data['report']]:
        position = data['models'][data['report']]['distanceFromSource']
    else:
        position = _get_first_element_position(data)
    v['beamlineFirstElementPosition'] = position
    # initial drift = 1/2 undulator length + 2 periods
    source_type = data['models']['simulation']['sourceType']
    drift = 0
    if source_type == 'u':
        drift = -0.5 * data['models']['undulator']['length'] - 2 * data[
            'models']['undulator']['period']
        # undulator longitudinal center only set with tabulatedUndulator
        v['tabulatedUndulator_longitudinalPosition'] = 0
    else:
        #TODO(pjm): allow this to be set in UI?
        drift = 0
    v['electronBeamInitialDrift'] = drift
    # 1: auto-undulator 2: auto-wiggler
    v['energyCalculationMethod'] = 2
    if source_type == 'u' or source_type == 't':
        v['energyCalculationMethod'] = 1
    v['userDefinedElectronBeam'] = 1
    if 'isReadOnly' in data['models']['electronBeam'] and data['models'][
            'electronBeam']['isReadOnly']:
        v['userDefinedElectronBeam'] = 0
    return pkjinja.render_resource('srw.py', v)
Ejemplo n.º 22
0
def _generate_parameters_file(data, run_dir=None, is_parallel=False):
    _validate_data(data, simulation_db.get_schema(SIM_TYPE))
    _convert_meters_to_centimeters(data['models'])
    _convert_meters_to_centimeters(data['models']['beamline'])
    v = template_common.flatten_data(data['models'], {})
    r = data['report']
    report_model = data['models'][r]
    beamline = data['models']['beamline']

    if r == 'initialIntensityReport':
        v['distanceFromSource'] = beamline[0]['position'] if len(
            beamline) else template_common.DEFAULT_INTENSITY_DISTANCE
    elif template_common.is_watchpoint(r):
        v['beamlineOptics'] = _generate_beamline_optics(
            data['models'], template_common.watchpoint_id(r))
    else:
        v['distanceFromSource'] = report_model['distanceFromSource']
    return pkjinja.render_resource('shadow.py', v)
Ejemplo n.º 23
0
def _generate_parameters_file(data):
    report = data.report if 'report' in data else None
    _set_mass_and_charge(data.models.ionBeam)
    template_common.validate_models(data, simulation_db.get_schema(SIM_TYPE))
    v = template_common.flatten_data(data.models, PKDict())
    v.beamEvolutionOutputFilename = _BEAM_EVOLUTION_OUTPUT_FILENAME
    v.runSimulation = report is None or report == 'animation'
    v.runRateCalculation = report is None or report == 'rateCalculationReport'
    if data.models.ring.latticeSource == 'madx':
        v.latticeFilename = _SIM_DATA.lib_file_name_with_model_field(
            'ring', 'lattice', v.ring_lattice)
    else:
        v.latticeFilename = JSPEC_TWISS_FILENAME
    if v.ionBeam_beam_type == 'continuous':
        v.ionBeam_rms_bunch_length = 0
    v.simulationSettings_ibs = 'on' if v.simulationSettings_ibs == '1' else 'off'
    v.simulationSettings_e_cool = 'on' if v.simulationSettings_e_cool == '1' else 'off'
    return template_common.render_jinja(SIM_TYPE, v)
Ejemplo n.º 24
0
def _generate_parameters_file(data):
    _validate_data(data, _SCHEMA)
    v = template_common.flatten_data(data['models'], {})
    beamline_map = _build_beamline_map(data)
    v['lattice'] = _generate_lattice(data, beamline_map, v)
    v['bunchFileName'] = OUTPUT_FILE['bunchReport']
    v['diagnosticFilename'] = OUTPUT_FILE['beamEvolutionAnimation']
    v['twissFileName'] = OUTPUT_FILE['twissReport']
    if data.models.bunch.distribution == 'file':
        v['bunchFile'] = template_common.lib_file_name('bunch', 'particleFile', data.models.bunch.particleFile)
    v['bunch'] = template_common.render_jinja(SIM_TYPE, v, 'bunch.py')
    res = template_common.render_jinja(SIM_TYPE, v, 'base.py')
    report = data['report'] if 'report' in data else ''
    if 'bunchReport' in report or 'twissReport' in report:
        res += template_common.render_jinja(SIM_TYPE, v, 'twiss.py')
        if 'bunchReport' in report:
            res += template_common.render_jinja(SIM_TYPE, v, 'bunch-report.py')
    else:
        res += template_common.render_jinja(SIM_TYPE, v, 'parameters.py')
    return res
Ejemplo n.º 25
0
def _generate_parameters_file(data, run_dir=None, is_parallel=False):
    v = None
    template_common.validate_models(data, simulation_db.get_schema(SIM_TYPE))
    v = template_common.flatten_data(data['models'], {})
    v['outputDir'] = '"{}"'.format(run_dir) if run_dir else None
    v['particlePeriod'] = _PARTICLE_PERIOD
    v['particleFile'] = _PARTICLE_FILE
    v['impactDensityCalculation'] = _generate_impact_density()
    v['egunCurrentFile'] = _EGUN_CURRENT_FILE
    v['conductorLatticeAndParticleScraper'] = _generate_lattice(data)
    template_name = ''
    if 'report' not in data:
        template_name = 'visualization'
    elif data['report'] == 'animation':
        if data['models']['simulation']['egun_mode'] == '1':
            v['egunStatusFile'] = _EGUN_STATUS_FILE
            template_name = 'egun'
        else:
            template_name = 'visualization'
    else:
        template_name = 'source-field'
    return template_common.render_jinja(SIM_TYPE, v, 'base.py') \
        + template_common.render_jinja(SIM_TYPE, v, '{}.py'.format(template_name))
Ejemplo n.º 26
0
def generate_parameters_file(data, is_parallel=False):
    _validate_data(data, _SCHEMA)
    v = template_common.flatten_data(data['models'], {})
    longitudinal_method = int(data['models']['bunch']['longitudinalMethod'])

    # sigma s, sigma dp, dp s coupling
    if longitudinal_method == 1:
        v['bunch_emit_z'] = 0
        v['bunch_beta_z'] = 0
        v['bunch_alpha_z'] = 0
    # sigma s, sigma dp, alpha z
    elif longitudinal_method == 2:
        v['bunch_emit_z'] = 0
        v['bunch_beta_z'] = 0
        v['bunch_dp_s_coupling'] = 0
    # emit z, beta z, alpha z
    elif longitudinal_method == 3:
        v['bunch_sigma_dp'] = 0
        v['bunch_sigma_s'] = 0
        v['bunch_dp_s_coupling'] = 0
    if data['models']['bunchSource']['inputSource'] == 'sdds_beam':
        v['bunch_beta_x'] = 5
        v['bunch_beta_y'] = 5
        v['bunch_alpha_x'] = 0
        v['bunch_alpha_x'] = 0
    v['rpn_variables'] = _generate_variables(data)

    if is_parallel:
        filename_map = _build_filename_map(data)
        beamline_map = _build_beamline_map(data)
        v['commands'] = _generate_commands(data, filename_map, beamline_map, v)
        v['lattice'] = generate_lattice(data, filename_map, beamline_map, v)
        v['simulationMode'] = data['models']['simulation']['simulationMode']
        return pkjinja.render_resource('elegant.py', v)

    return pkjinja.render_resource('elegant_bunch.py', v)
Ejemplo n.º 27
0
def generate_parameters_file(data, schema, run_dir=None, run_async=False):
    _validate_data(data, schema)
    v = template_common.flatten_data(data['models'], {})
    v['outputDir'] = '"{}"'.format(run_dir) if run_dir else None
    v['enablePlasma'] = 1
    return pkjinja.render_resource('warp.py', v)
Ejemplo n.º 28
0
def generate_parameters_file(data, schema, run_dir=None, run_async=False):
    _validate_data(data, schema)
    v = template_common.flatten_data(data['models'], {})
    return pkjinja.render_resource('elegant.py', v)
Ejemplo n.º 29
0
def generate_parameters_file(data, schema, run_dir=None, run_async=False):
    _validate_data(data, schema)
    v = template_common.flatten_data(data['models'], {})
    return pkjinja.render_resource('elegant.py', v)
Ejemplo n.º 30
0
def generate_parameters_file(data, schema, run_dir=None, run_async=False):
    _validate_data(data, schema)
    v = template_common.flatten_data(data['models'], {})
    v['outputDir'] = '"{}"'.format(run_dir) if run_dir else None
    v['enablePlasma'] = 1
    return pkjinja.render_resource('warp.py', v)