0% found this document useful (0 votes)
10 views3 pages

Vamsi - Assignment - Ipynb - Colab

Uploaded by

sandyvisha661981
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Vamsi - Assignment - Ipynb - Colab

Uploaded by

sandyvisha661981
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

12/2/24, 12:00 AM vamsi_assignment.

ipynb - Colab

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

# Load data from Excel


file_path = '/content/vamsi_coordinates.xlsx'
data = pd.read_excel(file_path).values # Assuming all columns are numeric

# Extract undeformed and deformed coordinates


undeformed_coords = data[:, 0:2] # Columns 1 and 2: Undeformed X, Y
deformed_coords = data[:, 2:4] # Columns 3 and 4: Deformed x, y

# Check the number of nodes


num_undeformed_coords = len(undeformed_coords)
num_deformed_coords = len(deformed_coords)
print(f"Number of undeformed coordinates: {num_undeformed_coords}")
print(f"Number of deformed coordinates: {num_deformed_coords}")

# Ensure that the data size matches the expected grid (15 x 18 = 270 nodes)
expected_num_coords = 15 * 18
if num_undeformed_coords != expected_num_coords or num_deformed_coords != expected_num_coords:
print("Warning: Number of coordinates does not match expected grid size!")

# Grid connectivity (15x18 grid)


num_elements = 15 * 17 # 15 rows, 17 elements per row
connectivity = np.zeros((num_elements, 4), dtype=int)

# Generate connectivity matrix (adjusted for 15x17 elements)


counter = 0
for j in range(15):
for i in range(17): # 17 elements per row, for the 15x18 grid
connectivity[counter, :] = [
j + i * 16,
j + 1 + i * 16,
j + (i + 1) * 16,
j + 1 + (i + 1) * 16
]
counter += 1

# Storage for tensors and values


F_all = np.zeros((num_elements, 2, 2)) # Deformation gradient
principal_stretches = np.zeros((num_elements, 2)) # \u03bb1, \u03bb2

# Material parameters
material_params = {
'Ogden': {'mu': 0.0783, 'alpha': 2.5279},
'Mooney-Rivlin': {'C1': 0.1037, 'C2': -0.0613},
'Neo-Hookean': {'C1': 0.0886},
'Yeoh': {'C1': 0.1522, 'C2': -0.0048, 'C3': 0.0001},
}

# Loop through all elements


for e, nodes in enumerate(connectivity):
# Undeformed and deformed coordinates
X = undeformed_coords[nodes, :]
x = deformed_coords[nodes, :]

# Edge vectors
V1 = X[1] - X[0]
V2 = X[3] - X[0]
v1 = x[1] - x[0]
v2 = x[3] - x[0]

# Deformation gradient
V = np.column_stack((V1, V2))
v = np.column_stack((v1, v2))
F = np.dot(v, np.linalg.inv(V))
F_all[e, :, :] = F

# Principal stretches (eigenvalues of C)


C = np.dot(F.T, F)
eigvals = np.linalg.eigvalsh(C)
principal_stretches[e, :] = np.sqrt(eigvals)

# Function to compute stresses


def compute_stresses(principal_stretches, material_params):
num elements = len(principal stretches)
https://colab.research.google.com/drive/1MRdp9Rd1zlFwPkoIpUUSPqUnPpntCYi9#scrollTo=7xPoRngdN_ip&printMode=true 1/3
12/2/24, 12:00 AM vamsi_assignment.ipynb - Colab
num_elements len(principal_stretches)
stresses = {model: np.zeros((num_elements, 2)) for model in material_params}

for e in range(num_elements):
lambda1, lambda2 = principal_stretches[e, :]

# Ogden Model
if 'Ogden' in material_params:
mu, alpha = material_params['Ogden']['mu'], material_params['Ogden']['alpha']
P1 = mu * (lambda1**(alpha - 1) - lambda1**(-0.5 * (alpha + 1)))
P2 = mu * (lambda2**(alpha - 1) - lambda2**(-0.5 * (alpha + 1)))
stresses['Ogden'][e, :] = [P1 / lambda1, P2 / lambda2]

# Mooney-Rivlin Model
if 'Mooney-Rivlin' in material_params:
C1, C2 = material_params['Mooney-Rivlin']['C1'], material_params['Mooney-Rivlin']['C2']
P1 = 2 * C1 * (lambda1 - 1 / lambda1**2) + 2 * C2 * (1 / lambda1 - lambda1**2)
P2 = 2 * C1 * (lambda2 - 1 / lambda2**2) + 2 * C2 * (1 / lambda2 - lambda2**2)
stresses['Mooney-Rivlin'][e, :] = [P1 / lambda1, P2 / lambda2]

# Neo-Hookean Model
if 'Neo-Hookean' in material_params:
C1 = material_params['Neo-Hookean']['C1']
P1 = 2 * C1 * (lambda1 - 1 / lambda1**2)
P2 = 2 * C1 * (lambda2 - 1 / lambda2**2)
stresses['Neo-Hookean'][e, :] = [P1 / lambda1, P2 / lambda2]

# Yeoh Model
if 'Yeoh' in material_params:
C1, C2, C3 = (material_params['Yeoh']['C1'],
material_params['Yeoh']['C2'],
material_params['Yeoh']['C3'])
P1 = 2 * (C1 * (lambda1 - 1 / lambda1**2) +
2 * C2 * (lambda1**2 - 3) * (lambda1 - 1 / lambda1**2) +
3 * C3 * (lambda1**2 - 3)**2 * (lambda1 - 1 / lambda1**2))
P2 = 2 * (C1 * (lambda2 - 1 / lambda2**2) +
2 * C2 * (lambda2**2 - 3) * (lambda2 - 1 / lambda2**2) +
3 * C3 * (lambda2**2 - 3)**2 * (lambda2 - 1 / lambda2**2))
stresses['Yeoh'][e, :] = [P1 / lambda1, P2 / lambda2]

return stresses

# Compute stresses
stresses = compute_stresses(principal_stretches, material_params)

# Visualization
fig, axes = plt.subplots(4, 2, figsize=(18, 16), dpi=200)
models = list(stresses.keys())

def plot_stress_component(ax, stress_data, title):


grid_data = stress_data.reshape(15, 17) # Adjusted for the number of elements
im = ax.imshow(grid_data, cmap='jet', aspect='auto')
ax.set_title(title)
plt.colorbar(im, ax=ax)

# Plot stress components for each model


for i, model in enumerate(models):
plot_stress_component(axes[i, 0], stresses[model][:, 0], f'{model} Model - Cauchy Stress (\u03c31)')
plot_stress_component(axes[i, 1], stresses[model][:, 1], f'{model} Model - Cauchy Stress (\u03c32)')

# Adjust layout and display


plt.tight_layout()
plt.show()

https://colab.research.google.com/drive/1MRdp9Rd1zlFwPkoIpUUSPqUnPpntCYi9#scrollTo=7xPoRngdN_ip&printMode=true 2/3
12/2/24, 12:00 AM vamsi_assignment.ipynb - Colab
Number of undeformed coordinates: 303
Number of deformed coordinates: 303
Warning: Number of coordinates does not match expected grid size!

https://colab.research.google.com/drive/1MRdp9Rd1zlFwPkoIpUUSPqUnPpntCYi9#scrollTo=7xPoRngdN_ip&printMode=true 3/3

You might also like