mail@pastecode.io avatar
6 months ago
2.1 kB
# For a compression test on materials, a typical approach involves applying a compressive force to a material specimen
# and measuring its response. The basic steps are:
# 1. Create a sample of the material with known dimensions.
# 2. Apply a compressive force to the sample.
# 3. Record the force and the corresponding deformation of the sample.
# 4. Calculate the stress (force divided by the cross-sectional area) and strain (deformation divided by original length).

# However, without specific material properties or test conditions, I'll provide a simple simulation of a compression test.
# This simulation assumes a linear elastic material (like a simplified steel or aluminum) for demonstration purposes.

import numpy as np
import matplotlib.pyplot as plt

# Material properties (assuming a linear elastic material)
elastic_modulus = 200000  # Modulus of Elasticity in MPa (e.g., for steel)
yield_strength = 250  # Yield Strength in MPa (typical value for a medium strength steel)

# Sample dimensions (for stress calculation)
cross_sectional_area = 10  # in square mm (e.g., a 10 mm diameter circular cross-section)

# Force application (simplified linear increase in force)
max_force = 5000  # Maximum force applied in N
force_steps = np.linspace(0, max_force, 100)  # Incremental steps of force

# Stress-Strain calculation
stress = force_steps / cross_sectional_area  # Stress = Force / Area
strain = stress / elastic_modulus  # Strain = Stress / Elastic Modulus (Hooke's Law)

# Yield point calculation (where material yields)
yield_point = np.where(stress >= yield_strength)[0][0]

# Plotting the Stress-Strain curve
plt.figure(figsize=(8, 6))
plt.plot(strain[:yield_point + 1], stress[:yield_point + 1], label='Elastic Region (Linear)')
plt.plot(strain[yield_point:], stress[yield_point:], label='Plastic Region (Yield Point Reached)', linestyle='dashed')
plt.axhline(y=yield_strength, color='r', linestyle='--', label='Yield Strength')
plt.title('Stress-Strain Curve of a Compression Test')
plt.ylabel('Stress (MPa)')
Leave a Comment