diff --git a/src/python/impactx/dashboard/Input/distributionParameters/distributionMain.py b/src/python/impactx/dashboard/Input/distributionParameters/distributionMain.py index cd664de92..741d13e9c 100644 --- a/src/python/impactx/dashboard/Input/distributionParameters/distributionMain.py +++ b/src/python/impactx/dashboard/Input/distributionParameters/distributionMain.py @@ -12,7 +12,13 @@ from impactx import distribution -from .. import TrameFunctions, generalFunctions, setup_server, vuetify +from .. import ( + DashboardDefaults, + TrameFunctions, + generalFunctions, + setup_server, + vuetify, +) from .distributionFunctions import DistributionFunctions server, state, ctrl = setup_server() @@ -117,13 +123,18 @@ def distribution_parameters(): @state.change("distribution") def on_distribution_name_change(distribution, **kwargs): - if distribution == "Thermal": - state.distribution_type = "Quadratic Form" + if distribution == "Thermal" or distribution == "Empty": + state.distribution_type = "" state.distribution_type_disable = True state.dirty("distribution_type") else: + type_list_default = DashboardDefaults.LISTS["distribution_type_list"] + type_default = DashboardDefaults.DISTRIBUTION_PARAMETERS["distribution_type"] + + if state.distribution_type not in type_list_default: + state.distribution_type = type_default + state.distribution_type_disable = False - populate_distribution_parameters() @state.change("distribution_type") diff --git a/src/python/impactx/dashboard/Input/space_charge_configuration/spaceChargeFunctions.py b/src/python/impactx/dashboard/Input/space_charge_configuration/spaceChargeFunctions.py index 1152eef2c..ddcf36f57 100644 --- a/src/python/impactx/dashboard/Input/space_charge_configuration/spaceChargeFunctions.py +++ b/src/python/impactx/dashboard/Input/space_charge_configuration/spaceChargeFunctions.py @@ -26,7 +26,7 @@ def validate_prob_relative_fields(index, prob_relative_value): if index == 0: if poisson_solver == "multigrid": - if prob_relative_value < 3: + if prob_relative_value <= 3: error_message = "Must be greater than 3." elif poisson_solver == "fft": if prob_relative_value <= 1: diff --git a/src/python/impactx/dashboard/Input/space_charge_configuration/spaceChargeMain.py b/src/python/impactx/dashboard/Input/space_charge_configuration/spaceChargeMain.py index 33f8101ab..5d1dc914b 100644 --- a/src/python/impactx/dashboard/Input/space_charge_configuration/spaceChargeMain.py +++ b/src/python/impactx/dashboard/Input/space_charge_configuration/spaceChargeMain.py @@ -17,25 +17,32 @@ # ----------------------------------------------------------------------------- -def populate_prob_relative_fields(max_level): - num_prob_relative_fields = int(max_level) + 1 +def populate_prob_relative_fields(): + tot_num_prob_relative_fields = int(state.max_level) + 1 fft_first_field_value = generalFunctions.get_default( "prob_relative_first_value_fft", "default_values" ) multigrid_first_field_value = generalFunctions.get_default( "prob_relative_first_value_multigrid", "default_values" ) - + first_field_value = 0 if state.poisson_solver == "fft": - state.prob_relative = [fft_first_field_value] + [0.0] * ( - num_prob_relative_fields - 1 - ) + first_field_value = fft_first_field_value elif state.poisson_solver == "multigrid": - state.prob_relative = [multigrid_first_field_value] + [0.0] * ( - num_prob_relative_fields - 1 - ) + first_field_value = multigrid_first_field_value + + if state.prob_relative: + size = len(state.prob_relative) + num_of_extra_fields = tot_num_prob_relative_fields - size + + if size < tot_num_prob_relative_fields: + state.prob_relative.extend([0.0] * (num_of_extra_fields)) + elif size > tot_num_prob_relative_fields: + state.prob_relative = state.prob_relative[:tot_num_prob_relative_fields] else: - state.prob_relative = [0.0] * num_prob_relative_fields + state.prob_relative = [first_field_value] + [0.0] * ( + tot_num_prob_relative_fields - 1 + ) state.prob_relative_fields = [ { @@ -45,7 +52,7 @@ def populate_prob_relative_fields(max_level): ), "step": generalFunctions.get_default("prob_relative", "steps"), } - for i in range(num_prob_relative_fields) + for i in range(tot_num_prob_relative_fields) ] @@ -83,7 +90,7 @@ def update_blocking_factor_and_n_cell(category, kwargs): # ----------------------------------------------------------------------------- @state.change("poisson_solver") def on_poisson_solver_change(poisson_solver, **kwargs): - populate_prob_relative_fields(state.max_level) + populate_prob_relative_fields() state.dirty("prob_relative_fields") generalFunctions.update_simulation_validation_status() @@ -96,7 +103,7 @@ def on_space_charge_change(space_charge, **kwargs): @state.change("max_level") def on_max_level_change(max_level, **kwargs): - populate_prob_relative_fields(max_level) + populate_prob_relative_fields() generalFunctions.update_simulation_validation_status() diff --git a/src/python/impactx/dashboard/Toolbar/exportTemplate.py b/src/python/impactx/dashboard/Toolbar/exportTemplate.py index c01b53e82..cc00cd452 100644 --- a/src/python/impactx/dashboard/Toolbar/exportTemplate.py +++ b/src/python/impactx/dashboard/Toolbar/exportTemplate.py @@ -14,15 +14,15 @@ def build_distribution_list(): Generates an instance of distribution inputs as a string for exporting purposes. """ - distribution_name = state.selected_distribution + distribution_name = state.distribution parameters = DistributionFunctions.convert_distribution_parameters_to_valid_type() - indentation = " " * (8 if state.selected_distribution_type == "Twiss" else 4) + indentation = " " * (8 if state.distribution_type == "Twiss" else 4) distribution_parameters = ",\n".join( f"{indentation}{key}={value}" for key, value in parameters.items() ) - if state.selected_distribution_type == "Twiss": + if state.distribution_type == "Twiss": return ( f"distr = distribution.{distribution_name}(\n" f" **twiss(\n"