Skip to content

Commit

Permalink
Relocated simulation file (#725)
Browse files Browse the repository at this point in the history
  • Loading branch information
proy30 authored Oct 3, 2024
1 parent a8d0b76 commit 085925c
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 80 deletions.
2 changes: 1 addition & 1 deletion src/python/impactx/dashboard/Analyze/plotsMain.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
from trame.widgets import matplotlib, plotly, vuetify
from wurlitzer import pipes

from ..simulation import run_simulation
from ..trame_setup import setup_server
from .analyzeFunctions import AnalyzeFunctions
from .plot_ParameterEvolutionOverS.overS import line_plot_1d
from .plot_PhaseSpaceProjections.phaseSpace import run_simulation

server, state, ctrl = setup_server()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,79 +1,81 @@
"""
This file is part of ImpactX
Copyright 2024 ImpactX contributors
Authors: Parthib Roy, Axel Huebl
License: BSD-3-Clause-LBNL
"""

from ...trame_setup import setup_server

server, state, ctrl = setup_server()

import base64
import io

from impactx import Config, ImpactX

from ...Input.distributionParameters.distributionMain import distribution_parameters
from ...Input.latticeConfiguration.latticeMain import lattice_elements
from ..plot_PhaseSpaceProjections.phaseSpaceSettings import adjusted_settings_plot

# Call MPI_Init and MPI_Finalize only once:
if Config.have_mpi:
from mpi4py import MPI # noqa


def fig_to_base64(fig):
"""
Puts png in trame-compatible form
"""
buf = io.BytesIO()
fig.savefig(buf, format="png")
buf.seek(0)
return base64.b64encode(buf.read()).decode("utf-8")


def run_simulation():
"""
This tests using ImpactX and Pandas Dataframes
"""
sim = ImpactX()

sim.particle_shape = state.particle_shape
sim.space_charge = False
sim.slice_step_diagnostics = True
sim.init_grids()

# init particle beam
kin_energy_MeV = state.kin_energy_MeV
bunch_charge_C = state.bunch_charge_C
npart = state.npart

# reference particle
pc = sim.particle_container()
ref = pc.ref_particle()
ref.set_charge_qe(state.charge_qe).set_mass_MeV(state.mass_MeV).set_kin_energy_MeV(
kin_energy_MeV
)

distribution = distribution_parameters()
sim.add_particles(bunch_charge_C, distribution, npart)

lattice_configuration = lattice_elements()

sim.lattice.extend(lattice_configuration)

# simulate
sim.evolve()

fig = adjusted_settings_plot(pc)
fig_original = pc.plot_phasespace()

if fig_original is not None:
image_base64 = fig_to_base64(fig_original)
state.image_data = f"data:image/png;base64, {image_base64}"

sim.finalize()

return fig
"""
This file is part of ImpactX
Copyright 2024 ImpactX contributors
Authors: Parthib Roy, Axel Huebl
License: BSD-3-Clause-LBNL
"""

from .trame_setup import setup_server

server, state, ctrl = setup_server()

import base64
import io

from impactx import Config, ImpactX

from .Analyze.plot_PhaseSpaceProjections.phaseSpaceSettings import (
adjusted_settings_plot,
)
from .Input.distributionParameters.distributionMain import distribution_parameters
from .Input.latticeConfiguration.latticeMain import lattice_elements

# Call MPI_Init and MPI_Finalize only once:
if Config.have_mpi:
from mpi4py import MPI # noqa


def fig_to_base64(fig):
"""
Puts png in trame-compatible form
"""
buf = io.BytesIO()
fig.savefig(buf, format="png")
buf.seek(0)
return base64.b64encode(buf.read()).decode("utf-8")


def run_simulation():
"""
This tests using ImpactX and Pandas Dataframes
"""
sim = ImpactX()

sim.particle_shape = state.particle_shape
sim.space_charge = False
sim.slice_step_diagnostics = True
sim.init_grids()

# init particle beam
kin_energy_MeV = state.kin_energy_MeV
bunch_charge_C = state.bunch_charge_C
npart = state.npart

# reference particle
pc = sim.particle_container()
ref = pc.ref_particle()
ref.set_charge_qe(state.charge_qe).set_mass_MeV(state.mass_MeV).set_kin_energy_MeV(
kin_energy_MeV
)

distribution = distribution_parameters()
sim.add_particles(bunch_charge_C, distribution, npart)

lattice_configuration = lattice_elements()

sim.lattice.extend(lattice_configuration)

# simulate
sim.evolve()

fig = adjusted_settings_plot(pc)
fig_original = pc.plot_phasespace()

if fig_original is not None:
image_base64 = fig_to_base64(fig_original)
state.image_data = f"data:image/png;base64, {image_base64}"

sim.finalize()

return fig

0 comments on commit 085925c

Please sign in to comment.