Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.ipynb_checkpoints
__pycache__
.vscode
.DS_Store
Outputs
6 changes: 5 additions & 1 deletion pylbm_ui/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ def duration(self):
return self.test_case.duration

def get_data(self, field, solid_value=np.NaN):
if self.sol is None:
return
to_subs = {str(k): self.sol.m[k] for k in self.sol.scheme.consm.keys()}
to_subs.update({str(k): v for k, v in self.sol.scheme.param.items()})

Expand Down Expand Up @@ -251,7 +253,7 @@ def save_data(self, field):
def save_one_field(f):
data = self.get_data(f)
h5.add_scalar(f, data)
if has_ref:
if has_ref and f in self.test_case.equation.get_fields():
if self.sol.dim == 1:
data_ref = self.test_case.ref_solution(self.sol.t, self.sol.domain.x, f)
elif self.sol.dim == 2:
Expand All @@ -269,6 +271,8 @@ def save_one_field(f):
h5.save()

def plot(self, fig, field, properties=None):
if self.sol is None:
return
data = self.get_data(field)
fig.plot(
self.sol.t, self.sol.domain, field, data,
Expand Down
221 changes: 190 additions & 31 deletions pylbm_ui/voila_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,84 @@

from schema import cases

@debug_func
def get_information(tab_id, mc, tc, lb):
if tab_id == 0:
sorted_list_tabs = [
'model', 'test case', 'scheme',
'linear stability', 'simulation',
'parametric study', 'post treatment',
'configuration',
'debug'
]


def change_list_tabs(link_widget_tab):
"""
create the list of tabs

Parameters
----------

link_widget_tab: dict
the dictionary (keys are title and value are tuple (widget, bool))

Returns
-------

tab_widgets: list
the list of the widget viewed in the tabs

tab_titles: list
the list of the titles viewed in the tabs

tab_indices: dict
the dictionary (keys are title and value are the index in the tab)
"""
tab_widgets, tab_titles = [], []
tab_indices, index = {}, 0
for title in sorted_list_tabs:
widget, view = link_widget_tab.get(title, (None, False))
if view:
tab_widgets.append(widget)
tab_titles.append(title)
tab_indices[title] = index
index += 1
return tab_widgets, tab_titles, tab_indices


def get_information(tab_name, mc, tc, lb, param):
"""
return the widget of informations if needed
according to the tab_name
"""

# nothing for the model
if tab_name == 'debug':
return []

# nothing for the model
if tab_name == 'model':
return []

# nothing for the post treatment
if tab_name == 'post treatment':
return []

# visualization of the options for the configuration
if tab_name == 'configuration':
lst_print = []
for name, option in param.list_options.items():
lst_print.append(
f"{name}: {option.widget.v_model}\n"
)
return [
v.Card(children=[
v.CardTitle(children=['Informations'], class_='pb-1'),
v.List(children=lst_print,
dense=True,
class_='pa-0')
])
]

# for test case, scheme, ...
items = [
v.ListItem(children=[
v.ListItemContent(children=[
Expand All @@ -44,11 +117,23 @@ def get_information(tab_id, mc, tc, lb):
],
class_='mb-0'),
]

num = 0
if tab_name == 'test case':
num = 1
if tab_name == 'scheme':
num = 2
if tab_name == 'linear stability':
num = 3
if tab_name == 'simulation':
num = 3
if tab_name == 'parametric study':
num = 3

return [
v.Card(children=[
v.CardTitle(children=['Information'], class_='pb-1'),
v.List(children=items[0:min(tab_id, 3)],
v.CardTitle(children=['Informations'], class_='pb-1'),
v.List(children=items[0:num],
dense=True,
class_='pa-0')
])
Expand All @@ -57,43 +142,44 @@ def get_information(tab_id, mc, tc, lb):
@debug_func
def main():

param = ParametersWidget()
mc = ModelWidget(cases)
tc = TestCaseWidget(mc)
lb = LBSchemeWidget(tc)

stability = StabilityWidget(tc, lb)
simulation = SimulationWidget(tc, lb)
parametric = ParametricStudyWidget(tc, lb, simulation.discret, simulation.codegen)
parametric = ParametricStudyWidget(
tc, lb, simulation.discret, simulation.codegen
)
posttreatment = PostTreatmentWidget()

class DebugWidget:
def __init__(self):
self.menu = []
self.main = [out]
bugtab = DebugWidget()

tab_widgets = [
mc,
tc, lb,
stability, simulation,
parametric, posttreatment,
DebugWidget()
]
tab_titles = [
'Model',
'Test case', 'Scheme',
'Linear stability', 'LBM Simulation',
'Parametric study', 'Post treatment',
'Debug'
]
link_widget_tab = {
'configuration': [param, True],
'model': [mc, True],
'test case': [tc, True],
'scheme': [lb, True],
'linear stability': [stability, True],
'simulation': [simulation, True],
'parametric study': [parametric, True],
'post treatment': [posttreatment, True],
'debug': [bugtab, True],
}

tab = v.Tabs(
v_model=0,
v_model=None,
center_active=True,
fixed_tabs=True,
slider_size=4,
align_with_title=True,
show_arrows=True,
children=[v.Tab(children=[k]) for k in tab_titles],
children=[]
)

menu = v.List(
Expand All @@ -103,12 +189,23 @@ def __init__(self):
)
content = v.Content(children=[])

@debug_func
def tab_change(change):
tab_id = tab.v_model
"""
change the tab
"""
# print(tab.v_model)
tab_widgets, tab_titles, tab_indices = change_list_tabs(link_widget_tab)
if tab.v_model is None:
tab_name = 'configuration'
tab_id = tab_indices.get(tab_name, 0)
else:
tab_id = tab.v_model
tab_name = tab_titles[tab_id]
# print(f"{tab_id}: {tab_name}")
# print(tab_titles)

items = []
if tab_id < 6:
items.extend(get_information(tab_id, mc, tc, lb))
items = get_information(tab_name, mc, tc, lb, param)

widget = tab_widgets[tab_id]
items.extend([
Expand All @@ -122,22 +219,84 @@ def tab_change(change):
menu.children = items
content.children = widget.main

if tab_id == 4:
if tab_name == 'simulation':
simulation.update_simu_cfg_list()

if tab_id == 5:
if tab_name == 'parametric study':
parametric.update_param_cfg_list()

if tab_id == 6:
if tab_name == 'post treatment':
posttreatment.update(None)

tab_change(None)
@debug_func
def list_tab_change(change):
"""
change the list of tabs
"""
# change the link_widget_tab dictionary
link_widget_tab['parametric study'][1] = param.list_options['ps'].widget.v_model
link_widget_tab['post treatment'][1] = param.list_options['pt'].widget.v_model
link_widget_tab['debug'][1] = param.list_options['debug'].widget.v_model

tab_id = tab.v_model # id in the old tab
if tab_id is not None:
tab_name = tab.children[tab_id].children[0] # title
else:
tab_name = 'configuration' # default title
# compute the new tab (parameters can modify the list)
_, tab_titles, tab_indices = change_list_tabs(link_widget_tab)
# update the widget with the new list of tabs
tab.children = [
v.Tab(children=[k]) for k in tab_titles
]
tab.v_model = tab_indices[tab_name]

# TO MODIFY ICON:
# https://materialdesignicons.com
param.add_option(
'ps',
v.Switch(
label='View parametric study tab',
v_model=False,
append_icon='mdi-eye-check-outline',
color='success',
hint="Click me to view the PARAMETRIC STUDY tab"
),
list_tab_change
)
param.add_option(
'pt',
v.Switch(
label='View post treatment tab',
v_model=False,
append_icon='mdi-eye-check-outline',
color='success',
hint="Click me to view the POST TREATMENT tab"
),
list_tab_change
)
param.add_option(
'debug',
v.Switch(
label='View debug tab',
v_model=False,
append_icon='mdi-atom',
color='error',
hint="Click me to view the DEBUG tab"
),
list_tab_change
)

# tab_change(None)
tab.observe(tab_change, 'v_model')
mc.select_category.observe(tab_change, 'v_model')
mc.select_model.observe(tab_change, 'v_model')
tc.select_case.observe(tab_change, 'v_model')
lb.select_case.observe(tab_change, 'v_model')

for option in param.list_options.values():
option.widget.observe(option.change, 'v_model')
list_tab_change(None)

navicon = v.AppBarNavIcon()

drawer = v.NavigationDrawer(
Expand Down
1 change: 1 addition & 0 deletions pylbm_ui/widgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#
# License: BSD 3 clause

from .parameters import ParametersWidget
from .model import ModelWidget
from .test_case import TestCaseWidget
from .lb_scheme import LBSchemeWidget
Expand Down
Loading