def model(builder='basic', ndm=None, ndf=None): """Create a new OpenSees model. Input arguments: builder = The builder to use. Only 'basic' is currently supported. ndm = number of dimensions (1-3) ndf = number of degrees of freedom per node (1-6) """ global _ndm, _ndf #--------- Process builder ---------# if builder.lower() == 'basic' or builder.lower() == 'basicbuilder': builder = 'basic' else: raise ValueError('Builder not supported: {}'.format(builder)) #----------- Process ndm -----------# if ndm is None: raise ValueError('ndm required') else: ndm = int(ndm) #----------- Process ndf -----------# # OpenSees default ndfs: if ndf == None: if ndm == 1: ndf = 1 elif ndm == 2: ndf = 3 elif ndm == 3: ndf = 6 else: raise ValueError('ndm must be between 1 and 3') else: ndf = int(ndf) if ndm == 1: if ndf != 1: raise ValueError('ndf must == 1 for ndm == 1') elif ndm == 2: if ndf not in range(1, 4): raise ValueError('ndf must be between 1 and 3 for ndm == 2') elif ndm == 3: if ndf not in range(1, 7): raise ValueError('ndf must be between 1 and 6 for ndm == 3') _ndm = ndm _ndf = ndf _ops.model(builder, '-ndm', ndm, '-ndf', ndf)
def test_recorder_time_step_can_handle_fp_precision(): import tempfile opy.model('basic', '-ndm', 2, '-ndf', 3) opy.node(1, 0.0, 0.0) opy.node(2, 0.0, 5.0) opy.fix(2, 0, 1, 0) opy.fix(1, 1, 1, 1) opy.equalDOF(2, 1, 2) opy.mass(2, 1.0, 0.0, 0.0) opy.geomTransf('Linear', 1, '-jntOffset') opy.element('elasticBeamColumn', 1, 1, 2, 1.0, 1e+06, 0.00164493, 1) opy.timeSeries('Path', 1, '-dt', 0.1, '-values', 0.0, -0.001, 0.001, -0.015, 0.033, 0.105, 0.18) opy.pattern('UniformExcitation', 1, 1, '-accel', 1) opy.rayleigh(0.0, 0.0159155, 0.0, 0.0) opy.wipeAnalysis() opy.algorithm('Newton') opy.system('SparseSYM') opy.numberer('RCM') opy.constraints('Transformation') opy.integrator('Newmark', 0.5, 0.25) opy.analysis('Transient') opy.test('EnergyIncr', 1e-07, 10, 0, 2) node_rec_ffp = tempfile.NamedTemporaryFile(delete=False).name ele_rec_ffp = tempfile.NamedTemporaryFile(delete=False).name rdt = 0.01 adt = 0.001 opy.recorder('Node', '-file', node_rec_ffp, '-precision', 16, '-dT', rdt, '-rTolDt', 0.00001, '-time', '-node', 1, '-dof', 1, 'accel') opy.recorder('Element', '-file', ele_rec_ffp, '-precision', 16, '-dT', rdt, '-rTolDt', 0.00001, '-time', '-ele', 1, 'force') opy.record() for i in range(1100): opy.analyze(1, adt) opy.getTime() opy.wipe() a = open(node_rec_ffp).read().splitlines() for i in range(len(a) - 1): dt = float(a[i + 1].split()[0]) - float(a[i].split()[0]) assert abs(dt - 0.01) < adt * 0.1, (i, dt) a = open(ele_rec_ffp).read().splitlines() for i in range(len(a) - 1): dt = float(a[i + 1].split()[0]) - float(a[i].split()[0]) assert abs(dt - 0.01) < adt * 0.1, (i, dt)
# # Written: Andreas Schellenberg ([email protected]) # Date: June 2017 # import the OpenSees Python module import opensees as ops # ------------------------------ # Start of model generation # ------------------------------ # remove existing model ops.wipe() # create ModelBuilder (with two-dimensions and 3 DOF/node) ops.model("BasicBuilder", "-ndm",2, "-ndf",3) # set default units ops.defaultUnits("-force", "kip", "-length", "in", "-time", "sec", "-temp", "F") # Create nodes # ------------ # Set parameters for overall model geometry width = 360.0 height = 144.0 # create nodes & add to Domain - command: node nodeId xCrd yCrd ops.node(1, 0.0, 0.0) ops.node(2, width, 0.0) ops.node(3, 0.0, height) ops.node(4, width, height)
# import openseespy.opensees as ops import opensees as ops # local compilation import opsvis as opsv import matplotlib.pyplot as plt ops.wipe() ops.model('basic', '-ndm', 2, '-ndf', 2) ops.node(1, 0., 0.) ops.node(2, 0., 1.) ops.node(3, 0., 2.) ops.node(4, 0., 3.) ops.node(5, 0., 4.) ops.node(6, 1., 0.) ops.node(7, 1., 1.) ops.node(8, 1., 2.) ops.node(9, 1., 3.) ops.node(10, 1., 4.) ops.node(11, 2., 0.) ops.node(12, 2., 1.) ops.node(13, 2., 2.) ops.node(14, 2., 3.) ops.node(15, 2., 4.) ops.node(16, 3., 0.) ops.node(17, 3., 1.) ops.node(18, 3., 2.) ops.node(19, 3., 3.) ops.node(20, 3., 4.) ops.node(21, 4., 0.) ops.node(22, 4., 1.) ops.node(23, 4., 2.)
# Written: Andreas Schellenberg ([email protected]) # Date: June 2017 # import the OpenSees Python module import opensees as ops import MomentCurvature # ------------------------------ # Start of model generation # ------------------------------ # remove existing model ops.wipe() # create ModelBuilder (with two-dimensions and 3 DOF/node) ops.model("BasicBuilder", "-ndm", 2, "-ndf", 3) # set default units ops.defaultUnits("-force", "kip", "-length", "in", "-time", "sec", "-temp", "F") # Define materials for nonlinear columns # ------------------------------------------ # CONCRETE tag f'c ec0 f'cu ecu # Core concrete (confined) ops.uniaxialMaterial("Concrete01", 1, -6.0, -0.004, -5.0, -0.014) # Cover concrete (unconfined) ops.uniaxialMaterial("Concrete01", 2, -5.0, -0.002, -0.0, -0.006) # STEEL # Reinforcing steel
Diameter = 0.635 # outer diameter [m] Thickness = 0.039 # thickness [m] Inner_Diameter = Diameter - 2 * Thickness A = math.pi * (Diameter**2 - Inner_Diameter**2) / 4.0 Iz = math.pi / 4 * (Diameter**4 - Inner_Diameter**4) Iy = Iz G = 26e6 # in kPa J = Iz + Iy # wipe the model op.wipe() # spring nodes created with 2 dim, 3 dof op.model('basic', '-ndm', 2, '-ndf', 3) # create nodes #---- Pile Node op.node(1, 0.0, 0.0) op.node(2, 0.0, 0.5) op.node(3, 0.0, 1.0) #---- Soil Node op.node(4, 0.0, 0.5) op.node(5, 0.0, 0) # fix the soil nodes op.fix(4, 1, 1, 1) op.fix(5, 1, 1, 1) # fix x dof of the pile nodes
# Date: September 2017 # import the OpenSees Python module import opensees as ops import RCsection import math # ---------------------------- # Start of model generation # ---------------------------- # remove existing model ops.wipe() # create ModelBuilder (with three-dimensions and 6 DOF/node) ops.model("BasicBuilder", "-ndm",3, "-ndf",6) # set default units ops.defaultUnits("-force", "kip", "-length", "in", "-time", "sec", "-temp", "F") # Define geometry # --------------- # Set parameters for model geometry h = 144.0; # Story height by = 240.0; # Bay width in Y-direction bx = 240.0; # Bay width in X-direction # Create nodes # tag X Y Z ops.node( 1, -bx/2.0, by/2.0, 0.0)
def get_inelastic_response(mass, k_spring, f_yield, motion, dt, xi=0.05, r_post=0.0): """ Run seismic analysis of a nonlinear SDOF :param mass: SDOF mass :param k_spring: spring stiffness :param f_yield: yield strength :param motion: list, acceleration values :param dt: float, time step of acceleration values :param xi: damping ratio :param r_post: post-yield stiffness :return: """ op.wipe() op.model('basic', '-ndm', 2, '-ndf', 3) # 2 dimensions, 3 dof per node # Establish nodes bot_node = 1 top_node = 2 op.node(bot_node, 0., 0.) op.node(top_node, 0., 0.) # Fix bottom node op.fix(top_node, opc.FREE, opc.FIXED, opc.FIXED) op.fix(bot_node, opc.FIXED, opc.FIXED, opc.FIXED) # Set out-of-plane DOFs to be slaved op.equalDOF(1, 2, *[2, 3]) # nodal mass (weight / g): op.mass(top_node, mass, 0., 0.) # Define material bilinear_mat_tag = 1 mat_type = "Steel01" mat_props = [f_yield, k_spring, r_post] op.uniaxialMaterial(mat_type, bilinear_mat_tag, *mat_props) # Assign zero length element beam_tag = 1 op.element('zeroLength', beam_tag, bot_node, top_node, "-mat", bilinear_mat_tag, "-dir", 1, '-doRayleigh', 1) # Define the dynamic analysis load_tag_dynamic = 1 pattern_tag_dynamic = 1 values = list(-1 * motion) # should be negative op.timeSeries('Path', load_tag_dynamic, '-dt', dt, '-values', *values) op.pattern('UniformExcitation', pattern_tag_dynamic, opc.X, '-accel', load_tag_dynamic) # set damping based on first eigen mode angular_freq = op.eigen('-fullGenLapack', 1)**0.5 alpha_m = 0.0 beta_k = 2 * xi / angular_freq beta_k_comm = 0.0 beta_k_init = 0.0 op.rayleigh(alpha_m, beta_k, beta_k_init, beta_k_comm) # Run the dynamic analysis op.wipeAnalysis() op.algorithm('Newton') op.system('SparseGeneral') op.numberer('RCM') op.constraints('Transformation') op.integrator('Newmark', 0.5, 0.25) op.analysis('Transient') tol = 1.0e-10 iterations = 10 op.test('EnergyIncr', tol, iterations, 0, 2) analysis_time = (len(values) - 1) * dt analysis_dt = 0.001 outputs = { "time": [], "rel_disp": [], "rel_accel": [], "rel_vel": [], "force": [] } while op.getTime() < analysis_time: curr_time = op.getTime() op.analyze(1, analysis_dt) outputs["time"].append(curr_time) outputs["rel_disp"].append(op.nodeDisp(top_node, 1)) outputs["rel_vel"].append(op.nodeVel(top_node, 1)) outputs["rel_accel"].append(op.nodeAccel(top_node, 1)) op.reactions() outputs["force"].append( -op.nodeReaction(bot_node, 1)) # Negative since diff node op.wipe() for item in outputs: outputs[item] = np.array(outputs[item]) return outputs
import sys sys.path.insert(0, '../SRC/interpreter/') # sys.path.insert(0, '../build/lib/') import opensees as ops ops.model('basic', '-ndm', 1, '-ndf', 1) ops.uniaxialMaterial('Elastic', 1, 3000.0) ops.node(1, 0.0) ops.node(2, 72.0) ops.fix(1, 1) ops.element('Truss', 1, 1, 2, 10.0, 1) ops.timeSeries('Linear', 1) ops.pattern('Plain', 1, 1) ops.load(2, 100.0) ops.constraints('Transformation') ops.numberer('ParallelPlain') ops.test('NormDispIncr', 1e-6, 6, 2) ops.system('ProfileSPD') ops.integrator('Newmark', 0.5, 0.25) # ops.analysis('Transient') ops.algorithm('Linear') ops.analysis('VariableTransient') ops.analyze(5, 0.0001, 0.00001, 0.001, 10) time = ops.getTime() print(f'time: ', ops.getTime())
# pile diameter diameter = 1.0 # number of pile elements nElePile = 84 # pile element length eleSize = (L1+L2)/nElePile # number of total pile nodes nNodePile = 1 + nElePile #---------------------------------------------------------- # create spring nodes #---------------------------------------------------------- # spring nodes created with 3 dim, 3 dof op.model('basic', '-ndm', 3, '-ndf', 3) # counter to determine number of embedded nodes count = 0 # create spring nodes #1 to 85 are spring nodes pile_nodes = dict() for i in range(nNodePile): zCoord = eleSize * i if zCoord <= L2: op.node(i+1, 0.0, 0.0, zCoord) op.node(i+101, 0.0, 0.0, zCoord)
def BuildOpsModel(GRS): ops.wipe() ops.model('BasicBuilder', '-ndm', 3, '-ndf', 6) # material matID = 66 matID1 = 67 sY = 235. * un.MPa if GRS.MatNL == False: ops.uniaxialMaterial('Elastic', matID, GRS.Es) else: ops.uniaxialMaterial('Steel4', matID1, sY, GRS.Es, '-kin', 4e-3, 50., 0.05, 0.15, '-ult', 360.* un.MPa, 5., ) ops.uniaxialMaterial('MinMax', matID, matID1, '-min', -0.20, '-max', 0.20) #ops.uniaxialMaterial('Steel4', matID, sY, GRS.Es, '-kin', 1e-2, 50., 0.05, 0.15, '-ult', 360.* un.MPa, 10., ) #ops.uniaxialMaterial('Steel4', matID, sY, GRS.Es, '-kin', 1e-2, 50., 0.05, 0.15) #ops.uniaxialMaterial('ElasticBilin', matID, GRS.Es, 210. * 1e7, sY / GRS.Es) #ops.uniaxialMaterial('ElasticBilin', matID, GRS.Es, 210. * 1e6, sY / GRS.Es) #ops.uniaxialMaterial('ElasticBilin', matID, GRS.Es, 1., sY / GRS.Es) #Oldalnyomasos igy futott le # cross-section CHSid = 99 CHSSection(CHSid, matID, GRS.secD, GRS.secT, 8, 1, GRS.Gs*GRS.secIt) # nodes for i in range(GRS.nbNsAll): ops.node(int(100+i), GRS.nsAll.x[i], GRS.nsAll.y[i], GRS.nsAll.z[i]) # ...create zeroLength element nodes... # end supports if GRS.SupType==0: # all boundary points fixed for deformations for i in range(GRS.nbBns): ops.fix(100+GRS.bn[i], 1, 1, 1, 0, 0, 0) elif GRS.SupType == 1: # oldalnyomasos for i in range(len(GRS.bnX)): ops.fix(100+GRS.bnX[i], 1, 0, 1, 0, 0, 0) for i in range(len(GRS.bnY)): ops.fix(100+GRS.bnY[i], 0, 1, 1, 0, 0, 0) for i in range(len(GRS.bnC)): ops.fix(100+GRS.bnC[i], 1, 1, 1, 0, 0, 0) elif GRS.SupType == 2: # oldalnyomasmentes for i in range(len(GRS.bnX)): ops.fix(100+GRS.bnX[i], 0, 0, 1, 0, 0, 0) for i in range(len(GRS.bnY)): ops.fix(100+GRS.bnY[i], 0, 0, 1, 0, 0, 0) #for i in range(len(GRS.bnC)): # ops.fix(100+GRS.bnC[i], 1, 1, 1, 0, 0, 0) ops.fix(100 + GRS.bnC[0], 1, 1, 1, 0, 0, 0) ops.fix(100 + GRS.bnC[1], 0, 0, 1, 0, 0, 0) ops.fix(100 + GRS.bnC[2], 1, 0, 1, 0, 0, 0) ops.fix(100 + GRS.bnC[3], 0, 0, 1, 0, 0, 0) elif GRS.SupType == 3: # felmerev #NOT WORKING YET pass elif GRS.SupType == 4: # sarkok for i in range(len(GRS.bnC)): ops.fix(100+GRS.bnC[i], 1, 1, 1, 0, 0, 0) elif GRS.SupType == 5: # dome oldalnyomasos for i in range(GRS.nbBns): if i==0: ops.fix(100+GRS.bn[i], 1, 1, 1, 0, 0, 0) elif i==10: ops.fix(100+GRS.bn[i], 0, 1, 1, 0, 0, 0) else: ops.fix(100+GRS.bn[i], 0, 0, 1, 0, 0, 0) elif GRS.SupType == 6: # dome #NOT WORKING YET pass # transformations TRtag = 55 if GRS.GeomNL == 1: TRType = 'Corotational' ops.geomTransf('Corotational', TRtag, 0., 0., 1.) else: TRType = 'Linear' ops.geomTransf('Linear', TRtag, 0., 0., 1.) # integration points gauss = 5 beamIntTag=44 ops.beamIntegration('Lobatto', beamIntTag, CHSid, gauss) # create elements for i in range(GRS.nbElAll): sID = GRS.lsAll.sID[i] eID = GRS.lsAll.eID[i] dx = abs(GRS.nsAll.x[sID] - GRS.nsAll.x[eID]) dy = abs(GRS.nsAll.y[sID] - GRS.nsAll.y[eID]) dz = abs(GRS.nsAll.z[sID] - GRS.nsAll.z[eID]) if dx+dy+dz == 0: ops.equalDOF(eID, sID, 1,2,3,4,5,6) # Grasshopper geomType=4 Zero length elements - should not come here else: ops.element('forceBeamColumn', int(1000 + i), int(100+sID), int(100+eID), TRtag, beamIntTag)
def test_recorder_time_step_is_stable(): opy.model('basic', '-ndm', 2, '-ndf', 2) opy.loadConst('-time', 1e+13) opy.node(1, 0.0, 0.0) opy.node(2, 0.5, 0.0) opy.node(3, 0.0, -0.5) opy.node(4, 0.5, -0.5) opy.equalDOF(3, 4, 1, 2) opy.node(5, 0.0, -1.0) opy.node(6, 0.5, -1.0) opy.equalDOF(5, 6, 1, 2) opy.node(7, 0.0, -1.5) opy.node(8, 0.5, -1.5) opy.equalDOF(7, 8, 1, 2) opy.node(9, 0.0, -2.0) opy.node(10, 0.5, -2.0) opy.equalDOF(9, 10, 1, 2) opy.node(11, 0.0, -2.5) opy.node(12, 0.5, -2.5) opy.equalDOF(11, 12, 1, 2) opy.node(13, 0.0, -3.0) opy.node(14, 0.5, -3.0) opy.equalDOF(13, 14, 1, 2) opy.fix(13, 0, 1) opy.fix(14, 0, 1) opy.node(15, 0.0, -3.0) opy.node(16, 0.0, -3.0) opy.fix(15, 1, 1) opy.fix(16, 0, 1) opy.equalDOF(13, 14, 1) opy.equalDOF(13, 16, 1) opy.nDMaterial('ElasticIsotropic', 1, 212500.0, 0.0, 1.7) opy.element('SSPquad', 1, 3, 4, 2, 1, 1, 'PlaneStrain', 1.0, 0.0, 16.677) opy.element('SSPquad', 2, 5, 6, 4, 3, 1, 'PlaneStrain', 1.0, 0.0, 16.677) opy.element('SSPquad', 3, 7, 8, 6, 5, 1, 'PlaneStrain', 1.0, 0.0, 16.677) opy.element('SSPquad', 4, 9, 10, 8, 7, 1, 'PlaneStrain', 1.0, 0.0, 16.677) opy.element('SSPquad', 5, 11, 12, 10, 9, 1, 'PlaneStrain', 1.0, 0.0, 16.677) opy.element('SSPquad', 6, 13, 14, 12, 11, 1, 'PlaneStrain', 1.0, 0.0, 16.677) opy.uniaxialMaterial('Viscous', 2, 212.5, 1.0) opy.element('zeroLength', 7, 15, 16, '-mat', 2, '-dir', 1) opy.constraints('Transformation') opy.test('NormDispIncr', 0.0001, 30, 0, 2) opy.algorithm('Newton', False, False, False) opy.numberer('RCM') opy.system('ProfileSPD') opy.integrator('Newmark', 0.5, 0.25) opy.analysis('Transient') opy.analyze(40, 1.0) opy.analyze(50, 0.5) opy.setTime(1.0e3) opy.wipeAnalysis() opy.recorder('Node', '-file', 'time_0_01.txt', '-precision', 16, '-dT', 0.01, '-rTolDt', 0.00001, '-time', '-node', 1, '-dof', 1, 'accel') opy.recorder('Element', '-file', 'etime_0_01.txt', '-precision', 16, '-dT', 0.01, '-rTolDt', 0.00001, '-time', '-ele', 1, 2, 'stress') opy.recorder('EnvelopeNode', '-file', 'entime_0_01.txt', '-precision', 16, '-dT', 0.01, '-time', '-node', 1, '-dof', 1, 'accel') # opy.recorder('Drift', '-file', 'dtime_0_01.txt', '-precision', 16, '-dT', 0.01, '-time', # '-iNode', 1, '-jNode', 2, '-dof', 1, '-perpDirn', 2) opy.timeSeries('Path', 1, '-dt', 0.01, '-values', -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -7.51325e-05) opy.pattern('Plain', 1, 1) opy.load(13, 1.0, 0.0) opy.algorithm('Newton', False, False, False) opy.system('SparseGeneral') opy.numberer('RCM') opy.constraints('Transformation') opy.integrator('Newmark', 0.5, 0.25) opy.rayleigh(0.17952, 0.000909457, 0.0, 0.0) opy.analysis('Transient') opy.test('EnergyIncr', 1e-07, 10, 0, 2) opy.record() opy.analyze(1, 0.001) for i in range(1100): print(i) opy.analyze(1, 0.001) cur_time = opy.getTime() opy.wipe() a = open('time_0_01.txt').read().splitlines() for i in range(len(a) - 1): dt = float(a[i + 1].split()[0]) - float(a[i].split()[0]) assert abs(dt - 0.01) < 0.0001, (i, dt)
# Units: kips, in, sec # # Written: Andreas Schellenberg ([email protected]) # Date: September 2017 # import the OpenSees Python module import opensees as ops # ---------------------------- # Start of model generation # ---------------------------- # remove existing model ops.wipe() # create ModelBuilder (with three-dimensions and 6 DOF/node) ops.model("BasicBuilder", "-ndm", 3, "-ndf", 6) # set default units ops.defaultUnits("-force", "kip", "-length", "in", "-time", "sec", "-temp", "F") # Define the section # ------------------ # secTag E nu h rho ops.section("ElasticMembranePlateSection", 1, 3.0E3, 0.25, 1.175, 1.27) # Define geometry # --------------- # these should both be even nx = 8 ny = 2
import opensees as ops # units: kip, in # remove existing model ops.wipe() # set modelbuilder ops.model('basic', '-ndm', 2, '-ndf', 2) # create nodes ops.node(1, 0.0, 0.0, "-disp", 0.0, 0.0, "-vel", 0.0,0.0, "-mass", 0.0,0.0) ops.node(2, 144.0, 0.0) ops.node(3, 168.0, 0.0) ops.node(4, 72.0, 96.0) # set boundary condition ops.fix(1, 1, 1) ops.fix(2, 1, 1) ops.fix(3, 1, 1) # define materials ops.uniaxialMaterial("Elastic", 1, 3000) # define elements ops.element("Truss",1,1,4,10.0,1) ops.element("Truss",2,2,4,5.0,1) ops.element("Truss",3,3,4,5.0,1) # create TimeSeries ops.timeSeries("Linear", 1)