Spaces:
Sleeping
Sleeping
Update simulators/python_simulation.py
Browse files- simulators/python_simulation.py +30 -12
simulators/python_simulation.py
CHANGED
@@ -1,26 +1,44 @@
|
|
1 |
import numpy as np
|
2 |
|
3 |
-
def run_python_simulation(apdl_path, simulation_type,
|
4 |
"""
|
5 |
-
Simulate
|
6 |
|
7 |
Parameters:
|
8 |
-
apdl_path (str):
|
9 |
simulation_type (str): 'plate' or 'beam'.
|
10 |
-
|
|
|
|
|
|
|
|
|
11 |
|
12 |
Returns:
|
13 |
-
stress (float):
|
14 |
-
deformation (float):
|
15 |
"""
|
16 |
-
#
|
|
|
|
|
|
|
17 |
if simulation_type == "plate":
|
18 |
-
stress
|
19 |
-
|
|
|
|
|
|
|
20 |
elif simulation_type == "beam":
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
23 |
else:
|
24 |
raise ValueError("Invalid simulation type.")
|
25 |
|
26 |
-
|
|
|
|
|
|
|
|
1 |
import numpy as np
|
2 |
|
3 |
+
def run_python_simulation(apdl_path, simulation_type, thickness, length, width, force, load):
|
4 |
"""
|
5 |
+
Simulate stress and deformation based on inputs.
|
6 |
|
7 |
Parameters:
|
8 |
+
apdl_path (str): APDL script path.
|
9 |
simulation_type (str): 'plate' or 'beam'.
|
10 |
+
thickness (float): Thickness of the material (mm).
|
11 |
+
length (float): Length of the material (mm).
|
12 |
+
width (float): Width of the material (mm).
|
13 |
+
force (float): Applied force (N) (optional).
|
14 |
+
load (float): Applied load (N) (optional).
|
15 |
|
16 |
Returns:
|
17 |
+
stress (float): Simulated stress (MPa).
|
18 |
+
deformation (float): Simulated deformation (mm).
|
19 |
"""
|
20 |
+
# Elastic modulus (Pa) for steel (rigid material)
|
21 |
+
E = 2e11 # 200 GPa (steel)
|
22 |
+
|
23 |
+
# Handle plate and beam separately
|
24 |
if simulation_type == "plate":
|
25 |
+
# Calculate stress: Force applied over cross-sectional area
|
26 |
+
stress = force / (length * width) if length * width > 0 else 0
|
27 |
+
# Calculate deformation: Axial deformation based on stress
|
28 |
+
deformation = (stress / E) * thickness
|
29 |
+
|
30 |
elif simulation_type == "beam":
|
31 |
+
# Moment of inertia for a rectangular beam
|
32 |
+
I = (width * thickness**3) / 12 # m^4
|
33 |
+
# Calculate deformation: Beam deflection under uniform load
|
34 |
+
deformation = (load * (length / 1000)**3) / (8 * E * I) if length > 0 else 0
|
35 |
+
# Calculate stress: Load applied over the cross-sectional area
|
36 |
+
stress = load / (width * thickness) if width * thickness > 0 else 0
|
37 |
+
|
38 |
else:
|
39 |
raise ValueError("Invalid simulation type.")
|
40 |
|
41 |
+
# Convert stress to MPa and deformation to mm
|
42 |
+
stress_mpa = stress * 1e-6
|
43 |
+
deformation_mm = deformation * 1e3 # Convert from meters to millimeters
|
44 |
+
return stress_mpa, deformation_mm
|