Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update UI interactions #779

Merged
merged 7 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] * (
Fixed Show fixed Hide fixed
tot_num_prob_relative_fields - 1
)

state.prob_relative_fields = [
{
Expand All @@ -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)
]


Expand Down Expand Up @@ -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()

Expand All @@ -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()


Expand Down
6 changes: 3 additions & 3 deletions src/python/impactx/dashboard/Toolbar/exportTemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading