Skip to content

Commit

Permalink
Re-arrange defaults.py and update corresponding code
Browse files Browse the repository at this point in the history
  • Loading branch information
proy30 committed Dec 25, 2024
1 parent de94727 commit 7cf5f61
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# Default State Variables
# -----------------------------------------------------------------------------

state.csr_bins = generalFunctions.get_default("csr_bins", "values")
state.csr_bins = generalFunctions.get_default("csr_bins", "default_values")
state.csr_bins_error_message = ""

# -----------------------------------------------------------------------------
Expand Down
68 changes: 47 additions & 21 deletions src/python/impactx/dashboard/Input/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,35 @@ class DashboardDefaults:
Defaults for input parameters in the ImpactX dashboard.
"""

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],
}
# -------------------------------------------------------------------------
# Inputs by section
# -------------------------------------------------------------------------

VALUES = {
# Input Parameters
INPUT_PARAMETERS = {
"space_charge": False,
"csr": False,
"charge_qe": -1,
"mass_MeV": 0.51099895,
"npart": 1000,
"kin_energy": 2e3,
"kin_energy_unit": "MeV",
"bunch_charge_C": 1e-9,
"particle_shape": 2,
# Space Charge
}

DISTRIBUTION = {
"selected_distribution": "Waterbag",
"selected_distribution_type": "Twiss",
}

LATTICE = {
"selected_lattice_list": [],
"selected_lattice": None,
}

SPACE_CHARGE = {
"dynamic_size": False,
"poisson_solver": "fft",
"particle_shape": 2,
"max_level": 0,
"n_cell": 32,
"blocking_factor": 16,
Expand All @@ -34,32 +41,51 @@ class DashboardDefaults:
"mlmg_absolute_tolerance": 0,
"mlmg_verbosity": 1,
"mlmg_max_iters": 100,
# CSR
}

CSR = {
"particle_shape": 2,
"csr_bins": 150,
}

# If parameter is not included in the dictionary, default step amount is 1.
LISTS = {
"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],
}

# -------------------------------------------------------------------------
# Main
# -------------------------------------------------------------------------

DEFAULT_VALUES = {
**INPUT_PARAMETERS,
**DISTRIBUTION,
**LATTICE,
**SPACE_CHARGE,
**CSR,
**LISTS,
}

# If a parameter is not included in the dictionary, default step amount is 1.
STEPS = {
# Single input
"mass_MeV": 0.1,
"bunch_charge_C": 1e-11,
"prob_relative": 0.1,
"mlmg_relative_tolerance": 1e-12,
"mlmg_absolute_tolerance": 1e-12,
# Shared inputs (x,y,z)
"beta": 0.1,
"emitt": 1e-7,
"alpha": 0.1,
}

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)
"beta": "m",
"emitt": "m",
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
# Defaults
# -----------------------------------------------------------------------------

state.selectedDistribution = generalFunctions.get_default("distribution", "defaults")
state.selectedDistribution = generalFunctions.get_default(
"selected_distribution", "default_values"
)
state.selectedDistributionType = generalFunctions.get_default(
"distribution_type", "defaults"
"selected_distribution_type", "default_values"
)
state.selectedDistributionParameters = []
state.distributionTypeDisabled = False
Expand Down Expand Up @@ -212,7 +214,7 @@ def card():
label="Type",
items=(
generalFunctions.get_default(
"distribution_type_list", "defaults"
"distribution_type_list", "default_values"
),
),
dense=True,
Expand Down
26 changes: 17 additions & 9 deletions src/python/impactx/dashboard/Input/inputParameters/inputMain.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,23 @@ class InputParameters:
"""

def __init__(self):
state.particle_shape = generalFunctions.get_default("particle_shape", "values")
state.npart = generalFunctions.get_default("npart", "values")
state.kin_energy = generalFunctions.get_default("kin_energy", "values")
state.particle_shape = generalFunctions.get_default(
"particle_shape", "default_values"
)
state.npart = generalFunctions.get_default("npart", "default_values")
state.kin_energy = generalFunctions.get_default("kin_energy", "default_values")
state.kin_energy_MeV = state.kin_energy
state.bunch_charge_C = generalFunctions.get_default("bunch_charge_C", "values")
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")
state.bunch_charge_C = generalFunctions.get_default(
"bunch_charge_C", "default_values"
)
state.kin_energy_unit = generalFunctions.get_default(
"kin_energy_unit", "default_values"
)
state.old_kin_energy_unit = generalFunctions.get_default(
"kin_energy_unit", "default_values"
)
state.charge_qe = generalFunctions.get_default("charge_qe", "default_values")
state.mass_MeV = generalFunctions.get_default("mass_MeV", "default_values")

state.npart_validation = []
state.kin_energy_validation = []
Expand Down Expand Up @@ -177,7 +185,7 @@ def card(self):
label="Unit",
items=(
generalFunctions.get_default(
"kin_energy_unit_list", "defaults"
"kin_energy_unit_list", "default_values"
),
),
change=(ctrl.kin_energy_unit_change, "[$event]"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
# Default
# -----------------------------------------------------------------------------

state.selectedLattice = generalFunctions.get_default("lattice", "defaults")
state.selectedLattice = generalFunctions.get_default("lattice", "default_values")
state.selectedLatticeList = []
state.nsliceDefaultValue = generalFunctions.get_default("n_slice", "values")
state.nsliceDefaultValue = generalFunctions.get_default("n_slice", "default_values")

# -----------------------------------------------------------------------------
# Main Functions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,37 @@
# Default
# -----------------------------------------------------------------------------

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")
state.dynamic_size = generalFunctions.get_default("dynamic_size", "default_values")
state.max_level = generalFunctions.get_default("max_level", "default_values")
state.particle_shape = generalFunctions.get_default("particle_shape", "default_values")
state.poisson_solver = generalFunctions.get_default("poisson_solver", "default_values")

state.prob_relative = []
state.prob_relative_fields = []

state.n_cell = []
state.n_cell_x = generalFunctions.get_default("n_cell", "values")
state.n_cell_y = generalFunctions.get_default("n_cell", "values")
state.n_cell_z = generalFunctions.get_default("n_cell", "values")
state.n_cell_x = generalFunctions.get_default("n_cell", "default_values")
state.n_cell_y = generalFunctions.get_default("n_cell", "default_values")
state.n_cell_z = generalFunctions.get_default("n_cell", "default_values")

state.blocking_factor_x = generalFunctions.get_default("blocking_factor", "values")
state.blocking_factor_y = generalFunctions.get_default("blocking_factor", "values")
state.blocking_factor_z = generalFunctions.get_default("blocking_factor", "values")
state.blocking_factor_x = generalFunctions.get_default(
"blocking_factor", "default_values"
)
state.blocking_factor_y = generalFunctions.get_default(
"blocking_factor", "default_values"
)
state.blocking_factor_z = generalFunctions.get_default(
"blocking_factor", "default_values"
)

state.mlmg_relative_tolerance = generalFunctions.get_default(
"mlmg_relative_tolerance", "values"
"mlmg_relative_tolerance", "default_values"
)
state.mlmg_absolute_tolerance = generalFunctions.get_default(
"mlmg_absolute_tolerance", "values"
"mlmg_absolute_tolerance", "default_values"
)
state.mlmg_max_iters = generalFunctions.get_default("mlmg_max_iters", "values")
state.mlmg_verbosity = generalFunctions.get_default("mlmg_verbosity", "values")
state.mlmg_max_iters = generalFunctions.get_default("mlmg_max_iters", "default_values")
state.mlmg_verbosity = generalFunctions.get_default("mlmg_verbosity", "default_values")

state.error_message_mlmg_relative_tolerance = ""
state.error_message_mlmg_absolute_tolerance = ""
Expand All @@ -49,10 +55,10 @@
def populate_prob_relative_fields(max_level):
num_prob_relative_fields = int(max_level) + 1
fft_first_field_value = generalFunctions.get_default(
"prob_relative_first_value_fft", "values"
"prob_relative_first_value_fft", "default_values"
)
multigrid_first_field_value = generalFunctions.get_default(
"prob_relative_first_value_multigrid", "values"
"prob_relative_first_value_multigrid", "default_values"
)

if state.poisson_solver == "fft":
Expand Down Expand Up @@ -215,7 +221,7 @@ def card():
v_model=("poisson_solver",),
items=(
generalFunctions.get_default(
"poisson_solver_list", "defaults"
"poisson_solver_list", "default_values"
),
),
dense=True,
Expand All @@ -227,7 +233,7 @@ def card():
v_model=("particle_shape",),
items=(
generalFunctions.get_default(
"particle_shape_list", "defaults"
"particle_shape_list", "default_values"
),
),
dense=True,
Expand All @@ -238,7 +244,7 @@ def card():
v_model=("max_level",),
items=(
generalFunctions.get_default(
"max_level_list", "defaults"
"max_level_list", "default_values"
),
),
dense=True,
Expand Down

0 comments on commit 7cf5f61

Please sign in to comment.