From 0314f1c7ce29b19929f188bcd5851d68ebed21b5 Mon Sep 17 00:00:00 2001 From: Parthib Roy Date: Mon, 16 Dec 2024 15:50:37 -0800 Subject: [PATCH] Add more defaults and rename default variables --- .../impactx/dashboard/Input/defaults.py | 19 +++++++++++++++--- .../distributionMain.py | 12 ++++++++--- .../dashboard/Input/generalFunctions.py | 4 +--- .../Input/inputParameters/inputMain.py | 10 +++++++--- .../Input/latticeConfiguration/latticeMain.py | 4 ++-- .../spaceChargeMain.py | 20 +++++++++++++++---- 6 files changed, 51 insertions(+), 18 deletions(-) diff --git a/src/python/impactx/dashboard/Input/defaults.py b/src/python/impactx/dashboard/Input/defaults.py index e79fd285e..d24f664a6 100644 --- a/src/python/impactx/dashboard/Input/defaults.py +++ b/src/python/impactx/dashboard/Input/defaults.py @@ -3,7 +3,18 @@ class DashboardDefaults: Defaults for input parameters in the ImpactX dashboard. """ - PARAMETER_VALUES = { + DEFAULTS = { + "distribution": "Waterbag", + "distribution_type": "Twiss", + "lattice": None, + "kin_energy_unit_list": ["meV", "eV", "keV", "MeV", "GeV", "TeV"], + "distribution_type_list": ["Twiss", "Quadratic"], + "poisson_solver_list": ["fft", "multigrid"], + "particle_shape_list": [1, 2, 3], + "max_level_list": [0, 1, 2, 3, 4], + } + + VALUES = { # Input Parameters "charge_qe": -1, "mass_MeV": 0.51099895, @@ -12,6 +23,7 @@ class DashboardDefaults: "bunch_charge_C": 1e-9, "particle_shape": 2, # Space Charge + "dynamic_size": False, "poisson_solver": "fft", "max_level": 0, "n_cell": 32, @@ -27,7 +39,7 @@ class DashboardDefaults: } # If parameter is not included in the dictionary, default step amount is 1. - PARAMETER_STEPS = { + STEPS = { # Single input "mass_MeV": 0.1, "bunch_charge_C": 1e-11, @@ -40,10 +52,11 @@ class DashboardDefaults: "alpha": 0.1, } - PARAMETER_UNITS = { + UNITS = { # Single input "charge_qe": "qe", "mass_MeV": "MeV", + "kin_energy": "MeV", "bunch_charge_C": "C", "mlmg_absolute_tolerance": "V/m", # Shared inputs (x,y,z) diff --git a/src/python/impactx/dashboard/Input/distributionParameters/distributionMain.py b/src/python/impactx/dashboard/Input/distributionParameters/distributionMain.py index 2b8aa141a..ff080f547 100644 --- a/src/python/impactx/dashboard/Input/distributionParameters/distributionMain.py +++ b/src/python/impactx/dashboard/Input/distributionParameters/distributionMain.py @@ -34,8 +34,10 @@ # Defaults # ----------------------------------------------------------------------------- -state.selectedDistribution = "Waterbag" -state.selectedDistributionType = "Twiss" +state.selectedDistribution = generalFunctions.get_default("distribution", "defaults") +state.selectedDistributionType = generalFunctions.get_default( + "distribution_type", "defaults" +) state.selectedDistributionParameters = [] state.distributionTypeDisabled = False @@ -208,7 +210,11 @@ def card(): vuetify.VSelect( v_model=("selectedDistributionType",), label="Type", - items=(["Twiss", "Quadratic Form"],), + items=( + generalFunctions.get_default( + "distribution_type_list", "defaults" + ), + ), dense=True, disabled=("distributionTypeDisabled",), ) diff --git a/src/python/impactx/dashboard/Input/generalFunctions.py b/src/python/impactx/dashboard/Input/generalFunctions.py index 454bdde4a..dc5fc8dd8 100644 --- a/src/python/impactx/dashboard/Input/generalFunctions.py +++ b/src/python/impactx/dashboard/Input/generalFunctions.py @@ -48,9 +48,7 @@ def documentation(section_name): @staticmethod def get_default(parameter, type): - parameter_type_dictionary = getattr( - DashboardDefaults, f"PARAMETER_{type.upper()}", None - ) + parameter_type_dictionary = getattr(DashboardDefaults, f"{type.upper()}", None) parameter_default = parameter_type_dictionary.get(parameter) if parameter_default is not None: diff --git a/src/python/impactx/dashboard/Input/inputParameters/inputMain.py b/src/python/impactx/dashboard/Input/inputParameters/inputMain.py index 6e2da6574..f7fdb093d 100644 --- a/src/python/impactx/dashboard/Input/inputParameters/inputMain.py +++ b/src/python/impactx/dashboard/Input/inputParameters/inputMain.py @@ -70,8 +70,8 @@ def __init__(self): state.kin_energy = generalFunctions.get_default("kin_energy", "values") state.kin_energy_MeV = state.kin_energy state.bunch_charge_C = generalFunctions.get_default("bunch_charge_C", "values") - state.kin_energy_unit = "MeV" - state.old_kin_energy_unit = "MeV" + state.kin_energy_unit = generalFunctions.get_default("kin_energy", "units") + state.old_kin_energy_unit = generalFunctions.get_default("kin_energy", "units") state.charge_qe = generalFunctions.get_default("charge_qe", "values") state.mass_MeV = generalFunctions.get_default("mass_MeV", "values") @@ -175,7 +175,11 @@ def card(self): vuetify.VSelect( v_model=("kin_energy_unit",), label="Unit", - items=(["meV", "eV", "keV", "MeV", "GeV", "TeV"],), + items=( + generalFunctions.get_default( + "kin_energy_unit_list", "defaults" + ), + ), change=(ctrl.kin_energy_unit_change, "[$event]"), dense=True, ) diff --git a/src/python/impactx/dashboard/Input/latticeConfiguration/latticeMain.py b/src/python/impactx/dashboard/Input/latticeConfiguration/latticeMain.py index 06f77494f..881102a87 100644 --- a/src/python/impactx/dashboard/Input/latticeConfiguration/latticeMain.py +++ b/src/python/impactx/dashboard/Input/latticeConfiguration/latticeMain.py @@ -32,9 +32,9 @@ # Default # ----------------------------------------------------------------------------- -state.selectedLattice = None +state.selectedLattice = generalFunctions.get_default("lattice", "defaults") state.selectedLatticeList = [] -state.nsliceDefaultValue = None +state.nsliceDefaultValue = generalFunctions.get_default("n_slice", "values") # ----------------------------------------------------------------------------- # Main Functions 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 07acc7d14..951e11013 100644 --- a/src/python/impactx/dashboard/Input/space_charge_configuration/spaceChargeMain.py +++ b/src/python/impactx/dashboard/Input/space_charge_configuration/spaceChargeMain.py @@ -10,7 +10,7 @@ # Default # ----------------------------------------------------------------------------- -state.dynamic_size = False +state.dynamic_size = generalFunctions.get_default("dynamic_size", "values") state.max_level = generalFunctions.get_default("max_level", "values") state.particle_shape = generalFunctions.get_default("particle_shape", "values") state.poisson_solver = generalFunctions.get_default("poisson_solver", "values") @@ -213,7 +213,11 @@ def card(): vuetify.VSelect( label="Poisson Solver", v_model=("poisson_solver",), - items=(["multigrid", "fft"],), + items=( + generalFunctions.get_default( + "poisson_solver_list", "defaults" + ), + ), dense=True, hide_details=True, ) @@ -221,14 +225,22 @@ def card(): vuetify.VSelect( label="Particle Shape", v_model=("particle_shape",), - items=([1, 2, 3],), + items=( + generalFunctions.get_default( + "particle_shape_list", "defaults" + ), + ), dense=True, ) with vuetify.VCol(cols=3, classes="py-0"): vuetify.VSelect( label="Max Level", v_model=("max_level",), - items=([0, 1, 2, 3, 4],), + items=( + generalFunctions.get_default( + "max_level_list", "defaults" + ), + ), dense=True, ) with vuetify.VCol(classes="pa-0"):