Last active
April 2, 2024 02:39
-
-
Save terjehaukaas/7fcf0fdc114c4b343297c102c68cdc92 to your computer and use it in GitHub Desktop.
G2 Example 11
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. | |
# ------------------------------------------------------------------------ | |
from G2AnalysisNonlinearDynamic import * | |
from G2Model import * | |
from GroundMotionHalfSineWave import * | |
# Input [N, m, kg, sec] | |
elementType = 12 | |
materialType = 'Bilinear' | |
L = 15.0 | |
nel = 5 | |
nsec = 5 | |
plotFlag = False | |
plotPause = 1 | |
E = 200e9 | |
fy = 350e6 | |
alpha = 0.02 | |
eta = 3 | |
gamma = 0.5 | |
beta = 0.5 | |
rho = 7850.0 | |
hw = 0.355 | |
bf = 0.365 | |
tf = 0.018 | |
tw = 0.011 | |
nf = 2 | |
nw = 8 | |
trackNode = [nel+1] | |
trackDOF = [1] | |
toElement = nel+1 | |
perturbationFraction = 1e-8 | |
# Ground motion | |
groundMotionFile = 'DDMcheckFile.txt' | |
sineWavePeriod = 1 | |
numHalfSineWaves = 1 | |
gmdt = 0.02 | |
amplitudeINg = 8 | |
createHalfSineWave(sineWavePeriod, numHalfSineWaves, gmdt, amplitudeINg, groundMotionFile) | |
gmScaling = 1 | |
duration = 2 | |
dtAnalysis = gmdt | |
# Damping options | |
targetDamping = 0.05 | |
cM = 1.0325643267913758 | |
cK = 0.0011851545669572102 | |
dampingModels = [['Rayleigh', 'Current', 'Current', 1, 2, targetDamping], | |
['Rayleigh', 'Current', 'Initial', 1, 2, targetDamping], | |
['Modal', 'Current', targetDamping], | |
['Modal', 'Initial', targetDamping], | |
['Rayleigh', 'Initial', 'Initial', 1, 2, targetDamping], | |
['Rayleigh', 'Initial', 'Given', cM, cK], | |
['Rayleigh', 'Current', 'Given', cM, cK]] | |
# Area, moment of inertia, nodal mass | |
A = tw * (hw - 2 * tf) + 2 * bf * tf | |
I = tw * (hw - 2 * tf) ** 3 / 12.0 + 2 * bf * tf * (0.5 * (hw - tf)) ** 2 | |
M = A * L/nel * rho | |
# Analytical eigenvalue | |
print('\n'"Analytical first natural frequency: %.2frad" % (1.875 ** 2 * np.sqrt(E * I / (rho * A * L**4)))) | |
# Nodal coordinates | |
NODES = [] | |
for i in range(nel+1): | |
NODES.append([0.0, i*L/nel]) | |
# Boundary conditions (0=free, 1=fixed, sets #DOFs per node) | |
CONSTRAINTS = [[1, 1, 1]] | |
for i in range(nel): | |
CONSTRAINTS.append([0, 0, 0]) | |
# Element connectivity and type | |
ELEMENTS = [] | |
for i in range(nel): | |
ELEMENTS.append([elementType, nsec, 0.0, i+1, i+2]) | |
# Section information (one section per element) | |
SECTIONS = [] | |
for i in range(nel): | |
SECTIONS.append(['WideFlange', hw, bf, tf, tw, nf, nw]) | |
# Material information (one material per element) | |
MATERIALS = [] | |
for i in range(nel): | |
if materialType == 'Bilinear': | |
MATERIALS.append(['Bilinear', E, fy, alpha]) | |
elif materialType == 'BoucWen': | |
MATERIALS.append(['BoucWen', E, fy, alpha, eta, beta, gamma]) | |
else: | |
print('\n'"Cannot understand the material type") | |
import sys | |
sys.exit() | |
# Nodal loads | |
LOADS = np.zeros((nel+1, 3)) | |
# Lumped mass | |
MASS = [[0, 0, 0]] | |
for i in range(nel-1): | |
MASS.append([M, 0, 0]) | |
MASS.append([0.5*M, 0, 0]) | |
# Collect input into an array | |
input = [NODES, CONSTRAINTS, ELEMENTS, SECTIONS, MATERIALS, LOADS, MASS] | |
# Loop over damping models and check DDM calculations | |
for dampingModel in dampingModels: | |
# E | |
m = model(input) | |
selectedDDMparameter = 'E' | |
theValue = 'value' | |
exec("%s = %s" % (theValue, selectedDDMparameter)) | |
DDMparameters = [['Element', selectedDDMparameter, range(1, toElement)]] | |
t, gm, u, v, a, dudx, dvdx, dadx, dnl1, dnl2 = nonlinearDynamicAnalysis(m, dampingModel, groundMotionFile, gmScaling, gmdt, dtAnalysis, duration, trackNode, trackDOF, DDMparameters, plotFlag) | |
m = model(input) | |
m.setParameters([['Element', selectedDDMparameter, range(1, toElement), value*(1.0+perturbationFraction)]]) | |
void, void, responsePert, void, void, void, void, void, void, void = nonlinearDynamicAnalysis(m, dampingModel, groundMotionFile, gmScaling, gmdt, dtAnalysis, duration, trackNode, trackDOF, [], plotFlag) | |
fdmSensitivity = np.subtract(responsePert[0,:], u[0,:]) / (value*perturbationFraction) | |
print('\n''\n'"Damping model:", dampingModel) | |
print("FDM-DDM difference for %s is %.4f percent" % (selectedDDMparameter, np.max(np.abs(np.subtract(fdmSensitivity, dudx[0,0,:]))) / np.max(np.abs(dudx[0,0,:])) * 100 )) | |
plt.ion() | |
plt.figure() | |
plt.autoscale(True) | |
plt.title(selectedDDMparameter) | |
plt.plot(t, fdmSensitivity, 'ro-', label='FDM') | |
plt.plot(t, dudx[0,0,:], 'k-', label='DDM') | |
plt.xlabel("Time") | |
plt.ylabel("Derivative") | |
plt.legend(loc='upper left') | |
plt.pause(plotPause) | |
# fy | |
m = model(input) | |
selectedDDMparameter = 'fy' | |
theValue = 'value' | |
exec("%s = %s" % (theValue, selectedDDMparameter)) | |
DDMparameters = [['Element', selectedDDMparameter, range(1, toElement)]] | |
t, gm, u, v, a, dudx, dvdx, dadx, dnl1, dnl2 = nonlinearDynamicAnalysis(m, dampingModel, groundMotionFile, gmScaling, gmdt, dtAnalysis, duration, trackNode, trackDOF, DDMparameters, plotFlag) | |
m = model(input) | |
m.setParameters([['Element', selectedDDMparameter, range(1, toElement), value*(1.0+perturbationFraction)]]) | |
void, void, responsePert, void, void, void, void, void, void, void = nonlinearDynamicAnalysis(m, dampingModel, groundMotionFile, gmScaling, gmdt, dtAnalysis, duration, trackNode, trackDOF, [], plotFlag) | |
fdmSensitivity = np.subtract(responsePert[0,:], u[0,:]) / (value*perturbationFraction) | |
print('\n''\n'"Damping model:", dampingModel) | |
print("FDM-DDM difference for %s is %.4f percent" % (selectedDDMparameter, np.max(np.abs(np.subtract(fdmSensitivity, dudx[0,0,:]))) / np.max(np.abs(dudx[0,0,:])) * 100 )) | |
plt.ion() | |
plt.figure() | |
plt.autoscale(True) | |
plt.title(selectedDDMparameter) | |
plt.plot(t, fdmSensitivity, 'ro-', label='FDM') | |
plt.plot(t, dudx[0,0,:], 'k-', label='DDM') | |
plt.xlabel("Time") | |
plt.ylabel("Derivative") | |
plt.legend(loc='upper left') | |
plt.pause(plotPause) | |
# alpha | |
m = model(input) | |
selectedDDMparameter = 'alpha' | |
theValue = 'value' | |
exec("%s = %s" % (theValue, selectedDDMparameter)) | |
DDMparameters = [['Element', selectedDDMparameter, range(1, toElement)]] | |
t, gm, u, v, a, dudx, dvdx, dadx, dnl1, dnl2 = nonlinearDynamicAnalysis(m, dampingModel, groundMotionFile, gmScaling, gmdt, dtAnalysis, duration, trackNode, trackDOF, DDMparameters, plotFlag) | |
m = model(input) | |
m.setParameters([['Element', selectedDDMparameter, range(1, toElement), value*(1.0+perturbationFraction)]]) | |
void, void, responsePert, void, void, void, void, void, void, void = nonlinearDynamicAnalysis(m, dampingModel, groundMotionFile, gmScaling, gmdt, dtAnalysis, duration, trackNode, trackDOF, [], plotFlag) | |
fdmSensitivity = np.subtract(responsePert[0,:], u[0,:]) / (value*perturbationFraction) | |
print('\n''\n'"Damping model:", dampingModel) | |
print("FDM-DDM difference for %s is %.4f percent" % (selectedDDMparameter, np.max(np.abs(np.subtract(fdmSensitivity, dudx[0,0,:]))) / np.max(np.abs(dudx[0,0,:])) * 100 )) | |
plt.ion() | |
plt.figure() | |
plt.autoscale(True) | |
plt.title(selectedDDMparameter) | |
plt.plot(t, fdmSensitivity, 'ro-', label='FDM') | |
plt.plot(t, dudx[0,0,:], 'k-', label='DDM') | |
plt.xlabel("Time") | |
plt.ylabel("Derivative") | |
plt.legend(loc='upper left') | |
plt.pause(plotPause) | |
# hw | |
m = model(input) | |
selectedDDMparameter = 'hw' | |
theValue = 'value' | |
exec("%s = %s" % (theValue, selectedDDMparameter)) | |
DDMparameters = [['Element', selectedDDMparameter, range(1, toElement)]] | |
t, gm, u, v, a, dudx, dvdx, dadx, dnl1, dnl2 = nonlinearDynamicAnalysis(m, dampingModel, groundMotionFile, gmScaling, gmdt, dtAnalysis, duration, trackNode, trackDOF, DDMparameters, plotFlag) | |
m = model(input) | |
m.setParameters([['Element', selectedDDMparameter, range(1, toElement), value*(1.0+perturbationFraction)]]) | |
void, void, responsePert, void, void, void, void, void, void, void = nonlinearDynamicAnalysis(m, dampingModel, groundMotionFile, gmScaling, gmdt, dtAnalysis, duration, trackNode, trackDOF, [], plotFlag) | |
fdmSensitivity = np.subtract(responsePert[0,:], u[0,:]) / (value*perturbationFraction) | |
print('\n''\n'"Damping model:", dampingModel) | |
print("FDM-DDM difference for %s is %.4f percent" % (selectedDDMparameter, np.max(np.abs(np.subtract(fdmSensitivity, dudx[0,0,:]))) / np.max(np.abs(dudx[0,0,:])) * 100 )) | |
plt.ion() | |
plt.figure() | |
plt.autoscale(True) | |
plt.title(selectedDDMparameter) | |
plt.plot(t, fdmSensitivity, 'ro-', label='FDM') | |
plt.plot(t, dudx[0,0,:], 'k-', label='DDM') | |
plt.xlabel("Time") | |
plt.ylabel("Derivative") | |
plt.legend(loc='upper left') | |
plt.pause(plotPause) | |
# bf | |
m = model(input) | |
selectedDDMparameter = 'bf' | |
theValue = 'value' | |
exec("%s = %s" % (theValue, selectedDDMparameter)) | |
DDMparameters = [['Element', selectedDDMparameter, range(1, toElement)]] | |
t, gm, u, v, a, dudx, dvdx, dadx, dnl1, dnl2 = nonlinearDynamicAnalysis(m, dampingModel, groundMotionFile, gmScaling, gmdt, dtAnalysis, duration, trackNode, trackDOF, DDMparameters, plotFlag) | |
m = model(input) | |
m.setParameters([['Element', selectedDDMparameter, range(1, toElement), value*(1.0+perturbationFraction)]]) | |
void, void, responsePert, void, void, void, void, void, void, void = nonlinearDynamicAnalysis(m, dampingModel, groundMotionFile, gmScaling, gmdt, dtAnalysis, duration, trackNode, trackDOF, [], plotFlag) | |
fdmSensitivity = np.subtract(responsePert[0,:], u[0,:]) / (value*perturbationFraction) | |
print('\n''\n'"Damping model:", dampingModel) | |
print("FDM-DDM difference for %s is %.4f percent" % (selectedDDMparameter, np.max(np.abs(np.subtract(fdmSensitivity, dudx[0,0,:]))) / np.max(np.abs(dudx[0,0,:])) * 100 )) | |
plt.ion() | |
plt.figure() | |
plt.autoscale(True) | |
plt.title(selectedDDMparameter) | |
plt.plot(t, fdmSensitivity, 'ro-', label='FDM') | |
plt.plot(t, dudx[0,0,:], 'k-', label='DDM') | |
plt.xlabel("Time") | |
plt.ylabel("Derivative") | |
plt.legend(loc='upper left') | |
plt.pause(plotPause) | |
# tf | |
m = model(input) | |
selectedDDMparameter = 'tf' | |
theValue = 'value' | |
exec("%s = %s" % (theValue, selectedDDMparameter)) | |
DDMparameters = [['Element', selectedDDMparameter, range(1, toElement)]] | |
t, gm, u, v, a, dudx, dvdx, dadx, dnl1, dnl2 = nonlinearDynamicAnalysis(m, dampingModel, groundMotionFile, gmScaling, gmdt, dtAnalysis, duration, trackNode, trackDOF, DDMparameters, plotFlag) | |
m = model(input) | |
m.setParameters([['Element', selectedDDMparameter, range(1, toElement), value*(1.0+perturbationFraction)]]) | |
void, void, responsePert, void, void, void, void, void, void, void = nonlinearDynamicAnalysis(m, dampingModel, groundMotionFile, gmScaling, gmdt, dtAnalysis, duration, trackNode, trackDOF, [], plotFlag) | |
fdmSensitivity = np.subtract(responsePert[0,:], u[0,:]) / (value*perturbationFraction) | |
print('\n''\n'"Damping model:", dampingModel) | |
print("FDM-DDM difference for %s is %.4f percent" % (selectedDDMparameter, np.max(np.abs(np.subtract(fdmSensitivity, dudx[0,0,:]))) / np.max(np.abs(dudx[0,0,:])) * 100 )) | |
plt.ion() | |
plt.figure() | |
plt.autoscale(True) | |
plt.title(selectedDDMparameter) | |
plt.plot(t, fdmSensitivity, 'ro-', label='FDM') | |
plt.plot(t, dudx[0,0,:], 'k-', label='DDM') | |
plt.xlabel("Time") | |
plt.ylabel("Derivative") | |
plt.legend(loc='upper left') | |
plt.pause(plotPause) | |
# tw | |
m = model(input) | |
selectedDDMparameter = 'tw' | |
theValue = 'value' | |
exec("%s = %s" % (theValue, selectedDDMparameter)) | |
DDMparameters = [['Element', selectedDDMparameter, range(1, toElement)]] | |
t, gm, u, v, a, dudx, dvdx, dadx, dnl1, dnl2 = nonlinearDynamicAnalysis(m, dampingModel, groundMotionFile, gmScaling, gmdt, dtAnalysis, duration, trackNode, trackDOF, DDMparameters, plotFlag) | |
m = model(input) | |
m.setParameters([['Element', selectedDDMparameter, range(1, toElement), value*(1.0+perturbationFraction)]]) | |
void, void, responsePert, void, void, void, void, void, void, void = nonlinearDynamicAnalysis(m, dampingModel, groundMotionFile, gmScaling, gmdt, dtAnalysis, duration, trackNode, trackDOF, [], plotFlag) | |
fdmSensitivity = np.subtract(responsePert[0,:], u[0,:]) / (value*perturbationFraction) | |
print('\n''\n'"Damping model:", dampingModel) | |
print("FDM-DDM difference for %s is %.4f percent" % (selectedDDMparameter, np.max(np.abs(np.subtract(fdmSensitivity, dudx[0,0,:]))) / np.max(np.abs(dudx[0,0,:])) * 100 )) | |
plt.ion() | |
plt.figure() | |
plt.autoscale(True) | |
plt.title(selectedDDMparameter) | |
plt.plot(t, fdmSensitivity, 'ro-', label='FDM') | |
plt.plot(t, dudx[0,0,:], 'k-', label='DDM') | |
plt.xlabel("Time") | |
plt.ylabel("Derivative") | |
plt.legend(loc='upper left') | |
plt.pause(plotPause) | |
# M | |
m = model(input) | |
dM = [[0, 0, 0]] | |
for i in range(nel-1): | |
dM.append([1, 0, 0]) | |
dM.append([0.5, 0, 0]) | |
DDMparameters = [['Node', 'M', dM]] | |
t, gm, u, v, a, dudx, dvdx, dadx, dnl1, dnl2 = nonlinearDynamicAnalysis(m, dampingModel, groundMotionFile, gmScaling, gmdt, dtAnalysis, duration, trackNode, trackDOF, DDMparameters, plotFlag) | |
pertMASS = [[0, 0, 0]] | |
for i in range(nel-1): | |
pertMASS.append([M*(1.0+perturbationFraction), 0, 0]) | |
pertMASS.append([0.5*M*(1.0+perturbationFraction), 0, 0]) | |
input = [NODES, CONSTRAINTS, ELEMENTS, SECTIONS, MATERIALS, LOADS, pertMASS] | |
m = model(input) | |
void, void, responsePert, void, void, void, void, void, void, void = nonlinearDynamicAnalysis(m, dampingModel, groundMotionFile, gmScaling, gmdt, dtAnalysis, duration, trackNode, trackDOF, [], plotFlag) | |
input = [NODES, CONSTRAINTS, ELEMENTS, SECTIONS, MATERIALS, LOADS, MASS] | |
fdmSensitivity = np.subtract(responsePert[0,:], u[0,:]) / (M*perturbationFraction) | |
print('\n''\n'"Damping model:", dampingModel) | |
print("FDM-DDM difference for M is %.4f percent" % (np.max(np.abs(np.subtract(fdmSensitivity, dudx[0,0,:]))) / np.max(np.abs(dudx[0,0,:])) * 100 )) | |
plt.ion() | |
plt.figure() | |
plt.autoscale(True) | |
plt.title("M") | |
plt.plot(t, fdmSensitivity, 'ro-', label='FDM') | |
plt.plot(t, dudx[0,0,:], 'k-', label='DDM') | |
plt.xlabel("Time") | |
plt.ylabel("Derivative") | |
plt.legend(loc='upper right') | |
plt.pause(plotPause) | |
# Target damping | |
if dampingModel[0] == 'Modal' or dampingModel[2] == 'Current' or dampingModel[2] == 'Initial': | |
m = model(input) | |
DDMparameters = [['Model', 'targetDamping']] | |
t, gm, u, v, a, dudx, dvdx, dadx, dnl1, dnl2 = nonlinearDynamicAnalysis(m, dampingModel, groundMotionFile, gmScaling, gmdt, dtAnalysis, duration, trackNode, trackDOF, DDMparameters, plotFlag) | |
m = model(input) | |
dampingModel[len(dampingModel)-1] = targetDamping*(1+perturbationFraction) | |
void, void, responsePert, void, void, void, void, void, void, void = nonlinearDynamicAnalysis(m, dampingModel, groundMotionFile, gmScaling, gmdt, dtAnalysis, duration, trackNode, trackDOF, [], plotFlag) | |
dampingModel[len(dampingModel)-1] = targetDamping | |
fdmSensitivity = np.subtract(responsePert[0,:], u[0,:]) / (targetDamping*perturbationFraction) | |
print('\n''\n'"Damping model:", dampingModel) | |
print("FDM-DDM difference for Zeta is %.4f percent" % (np.max(np.abs(np.subtract(fdmSensitivity, dudx[0,0,:]))) / np.max(np.abs(dudx[0,0,:])) * 100 )) | |
plt.ion() | |
plt.figure() | |
plt.autoscale(True) | |
plt.title("Target damping") | |
plt.plot(t, fdmSensitivity, 'ro-', label='FDM') | |
plt.plot(t, dudx[0,0,:], 'k-', label='DDM') | |
plt.xlabel("Time") | |
plt.ylabel("Derivative") | |
plt.legend(loc='upper right') | |
plt.pause(plotPause) | |
if dampingModel[2] == 'Given': | |
# cM | |
a = [NODES, CONSTRAINTS, ELEMENTS, SECTIONS, MATERIALS, LOADS, MASS] | |
m = model(input) | |
DDMparameters = [['Model', 'cM']] | |
t, gm, u, v, a, dudx, dvdx, dadx, dnl1, dnl2 = nonlinearDynamicAnalysis(m, dampingModel, groundMotionFile, gmScaling, gmdt, dtAnalysis, duration, trackNode, trackDOF, DDMparameters, plotFlag) | |
a = [NODES, CONSTRAINTS, ELEMENTS, SECTIONS, MATERIALS, LOADS, MASS] | |
m = model(input) | |
dampingModel[len(dampingModel)-2] = cM*(1+perturbationFraction) | |
void, void, responsePert, void, void, void, void, void, void, void = nonlinearDynamicAnalysis(m, dampingModel, groundMotionFile, gmScaling, gmdt, dtAnalysis, duration, trackNode, trackDOF, [], plotFlag) | |
dampingModel[len(dampingModel)-2] = cM | |
fdmSensitivity = np.subtract(responsePert[0,:], u[0,:]) / (cM*perturbationFraction) | |
print('\n''\n'"Damping model:", dampingModel) | |
print("FDM-DDM difference for cM is %.4f percent" % (np.max(np.abs(np.subtract(fdmSensitivity, dudx[0,0,:]))) / np.max(np.abs(dudx[0,0,:])) * 100 )) | |
plt.ion() | |
plt.figure() | |
plt.autoscale(True) | |
plt.title("cM") | |
plt.plot(t, fdmSensitivity, 'ro-', label='FDM') | |
plt.plot(t, dudx[0,0,:], 'k-', label='DDM') | |
plt.xlabel("Time") | |
plt.ylabel("Derivative") | |
plt.legend(loc='upper right') | |
plt.pause(plotPause) | |
# cK | |
a = [NODES, CONSTRAINTS, ELEMENTS, SECTIONS, MATERIALS, LOADS, MASS] | |
m = model(input) | |
DDMparameters = [['Model', 'cK']] | |
t, gm, u, v, a, dudx, dvdx, dadx, dnl1, dnl2 = nonlinearDynamicAnalysis(m, dampingModel, groundMotionFile, gmScaling, gmdt, dtAnalysis, duration, trackNode, trackDOF, DDMparameters, plotFlag) | |
a = [NODES, CONSTRAINTS, ELEMENTS, SECTIONS, MATERIALS, LOADS, MASS] | |
m = model(input) | |
dampingModel[len(dampingModel)-1] = cK*(1+perturbationFraction) | |
void, void, responsePert, void, void, void, void, void, void, void = nonlinearDynamicAnalysis(m, dampingModel, groundMotionFile, gmScaling, gmdt, dtAnalysis, duration, trackNode, trackDOF, [], plotFlag) | |
dampingModel[len(dampingModel)-1] = cK | |
fdmSensitivity = np.subtract(responsePert[0,:], u[0,:]) / (cK*perturbationFraction) | |
print('\n''\n'"Damping model:", dampingModel) | |
print("FDM-DDM difference for cK is %.4f percent" % (np.max(np.abs(np.subtract(fdmSensitivity, dudx[0,0,:]))) / np.max(np.abs(dudx[0,0,:])) * 100 )) | |
plt.ion() | |
plt.figure() | |
plt.autoscale(True) | |
plt.title("cK") | |
plt.plot(t, fdmSensitivity, 'ro-', label='FDM') | |
plt.plot(t, dudx[0,0,:], 'k-', label='DDM') | |
plt.xlabel("Time") | |
plt.ylabel("Derivative") | |
plt.legend(loc='upper right') | |
plt.pause(plotPause) | |
# Check DDM with respect to ordinate values of the ground motion record | |
a = [NODES, CONSTRAINTS, ELEMENTS, SECTIONS, MATERIALS, LOADS, MASS] | |
m = model(input) | |
pointOfTime = 13 | |
DDMparameters = [['GroundMotion', 'Point', pointOfTime]] | |
t, gm, u, v, a, dudx, dvdx, dadx, dnl1, dnl2 = nonlinearDynamicAnalysis(m, dampingModel, groundMotionFile, gmScaling, gmdt, dtAnalysis, duration, trackNode, trackDOF, DDMparameters, plotFlag) | |
rawGroundMotion = [] | |
f = open(groundMotionFile, "r") | |
lines = f.readlines() | |
for oneline in lines: | |
splitline = oneline.split() | |
for j in range(len(splitline)): | |
value = float(splitline[j]) | |
rawGroundMotion.append(value) | |
f.close() | |
open('GroundMotionPerturbed.txt', 'w').close() | |
file = open('GroundMotionPerturbed.txt', 'w') | |
for i in range(len(rawGroundMotion)): | |
if i == pointOfTime: | |
file.write("%.15f " % (rawGroundMotion[i]*(1+perturbationFraction))) | |
gmPerturbation = rawGroundMotion[i]*perturbationFraction | |
else: | |
file.write("%.15f " % rawGroundMotion[i]) | |
file.close() | |
m = model(input) | |
void, void, responsePert, void, void, void, void, void, void, void = nonlinearDynamicAnalysis(m, dampingModel, "GroundMotionPerturbed.txt", gmScaling, gmdt, dtAnalysis, duration, trackNode, trackDOF, [], plotFlag) | |
if pointOfTime*dtAnalysis > duration: | |
print('\n'"Zero sensitivity to ground motion value beyond analysis duration.") | |
else: | |
fdmSensitivity = np.subtract(responsePert[0,:], u[0,:]) / gmPerturbation | |
print('\n''\n'"Damping model:", dampingModel) | |
print("FDM-DDM difference for ground motion point is %.4f percent" % (np.max(np.abs(np.subtract(fdmSensitivity, dudx[:, 0]))) / np.max(np.abs(dudx[:, 0])) * 100)) | |
plt.ion() | |
plt.figure() | |
plt.autoscale(True) | |
plt.title("GM point") | |
plt.plot(t, fdmSensitivity, 'ro-', label='FDM') | |
plt.plot(t, dudx[0,0,:], 'k-', label='DDM') | |
plt.xlabel("Time") | |
plt.ylabel("Derivative") | |
plt.legend(loc='upper right') | |
plt.pause(plotPause) | |
print('\n'"Click somewhere in the plot to continue...") | |
plt.waitforbuttonpress() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment