jithenderchoudary commited on
Commit
efee3b8
·
verified ·
1 Parent(s): caa40d3

Update simulators/pycalculix_simulation.py

Browse files
Files changed (1) hide show
  1. simulators/pycalculix_simulation.py +36 -0
simulators/pycalculix_simulation.py CHANGED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pycalculix import *
2
+
3
+ def run_pycalculix_simulation(length, width, thickness, force):
4
+ """
5
+ Executes a PyCalculix simulation.
6
+
7
+ Parameters:
8
+ length (float): Length of the plate/beam.
9
+ width (float): Width of the plate/beam.
10
+ thickness (float): Thickness of the plate/beam.
11
+ force (float): Applied force.
12
+
13
+ Returns:
14
+ tuple: (stress, deformation) from the simulation.
15
+ """
16
+ # Create a PyCalculix model
17
+ model = Model("Plate")
18
+ part = model.make_rect(length, width)
19
+
20
+ # Apply material properties
21
+ mat = Material("Steel")
22
+ mat.set_mech_props(210e9, 0.3) # Elastic modulus (Pa) and Poisson's ratio
23
+ model.set_matl(part, mat)
24
+
25
+ # Apply boundary conditions
26
+ model.set_constr_bc(part.get_edge("LEFT"), 'ALL') # Clamped edge
27
+ model.set_force_bc(part.get_edge("RIGHT"), 'FY', force)
28
+
29
+ # Solve the model
30
+ model.run_sim()
31
+
32
+ # Extract results
33
+ stress = model.get_max_stress()
34
+ deformation = model.get_max_displacement()
35
+
36
+ return stress, deformation