Skip to content

Commit 0087d9b

Browse files
committed
now plotting graphs
1 parent 86991df commit 0087d9b

File tree

2 files changed

+130
-8
lines changed

2 files changed

+130
-8
lines changed

Dockerfile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212
FROM ghcr.io/openmc-data-storage/nuclear_data_base_docker:h5_base
1313

1414

15-
RUN pip3 install streamlit
16-
RUN pip3 install plotly
15+
# RUN pip3 install streamlit
16+
# RUN pip3 install plotly
17+
18+
COPY requirements.txt .
19+
RUN pip install -r requirements.txt
1720

1821

1922
ENV OPENMC_CROSS_SECTIONS=/tendl-2019-hdf5/cross_sections.xml
20-
COPY index.py .
23+
COPY app.py .
2124

2225
EXPOSE 8080
2326

24-
ENTRYPOINT ["streamlit", "run", "index.py"]
25-
27+
ENTRYPOINT ["python", "app.py"]

app.py

Lines changed: 123 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import dash_html_components as html
66
import dash_daq as daq
77
from options import element_names, reaction_names
8+
import openmc
9+
from openmc.data import REACTION_MT
10+
from openmc.data.reaction import REACTION_NAME
811

912
app = dash.Dash(__name__)
1013

@@ -20,6 +23,7 @@
2023
),
2124
dcc.Input(
2225
id='fraction_value',
26+
placeholder='Mass fraction',
2327
value='',
2428
type='number',
2529
style={'padding': 10},
@@ -58,6 +62,7 @@
5862
),
5963
dcc.Input(
6064
id='density_value',
65+
placeholder='density in g/cm3',
6166
value='',
6267
type='number',
6368
style={'padding': 10},
@@ -83,17 +88,95 @@
8388
[
8489
Input("update_plot", "n_clicks"),
8590
Input("reaction_names", "value"),
86-
# Input("density_value", "value"),
91+
Input("adding-rows-table", "data"),
92+
Input("density_value", "value"),
8793
# Input("adding-rows-table", "rows"),
8894
],
8995
# [dash.dependencies.Input('update_plot', 'n_clicks')],
9096
# [dash.dependencies.State('input-on-submit', 'value')]
9197
)
92-
def update_output(n_clicks, value):
98+
def update_output(n_clicks, reaction_names, rows, density_value):
9399
if n_clicks is None:
94100
raise dash.exceptions.PreventUpdate
95101
if n_clicks > 0:
96-
print('got here')
102+
trigger_id = dash.callback_context.triggered[0]["prop_id"].split(".")[0]
103+
104+
if trigger_id == "update_plot":
105+
106+
print('reaction_names', reaction_names)
107+
print('rows', rows)
108+
print('density_value', density_value)
109+
110+
my_mat = openmc.Material(name='my_mat')
111+
112+
for entry in rows:
113+
# for key, values in entry.items():
114+
print(entry)
115+
# print('key',key, 'values',values)
116+
117+
my_mat.add_element(
118+
entry['Elements'],
119+
entry['Fractions'],
120+
percent_type='ao'
121+
)
122+
123+
my_mat.set_density('g/cm3', density_value)
124+
125+
energy, xs_data_set = openmc.calculate_cexs(
126+
my_mat,
127+
'material',
128+
reaction_names
129+
)
130+
131+
all_x_y_data = []
132+
133+
for xs_data, reaction_name in zip(xs_data_set, reaction_names):
134+
all_x_y_data.append(
135+
{
136+
"y": xs_data,
137+
"x": energy,
138+
"type": "scatter",
139+
"name": f'MT {reaction_name}'
140+
# "marker": {"color": colors},
141+
}
142+
)
143+
energy_units = 'eV'
144+
xs_units = 'Macroscopic cross section $m^-1$'
145+
return [
146+
dcc.Graph(
147+
config=dict(showSendToCloud=True),
148+
figure={
149+
"data": all_x_y_data,
150+
"layout": {
151+
"height":800,
152+
# "width":1600,
153+
"margin": {"l": 3, "r": 2, "t": 15, "b": 60},
154+
"xaxis": {
155+
"title": {"text": f"Energy {energy_units}"},
156+
# "type": xaxis_scale,
157+
"type": 'log',
158+
"tickformat": ".1e",
159+
"tickangle": 45,
160+
},
161+
"yaxis": {
162+
"automargin": True,
163+
# "title": {"text": f"Cross Section {xs_units}"},
164+
"title": {"text": xs_units},
165+
"type": 'log',
166+
# "type": yaxis_scale,
167+
"tickformat": ".1e",
168+
},
169+
"showlegend": True,
170+
# "height": 250,
171+
# "margin": {"t": 10, "l": 10, "r": 10},
172+
},
173+
},
174+
)
175+
]
176+
177+
178+
# print('energy',energy)
179+
# print('xs_data',xs_data)
97180

98181
@app.callback(
99182
Output('adding-rows-table', 'data'),
@@ -143,5 +226,42 @@ def add_row(n_clicks, rows, element_name, fraction_value):
143226
# }
144227

145228

229+
# def create_material_plot(materials, reaction):
230+
231+
# if reaction not in REACTION_MT.keys():
232+
# print('Reaction not found, only these reactions are accepted', REACTION_MT.keys())
233+
# return None
234+
235+
# # fig = create_plotly_figure(y_axis_label='Macroscopic Cross Section (1/cm)')
236+
237+
# # if isinstance(reaction, str):
238+
# # REACTION_NUMBER = dict(zip(REACTION_NAME.values(), REACTION_NAME.keys()))
239+
# # MT_number = REACTION_NUMBER[reaction]
240+
# # else:
241+
# # MT_number = reaction
242+
# # reaction = REACTION_NAME[MT_number]
243+
244+
# # if not isinstance(materials, list):
245+
# # materials = [materials]
246+
247+
# # for material in materials:
248+
# # extracts energy and cross section for the material for the provided MT reaction mumber
249+
# energy, xs_data = openmc.calculate_cexs(
250+
# material,
251+
# 'material',
252+
# [MT_number])
253+
254+
# # adds the energy dependnat cross sction to the plot
255+
# fig.add_trace(go.Scatter(
256+
# x=energy,
257+
# y=xs_data[0],
258+
# mode='lines',
259+
# name=material.name + ' ' + reaction)
260+
# )
261+
262+
# return fig
263+
264+
265+
146266
if __name__ == '__main__':
147267
app.run_server(debug=True)

0 commit comments

Comments
 (0)