3dsimulation2.0 / simulators /python_simulation.py
karthikmn's picture
Create python_simulation.py
be44ec8 verified
import numpy as np
def run_python_simulation(apdl_path, simulation_type, thickness, length, width, force, load, elastic_modulus):
"""
Simulates stress and deformation using analytical formulas.
Parameters:
apdl_path (str): Path to the APDL script.
simulation_type (str): 'plate' or 'beam'.
thickness (float): Thickness of the material.
length (float): Length of the material.
width (float): Width of the material.
force (float): Applied force.
load (float): Applied load.
elastic_modulus (float): Elastic modulus of the material.
Returns:
tuple: (stress, deformation).
"""
if simulation_type == "plate":
stress = force / (length * width) if length * width > 0 else 0
deformation = (stress / elastic_modulus) * thickness
elif simulation_type == "beam":
I = (width * thickness**3) / 12 # Moment of inertia
deformation = (load * (length / 1000)**3) / (8 * elastic_modulus * I) if length > 0 else 0
stress = load / (width * thickness) if width * thickness > 0 else 0
else:
raise ValueError("Invalid simulation type.")
return stress * 1e-6, deformation * 1e3 # Convert to MPa and mm