#######################
# Import libraries
import streamlit as st
import pandas as pd
import altair as alt
# import plotly.express as px
from PIL import Image # Used to open and handle image files
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
from model_fdm import inverse_design
#######################
# Page configuration
st.set_page_config(
page_title="Inverse Design of Thermoplastic Composites for Thermoforming",
# page_icon="🏂",
layout="wide",
initial_sidebar_state="collapsed")
alt.themes.enable('default')
#######################
# CSS styling
st.markdown("""
""", unsafe_allow_html=True)
st.markdown("""
""", unsafe_allow_html=True)
st.markdown("""
""", unsafe_allow_html=True)
st.markdown("""
""", unsafe_allow_html=True)
st.set_page_config(initial_sidebar_state="collapsed")
st.markdown(
"""
""",
unsafe_allow_html=True,
)
st.markdown("""
""", unsafe_allow_html=True)
st.markdown("""
""", unsafe_allow_html=True)
#######################
font = {'size' : 18}
matplotlib.rc('font', **font)
#######################
if 'input_changed' not in st.session_state:
st.session_state.input_changed= False
def input_typed_in():
st.session_state.input_changed= True
if 'AM_input_changed' not in st.session_state:
st.session_state.AM_input_changed= False
def AM_typed_in():
st.session_state.AM_input_changed= True
if 'AM_input_button_clicked' not in st.session_state:
st.session_state.AM_input_button_clicked= False
def AM_input_click():
st.session_state.AM_input_button_clicked = True
if 'AM_design_button_clicked' not in st.session_state:
st.session_state.AM_design_button_clicked= False
def AM_design_click():
st.session_state.AM_design_button_clicked = True
def style_dataframe_borders(df):
return df.style.set_table_styles([
{'selector': 'td, th', 'props': [('border', '2px solid #000000')]} # Green border
])
#######################
# Load data
#df_reshaped = pd.read_csv('data/us-population-2010-2019-reshaped.csv')
######## Initialize data #############
nlayers=4
vf=0.5
angle=30
#######################
# Main Panel
data_materials={
'Matrix':['ABS','Polyurethane','Nylon 6','Nylon 6','Nylon 66','PE','PP'],
'Filler':['Carbon Black','Glass Fiber','Glass Fiber','Carbon Fiber','Glass Fiber','Carbon Fiber','Glass Fiber'],
'VF':['15%','20%','20%','40%','30%','20%','30%'],
'Feature':['Blend','Extruded','Molded','Molded','Molded','Molded','Molded']
}
data_physical = {
'Forming T (C)': ['180', '185', '190'],
'Punch V (m/s)': ['1.05', '1.8','1.67'],
'Cooling time (s)': ['45','80','120'],
'Holding force (kN)': ['23','24','25']
}
st.title("Inverse Design of Thermoplastic Composites for Additive Manufacturing")
st.write("")
st.write("")
st.write("")
st.write("")
st.write(r"$\textsf{\textbf{\Large Additive Manufacturing Requirements}}$")
col1_row1, col2_row1, col3_row1, col4_row1 = st.columns([0.25,0.25,0.25,0.25])
with col1_row1:
with st.container(border=False): # Container with a border
angleA= st.number_input("Maximum warpage angle A (degree):", format="%.2f", width=300, value=1.0, key="A", on_change=AM_typed_in)
angleB= st.number_input("Maximum warpage angle B (degree):", format="%.2f", width=300, value=1.0, key="B", on_change=AM_typed_in)
with col2_row1:
with st.container(border=False): # Container with a border
angleC= st.number_input("Maximum warpage angle C (degree):", format="%.2f", width=300, value=1.0, key="C", on_change=AM_typed_in)
max_stress= st.number_input("Maximum residual stress (MPa):", format="%.2f", width=300, value=100.0, key="max_stress", on_change=AM_typed_in)
with col3_row1:
with st.container(border=False): # Container with a border
image = Image.open('figures/Hat_Section_AM1.png')
new_image = image.resize((350, 200))
st.image(new_image, caption='')
with col4_row1:
with st.container(border=False): # Container with a border
image = Image.open('figures/Hat_Section_AM2.png')
new_image = image.resize((350, 200))
st.image(new_image, caption='')
st.write("")
if st.session_state.AM_input_changed == True:
st.session_state.AM_design_button_clicked = False
st.session_state.AM_input_changed = False
st.button("AM process design", use_container_width=True, on_click=AM_design_click)
if st.session_state.AM_design_button_clicked == True:
st.write("Process parameters")
data1 = pd.DataFrame({
'Matrix material': ['PP'],
'Fiber material': ['Glass'],
'Build direction': ['Vertical']})
y_target = np.array([angleA, angleB, angleC, max_stress])
best = inverse_design(material_base="PP", fiber="GF", fiber_vf=45.0,
y_target=y_target, n_restarts=20, epochs=100, use_lbfgs=True)
#st.table(data1)
# Define styles
styles = [
dict(selector="th", props=[('font-size', '14px')]), # Header font size
dict(selector="td", props=[('font-size', '12px')]) # Cell font size
]
styled_df = style_dataframe_borders(data1)
st.dataframe(data1, hide_index=True, width=500)
data2 = pd.DataFrame({
'Nozzel velocity (cm/s)': [best['input'][0]],
'Extruder temperature (C)': [best['input'][1]],
'Bed temperature (C)': [best['input'][2]]})
st.dataframe(data2, hide_index=True, width=500)
data3 = pd.DataFrame({
'Maximum angle A (degree)': [best['output'][0]],
'Maximum angle B (degree)': [best['output'][1]],
'Maximum angle C (degree)': [best['output'][2]],
'Maximum residual stress': [best['output'][3]]
})
st.dataframe(data3, hide_index=True, width=700)