Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -5,85 +5,77 @@ import time
|
|
5 |
|
6 |
# Page Configurations
|
7 |
st.set_page_config(
|
8 |
-
page_title="Gun Firing
|
9 |
layout="centered"
|
10 |
)
|
11 |
|
12 |
# Title and Description
|
13 |
-
st.title("Gun Firing
|
14 |
-
st.write("This app simulates the
|
15 |
|
16 |
# Parameters Input
|
17 |
st.sidebar.header("Simulation Parameters")
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
21 |
|
22 |
-
def
|
23 |
# Constants
|
24 |
-
|
25 |
-
|
26 |
-
#
|
27 |
-
|
28 |
-
|
29 |
-
#
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
#
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
43 |
|
44 |
# Simulate and Plot
|
45 |
-
if st.button("
|
46 |
-
st.write("##
|
47 |
-
st.write("Simulating
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
# Plot
|
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 |
-
bullet_ax.set_xlim(0, max(x))
|
80 |
-
bullet_ax.set_ylim(0, max(y) + 5)
|
81 |
-
bullet_ax.set_xlabel("Distance (m)")
|
82 |
-
bullet_ax.set_ylabel("Height (m)")
|
83 |
-
bullet_ax.set_title("Bullet Animation")
|
84 |
-
bullet_ax.legend()
|
85 |
-
st.pyplot(bullet_fig)
|
86 |
-
progress_bar.progress(int((i / len(x)) * 100))
|
87 |
-
time.sleep(0.01)
|
88 |
-
|
89 |
-
st.write("Simulation Complete!")
|
|
|
5 |
|
6 |
# Page Configurations
|
7 |
st.set_page_config(
|
8 |
+
page_title="CBT: Gun Firing Internal Mechanism",
|
9 |
layout="centered"
|
10 |
)
|
11 |
|
12 |
# Title and Description
|
13 |
+
st.title("CBT: Gun Firing Internal Mechanism")
|
14 |
+
st.write("This app simulates the internal mechanism of a gun firing process, including the combustion and pressure dynamics inside the chamber.")
|
15 |
|
16 |
# Parameters Input
|
17 |
st.sidebar.header("Simulation Parameters")
|
18 |
+
chamber_pressure = st.sidebar.number_input("Chamber Pressure (MPa):", min_value=1, max_value=100, value=50, step=1)
|
19 |
+
barrel_length = st.sidebar.number_input("Barrel Length (cm):", min_value=10, max_value=200, value=50, step=5)
|
20 |
+
bullet_mass = st.sidebar.number_input("Bullet Mass (grams):", min_value=1, max_value=50, value=10, step=1)
|
21 |
+
gas_expansion_ratio = st.sidebar.slider("Gas Expansion Ratio:", min_value=1.0, max_value=5.0, value=1.5, step=0.1)
|
22 |
|
23 |
+
def simulate_internal_mechanism():
|
24 |
# Constants
|
25 |
+
chamber_pressure_pa = chamber_pressure * 1e6 # Convert MPa to Pa
|
26 |
+
barrel_length_m = barrel_length / 100 # Convert cm to meters
|
27 |
+
bullet_mass_kg = bullet_mass / 1000 # Convert grams to kg
|
28 |
+
|
29 |
+
# Time array for simulation (arbitrary resolution)
|
30 |
+
time_steps = np.linspace(0, 0.01, num=500) # 10 ms simulation
|
31 |
+
|
32 |
+
# Pressure dynamics (simplified as linear decay for simulation purposes)
|
33 |
+
pressure_profile = chamber_pressure_pa * np.exp(-time_steps / (gas_expansion_ratio * 0.002))
|
34 |
+
|
35 |
+
# Force on bullet
|
36 |
+
force_profile = pressure_profile * (np.pi * (0.01)**2) # Assuming a barrel diameter of 2 cm
|
37 |
+
|
38 |
+
# Acceleration of bullet
|
39 |
+
acceleration_profile = force_profile / bullet_mass_kg
|
40 |
+
|
41 |
+
# Velocity and displacement
|
42 |
+
velocity = np.cumsum(acceleration_profile * np.diff(np.insert(time_steps, 0, 0)))
|
43 |
+
displacement = np.cumsum(velocity * np.diff(np.insert(time_steps, 0, 0)))
|
44 |
+
|
45 |
+
return time_steps, pressure_profile, velocity, displacement
|
46 |
|
47 |
# Simulate and Plot
|
48 |
+
if st.button("Simulate Gun Firing!"):
|
49 |
+
st.write("## Internal Mechanism Simulation")
|
50 |
+
st.write("Simulating the internal dynamics of the gun firing process...")
|
51 |
+
|
52 |
+
time_steps, pressure_profile, velocity, displacement = simulate_internal_mechanism()
|
53 |
+
|
54 |
+
# Plot Chamber Pressure
|
55 |
+
fig1, ax1 = plt.subplots()
|
56 |
+
ax1.plot(time_steps * 1000, pressure_profile / 1e6, label="Chamber Pressure")
|
57 |
+
ax1.set_xlabel("Time (ms)")
|
58 |
+
ax1.set_ylabel("Pressure (MPa)")
|
59 |
+
ax1.set_title("Chamber Pressure Over Time")
|
60 |
+
ax1.legend()
|
61 |
+
st.pyplot(fig1)
|
62 |
+
|
63 |
+
# Plot Bullet Velocity
|
64 |
+
fig2, ax2 = plt.subplots()
|
65 |
+
ax2.plot(time_steps * 1000, velocity, label="Bullet Velocity")
|
66 |
+
ax2.set_xlabel("Time (ms)")
|
67 |
+
ax2.set_ylabel("Velocity (m/s)")
|
68 |
+
ax2.set_title("Bullet Velocity Over Time")
|
69 |
+
ax2.legend()
|
70 |
+
st.pyplot(fig2)
|
71 |
+
|
72 |
+
# Plot Bullet Displacement
|
73 |
+
fig3, ax3 = plt.subplots()
|
74 |
+
ax3.plot(time_steps * 1000, displacement, label="Bullet Displacement")
|
75 |
+
ax3.set_xlabel("Time (ms)")
|
76 |
+
ax3.set_ylabel("Displacement (m)")
|
77 |
+
ax3.set_title("Bullet Displacement Over Time")
|
78 |
+
ax3.legend()
|
79 |
+
st.pyplot(fig3)
|
80 |
+
|
81 |
+
st.write("Simulation Complete! Explore the dynamics of the gun's internal firing mechanism.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|