Last active
April 2, 2024 02:31
-
-
Save terjehaukaas/919433e85d5f94bd364b0c776f9d0257 to your computer and use it in GitHub Desktop.
G2 Example 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ------------------------------------------------------------------------ | |
# The following Python code is implemented by Professor Terje Haukaas at | |
# the University of British Columbia in Vancouver, Canada. It is made | |
# freely available online at terje.civil.ubc.ca together with notes, | |
# examples, and additional Python code. Please be cautious when using | |
# this code; it may contain bugs and comes without warranty of any kind. | |
# ------------------------------------------------------------------------ | |
import matplotlib.pyplot as plt | |
from G2MaterialPlasticity import * | |
from G2MaterialBilinear import * | |
from G2MaterialBoucWen import * | |
# ------------------------------------------------------------------------ | |
# INPUT | |
# ------------------------------------------------------------------------ | |
# Applied strain history | |
strain0 = 0.005 # Magnitude of sin(x) strain history | |
nsine = 1.02 # Number of sine waves of length 2*pi | |
nsteps = 100 # Number of time steps from 0 to 2*pi | |
# Material parameters | |
E = 200000.0 # Young's modulus | |
fy = 350.0 # Yield stress | |
alpha = 0.01 # Second-slope stiffness factor | |
eta = 3 # Bouc-Wen sharpness | |
gamma = 0.5 # Bouc-Wen parameter | |
beta = 0.5 # Bouc-Wen parameter | |
tolerance = 1e-3 # Newton-Raphson within Bouc-Wen | |
maxNumIter = 100 # Newton-Raphson within Bouc-Wen | |
H = alpha*E/(1-alpha) # Kinematic hardening parameter | |
K = 1 # Linear isotropic hardening parameter | |
delta = 0 # Saturation isotropic hardening parameter | |
fy_inf = 100.0 # Asymptotic yield stress for saturation isotropic hardening | |
# ------------------------------------------------------------------------ | |
# RESPONSE TO sin(x) STRAIN HISTORY | |
# ------------------------------------------------------------------------ | |
# Create the plot | |
plt.clf() | |
plt.ion() | |
plt.title('Stress-strain curve') | |
plt.grid(True) | |
plt.autoscale(True) | |
plt.ylabel('Stress') | |
plt.xlabel('Strain') | |
# Create storage for results | |
pseudoTime = [] | |
strainArray = [] | |
bilinearStressArray = [] | |
plasticStressArray = [] | |
boucWenStressArray = [] | |
# Start at zero | |
pseudoTime.append(0.0) | |
strainArray.append(0.0) | |
bilinearStressArray.append(0.0) | |
plasticStressArray.append(0.0) | |
boucWenStressArray.append(0.0) | |
# Create the material objects | |
thePlasticityMaterial = plasticityMaterial(['Plasticity', E, fy, H, K, delta, fy_inf]) | |
theBilinearMaterial = bilinearMaterial(['Bilinear', E, fy, alpha]) | |
theBoucWenMaterial = boucWenMaterial(['BoucWen', E, fy, alpha, eta, beta, gamma, tolerance, maxNumIter]) | |
# Walk along the sine function | |
previousStrain = 0.0 | |
for n in range(int(nsine*float(nsteps))): | |
# Compute value of strain driving the problem | |
totalStrain = strain0 * np.sin(n * 2 * np.pi / nsteps) | |
strainIncrement = totalStrain - previousStrain | |
previousStrain = totalStrain | |
# Material state determination (give strain in U-vector format) | |
[plasticStress, stiffness] = thePlasticityMaterial.state([totalStrain, 0.0, 0.0]) | |
[bilinearStress, stiffness] = theBilinearMaterial.state([totalStrain, strainIncrement, 0.0]) | |
[boucWenStress, stiffness] = theBoucWenMaterial.state([totalStrain, strainIncrement, 0.0]) | |
# Commit the state | |
thePlasticityMaterial.commit() | |
theBilinearMaterial.commit() | |
theBoucWenMaterial.commit() | |
# Add results to storage | |
pseudoTime.append(n+1) | |
strainArray.append(totalStrain) | |
bilinearStressArray.append(bilinearStress) | |
plasticStressArray.append(plasticStress) | |
boucWenStressArray.append(boucWenStress) | |
# Add points to plot | |
plt.plot(strainArray, bilinearStressArray, 'bo-', linewidth=1.0, markersize=5, label='Bilinear') | |
plt.plot(strainArray, plasticStressArray, 'ro-', linewidth=1.0, markersize=2, label='Plasticity') | |
plt.plot(strainArray, boucWenStressArray, 'ko-', linewidth=1.0, markersize=2, label='Bouc-Wen') | |
if n == 0: | |
plt.legend() | |
plt.pause(0.001) | |
# Pause and view the plot | |
print('\n'"Click somewhere in the plot to continue...") | |
#plt.savefig('Figure.pdf', format='pdf') | |
plt.waitforbuttonpress() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment