Skip to content

Commit

Permalink
Merge remote-tracking branch 'mainline/development' into dashboard/ad…
Browse files Browse the repository at this point in the history
…d-ref-particle_user_inputs
  • Loading branch information
proy30 committed Oct 3, 2024
2 parents 5c14518 + 4a7da60 commit 3e859fa
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ repos:
# Python: Ruff linter & formatter
# https://docs.astral.sh/ruff/
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.7
rev: v0.6.8
hooks:
# Run the linter
- id: ruff
Expand Down
2 changes: 1 addition & 1 deletion cmake/dependencies/ABLASTR.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ set(ImpactX_openpmd_src ""
set(ImpactX_ablastr_repo "https://github.com/ECP-WarpX/WarpX.git"
CACHE STRING
"Repository URI to pull and build ABLASTR from if(ImpactX_ablastr_internal)")
set(ImpactX_ablastr_branch "24.09"
set(ImpactX_ablastr_branch "d1a338e90ed1ad7ac2f010f47409aa48a2265c88"
CACHE STRING
"Repository branch for ImpactX_ablastr_repo if(ImpactX_ablastr_internal)")

Expand Down
2 changes: 1 addition & 1 deletion cmake/dependencies/pyAMReX.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ option(ImpactX_pyamrex_internal "Download & build pyAMReX" ON)
set(ImpactX_pyamrex_repo "https://github.com/AMReX-Codes/pyamrex.git"
CACHE STRING
"Repository URI to pull and build pyamrex from if(ImpactX_pyamrex_internal)")
set(ImpactX_pyamrex_branch "24.09"
set(ImpactX_pyamrex_branch "1c66690f83244196c5655293f1381303a7d1589d"
CACHE STRING
"Repository branch for ImpactX_pyamrex_repo if(ImpactX_pyamrex_internal)")

Expand Down
20 changes: 3 additions & 17 deletions src/particles/spacecharge/PoissonSolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,6 @@ namespace impactx::spacecharge
pp_algo.queryAdd("mlmg_max_iters", mlmg_max_iters);
pp_algo.queryAdd("mlmg_verbosity", mlmg_verbosity);

struct PoissonBoundaryHandler {
amrex::Array<amrex::LinOpBCType, AMREX_SPACEDIM> const lobc = {
amrex::LinOpBCType::Dirichlet,
amrex::LinOpBCType::Dirichlet,
amrex::LinOpBCType::Dirichlet
};
amrex::Array<amrex::LinOpBCType, AMREX_SPACEDIM> const hibc = {
amrex::LinOpBCType::Dirichlet,
amrex::LinOpBCType::Dirichlet,
amrex::LinOpBCType::Dirichlet
};
//bool bcs_set = false;
//std::array<bool, AMREX_SPACEDIM * 2> dirichlet_flag;
//bool has_non_periodic = false;
} poisson_boundary_handler;

// create a vector to our fields, sorted by level
amrex::Vector<amrex::MultiFab*> sorted_rho;
amrex::Vector<amrex::MultiFab*> sorted_phi;
Expand All @@ -97,6 +81,7 @@ namespace impactx::spacecharge
}

const bool do_single_precision_comms = false;
const bool eb_enabled = false;
ablastr::fields::computePhi(
sorted_rho,
sorted_phi,
Expand All @@ -109,12 +94,13 @@ namespace impactx::spacecharge
pc.GetParGDB()->DistributionMap(),
pc.GetParGDB()->boxArray(),
ablastr::utils::enums::GridType::Collocated,
poisson_boundary_handler,
is_solver_igf_on_lev0,
eb_enabled,
do_single_precision_comms,
rel_ref_ratio
/*
post_phi_calculation,
poisson_boundary_handler
gett_new(0),
eb_farray_box_factory
*/
Expand Down
6 changes: 3 additions & 3 deletions src/python/impactx/dashboard/Analyze/plotsMain.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"""

import asyncio
import contextlib
import glob
import io
import os

from trame.widgets import matplotlib, plotly, vuetify
from wurlitzer import pipes

from ..trame_setup import setup_server
from .analyzeFunctions import AnalyzeFunctions
Expand Down Expand Up @@ -140,11 +140,11 @@ def update_plot():
def run_simulation_impactX():
buf = io.StringIO()

with contextlib.redirect_stdout(buf), contextlib.redirect_stderr(buf):
with pipes(stdout=buf, stderr=buf):
state.simulation_data = run_simulation()

buf.seek(0)
lines = [line.strip() for line in buf]
lines = [line.strip() for line in buf.getvalue().splitlines()]

# Use $nextTick to ensure the terminal is fully rendered before printing
async def print_lines():
Expand Down
91 changes: 91 additions & 0 deletions src/python/impactx/dashboard/Toolbar/exportTemplate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
from ..Input.distributionParameters.distributionMain import parameter_input_checker
from ..Input.latticeConfiguration.latticeMain import parameter_input_checker_for_lattice
from ..trame_setup import setup_server

server, state, ctrl = setup_server()

# -----------------------------------------------------------------------------
# Helper Functions
# -----------------------------------------------------------------------------


def build_distribution_list():
"""
Generates an instance of distribution inputs
as a string for exporting purposes.
"""
distribution_name = state.selectedDistribution
parameters = parameter_input_checker()

distribution_parameters = ",\n ".join(
f"{key}={value}" for key, value in parameters.items()
)

return (
f"distr = distribution.{distribution_name}(\n {distribution_parameters},\n)"
)


def build_lattice_list():
"""
Generates a string representation of lattice element
inputs for export purposes.
"""

lattice_elements = ",\n ".join(
f'elements.{element["name"]}('
+ ", ".join(
f"{key}={value}"
for key, value in parameter_input_checker_for_lattice(element).items()
)
+ ")"
for element in state.selectedLatticeList
)

return f"lattice_configuration = [\n {lattice_elements}\n]"


# -----------------------------------------------------------------------------
# Trame setup
# -----------------------------------------------------------------------------


def input_file():
"""
This function creates the template to export
dashboard user inputs into a python script.
"""
script = f"""
from impactx import ImpactX, distribution, elements
sim = ImpactX()
sim.particle_shape = {state.particle_shape}
sim.space_charge = False
sim.csr = False
sim.slice_step_diagnostics = True
sim.init_grids()
# Initialize particle beam
kin_energy_MeV = {state.kin_energy_MeV}
bunch_charge_C = {state.bunch_charge_C}
npart = {state.npart}
# Reference particle
ref = sim.particle_container().ref_particle()
ref.set_charge_qe(-1.0).set_mass_MeV(0.510998950).set_kin_energy_MeV(kin_energy_MeV)
{build_distribution_list()}
sim.add_particles(bunch_charge_C, distr, npart)
{build_lattice_list()}
sim.lattice.extend(lattice_configuration)
# Simulate
sim.evolve()
sim.finalize()
"""

return script
22 changes: 22 additions & 0 deletions src/python/impactx/dashboard/Toolbar/toolbarMain.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,22 @@
from trame.widgets import vuetify

from ..trame_setup import setup_server
from .exportTemplate import input_file

server, state, ctrl = setup_server()

state.show_dashboard_alert = True

# -----------------------------------------------------------------------------
# Triggers
# -----------------------------------------------------------------------------


@ctrl.trigger("export")
def on_export_click():
return input_file()


# -----------------------------------------------------------------------------
# Common toolbar elements
# -----------------------------------------------------------------------------
Expand All @@ -25,6 +36,15 @@ class ToolbarElements:
Vuetify UI elements for toolbar.
"""

@staticmethod
def export_input_data():
vuetify.VIcon(
"mdi-download",
style="color: #00313C;",
click="utils.download('impactx_simulation.py', trigger('export'), 'text/plain')",
disabled=("disableRunSimulationButton", True),
)

@staticmethod
def plot_options():
vuetify.VSelect(
Expand Down Expand Up @@ -75,6 +95,8 @@ def input_toolbar():
"""

(ToolbarElements.dashboard_info(),)
vuetify.VSpacer()
ToolbarElements.export_input_data()

@staticmethod
def run_toolbar():
Expand Down
1 change: 1 addition & 0 deletions src/python/impactx/dashboard/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ trame-plotly>=3.0.2
trame-router>=2.2.0
trame-vuetify>=2.6.2
trame-xterm>=0.2.1
wurlitzer>=3.1.1

0 comments on commit 3e859fa

Please sign in to comment.