File size: 8,330 Bytes
c4ec6ec
 
 
 
 
6977ea8
c4ec6ec
 
 
 
 
6977ea8
c4ec6ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
741fd5f
c4ec6ec
 
 
 
 
 
 
 
 
 
 
 
741fd5f
 
c4ec6ec
 
 
 
 
 
 
 
 
 
 
 
 
 
c23f1ad
c4ec6ec
 
 
 
 
c7147bd
 
 
 
c4ec6ec
 
 
 
 
 
 
 
c7147bd
c4ec6ec
6977ea8
 
c4ec6ec
c23f1ad
 
 
 
c7147bd
 
c4ec6ec
6977ea8
 
 
 
 
c4ec6ec
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#######################
# 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_inverse 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("""
<style>
/* Target the input element within its container (adjust class name as needed via browser inspection) */
.stTextInput input {
    border: 1px solid #333333; /* Set border width, style, and color */
    border-radius: 6px; /* Optional: adds rounded corners */
    padding: 10px; /* Optional: adds inner spacing */
}
</style>
""", unsafe_allow_html=True)

st.markdown("""
<style>

[data-testid="block-container"] {
    padding-left: 2rem;
    padding-right: 2rem;
    padding-top: 1rem;
    padding-bottom: 0rem;
    margin-bottom: -7rem;
}

[data-testid="stVerticalBlock"] {
    padding-left: 0rem;
    padding-right: 0rem;
}

[data-testid="stMetric"] {
    background-color: #393939;
    text-align: center;
    padding: 15px 0;
}

[data-testid="stMetricLabel"] {
  display: flex;
  justify-content: center;
  align-items: center;
}

[data-testid="stMetricDeltaIcon-Up"] {
    position: relative;
    left: 38%;
    -webkit-transform: translateX(-50%);
    -ms-transform: translateX(-50%);
    transform: translateX(-50%);
}

[data-testid="stMetricDeltaIcon-Down"] {
    position: relative;
    left: 38%;
    -webkit-transform: translateX(-50%);
    -ms-transform: translateX(-50%);
    transform: translateX(-50%);
}

/* Main app + sidebar, target the label element itself */
[data-testid="stAppViewContainer"] label,
[data-testid="stWidgetLabel"] label {
font-size: 18px !important;
font-weight: 600 !important;   /* optional */
color: #444 !important;         /* optional */
}

/* Some versions wrap label text inside a <div><p> */
[data-testid="stAppViewContainer"] label > div > p,
[data-testid="stWidgetLabel"] label > div > p {
font-size: 18px !important;
font-weight: 600 !important;
}
</style>
""", unsafe_allow_html=True)

st.markdown("""
<style>
div.stButton > button:first-child {
    background-color: #ee7700; /* background */
    color: white; /* White text */
    font-size: 20px;
    border-radius: 10px;
    # display: block; # this line and the next center the button horizontally 
    # margin: 0 auto;
}
</style>
""", unsafe_allow_html=True)

st.markdown("""
<style>
div[data-testid="stVirtualDropdown"] > div {
    max-height: 10px !important; /* Adjust this value as needed */
    overflow-y: auto;
}
</style>
""", unsafe_allow_html=True)


st.set_page_config(initial_sidebar_state="collapsed")

st.markdown(
    """
<style>
    [data-testid="collapsedControl"] {
        display: none
    }
</style>
""",
    unsafe_allow_html=True,
)


st.markdown("""
<style>
/* Target all table cells and headers */
table, th, td {
    border: 2px solid #333333; /* Change to your desired color */
    border-collapse: collapse; /* Ensure borders touch */
}
/* Optional: adjust padding */
th, td {
    padding: 8px; 
}
</style>
""", unsafe_allow_html=True)

st.markdown("""
<style>
/* Targets the table headers */
.stDataFrame table th {
    font-size: 26px; 
}
/* Targets the table data cells */
.stDataFrame table td {
    font-size: 24px; 
}
</style>
""", 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 Injection Molding")
st.write("")
st.write("")
st.write("")

st.write("")
st.write(r"$\textsf{\textbf{\Large Injection Molding Requirements}}$")

col1_row1, col2_row1, col3_row1, col4_row1 = st.columns([0.25,0.25,0.15,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/image001.png')
        new_image = image.resize((150, 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("Injection molding process design", 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'],
    'Fiber volume fraction (%)': [10],
    'Gate location': [1]
    })
    
    #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=600)
    
    best = inverse_design(gate_loc=1, matrix='PP', fiber='GF', fiber_vf=0.1, y_target=np.array([angleA, angleB, angleC]), n_restarts=5, epochs=100, use_lbfgs=True)
    
    data2 = pd.DataFrame({
    'Packing pressure (MPa)': [best["input"][0]],
    'Packing time (s)': [best["input"][1]],
    'Mold temperature (C)': [best["input"][2]],
    'Injection speed (cm^3/s)': [best["input"][3]]
    })
    st.dataframe(data2, hide_index=True, width=600)
 
    # data3 = pd.DataFrame({
    # 'Maximum angle A': [1.2],
    # 'Maximum angle B': [2.2],
    # 'Maximum angle C': [1.0]})
    # st.dataframe(data3, hide_index=True, width=600)