File size: 1,239 Bytes
be44ec8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

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