File size: 2,806 Bytes
fea61f6
 
856260a
fea61f6
856260a
 
 
 
 
 
 
 
 
 
fea61f6
856260a
 
 
 
 
 
 
 
 
077a4b7
856260a
fea61f6
856260a
fea61f6
856260a
077a4b7
856260a
077a4b7
856260a
 
 
 
 
fea61f6
856260a
fea61f6
856260a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fea61f6
856260a
 
fea61f6
856260a
 
fea61f6
856260a
fea61f6
 
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import matplotlib.pyplot as plt

def visualize_results(simulator, length, width, thickness, stress, deformation):
    """
    Generates 2D visualizations for simulation results.
    Parameters:
        simulator (str): Name of the simulator (e.g., 'Python-Based Solver').
        length (float): Length of the object.
        width (float): Width of the object.
        thickness (float): Thickness of the object.
        stress (float): Stress value.
        deformation (float): Deformation value.
    Returns:
        str: Path to the 2D visualization image.
    """
    # Generate 2D bar chart
    fig, ax = plt.subplots(figsize=(6, 4))
    ax.bar(["Stress", "Deformation"], [stress, deformation], color=["red", "blue"])
    ax.set_title(f"Simulation Results ({simulator})")
    ax.set_ylabel("Magnitude")
    ax.grid(True, linestyle="--", alpha=0.6)
    
    # Save the chart
    output_path = "results_2d.png"
    plt.savefig(output_path)
    plt.close(fig)

    return output_path, None

def visualize_end_product(simulation_type, length, width, thickness, deformation):
    """
    Visualize the end product based on the parameters.
    Parameters:
        simulation_type (str): 'plate' or 'beam'.
        length (float): Length of the product (mm).
        width (float): Width of the product (mm).
        thickness (float): Thickness of the product (mm).
        deformation (float): Deformation (mm).
    Returns:
        str: Path to the saved image of the visualization.
    """
    fig, ax = plt.subplots(figsize=(6, 4))
    
    if simulation_type == "plate":
        # Draw the plate
        rect = plt.Rectangle((0, 0), length, width, color="lightblue", alpha=0.8)
        ax.add_patch(rect)
        # Add deformation as text
        ax.text(
            length / 2, width / 2,
            f"Deformation: {deformation:.2f} mm",
            color="red", fontsize=10, ha="center"
        )
    elif simulation_type == "beam":
        # Draw the beam
        rect = plt.Rectangle((0, 0), length, thickness, color="lightgreen", alpha=0.8)
        ax.add_patch(rect)
        # Add deformation as text
        ax.text(
            length / 2, thickness / 2,
            f"Deflection: {deformation:.2f} mm",
            color="red", fontsize=10, ha="center"
        )
    else:
        raise ValueError("Invalid simulation type.")

    # Add dimensions
    ax.set_xlim(-10, length + 10)
    ax.set_ylim(-10, max(width, thickness) + 10)
    ax.set_title(f"Visualization of {simulation_type.capitalize()} End Product")
    ax.set_xlabel("Length (mm)")
    ax.set_ylabel("Width/Thickness (mm)")
    ax.grid(True, linestyle="--", alpha=0.6)

    # Save the visualization
    output_path = f"{simulation_type}_end_product.png"
    plt.savefig(output_path)
    plt.close(fig)

    return output_path