Skip to content

Instantly share code, notes, and snippets.

@terjehaukaas
Last active April 2, 2024 02:30
Show Gist options
  • Save terjehaukaas/08d00d8d79440c327ee53dd97ffd06d5 to your computer and use it in GitHub Desktop.
Save terjehaukaas/08d00d8d79440c327ee53dd97ffd06d5 to your computer and use it in GitHub Desktop.
G2 Example 3
# ------------------------------------------------------------------------
# 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.
# ------------------------------------------------------------------------
from G2AnalysisNonlinearStatic import *
from G2Model import *
# | | |
# | P | P | P
# | | |
# 2 (3) V 4 (7) V 6 (11) V 8
# ###*-----------------*-----------------*------------------* A
# | * | * | * | |
# | * (4) | * (8) | * (12) | |
# |(2) * |(6) * |(10) * |(13) | H
# | * | * | * | |
# | 1 (1) * | 3 (5) * | 5 (9) * | 7 |
# ###*-----------------*-----------------*------------------* V
#
# <------- L -------><------- L ------><------- L ------->
# Input [N, m, kg, sec]
elementType = 2 # Nonlinear truss element with path-dependent material
materialType = 'BoucWen' # 'Bilinear' / 'Plasticity' / 'BoucWen'
L = 2.0 # Dimension in figure above
H = 2.0 # Dimension in figure above
P = 100e3 # Load in figure above
A = 0.04**2 # Section area
E = 200e9 # Young's modulus
fy = 350e6 # Yield stress
alpha = 0.02 # Second-slope stiffness
eta = 2 # Bouc-Wen sharpness
gamma = 0.5 # Bouc-Wen parameter
beta = 0.5 # Bouc-Wen parameter
Hk = alpha*E/(1-alpha) # Kinematic hardening parameter
K = 0 # Linear isotropic hardening parameter
delta = 0 # Saturation isotropic hardening parameter
fy_inf = 100.0 # Asymptotic yield stress for saturation isotropic hardening
dt = 1/20 # Delta-t
nsteps = 25 # Number of pseudo-time steps, each of length dt
KcalcFrequency = 1 # 0=initial stress method, 1=Newton-Raphson, maxIter=Modified NR
maxIter = 100 # Maximum number of equilibrium iterations in the Newton-Raphson algorithm
tol = 1e-5 # Convergence tolerance for the Newton-Raphson algorithm
trackNode = 8 # Node to be plotted
trackDOF = 2 # DOF to be plotted
# Nodal coordinates
NODES = [[0.0, 0.0],
[0.0, H],
[L, 0.0],
[L, H],
[2*L, 0.0],
[2*L, H],
[3*L, 0.0],
[3*L, H]]
# Boundary conditions (0=free, 1=fixed, sets #DOFs per node)
CONSTRAINTS = [[1, 1],
[1, 1],
[0, 0],
[0, 0],
[0, 0],
[0, 0],
[0, 0],
[0, 0]]
# Element connectivity and type
ELEMENTS = [[elementType, 0, 1, 3],
[elementType, 0, 1, 2],
[elementType, 0, 2, 4],
[elementType, 0, 2, 3],
[elementType, 0, 3, 5],
[elementType, 0, 3, 4],
[elementType, 0, 4, 6],
[elementType, 0, 4, 5],
[elementType, 0, 5, 7],
[elementType, 0, 5, 6],
[elementType, 0, 6, 8],
[elementType, 0, 6, 7],
[elementType, 0, 7, 8]]
# Section information (one section per element)
nel = len(ELEMENTS)
SECTIONS = []
for i in range(nel):
SECTIONS.append(['Truss', A])
# Material information (one material per element)
MATERIALS = []
for i in range(nel):
if materialType == 'Bilinear':
MATERIALS.append(['Bilinear', E, fy, alpha])
elif materialType == 'Plasticity':
MATERIALS.append(['Plasticity', E, fy, Hk, K, delta, fy_inf])
elif materialType == 'BoucWen':
MATERIALS.append(['BoucWen', E, fy, alpha, eta, beta, gamma])
else:
print('\n'"Error: Wrong material type")
import sys
sys.exit()
# Nodal loads
LOADS = [[0.0, 0.0],
[0.0, 0.0],
[0.0, 0.0],
[0.0, -P],
[0.0, 0.0],
[0.0, -P],
[0.0, 0.0],
[0.0, -P]]
# Placeholder for mass matrix
MASS = [[0, 0],
[0, 0],
[0, 0],
[0, 0],
[0, 0],
[0, 0],
[0, 0],
[0, 0]]
# Create the model object
a = [NODES, CONSTRAINTS, ELEMENTS, SECTIONS, MATERIALS, LOADS, MASS]
m = model(a)
# Analyze
loadFactor, u, dudx = nonlinearStaticAnalysis(m, nsteps, dt, maxIter, KcalcFrequency, tol, trackNode, trackDOF, [])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment