Spaces:
Build error
Build error
Create apdl_generator/apdl_plate.py
Browse files- apdl_generator/apdl_plate.py +42 -0
apdl_generator/apdl_plate.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# apdl_generator/apdl_plate.py
|
| 2 |
+
|
| 3 |
+
def generate_plate_apdl(thickness, length, width, hole_diameter, force):
|
| 4 |
+
"""
|
| 5 |
+
Generate APDL script for a plate with an optional hole.
|
| 6 |
+
|
| 7 |
+
Parameters:
|
| 8 |
+
thickness (float): Thickness of the plate in mm.
|
| 9 |
+
length (float): Length of the plate in mm.
|
| 10 |
+
width (float): Width of the plate in mm.
|
| 11 |
+
hole_diameter (float): Diameter of the hole (0 if no hole).
|
| 12 |
+
force (float): Force applied to the plate in N.
|
| 13 |
+
|
| 14 |
+
Returns:
|
| 15 |
+
str: Path to the generated APDL file.
|
| 16 |
+
"""
|
| 17 |
+
# Generate the APDL script for a plate
|
| 18 |
+
apdl_script = f"""
|
| 19 |
+
! APDL script for Plate Simulation
|
| 20 |
+
/PREP7
|
| 21 |
+
BLC4, 0, {length}, {width}, {thickness} ! Create plate geometry
|
| 22 |
+
! Create hole if applicable
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
if hole_diameter > 0:
|
| 26 |
+
apdl_script += f"""
|
| 27 |
+
CIRC, {length / 2}, {width / 2}, {hole_diameter / 2} ! Create hole in the center
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
+
apdl_script += f"""
|
| 31 |
+
/SOLU
|
| 32 |
+
F, 1, FX, {force} ! Apply force at node 1
|
| 33 |
+
SOLVE
|
| 34 |
+
FINISH
|
| 35 |
+
"""
|
| 36 |
+
|
| 37 |
+
# Save APDL script to a file
|
| 38 |
+
apdl_file_path = "/tmp/generated_plate_apdl.txt"
|
| 39 |
+
with open(apdl_file_path, "w") as f:
|
| 40 |
+
f.write(apdl_script)
|
| 41 |
+
|
| 42 |
+
return apdl_file_path
|