SuriRaja commited on
Commit
bd68c65
·
verified ·
1 Parent(s): c260894

Update simulators/python_simulation.py

Browse files
Files changed (1) hide show
  1. 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, **kwargs):
4
  """
5
- Simulate results based on the APDL script using Python.
6
 
7
  Parameters:
8
- apdl_path (str): Path to the APDL script file.
9
  simulation_type (str): 'plate' or 'beam'.
10
- kwargs: Simulation parameters.
 
 
 
 
11
 
12
  Returns:
13
- stress (float): Calculated stress (MPa).
14
- deformation (float): Total deformation (mm).
15
  """
16
- # Simplified simulation logic
 
 
 
17
  if simulation_type == "plate":
18
- stress = kwargs["force"] / (kwargs["length"] * kwargs["width"])
19
- deformation = stress / (2e11) * kwargs["thickness"]
 
 
 
20
  elif simulation_type == "beam":
21
- stress = kwargs["load"] / (kwargs["length"] * kwargs["width"])
22
- deformation = stress / (2e11) * kwargs["length"]
 
 
 
 
 
23
  else:
24
  raise ValueError("Invalid simulation type.")
25
 
26
- return stress * 1e6, deformation * 1e3
 
 
 
 
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