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

Create pycalculix_simulation.py

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