Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pyvista as pv
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from streamlit_pyvista import st_pyvista
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
# Material properties (dummy data)
|
| 7 |
+
materials = {
|
| 8 |
+
"Steel": {"Density": 7850, "Yield Strength": 250},
|
| 9 |
+
"Aluminum": {"Density": 2700, "Yield Strength": 50},
|
| 10 |
+
"Brass": {"Density": 8500, "Yield Strength": 200},
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
# Streamlit App
|
| 14 |
+
st.title("Interactive Punch and Die Design Tool")
|
| 15 |
+
st.sidebar.header("Input Parameters")
|
| 16 |
+
|
| 17 |
+
# User inputs for Punch Dimensions
|
| 18 |
+
st.sidebar.subheader("Punch Dimensions")
|
| 19 |
+
length = st.sidebar.slider("Length (mm)", 10, 200, 50)
|
| 20 |
+
width = st.sidebar.slider("Width (mm)", 10, 200, 30)
|
| 21 |
+
height = st.sidebar.slider("Height (mm)", 5, 100, 10)
|
| 22 |
+
|
| 23 |
+
# User inputs for Die Dimensions
|
| 24 |
+
st.sidebar.subheader("Die Dimensions")
|
| 25 |
+
inner_width = st.sidebar.slider("Inner Width (mm)", 10, 150, 40)
|
| 26 |
+
inner_height = st.sidebar.slider("Inner Height (mm)", 10, 150, 20)
|
| 27 |
+
die_thickness = st.sidebar.slider("Die Thickness (mm)", 5, 50, 15)
|
| 28 |
+
|
| 29 |
+
# Material Selection
|
| 30 |
+
st.sidebar.subheader("Material Selection")
|
| 31 |
+
material = st.sidebar.selectbox("Material", list(materials.keys()))
|
| 32 |
+
mesh_size = st.sidebar.slider("Mesh Size (mm)", 1, 10, 5)
|
| 33 |
+
force = st.sidebar.slider("Force Applied (kN)", 1, 1000, 200)
|
| 34 |
+
|
| 35 |
+
# Display selected material properties
|
| 36 |
+
st.sidebar.subheader("Material Properties")
|
| 37 |
+
st.sidebar.write(f"Density: {materials[material]['Density']} kg/m³")
|
| 38 |
+
st.sidebar.write(f"Yield Strength: {materials[material]['Yield Strength']} MPa")
|
| 39 |
+
|
| 40 |
+
# Function to create punch and die geometry
|
| 41 |
+
def create_geometry(length, width, height, inner_width, inner_height, thickness):
|
| 42 |
+
punch = pv.Box(bounds=(0, length, 0, width, 0, height))
|
| 43 |
+
die = pv.Box(bounds=(-inner_width / 2, inner_width / 2,
|
| 44 |
+
-inner_height / 2, inner_height / 2,
|
| 45 |
+
-thickness, 0))
|
| 46 |
+
return punch, die
|
| 47 |
+
|
| 48 |
+
# Generate models
|
| 49 |
+
punch, die = create_geometry(length, width, height, inner_width, inner_height, die_thickness)
|
| 50 |
+
|
| 51 |
+
# Display 3D Visualization
|
| 52 |
+
st.subheader("3D Visualization of Punch and Die")
|
| 53 |
+
plotter = pv.Plotter()
|
| 54 |
+
plotter.add_mesh(punch, color="blue", opacity=0.5, label="Punch")
|
| 55 |
+
plotter.add_mesh(die, color="red", opacity=0.5, label="Die")
|
| 56 |
+
plotter.add_axes()
|
| 57 |
+
plotter.show_bounds()
|
| 58 |
+
plotter.view_xy()
|
| 59 |
+
|
| 60 |
+
# Show the visualization in Streamlit
|
| 61 |
+
st_pyvista(plotter)
|
| 62 |
+
|
| 63 |
+
# Generate APDL Script
|
| 64 |
+
st.subheader("Generated APDL Script")
|
| 65 |
+
apdl_script = f"""
|
| 66 |
+
/PREP7
|
| 67 |
+
! Define material properties
|
| 68 |
+
MP,DENS,1,{materials[material]['Density']}
|
| 69 |
+
MP,YIELD,1,{materials[material]['Yield Strength']}
|
| 70 |
+
! Define punch geometry
|
| 71 |
+
BLOCK,0,{length},0,{width},0,{height}
|
| 72 |
+
! Define die geometry
|
| 73 |
+
BLOCK,-{inner_width/2},{inner_width/2},-{inner_height/2},{inner_height/2},-{die_thickness},0
|
| 74 |
+
! Mesh settings
|
| 75 |
+
ESIZE,{mesh_size}
|
| 76 |
+
! Apply force
|
| 77 |
+
F,1,FZ,{force}
|
| 78 |
+
/SOLU
|
| 79 |
+
SOLVE
|
| 80 |
+
/POST1
|
| 81 |
+
"""
|
| 82 |
+
|
| 83 |
+
st.code(apdl_script)
|
| 84 |
+
|
| 85 |
+
# Option to download APDL Script
|
| 86 |
+
st.download_button("Download APDL Script", apdl_script, "generated_apdl_script.txt")
|
| 87 |
+
|
| 88 |
+
# Placeholder for future validation results
|
| 89 |
+
st.subheader("Validation Feedback")
|
| 90 |
+
st.write("Validation results and stress maps will be shown here.")
|