karthikmn commited on
Commit
be44ec8
·
verified ·
1 Parent(s): 3d5395a

Create python_simulation.py

Browse files
Files changed (1) hide show
  1. simulators/python_simulation.py +29 -0
simulators/python_simulation.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import numpy as np
3
+
4
+ def run_python_simulation(apdl_path, simulation_type, thickness, length, width, force, load, elastic_modulus):
5
+ """
6
+ Simulates stress and deformation using analytical formulas.
7
+ Parameters:
8
+ apdl_path (str): Path to the APDL script.
9
+ simulation_type (str): 'plate' or 'beam'.
10
+ thickness (float): Thickness of the material.
11
+ length (float): Length of the material.
12
+ width (float): Width of the material.
13
+ force (float): Applied force.
14
+ load (float): Applied load.
15
+ elastic_modulus (float): Elastic modulus of the material.
16
+ Returns:
17
+ tuple: (stress, deformation).
18
+ """
19
+ if simulation_type == "plate":
20
+ stress = force / (length * width) if length * width > 0 else 0
21
+ deformation = (stress / elastic_modulus) * thickness
22
+ elif simulation_type == "beam":
23
+ I = (width * thickness**3) / 12 # Moment of inertia
24
+ deformation = (load * (length / 1000)**3) / (8 * elastic_modulus * I) if length > 0 else 0
25
+ stress = load / (width * thickness) if width * thickness > 0 else 0
26
+ else:
27
+ raise ValueError("Invalid simulation type.")
28
+
29
+ return stress * 1e-6, deformation * 1e3 # Convert to MPa and mm