Skip to content

Commit

Permalink
Update simulation station function
Browse files Browse the repository at this point in the history
to ensure that users cannot run a simulation when inputs have errors
  • Loading branch information
proy30 committed Nov 7, 2024
1 parent 6a60bec commit 571ebd9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/python/impactx/dashboard/Input/generalFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,31 @@ def update_simulation_validation_status():
if state.csr_bins_error_message:
error_details.append(f"CSR Bins: {state.csr_bins_error_message}")

# Check for errors in Space Charge parameters
if state.space_charge:
# n_cell parameters
for direction in ["x", "y", "z"]:
n_cell_error = getattr(state, f"error_message_n_cell_{direction}")
if n_cell_error:
error_details.append(f"n_cell_{direction}: {n_cell_error}")

# Blocking factor parameters
for direction in ["x", "y", "z"]:
blocking_factor_error = getattr(
state, f"error_message_blocking_factor_{direction}"
)
if blocking_factor_error:
error_details.append(
f"blocking_factor_{direction}: {blocking_factor_error}"
)

# Prob Relative Fields
for index, field in enumerate(state.prob_relative_fields):
if field["error_message"]:
error_details.append(
f"prob_relative[{index}]: {field['error_message']}"
)

state.disableRunSimulationButton = bool(error_details)

# -----------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,31 @@ def update_blocking_factor_and_n_cell(category, kwargs):
def on_poisson_solver_change(poisson_solver, **kwargs):
populate_prob_relative_fields(state.max_level)
state.dirty("prob_relative_fields")
generalFunctions.update_simulation_validation_status()


@state.change("space_charge")
def on_space_charge_change(space_charge, **kwargs):
state.dynamic_size = space_charge
generalFunctions.update_simulation_validation_status()


@state.change("max_level")
def on_max_level_change(max_level, **kwargs):
populate_prob_relative_fields(max_level)
generalFunctions.update_simulation_validation_status()


@state.change("blocking_factor_x", "blocking_factor_y", "blocking_factor_z")
def on_blocking_factor_change(**kwargs):
update_blocking_factor_and_n_cell("blocking_factor", kwargs)
generalFunctions.update_simulation_validation_status()


@state.change("n_cell_x", "n_cell_y", "n_cell_z")
def on_n_cell_change(**kwargs):
update_blocking_factor_and_n_cell("n_cell", kwargs)
generalFunctions.update_simulation_validation_status()


@ctrl.add("update_prob_relative")
Expand Down Expand Up @@ -149,6 +154,7 @@ def on_update_prob_relative_call(index, value):
state.prob_relative_fields[index + 1]["error_message"] = next_error_message

state.dirty("prob_relative_fields")
generalFunctions.update_simulation_validation_status()


# -----------------------------------------------------------------------------
Expand Down

0 comments on commit 571ebd9

Please sign in to comment.