Skip to content

Instantly share code, notes, and snippets.

@shkiefer
shkiefer / pyAnsys_DPF_example_1.py
Created December 31, 2021 21:11
pyAnsys_DPF_example
# %%
import numpy as np
from ansys.dpf import post
from ansys.dpf import core as dpf
from ansys.dpf.core import examples
rst = examples.simple_bar
model = dpf.Model(rst)
tfs = model.metadata.time_freq_support.time_frequencies.data
print(model)
@shkiefer
shkiefer / dash_vtk_unstructured, callback.py
Last active April 18, 2021 23:42
dash_vtk_unstructured, allback
@app.callback(
Output(f'{APP_ID}_geom_rep', 'children'),
Output(f'{APP_ID}_store', 'data'),
Output(f'{APP_ID}_nodes_upload', 'contents'),
Output(f'{APP_ID}_elems_upload', 'contents'),
Input(f'{APP_ID}_nodes_upload', 'contents'),
Input(f'{APP_ID}_elems_upload', 'contents'),
Input(f'{APP_ID}_elem_data_upload', 'contents'),
Input(f'{APP_ID}_dropdown_cs', 'value'),
Input(f'{APP_ID}_range_slider', 'value'),
@shkiefer
shkiefer / ns_export_to_uGrid, cell results.py
Created April 18, 2021 23:00
dash_vtk_unstructured, ns_export_to_uGrid, cell results
if e_data_b64:
decoded_ed = base64.b64decode(e_data_b64.split(',')[1])
df_elem_data = pd.read_csv(
io.StringIO(decoded_ed.decode('utf-8')),
delim_whitespace=True,
header=None,
skiprows=1,
names=['id', 'val']
)
df_elem_data = df_elem_data.sort_values('id').set_index('id', drop=True)
@shkiefer
shkiefer / dash_vtk_unstructured_layout.py
Created April 18, 2021 22:49
dash_vtk_unstructured, layout
layout = dbc.Container([
html.H1('Unstructured Mesh Viewer'),
dbc.Row([
dbc.Col([
html.H3('Step 1: Upload your mesh'),
# upload for nodes
dcc.Store(id=f'{APP_ID}_store', data=[True]),
dcc.Upload(
id=f'{APP_ID}_nodes_upload',
multiple=False,
@shkiefer
shkiefer / ns_export_to_uGrid.py
Last active April 18, 2021 22:25
dash_vtk_unstructured, ns_export_to_uGrid, nodes
def ns_export_to_uGrid(n_ns_b64, e_ns_b64, e_data_b64=None):
decoded_n = base64.b64decode(n_ns_b64.split(',')[1])
decoded_e = base64.b64decode(e_ns_b64.split(',')[1])
df_nodes = pd.read_csv(io.StringIO(decoded_n.decode('utf-8')), delim_whitespace=True, header=None, skiprows=1, names=['id', 'x', 'y', 'z'])
df_nodes['id'] = df_nodes['id'].astype(int)
df_nodes = df_nodes.set_index('id', drop=True)
# fill missing ids in range as VTK uses position (index) to map cells to points
df_nodes = df_nodes.reindex(np.arange(df_nodes.index.min(), df_nodes.index.max() + 1), fill_value=0)
@shkiefer
shkiefer / ip_elems.txt
Last active April 18, 2021 21:45
dash_vtk_unstructured
Element Number Element Type Nodes
1 Tet10 13678 14398 16466 16375 94108 97821 94113 94112 97819 102577
2 Tet10 13468 14398 16466 13678 93150 97821 93155 93149 94108 94113
3 Tet10 13064 16466 14398 16375 90412 97821 90409 90411 102577 97819
4 Tet10 12489 13064 16466 14398 86479 90412 86481 86480 90409 97821
5 Tet10 12495 16466 13064 15007 86521 90412 86516 86518 100327 90410
@shkiefer
shkiefer / user_large_data_sql_process.py
Created September 12, 2020 08:27
Callback that processes the user data
@app.callback(
[
Output(f'{APP_ID}_session_store', 'data'),
Output(f'{APP_ID}_xaxis_select', 'options'),
Output(f'{APP_ID}_yaxis_select', 'options'),
],
[
Input(f'{APP_ID}_process_data_button', 'n_clicks'),
],
[
@shkiefer
shkiefer / user_large_data_sql_upload.py
Created September 12, 2020 08:21
callback initiated on user upload (enables process data button)
@app.callback(
Output(f'{APP_ID}_process_data_button', 'disabled'),
[
Input(f'{APP_ID}_large_upload_fn_store', 'data'),
Input(f'{APP_ID}_dcc_upload', 'contents')
],
[
State(f'{APP_ID}_dcc_upload', 'filename')
]
)
@shkiefer
shkiefer / user_large_data_sql_layout.py
Created September 12, 2020 08:16
layout for plotting user-uploaded json-like data
layout = dbc.Container([
html.H1('Large User Input File Upload'),
dcc.Store(id=f'{APP_ID}_session_store'),
dcc.Store(id=f'{APP_ID}_large_upload_fn_store'),
dbc.Row([
dbc.Col(
du.Upload(id=f'{APP_ID}_large_upload')
),
dbc.Col(
dcc.Upload(
@shkiefer
shkiefer / user_large_data_cache.py
Created September 12, 2020 08:04
Using serverside caching with large use inputs
@app.callback(
[
ServersideOutput(f'{APP_ID}_session_store', 'data'),
Output(f'{APP_ID}_xaxis_select', 'options'),
Output(f'{APP_ID}_yaxis_select', 'options'),
],
[
Input(f'{APP_ID}_process_data_button', 'n_clicks'),
],
[