예제 #1
0
def test_add_fixity_to_dof():
    osi = o3.OpenSeesInstance(ndm=3, ndf=3)

    n1 = o3.node.Node(osi, 1., 1., 1.)
    o3.Fix3DOF(osi, n1, o3.cc.FIXED, o3.cc.FREE, o3.cc.FIXED)
    o3.Fix3DOF(osi, n1, o3.cc.FREE, o3.cc.FREE, o3.cc.FREE)
    # o3.Fix3DOF(osi, n1, o3.cc.FREE, o3.cc.FREE, o3.cc.FIXED)  # fails with this
    o3.add_fixity_to_dof(osi, o3.cc.DOF2D_ROTZ, [n1])
예제 #2
0
def test_ele_load_uniform():
    osi = o3.OpenSeesInstance(ndm=2, state=3)
    ele_len = 2.0
    coords = [[0, 0], [ele_len, 0]]
    ele_nodes = [o3.node.Node(osi, *coords[x]) for x in range(len(coords))]
    transf = o3.geom_transf.Linear2D(osi, [])
    ele = o3.element.ElasticBeamColumn2D(osi,
                                         ele_nodes=ele_nodes,
                                         area=1.0,
                                         e_mod=1.0,
                                         iz=1.0,
                                         transf=transf,
                                         mass=1.0,
                                         c_mass="string")

    for i, node in enumerate(ele_nodes):
        if i == 0:
            o3.Fix3DOF(osi, node, o3.cc.FIXED, o3.cc.FIXED, o3.cc.FIXED)
        else:
            o3.Fix3DOF(osi, node, o3.cc.FREE, o3.cc.FIXED, o3.cc.FIXED)

    ts_po = o3.time_series.Linear(osi, factor=1)
    o3.pattern.Plain(osi, ts_po)
    udl = 10.
    o3.EleLoad2DUniform(osi, ele, w_y=-udl)

    tol = 1.0e-4
    o3.constraints.Plain(osi)
    o3.numberer.RCM(osi)
    o3.system.BandGeneral(osi)
    o3.test_check.NormDispIncr(osi, tol, 6)
    o3.algorithm.Newton(osi)
    n_steps_gravity = 1
    d_gravity = 1. / n_steps_gravity
    o3.integrator.LoadControl(osi, d_gravity, num_iter=10)
    o3.analysis.Static(osi)
    o3.analyze(osi, n_steps_gravity)
    opy.reactions()
    ele_loads = o3.get_ele_response(osi, ele, 'force')
    assert np.isclose(ele_loads[0], 0.0)
    assert np.isclose(ele_loads[1], udl * ele_len / 2)
    assert np.isclose(ele_loads[2], udl * ele_len**2 / 12)
    assert np.isclose(ele_loads[3], 0.0)
    assert np.isclose(ele_loads[4], udl * ele_len / 2)
    assert np.isclose(ele_loads[5], -udl * ele_len**2 / 12)
    assert np.isclose(o3.get_node_reaction(osi, ele_nodes[0], o3.cc.Y),
                      udl * ele_len / 2)
def run_analysis(asig, period, xi, f_yield, etype):
    # Load a ground motion

    # Define inelastic SDOF
    mass = 1.0

    r_post = 0.0

    # Initialise OpenSees instance
    osi = o3.OpenSeesInstance(ndm=2, state=0)

    # Establish nodes
    bot_node = o3.node.Node(osi, 0, 0)
    top_node = o3.node.Node(osi, 0, 0)

    # Fix bottom node
    o3.Fix3DOF(osi, top_node, o3.cc.FREE, o3.cc.FIXED, o3.cc.FIXED)
    o3.Fix3DOF(osi, bot_node, o3.cc.FIXED, o3.cc.FIXED, o3.cc.FIXED)
    # Set out-of-plane DOFs to be slaved
    o3.EqualDOF(osi, top_node, bot_node, [o3.cc.Y, o3.cc.ROTZ])

    # nodal mass (weight / g):
    o3.Mass(osi, top_node, mass, 0., 0.)

    # Define material
    k_spring = 4 * np.pi**2 * mass / period**2
    bilinear_mat = o3.uniaxial_material.Steel01(osi,
                                                fy=f_yield,
                                                e0=k_spring,
                                                b=r_post)

    # Assign zero length element, # Note: pass actual node and material objects into element
    o3.element.ZeroLength(osi, [bot_node, top_node],
                          mats=[bilinear_mat],
                          dirs=[o3.cc.DOF2D_X],
                          r_flag=1)

    # Define the dynamic analysis

    # Define the dynamic analysis
    acc_series = o3.time_series.Path(osi, dt=asig.dt, values=-1 *
                                     asig.values)  # should be negative
    o3.pattern.UniformExcitation(osi, dir=o3.cc.X, accel_series=acc_series)

    # set damping based on first eigen mode
    angular_freqs = np.array(o3.get_eigen(osi, solver='fullGenLapack',
                                          n=1))**0.5
    beta_k = 2 * xi / angular_freqs[0]
    print('angular_freqs: ', angular_freqs)
    periods = 2 * np.pi / angular_freqs

    o3.rayleigh.Rayleigh(osi,
                         alpha_m=0.0,
                         beta_k=beta_k,
                         beta_k_init=0.0,
                         beta_k_comm=0.0)

    # Run the dynamic analysis
    o3.wipe_analysis(osi)

    # Run the dynamic analysis
    o3.constraints.Transformation(osi)
    o3.test_check.NormDispIncr(osi, tol=1.0e-6, max_iter=35, p_flag=0)
    o3.numberer.RCM(osi)
    if etype == 'implicit':
        o3.algorithm.Newton(osi)
        o3.system.SparseGeneral(osi)
        o3.integrator.Newmark(osi, gamma=0.5, beta=0.25)
        analysis_dt = 0.01
    else:
        o3.algorithm.Linear(osi, factor_once=True)
        o3.system.FullGeneral(osi)
        if etype == 'newmark_explicit':
            o3.integrator.NewmarkExplicit(osi, gamma=0.6)
            explicit_dt = periods[0] / np.pi / 32
        elif etype == 'central_difference':
            o3.integrator.CentralDifference(osi)
            o3.opy.integrator('HHTExplicit')
            explicit_dt = periods[0] / np.pi / 16  # 0.5 is a factor of safety
        elif etype == 'explicit_difference':
            o3.integrator.ExplicitDifference(osi)
            explicit_dt = periods[0] / np.pi / 32
        else:
            raise ValueError(etype)
        print('explicit_dt: ', explicit_dt)
        analysis_dt = explicit_dt
    o3.analysis.Transient(osi)

    analysis_time = asig.time[-1]

    outputs = {
        "time": [],
        "rel_disp": [],
        "rel_accel": [],
        "rel_vel": [],
        "force": []
    }

    while o3.get_time(osi) < analysis_time:
        o3.analyze(osi, 1, analysis_dt)
        curr_time = o3.get_time(osi)
        outputs["time"].append(curr_time)
        outputs["rel_disp"].append(o3.get_node_disp(osi, top_node, o3.cc.X))
        outputs["rel_vel"].append(o3.get_node_vel(osi, top_node, o3.cc.X))
        outputs["rel_accel"].append(o3.get_node_accel(osi, top_node, o3.cc.X))
        o3.gen_reactions(osi)
        outputs["force"].append(-o3.get_node_reaction(
            osi, bot_node, o3.cc.X))  # Negative since diff node
    o3.wipe(osi)
    for item in outputs:
        outputs[item] = np.array(outputs[item])
    return outputs
def run_analysis(etype, asig, use_modal_damping=0):
    osi = o3.OpenSeesInstance(ndm=2, ndf=3)
    nodes = [
        o3.node.Node(osi, 0.0, 0.0),
        o3.node.Node(osi, 5.5, 0.0),
        o3.node.Node(osi, 0.0, 3.3),
        o3.node.Node(osi, 5.5, 3.3)
    ]
    o3.Mass2D(osi, nodes[2], 1e5, 1e5, 1e6)
    o3.Mass2D(osi, nodes[3], 1e5, 1e5, 1e6)
    o3.Fix3DOF(osi, nodes[0], o3.cc.FIXED, o3.cc.FIXED, o3.cc.FIXED)
    o3.Fix3DOF(osi, nodes[1], o3.cc.FIXED, o3.cc.FIXED, o3.cc.FIXED)

    steel_mat = o3.uniaxial_material.Steel01(osi, 300.0e6, 200.0e9, b=0.02)

    # o3.element.DispBeamColumn(osi, [nodes[2], nodes[3]], )
    tran = o3.geom_transf.Linear2D(osi)
    e_mod = 200.0e9
    iz = 1.0e-4
    area = 0.01
    # o3.element.ElasticBeamColumn2D(osi, [nodes[2], nodes[3]], 0.01, 200.0e9, iz=1.0e-4, transf=tran)
    ei = e_mod * iz
    ea = e_mod * area
    phi_y = 0.001
    my = ei * phi_y
    print('my: ', my)
    mat = o3.uniaxial_material.ElasticBilin(osi, ei, 0.01 * ei, phi_y)
    mat_axial = o3.uniaxial_material.Elastic(osi, ea)
    top_sect = o3.section.Aggregator(osi,
                                     mats=[[mat_axial, o3.cc.P],
                                           [mat, o3.cc.M_Z]])
    bot_sect = o3.section.Aggregator(osi,
                                     mats=[[mat_axial, o3.cc.P],
                                           [mat, o3.cc.M_Z]])

    centre_sect = o3.section.Elastic2D(osi, e_mod, area, iz)
    lplas = 0.2

    integ = o3.beam_integration.HingeMidpoint(osi, bot_sect, lplas, top_sect,
                                              lplas, centre_sect)

    beam = o3.element.ForceBeamColumn(osi, [nodes[2], nodes[3]], tran, integ)

    o3.element.ElasticBeamColumn2D(osi, [nodes[0], nodes[2]],
                                   0.01,
                                   200.0e9,
                                   iz=1.0e-4,
                                   transf=tran)
    o3.element.ElasticBeamColumn2D(osi, [nodes[1], nodes[3]],
                                   0.01,
                                   200.0e9,
                                   iz=1.0e-4,
                                   transf=tran)

    a_series = o3.time_series.Path(osi, dt=asig.dt, values=-1 *
                                   asig.values)  # should be negative
    o3.pattern.UniformExcitation(osi, dir=o3.cc.X, accel_series=a_series)

    xi = 0.04
    angular_freqs = np.array(o3.get_eigen(osi, n=4))**0.5
    print('angular_freqs: ', angular_freqs)
    periods = 2 * np.pi / angular_freqs
    print('periods: ', periods)

    if use_modal_damping:  # Does not support modal damping
        freqs = [0.5, 5]
        omega_1 = 2 * np.pi * freqs[0]
        omega_2 = 2 * np.pi * freqs[1]
        a0 = 2 * xi * omega_1 * omega_2 / (omega_1 + omega_2)
        a1 = 2 * xi / (omega_1 + omega_2)
        o3.rayleigh.Rayleigh(osi, a0, 0, a1, 0)
    else:
        o3.ModalDamping(osi, [xi])

    o3.constraints.Transformation(osi)
    o3.test_check.NormDispIncr(osi, tol=1.0e-5, max_iter=35, p_flag=0)
    o3.numberer.RCM(osi)
    if use_modal_damping:
        o3_sys = o3.system.ProfileSPD  # not sure why don't need to use FullGen here? since matrix is full?
    else:
        o3_sys = o3.system.ProfileSPD
    if etype == 'implicit':
        o3.algorithm.Newton(osi)
        o3_sys(osi)
        o3.integrator.Newmark(osi, gamma=0.5, beta=0.25)
        dt = 0.01
    else:
        o3.algorithm.Linear(osi, factor_once=True)

        if etype == 'newmark_explicit':
            o3_sys(osi)
            o3.integrator.NewmarkExplicit(osi, gamma=0.5)
            explicit_dt = periods[-1] / np.pi / 4
        elif etype == 'central_difference':
            o3_sys(osi)
            o3.integrator.CentralDifference(osi)
            explicit_dt = periods[-1] / np.pi / 4  # 0.5 is a factor of safety
        elif etype == 'explicit_difference':
            o3.system.Diagonal(osi)
            o3.integrator.ExplicitDifference(osi)
            explicit_dt = periods[-1] / np.pi / 4
        else:
            raise ValueError(etype)
        print('explicit_dt: ', explicit_dt)
        dt = explicit_dt
    o3.analysis.Transient(osi)

    roof_disp = o3.recorder.NodeToArrayCache(osi,
                                             nodes[2],
                                             dofs=[o3.cc.X],
                                             res_type='disp')
    time = o3.recorder.TimeToArrayCache(osi)
    ele_resp = o3.recorder.ElementToArrayCache(osi, beam, arg_vals=['force'])
    ttotal = 10.0
    o3.analyze(osi, int(ttotal / dt), dt)
    o3.wipe(osi)
    return time.collect(), roof_disp.collect(), ele_resp.collect()
def run(show=0):
    # Load a ground motion
    record_filename = 'test_motion_dt0p01.txt'
    asig = eqsig.load_asig(ap.MODULE_DATA_PATH + 'gms/' + record_filename,
                           m=0.5)

    # Define inelastic SDOF
    period = 1.0
    xi = 0.05
    mass = 1.0
    f_yield = 1.5  # Reduce this to make it nonlinear
    r_post = 0.0

    # Initialise OpenSees instance
    osi = o3.OpenSeesInstance(ndm=2, state=0)

    # Establish nodes
    bot_node = o3.node.Node(osi, 0, 0)
    top_node = o3.node.Node(osi, 0, 0)

    # Fix bottom node
    o3.Fix3DOF(osi, top_node, o3.cc.FREE, o3.cc.FIXED, o3.cc.FIXED)
    o3.Fix3DOF(osi, bot_node, o3.cc.FIXED, o3.cc.FIXED, o3.cc.FIXED)
    # Set out-of-plane DOFs to be slaved
    o3.EqualDOF(osi, top_node, bot_node, [o3.cc.Y, o3.cc.ROTZ])

    # nodal mass (weight / g):
    o3.Mass(osi, top_node, mass, 0., 0.)

    # Define material
    k_spring = 4 * np.pi**2 * mass / period**2
    bilinear_mat = o3.uniaxial_material.Steel01(osi,
                                                fy=f_yield,
                                                e0=k_spring,
                                                b=r_post)

    # Assign zero length element, # Note: pass actual node and material objects into element
    o3.element.ZeroLength(osi, [bot_node, top_node],
                          mats=[bilinear_mat],
                          dirs=[o3.cc.DOF2D_X],
                          r_flag=1)

    # Define the dynamic analysis

    # Define the dynamic analysis
    acc_series = o3.time_series.Path(osi, dt=asig.dt, values=-1 *
                                     asig.values)  # should be negative
    o3.pattern.UniformExcitation(osi, dir=o3.cc.X, accel_series=acc_series)

    # set damping based on first eigen mode
    angular_freq = o3.get_eigen(osi, solver='fullGenLapack', n=1)[0]**0.5
    beta_k = 2 * xi / angular_freq
    o3.rayleigh.Rayleigh(osi,
                         alpha_m=0.0,
                         beta_k=beta_k,
                         beta_k_init=0.0,
                         beta_k_comm=0.0)

    # Run the dynamic analysis
    o3.wipe_analysis(osi)

    # Run the dynamic analysis
    o3.algorithm.Newton(osi)
    o3.system.SparseGeneral(osi)
    o3.numberer.RCM(osi)
    o3.constraints.Transformation(osi)
    o3.integrator.Newmark(osi, gamma=0.5, beta=0.25)
    o3.analysis.Transient(osi)

    o3.test_check.EnergyIncr(osi, tol=1.0e-10, max_iter=10)
    analysis_time = asig.time[-1]
    analysis_dt = 0.001
    outputs = {
        "time": [],
        "rel_disp": [],
        "rel_accel": [],
        "rel_vel": [],
        "force": []
    }

    while o3.get_time(osi) < analysis_time:
        o3.analyze(osi, 1, analysis_dt)
        curr_time = o3.get_time(osi)
        outputs["time"].append(curr_time)
        outputs["rel_disp"].append(o3.get_node_disp(osi, top_node, o3.cc.X))
        outputs["rel_vel"].append(o3.get_node_vel(osi, top_node, o3.cc.X))
        outputs["rel_accel"].append(o3.get_node_accel(osi, top_node, o3.cc.X))
        o3.gen_reactions(osi)
        outputs["force"].append(-o3.get_node_reaction(
            osi, bot_node, o3.cc.X))  # Negative since diff node
    o3.wipe(osi)
    for item in outputs:
        outputs[item] = np.array(outputs[item])

    if show:
        import matplotlib.pyplot as plt
        plt.plot(outputs['time'], outputs['rel_disp'], label='o3seespy')
        periods = np.array([period])

        # Compare closed form elastic solution
        from eqsig import sdof
        resp_u, resp_v, resp_a = sdof.response_series(motion=asig.values,
                                                      dt=asig.dt,
                                                      periods=periods,
                                                      xi=xi)
        plt.plot(asig.time, resp_u[0], ls='--', label='Elastic')
        plt.legend()
        plt.show()
def test_disp_control_cantilever_nonlinear():
    osi = o3.OpenSeesInstance(ndm=2, state=3)

    ele_len = 4.0

    # Establish nodes
    left_node = o3.node.Node(osi, 0, 0)
    right_node = o3.node.Node(osi, ele_len, 0)

    # Fix bottom node
    o3.Fix3DOF(osi, left_node, o3.cc.FIXED, o3.cc.FIXED, o3.cc.FIXED)
    o3.Fix3DOF(osi, right_node, o3.cc.FREE, o3.cc.FREE, o3.cc.FREE)
    e_mod = 200.0
    i_sect = 0.1
    area = 0.5
    lp_i = 0.1
    lp_j = 0.1

    m_cap = 0.30
    b = 0.05
    phi = m_cap / (e_mod * i_sect)
    # mat_flex = o3.uniaxial_material.Steel01(osi, m_cap, e0=e_mod * i_sect, b=b)
    mat_flex = o3.uniaxial_material.ElasticBilin(osi, e_mod * i_sect,
                                                 e_mod * i_sect * b, phi)
    mat_axial = o3.uniaxial_material.Elastic(osi, e_mod * area)
    left_sect = o3.section.Aggregator(osi,
                                      mats=[[mat_axial, o3.cc.P],
                                            [mat_flex, o3.cc.M_Z],
                                            [mat_flex, o3.cc.M_Y]])
    right_sect = o3.section.Elastic2D(osi, e_mod, area, i_sect)
    centre_sect = o3.section.Elastic2D(osi, e_mod, area, i_sect)
    integ = o3.beam_integration.HingeMidpoint(osi, left_sect, lp_i, right_sect,
                                              lp_j, centre_sect)
    beam_transf = o3.geom_transf.Linear2D(osi, )
    ele = o3.element.ForceBeamColumn(osi, [left_node, right_node], beam_transf,
                                     integ)

    # start displacement controlled
    d_inc = 0.01

    # opy.wipeAnalysis()
    o3.constraints.Plain(osi)
    o3.numberer.RCM(osi)
    o3.system.BandGeneral(osi)
    o3.test_check.NormUnbalance(osi, 2, max_iter=10, p_flag=0)
    # o3.test_check.FixedNumIter(osi, max_iter=10)
    # o3.test_check.NormDispIncr(osi, 0.002, 10, p_flag=0)
    o3.algorithm.Newton(osi)
    o3.integrator.DisplacementControl(osi, right_node, o3.cc.Y, d_inc)
    o3.analysis.Static(osi)
    ts_po = o3.time_series.Linear(osi, factor=1)
    o3.pattern.Plain(osi, ts_po)
    o3.Load(osi, right_node, [0.0, 1.0, 0])
    o3.analyze(osi, 4)
    end_disp = o3.get_node_disp(osi, right_node, dof=o3.cc.Y)
    r = o3.get_ele_response(osi, ele, 'force')[:3]
    k = r[1] / -end_disp
    k_elastic_expected = 1. / (ele_len**3 / (3 * e_mod * i_sect))
    assert np.isclose(k, k_elastic_expected)
    o3.analyze(osi, 6)
    end_disp = o3.get_node_disp(osi, right_node, dof=o3.cc.Y)
    r = o3.get_ele_response(osi, ele, 'force')[:3]
    k = r[1] / -end_disp
    assert k < 0.95 * k_elastic_expected
def get_inelastic_response(fb, asig, extra_time=0.0, xi=0.05, analysis_dt=0.001):
    """
    Run seismic analysis of a nonlinear FrameBuilding

    Parameters
    ----------
    fb: sfsimodels.Frame2DBuilding object
    asig: eqsig.AccSignal object
    extra_time
    xi
    analysis_dt

    Returns
    -------

    """
    osi = o3.OpenSeesInstance(ndm=2)

    q_floor = 10000.  # kPa
    trib_width = fb.floor_length
    trib_mass_per_length = q_floor * trib_width / 9.8

    # Establish nodes and set mass based on trib area
    # Nodes named as: C<column-number>-S<storey-number>, first column starts at C1-S0 = ground level left
    nd = OrderedDict()
    col_xs = np.cumsum(fb.bay_lengths)
    col_xs = np.insert(col_xs, 0, 0)
    n_cols = len(col_xs)
    sto_ys = fb.heights
    sto_ys = np.insert(sto_ys, 0, 0)
    for cc in range(1, n_cols + 1):
        for ss in range(fb.n_storeys + 1):
            nd[f"C{cc}-S{ss}"] = o3.node.Node(osi, col_xs[cc - 1], sto_ys[ss])

            if ss != 0:
                if cc == 1:
                    node_mass = trib_mass_per_length * fb.bay_lengths[0] / 2
                elif cc == n_cols:
                    node_mass = trib_mass_per_length * fb.bay_lengths[-1] / 2
                else:
                    node_mass = trib_mass_per_length * (fb.bay_lengths[cc - 2] + fb.bay_lengths[cc - 1] / 2)
                o3.set_node_mass(osi, nd[f"C{cc}-S{ss}"], node_mass, 0., 0.)

    # Set all nodes on a storey to have the same displacement
    for ss in range(0, fb.n_storeys + 1):
        for cc in range(1, n_cols + 1):
            o3.set_equal_dof(osi, nd[f"C1-S{ss}"], nd[f"C{cc}-S{ss}"], o3.cc.X)

    # Fix all base nodes
    for cc in range(1, n_cols + 1):
        o3.Fix3DOF(osi, nd[f"C{cc}-S0"], o3.cc.FIXED, o3.cc.FIXED, o3.cc.FIXED)

    # Coordinate transformation
    transf = o3.geom_transf.Linear2D(osi, [])

    l_hinge = fb.bay_lengths[0] * 0.1

    # Define material
    e_conc = 30.0e6
    i_beams = 0.4 * fb.beam_widths * fb.beam_depths ** 3 / 12
    i_columns = 0.5 * fb.column_widths * fb.column_depths ** 3 / 12
    a_beams = fb.beam_widths * fb.beam_depths
    a_columns = fb.column_widths * fb.column_depths
    ei_beams = e_conc * i_beams
    ei_columns = e_conc * i_columns
    eps_yield = 300.0e6 / 200e9
    phi_y_col = calc_yield_curvature(fb.column_depths, eps_yield)
    phi_y_beam = calc_yield_curvature(fb.beam_depths, eps_yield) * 10  # TODO: re-evaluate

    # Define beams and columns
    # Columns named as: C<column-number>-S<storey-number>, first column starts at C1-S0 = ground floor left
    # Beams named as: B<bay-number>-S<storey-number>, first beam starts at B1-S1 = first storey left (foundation at S0)

    md = OrderedDict()  # material dict
    sd = OrderedDict()  # section dict
    ed = OrderedDict()  # element dict

    for ss in range(fb.n_storeys):

        # set columns
        for cc in range(1, fb.n_cols + 1):
            lp_i = 0.4
            lp_j = 0.4  # plastic hinge length
            ele_str = f"C{cc}-S{ss}S{ss+1}"

            top_sect = o3.section.Elastic2D(osi, e_conc, a_columns[ss][cc - 1], i_columns[ss][cc - 1])
            bot_sect = o3.section.Elastic2D(osi, e_conc, a_columns[ss][cc - 1], i_columns[ss][cc - 1])
            centre_sect = o3.section.Elastic2D(osi, e_conc, a_columns[ss][cc - 1], i_columns[ss][cc - 1])
            sd[ele_str + "T"] = top_sect
            sd[ele_str + "B"] = bot_sect
            sd[ele_str + "C"] = centre_sect

            integ = o3.beam_integration.HingeMidpoint(osi, bot_sect, lp_i, top_sect, lp_j, centre_sect)

            bot_node = nd[f"C{cc}-S{ss}"]
            top_node = nd[f"C{cc}-S{ss+1}"]
            ed[ele_str] = o3.element.ForceBeamColumn(osi, [bot_node, top_node], transf, integ)

        # Set beams
        for bb in range(1, fb.n_bays + 1):
            lp_i = 0.5
            lp_j = 0.5
            ele_str = f"C{bb-1}C{bb}-S{ss}"

            mat = o3.uniaxial_material.ElasticBilin(osi, ei_beams[ss][bb - 1], 0.05 * ei_beams[ss][bb - 1], phi_y_beam[ss][bb - 1])
            md[ele_str] = mat
            left_sect = o3.section.Uniaxial(osi, mat, quantity=o3.cc.M_Z)
            right_sect = o3.section.Uniaxial(osi, mat, quantity=o3.cc.M_Z)
            centre_sect = o3.section.Elastic2D(osi, e_conc, a_beams[ss][bb - 1], i_beams[ss][bb - 1])
            integ = o3.beam_integration.HingeMidpoint(osi, left_sect, lp_i, right_sect, lp_j, centre_sect)

            left_node = nd[f"C{bb}-S{ss+1}"]
            right_node = nd[f"C{bb+1}-S{ss+1}"]
            ed[ele_str] = o3.element.ForceBeamColumn(osi, [left_node, right_node], transf, integ)

    # Define the dynamic analysis
    a_series = o3.time_series.Path(osi, dt=asig.dt, values=-1 * asig.values)  # should be negative
    o3.pattern.UniformExcitation(osi, dir=o3.cc.X, accel_series=a_series)

    # set damping based on first eigen mode
    angular_freq_sqrd = o3.get_eigen(osi, solver='fullGenLapack', n=1)
    if hasattr(angular_freq_sqrd, '__len__'):
        angular_freq = angular_freq_sqrd[0] ** 0.5
    else:
        angular_freq = angular_freq_sqrd ** 0.5
    if isinstance(angular_freq, complex):
        raise ValueError("Angular frequency is complex, issue with stiffness or mass")
    beta_k = 2 * xi / angular_freq
    o3.rayleigh.Rayleigh(osi, alpha_m=0.0, beta_k=beta_k, beta_k_init=0.0, beta_k_comm=0.0)

    # Run the dynamic analysis

    o3.wipe_analysis(osi)

    o3.algorithm.Newton(osi)
    o3.system.SparseGeneral(osi)
    o3.numberer.RCM(osi)
    o3.constraints.Transformation(osi)
    o3.integrator.Newmark(osi, 0.5, 0.25)
    o3.analysis.Transient(osi)

    tol = 1.0e-4
    iter = 4
    o3.test_check.EnergyIncr(osi, tol, iter, 0, 2)
    analysis_time = (len(asig.values) - 1) * asig.dt + extra_time
    outputs = {
        "time": [],
        "rel_disp": [],
        "rel_accel": [],
        "rel_vel": [],
        "force": [],
        "ele_mom": [],
        "ele_curve": [],
    }
    print("Analysis starting")
    while o3.get_time(osi) < analysis_time:
        curr_time = opy.getTime()
        o3.analyze(osi, 1, analysis_dt)
        outputs["time"].append(curr_time)
        outputs["rel_disp"].append(o3.get_node_disp(osi, nd["C%i-S%i" % (1, fb.n_storeys)], o3.cc.X))
        outputs["rel_vel"].append(o3.get_node_vel(osi, nd["C%i-S%i" % (1, fb.n_storeys)], o3.cc.X))
        outputs["rel_accel"].append(o3.get_node_accel(osi, nd["C%i-S%i" % (1, fb.n_storeys)], o3.cc.X))
        # outputs['ele_mom'].append(opy.eleResponse('-ele', [ed['B%i-S%i' % (1, 0)], 'basicForce']))
        o3.gen_reactions(osi)
        react = 0
        for cc in range(1, fb.n_cols):
            react += -o3.get_node_reaction(osi, nd["C%i-S%i" % (cc, 0)], o3.cc.X)
        outputs["force"].append(react)  # Should be negative since diff node
    o3.wipe(osi)
    for item in outputs:
        outputs[item] = np.array(outputs[item])

    return outputs
def run_analysis(etype, asig, xi, sdt, use_modal_damping=0):
    osi = o3.OpenSeesInstance(ndm=2, ndf=3)
    nodes = [
        o3.node.Node(osi, 0.0, 0.0),
        o3.node.Node(osi, 5.5, 0.0),
        o3.node.Node(osi, 0.0, 3.3),
        o3.node.Node(osi, 5.5, 3.3)
    ]
    o3.Mass2D(osi, nodes[2], 1e5, 1e5, 1e6)
    o3.Mass2D(osi, nodes[3], 1e5, 1e5, 1e6)
    o3.Fix3DOF(osi, nodes[0], o3.cc.FIXED, o3.cc.FIXED, o3.cc.FIXED)
    o3.Fix3DOF(osi, nodes[1], o3.cc.FIXED, o3.cc.FIXED, o3.cc.FIXED)

    steel_mat = o3.uniaxial_material.Steel01(osi, 300.0e6, 200.0e9, b=0.02)

    tran = o3.geom_transf.Linear2D(osi)
    o3.element.ElasticBeamColumn2D(osi, [nodes[2], nodes[3]],
                                   0.01,
                                   200.0e9,
                                   iz=1.0e-4,
                                   transf=tran)
    o3.element.ElasticBeamColumn2D(osi, [nodes[0], nodes[2]],
                                   0.01,
                                   200.0e9,
                                   iz=1.0e-4,
                                   transf=tran)
    o3.element.ElasticBeamColumn2D(osi, [nodes[1], nodes[3]],
                                   0.01,
                                   200.0e9,
                                   iz=1.0e-4,
                                   transf=tran)

    a_series = o3.time_series.Path(osi, dt=asig.dt, values=-1 *
                                   asig.values)  # should be negative
    o3.pattern.UniformExcitation(osi, dir=o3.cc.X, accel_series=a_series)

    angular_freqs = np.array(o3.get_eigen(osi, n=5))**0.5
    print('angular_freqs: ', angular_freqs)
    periods = 2 * np.pi / angular_freqs
    print('periods: ', periods)

    if use_modal_damping:
        o3.ModalDamping(osi, [xi])
    else:
        freqs = [0.5, 5]
        omega_1 = 2 * np.pi * freqs[0]
        omega_2 = 2 * np.pi * freqs[1]
        a0 = 2 * xi * omega_1 * omega_2 / (omega_1 + omega_2)
        a1 = 2 * xi / (omega_1 + omega_2)
        o3.rayleigh.Rayleigh(osi, a0, 0, a1, 0)

    o3.constraints.Transformation(osi)
    o3.test_check.NormDispIncr(osi, tol=1.0e-5, max_iter=35, p_flag=0)
    o3.numberer.RCM(osi)
    if etype == 'implicit':
        o3.algorithm.Newton(osi)
        o3.system.FullGeneral(osi)
        o3.integrator.Newmark(osi, gamma=0.5, beta=0.25)
        dt = 0.01
    else:
        o3.algorithm.Linear(osi)

        if etype == 'newmark_explicit':
            o3.system.FullGeneral(osi)
            o3.integrator.NewmarkExplicit(osi, gamma=0.5)
            explicit_dt = periods[-1] / np.pi / 8
        elif etype == 'central_difference':
            if use_modal_damping:
                o3.system.FullGeneral(osi)
                explicit_dt = periods[
                    -1] / np.pi / 1.5 * sdt  # 1.5 is a factor of safety for damping
            else:
                o3.system.ProfileSPD(osi)
                explicit_dt = periods[-1] / np.pi / 1.1 * sdt
            o3.integrator.CentralDifference(osi)
        elif etype == 'explicit_difference':
            o3.system.Diagonal(osi)
            o3.integrator.ExplicitDifference(osi)
            explicit_dt = periods[-1] / np.pi / 1.5
        else:
            raise ValueError(etype)
        print('explicit_dt: ', explicit_dt)
        dt = explicit_dt
    o3.analysis.Transient(osi)

    roof_disp = o3.recorder.NodeToArrayCache(osi,
                                             nodes[2],
                                             dofs=[o3.cc.X],
                                             res_type='disp')
    time = o3.recorder.TimeToArrayCache(osi)
    ttotal = 15.0

    while o3.get_time(osi) < ttotal:
        if o3.analyze(osi, 10, dt):
            print('failed')
            break
        ddisp = o3.get_node_disp(osi, nodes[2], dof=o3.cc.X)
        if abs(ddisp) > 0.1:
            print('Break')
            break
    o3.wipe(osi)
    return time.collect(), roof_disp.collect()
def get_inelastic_response(fb,
                           roof_drift_ratio=0.05,
                           elastic=False,
                           w_sfsi=False,
                           out_folder=''):
    """
    Run seismic analysis of a nonlinear FrameBuilding

    Units: Pa, N, m, s

    Parameters
    ----------
    fb: sfsimodels.Frame2DBuilding object
    xi

    Returns
    -------

    """
    osi = o3.OpenSeesInstance(ndm=2, state=3)

    q_floor = 7.0e3  # Pa
    trib_width = fb.floor_length
    trib_mass_per_length = q_floor * trib_width / 9.8

    # Establish nodes and set mass based on trib area
    # Nodes named as: C<column-number>-S<storey-number>, first column starts at C1-S0 = ground level left
    nd = OrderedDict()
    col_xs = np.cumsum(fb.bay_lengths)
    col_xs = np.insert(col_xs, 0, 0)
    n_cols = len(col_xs)
    sto_ys = fb.heights
    sto_ys = np.insert(sto_ys, 0, 0)
    for cc in range(1, n_cols + 1):
        for ss in range(fb.n_storeys + 1):
            nd[f"C{cc}-S{ss}"] = o3.node.Node(osi, col_xs[cc - 1], sto_ys[ss])

            if ss != 0:
                if cc == 1:
                    node_mass = trib_mass_per_length * fb.bay_lengths[0] / 2
                elif cc == n_cols:
                    node_mass = trib_mass_per_length * fb.bay_lengths[-1] / 2
                else:
                    node_mass = trib_mass_per_length * (
                        fb.bay_lengths[cc - 2] + fb.bay_lengths[cc - 1] / 2)
                o3.set_node_mass(osi, nd[f"C{cc}-S{ss}"], node_mass, 0., 0.)

    # Set all nodes on a storey to have the same displacement
    for ss in range(0, fb.n_storeys + 1):
        for cc in range(2, n_cols + 1):
            o3.set_equal_dof(osi, nd[f"C1-S{ss}"], nd[f"C{cc}-S{ss}"], o3.cc.X)

    # Fix all base nodes
    for cc in range(1, n_cols + 1):
        o3.Fix3DOF(osi, nd[f"C{cc}-S0"], o3.cc.FIXED, o3.cc.FIXED, o3.cc.FIXED)

    # Define material
    e_conc = 30.0e9  # kPa
    i_beams = 0.4 * fb.beam_widths * fb.beam_depths**3 / 12
    i_columns = 0.5 * fb.column_widths * fb.column_depths**3 / 12
    a_beams = fb.beam_widths * fb.beam_depths
    a_columns = fb.column_widths * fb.column_depths
    ei_beams = e_conc * i_beams
    ei_columns = e_conc * i_columns
    eps_yield = 300.0e6 / 200e9
    phi_y_col = calc_yield_curvature(fb.column_depths, eps_yield)
    phi_y_beam = calc_yield_curvature(fb.beam_depths, eps_yield)

    # Define beams and columns
    # Columns named as: C<column-number>-S<storey-number>, first column starts at C1-S0 = ground floor left
    # Beams named as: B<bay-number>-S<storey-number>, first beam starts at B1-S1 = first storey left (foundation at S0)

    md = OrderedDict()  # material dict
    sd = OrderedDict()  # section dict
    ed = OrderedDict()  # element dict

    for ss in range(fb.n_storeys):

        # set columns
        lp_i = 0.4
        lp_j = 0.4  # plastic hinge length
        col_transf = o3.geom_transf.Linear2D(
            osi, )  # d_i=[0.0, lp_i], d_j=[0.0, -lp_j]
        for cc in range(1, fb.n_cols + 1):

            ele_str = f"C{cc}-S{ss}S{ss + 1}"

            if elastic:
                top_sect = o3.section.Elastic2D(osi, e_conc,
                                                a_columns[ss][cc - 1],
                                                i_columns[ss][cc - 1])
                bot_sect = o3.section.Elastic2D(osi, e_conc,
                                                a_columns[ss][cc - 1],
                                                i_columns[ss][cc - 1])
            else:
                m_cap = ei_columns[ss][cc - 1] * phi_y_col[ss][cc - 1]
                mat = o3.uniaxial_material.ElasticBilin(
                    osi, ei_columns[ss][cc - 1], 0.05 * ei_columns[ss][cc - 1],
                    1 * phi_y_col[ss][cc - 1])
                mat_axial = o3.uniaxial_material.Elastic(
                    osi, e_conc * a_columns[ss][cc - 1])
                top_sect = o3.section.Aggregator(osi,
                                                 mats=[[mat_axial, o3.cc.P],
                                                       [mat, o3.cc.M_Z]])
                bot_sect = o3.section.Aggregator(osi,
                                                 mats=[[mat_axial, o3.cc.P],
                                                       [mat, o3.cc.M_Z]])

            centre_sect = o3.section.Elastic2D(osi, e_conc,
                                               a_columns[ss][cc - 1],
                                               i_columns[ss][cc - 1])
            sd[ele_str + "T"] = top_sect
            sd[ele_str + "B"] = bot_sect
            sd[ele_str + "C"] = centre_sect

            integ = o3.beam_integration.HingeMidpoint(osi, bot_sect, lp_i,
                                                      top_sect, lp_j,
                                                      centre_sect)

            bot_node = nd[f"C{cc}-S{ss}"]
            top_node = nd[f"C{cc}-S{ss + 1}"]
            ed[ele_str] = o3.element.ForceBeamColumn(osi, [bot_node, top_node],
                                                     col_transf, integ)
            print('mc: ', ei_columns[ss][cc - 1] * phi_y_col[ss][cc - 1])
        # Set beams
        lp_i = 0.4
        lp_j = 0.4
        beam_transf = o3.geom_transf.Linear2D(osi, )
        for bb in range(1, fb.n_bays + 1):

            ele_str = f"C{bb}C{bb + 1}-S{ss + 1}"

            print('mb: ', ei_beams[ss][bb - 1] * phi_y_beam[ss][bb - 1])
            print('phi_b: ', phi_y_beam[ss][bb - 1])

            if elastic:
                left_sect = o3.section.Elastic2D(osi, e_conc,
                                                 a_beams[ss][bb - 1],
                                                 i_beams[ss][bb - 1])
                right_sect = o3.section.Elastic2D(osi, e_conc,
                                                  a_beams[ss][bb - 1],
                                                  i_beams[ss][bb - 1])
            else:
                m_cap = ei_beams[ss][bb - 1] * phi_y_beam[ss][bb - 1]
                # mat_flex = o3.uniaxial_material.ElasticBilin(osi, ei_beams[ss][bb - 1], 0.05 * ei_beams[ss][bb - 1], phi_y_beam[ss][bb - 1])
                mat_flex = o3.uniaxial_material.Steel01(osi,
                                                        m_cap,
                                                        e0=ei_beams[ss][bb -
                                                                        1],
                                                        b=0.05)
                mat_axial = o3.uniaxial_material.Elastic(
                    osi, e_conc * a_beams[ss][bb - 1])
                left_sect = o3.section.Aggregator(osi,
                                                  mats=[[mat_axial, o3.cc.P],
                                                        [mat_flex, o3.cc.M_Z],
                                                        [mat_flex, o3.cc.M_Y]])
                right_sect = o3.section.Aggregator(osi,
                                                   mats=[[mat_axial, o3.cc.P],
                                                         [mat_flex, o3.cc.M_Z],
                                                         [mat_flex,
                                                          o3.cc.M_Y]])

            centre_sect = o3.section.Elastic2D(osi, e_conc,
                                               a_beams[ss][bb - 1],
                                               i_beams[ss][bb - 1])
            integ = o3.beam_integration.HingeMidpoint(osi, left_sect, lp_i,
                                                      right_sect, lp_j,
                                                      centre_sect)

            left_node = nd[f"C{bb}-S{ss + 1}"]
            right_node = nd[f"C{bb + 1}-S{ss + 1}"]
            ed[ele_str] = o3.element.ForceBeamColumn(osi,
                                                     [left_node, right_node],
                                                     beam_transf, integ)

    # Apply gravity loads
    gravity = 9.8 * 1e-2
    # If true then load applied along beam
    g_beams = 0  # TODO: when this is true and analysis is inelastic then failure
    ts_po = o3.time_series.Linear(osi, factor=1)
    o3.pattern.Plain(osi, ts_po)

    for ss in range(1, fb.n_storeys + 1):
        print('ss:', ss)
        if g_beams:
            for bb in range(1, fb.n_bays + 1):
                ele_str = f"C{bb}C{bb + 1}-S{ss}"
                o3.EleLoad2DUniform(osi, ed[ele_str],
                                    -trib_mass_per_length * gravity)
        else:
            for cc in range(1, fb.n_cols + 1):
                if cc == 1 or cc == n_cols:
                    node_mass = trib_mass_per_length * fb.bay_lengths[0] / 2
                elif cc == n_cols:
                    node_mass = trib_mass_per_length * fb.bay_lengths[-1] / 2
                else:
                    node_mass = trib_mass_per_length * (
                        fb.bay_lengths[cc - 2] + fb.bay_lengths[cc - 1] / 2)
                # This works
                o3.Load(osi, nd[f"C{cc}-S{ss}"], [0, -node_mass * gravity, 0])

    tol = 1.0e-3
    o3.constraints.Plain(osi)
    o3.numberer.RCM(osi)
    o3.system.BandGeneral(osi)
    o3.test_check.NormDispIncr(osi, tol, 10)
    o3.algorithm.Newton(osi)
    n_steps_gravity = 10
    d_gravity = 1. / n_steps_gravity
    o3.integrator.LoadControl(osi, d_gravity, num_iter=10)
    o3.analysis.Static(osi)
    o3.analyze(osi, n_steps_gravity)
    o3.gen_reactions(osi)
    print('b1_int: ', o3.get_ele_response(osi, ed['C1C2-S1'], 'force'))
    print('c1_int: ', o3.get_ele_response(osi, ed['C1-S0S1'], 'force'))

    # o3.extensions.to_py_file(osi, 'po.py')
    o3.load_constant(osi, time=0.0)

    # Define the analysis

    # set damping based on first eigen mode
    angular_freq = o3.get_eigen(osi, solver='fullGenLapack', n=1)[0]**0.5
    if isinstance(angular_freq, complex):
        raise ValueError(
            "Angular frequency is complex, issue with stiffness or mass")
    print('angular_freq: ', angular_freq)
    response_period = 2 * np.pi / angular_freq
    print('response period: ', response_period)

    # Run the analysis
    o3r = o3.results.Results2D()
    o3r.cache_path = out_folder
    o3r.dynamic = True
    o3r.pseudo_dt = 0.001  # since analysis is actually static
    o3.set_time(osi, 0.0)
    o3r.start_recorders(osi)
    # o3res.coords = o3.get_all_node_coords(osi)
    # o3res.ele2node_tags = o3.get_all_ele_node_tags_as_dict(osi)
    d_inc = 0.0001

    o3.numberer.RCM(osi)
    o3.system.BandGeneral(osi)
    # o3.test_check.NormUnbalance(osi, 2, max_iter=10, p_flag=2)
    # o3.test_check.FixedNumIter(osi, max_iter=10)
    o3.test_check.NormDispIncr(osi, 0.002, 10, p_flag=0)
    o3.algorithm.Newton(osi)
    o3.integrator.DisplacementControl(osi, nd[f"C1-S{fb.n_storeys}"], o3.cc.X,
                                      d_inc)
    o3.analysis.Static(osi)

    d_max = 0.05 * fb.max_height  # TODO: set to 5%
    print('d_max: ', d_max)
    # n_steps = int(d_max / d_inc)

    print("Analysis starting")
    print('int_disp: ',
          o3.get_node_disp(osi, nd[f"C1-S{fb.n_storeys}"], o3.cc.X))
    # opy.recorder('Element', '-file', 'ele_out.txt', '-time', '-ele', 1, 'force')
    tt = 0
    outputs = {
        'h_disp': [],
        'vb': [],
        'REACT-C1C2-S1': [],
        'REACT-C1-S0S1': [],
    }
    hd = 0
    n_max = 2
    n_cycs = 0
    xs = fb.heights / fb.max_height  # TODO: more sophisticated displacement profile
    ts_po = o3.time_series.Linear(osi, factor=1)
    o3.pattern.Plain(osi, ts_po)
    for i, xp in enumerate(xs):
        o3.Load(osi, nd[f"C1-S{i + 1}"], [xp, 0.0, 0])

    # o3.analyze(osi, 2)
    # n_max = 0
    time = [0]
    while n_cycs < n_max:
        print('n_cycles: ', n_cycs)
        for i in range(2):
            if i == 0:
                o3.integrator.DisplacementControl(osi,
                                                  nd[f"C1-S{fb.n_storeys}"],
                                                  o3.cc.X, d_inc)
            else:
                o3.integrator.DisplacementControl(osi,
                                                  nd[f"C1-S{fb.n_storeys}"],
                                                  o3.cc.X, -d_inc)
            while hd * (-1)**i < d_max:
                ok = o3.analyze(osi, 10)
                time.append(time[len(time) - 1] + 1)
                hd = o3.get_node_disp(osi, nd[f"C1-S{fb.n_storeys}"], o3.cc.X)
                outputs['h_disp'].append(hd)
                o3.gen_reactions(osi)
                vb = 0
                for cc in range(1, fb.n_cols + 1):
                    vb += o3.get_node_reaction(osi, nd[f"C{cc}-S0"], o3.cc.X)
                outputs['vb'].append(-vb)
                outputs['REACT-C1C2-S1'].append(
                    o3.get_ele_response(osi, ed['C1C2-S1'], 'force'))
                outputs['REACT-C1-S0S1'].append(
                    o3.get_ele_response(osi, ed['C1-S0S1'], 'force'))

        n_cycs += 1

    o3.wipe(osi)
    o3r.save_to_cache()
    for item in outputs:
        outputs[item] = np.array(outputs[item])
    print('complete')
    return outputs
예제 #10
0
def get_response(bd, asig, l_ph):
    """
    Compute the response of a nonlinear lollipop on a foundation with linear/nonlinear soil
    Units are N, m, s

    :param bd:
        SDOF building object
    :param asig:
        Acceleration signal object
    :return:
    """
    osi = o3.OpenSeesInstance(ndm=2, state=3)

    # Establish nodes
    top_ss_node = o3.node.Node(osi, 0, bd.h_eff)
    bot_ss_node = o3.node.Node(osi, 0, 0)

    # Fix bottom node
    o3.Fix3DOF(osi, bot_ss_node, o3.cc.FIXED, o3.cc.FIXED, o3.cc.FIXED)

    # nodal mass (weight / g):
    o3.Mass(osi, top_ss_node, bd.mass_eff, 0.0, 0)

    # Define a column element with a plastic hinge at base
    transf = o3.geom_transf.Linear2D(osi, [])  # can change for P-delta effects
    area = 1.0
    e_mod = 200.0e9
    iz = bd.k_eff * bd.h_eff**3 / (3 * e_mod)
    ele_nodes = [bot_ss_node, top_ss_node]

    # Superstructure element
    elastic_sect = o3.section.Elastic2D(osi, e_mod, area, iz)
    integ = o3.beam_integration.HingeMidpoint(osi, elastic_sect, l_ph,
                                              elastic_sect, l_ph, elastic_sect)
    vert_ele = o3.element.ForceBeamColumn(osi, ele_nodes, transf, integ)

    omega = 2 * np.pi / bd.t_fixed

    beta_k = 2 * bd.xi / omega
    o3.rayleigh.Rayleigh(osi, 0, 0, beta_k_init=beta_k, beta_k_comm=0.0)

    # Define the input motion for the dynamic analysis
    acc_series = o3.time_series.Path(osi, dt=asig.dt,
                                     values=-asig.values)  # should be negative
    o3.pattern.UniformExcitation(osi, dir=o3.cc.X, accel_series=acc_series)
    print('loaded gm')
    o3.wipe_analysis(osi)

    o3.algorithm.Newton(osi)
    o3.system.SparseGeneral(osi)
    o3.numberer.RCM(osi)
    o3.constraints.Transformation(osi)
    o3.integrator.Newmark(osi, 0.5, 0.25)
    o3.analysis.Transient(osi)

    o3.test_check.NormDispIncr(osi, tol=1.0e-6, max_iter=10)
    analysis_time = asig.time[-1]
    analysis_dt = 0.001

    # define outputs of analysis
    od = {
        "time":
        o3.recorder.TimeToArrayCache(osi),
        "rel_deck_disp":
        o3.recorder.NodeToArrayCache(osi, top_ss_node, [o3.cc.DOF2D_X],
                                     'disp'),
        "deck_accel":
        o3.recorder.NodeToArrayCache(osi, top_ss_node, [o3.cc.DOF2D_X],
                                     'accel'),
        "deck_rot":
        o3.recorder.NodeToArrayCache(osi, top_ss_node, [o3.cc.DOF2D_ROTZ],
                                     'disp'),
        "chord_rots":
        o3.recorder.ElementToArrayCache(osi,
                                        vert_ele,
                                        arg_vals=['chordRotation']),
        "col_forces":
        o3.recorder.ElementToArrayCache(osi, vert_ele, arg_vals=['force']),
    }

    o3.analyze(osi, int(analysis_time / analysis_dt), analysis_dt)

    o3.wipe(osi)

    for item in od:
        od[item] = od[item].collect()
    od['col_shear'] = -od['col_forces'][:, 0]
    od['col_moment'] = od['col_forces'][:, 2]
    od['hinge_rotation'] = od['chord_rots'][:, 1]
    od['hinge_rotation1'] = -od['chord_rots'][:, 2]
    del od['col_forces']
    del od['chord_rots']

    return od
예제 #11
0
def test_fix3dof():
    osi = o3.OpenSeesInstance(ndm=2, ndf=3)
    node = o3.node.Node(osi, 3, 4)
    o3.Fix3DOF(osi, node, o3.cc.FIXED, o3.cc.FIXED, o3.cc.FIXED)
    sn = o3.node.build_regular_node_mesh(osi, [3, 4], [1, 6])
    o3.Fix3DOFMulti(osi, sn[0], o3.cc.FREE, o3.cc.FIXED, o3.cc.FIXED)
def gen_response(period, xi, asig, etype, fos_for_dt=None):

    # Define inelastic SDOF
    mass = 1.0
    f_yield = 1.5  # Reduce this to make it nonlinear
    r_post = 0.0

    # Initialise OpenSees instance
    osi = o3.OpenSeesInstance(ndm=2, state=0)

    # Establish nodes
    bot_node = o3.node.Node(osi, 0, 0)
    top_node = o3.node.Node(osi, 0, 0)

    # Fix bottom node
    o3.Fix3DOF(osi, top_node, o3.cc.FREE, o3.cc.FIXED, o3.cc.FIXED)
    o3.Fix3DOF(osi, bot_node, o3.cc.FIXED, o3.cc.FIXED, o3.cc.FIXED)
    # Set out-of-plane DOFs to be slaved
    o3.EqualDOF(osi, top_node, bot_node, [o3.cc.Y, o3.cc.ROTZ])

    # nodal mass (weight / g):
    o3.Mass(osi, top_node, mass, 0., 0.)

    # Define material
    k_spring = 4 * np.pi**2 * mass / period**2
    # bilinear_mat = o3.uniaxial_material.Steel01(osi, fy=f_yield, e0=k_spring, b=r_post)
    mat = o3.uniaxial_material.Elastic(osi, e_mod=k_spring)

    # Assign zero length element, # Note: pass actual node and material objects into element
    o3.element.ZeroLength(osi, [bot_node, top_node],
                          mats=[mat],
                          dirs=[o3.cc.DOF2D_X],
                          r_flag=1)

    # Define the dynamic analysis

    # Define the dynamic analysis
    acc_series = o3.time_series.Path(osi, dt=asig.dt, values=-1 *
                                     asig.values)  # should be negative
    o3.pattern.UniformExcitation(osi, dir=o3.cc.X, accel_series=acc_series)

    # set damping based on first eigen mode
    angular_freq = o3.get_eigen(osi, solver='fullGenLapack', n=1)[0]**0.5
    period = 2 * np.pi / angular_freq
    beta_k = 2 * xi / angular_freq
    o3.rayleigh.Rayleigh(osi,
                         alpha_m=0.0,
                         beta_k=beta_k,
                         beta_k_init=0.0,
                         beta_k_comm=0.0)

    o3.set_time(osi, 0.0)
    # Run the dynamic analysis
    o3.wipe_analysis(osi)

    # Run the dynamic analysis
    o3.numberer.RCM(osi)
    o3.system.FullGeneral(osi)
    if etype == 'central_difference':
        o3.algorithm.Linear(osi, factor_once=True)
        o3.integrator.CentralDifference(osi)
        explicit_dt = 2 / angular_freq / fos_for_dt
        analysis_dt = explicit_dt
    elif etype == 'implicit':
        o3.algorithm.Newton(osi)
        o3.integrator.Newmark(osi, gamma=0.5, beta=0.25)
        analysis_dt = 0.001
    else:
        raise ValueError()
    o3.constraints.Transformation(osi)
    o3.analysis.Transient(osi)

    o3.test_check.EnergyIncr(osi, tol=1.0e-10, max_iter=10)
    analysis_time = asig.time[-1]

    outputs = {
        "time": [],
        "rel_disp": [],
        "rel_accel": [],
        "rel_vel": [],
        "force": []
    }
    rec_dt = 0.002
    n_incs = int(analysis_dt / rec_dt)
    n_incs = 1
    while o3.get_time(osi) < analysis_time:
        o3.analyze(osi, n_incs, analysis_dt)
        curr_time = o3.get_time(osi)
        outputs["time"].append(curr_time)
        outputs["rel_disp"].append(o3.get_node_disp(osi, top_node, o3.cc.X))
        outputs["rel_vel"].append(o3.get_node_vel(osi, top_node, o3.cc.X))
        outputs["rel_accel"].append(o3.get_node_accel(osi, top_node, o3.cc.X))
        o3.gen_reactions(osi)
        outputs["force"].append(-o3.get_node_reaction(
            osi, bot_node, o3.cc.X))  # Negative since diff node
    o3.wipe(osi)
    for item in outputs:
        outputs[item] = np.array(outputs[item])
    return outputs
    def run_w_settings(ele_len, e_mod, i_sect, pload, udl, beam_in_parts,
                       use_pload):
        osi = o3.OpenSeesInstance(ndm=2, state=3)

        # Establish nodes
        left_node = o3.node.Node(osi, 0, 0)
        right_node = o3.node.Node(osi, ele_len, 0)

        # Fix bottom node
        o3.Fix3DOF(osi, left_node, o3.cc.FIXED, o3.cc.FIXED, o3.cc.FIXED)
        o3.Fix3DOF(osi, right_node, o3.cc.FREE, o3.cc.FREE, o3.cc.FREE)

        area = 0.5
        lp_i = 0.2
        lp_j = 0.2

        if beam_in_parts:
            elastic = 1

            if elastic:
                left_sect = o3.section.Elastic2D(osi, e_mod, area, i_sect)
            else:
                m_cap = 600.0
                b = 0.05
                phi = m_cap / (e_mod * i_sect)
                # mat_flex = o3.uniaxial_material.Steel01(osi, m_cap, e0=e_mod * i_sect, b=b)
                mat_flex = o3.uniaxial_material.ElasticBilin(
                    osi, e_mod * i_sect, e_mod * i_sect * b, phi)
                mat_axial = o3.uniaxial_material.Elastic(osi, e_mod * area)
                left_sect = o3.section.Aggregator(osi,
                                                  mats=[
                                                      mat_axial.tag, o3.cc.P,
                                                      mat_flex.tag, o3.cc.M_Z,
                                                      mat_flex.tag, o3.cc.M_Y
                                                  ])
            right_sect = o3.section.Elastic2D(osi, e_mod, area, i_sect)
            centre_sect = o3.section.Elastic2D(osi, e_mod, area, i_sect)
            integ = o3.beam_integration.HingeMidpoint(osi, left_sect, lp_i,
                                                      right_sect, lp_j,
                                                      centre_sect)
            beam_transf = o3.geom_transf.Linear2D(osi, )
            ele = o3.element.ForceBeamColumn(osi, [left_node, right_node],
                                             beam_transf, integ)
        else:
            beam_transf = o3.geom_transf.Linear2D(osi)
            ele = o3.element.ElasticBeamColumn2D(osi, [left_node, right_node],
                                                 area, e_mod, i_sect,
                                                 beam_transf)
        # Apply gravity loads

        # If true then load applied along beam

        ts_po = o3.time_series.Linear(osi, factor=1)
        o3.pattern.Plain(osi, ts_po)
        if use_pload:
            o3.Load(osi, right_node, [0, -pload, 0])
        else:
            o3.EleLoad2DUniform(osi, ele, -udl)

        tol = 1.0e-3
        o3.constraints.Plain(osi)
        o3.numberer.RCM(osi)
        o3.system.BandGeneral(osi)
        n_steps_gravity = 10
        o3.integrator.LoadControl(osi, 1. / n_steps_gravity, num_iter=10)
        o3.test_check.NormDispIncr(osi, tol, 10)
        o3.algorithm.Linear(osi)
        o3.analysis.Static(osi)
        o3.analyze(osi, n_steps_gravity)
        o3.gen_reactions(osi)
        end_disp = o3.get_node_disp(osi, right_node, dof=o3.cc.Y)
        return o3.get_ele_response(osi, ele, 'force')[:3], end_disp
예제 #14
0
def get_response(bd, asig, dtype, l_ph):
    """
    Compute the response of a nonlinear lollipop on a foundation with linear/nonlinear soil
    Units are N, m, s

    :param bd:
        SDOF building object
    :param asig:
        Acceleration signal object
    :return:
    """
    osi = o3.OpenSeesInstance(ndm=2, state=3)

    # Establish nodes
    top_ss_node = o3.node.Node(osi, 0, bd.h_eff)
    bot_ss_node = o3.node.Node(osi, 0, 0)

    # Fix bottom node
    o3.Fix3DOF(osi, bot_ss_node, o3.cc.FIXED, o3.cc.FIXED, o3.cc.FIXED)

    # nodal mass (weight / g):
    o3.Mass(osi, top_ss_node, bd.mass_eff, 0.0, 0)

    # Define a column element with a plastic hinge at base
    transf = o3.geom_transf.Linear2D(osi, [])  # can change for P-delta effects
    area = 1.0
    e_mod = 200.0e9
    iz = bd.k_eff * bd.h_eff ** 3 / (3 * e_mod)
    ele_nodes = [bot_ss_node, top_ss_node]

    # Superstructure element
    vert_ele = o3.element.ElasticBeamColumn2D(osi, ele_nodes, area=area, e_mod=e_mod, iz=iz, transf=transf)

    omega = 2 * np.pi / bd.t_fixed

    # define superstructure damping using rotational spring approach from Millen et al. (2017) to avoid double damping
    if dtype == 'rot_dashpot':
        cxx = bd.xi * 2 * np.sqrt(bd.mass_eff * bd.k_eff)
        equiv_c_rot = cxx * (2.0 / 3) ** 2 * bd.h_eff ** 2
        ss_rot_dashpot_mat = o3.uniaxial_material.Viscous(osi, equiv_c_rot, alpha=1.)
        sfi_dashpot_ele = o3.element.TwoNodeLink(osi, [bot_ss_node, top_ss_node], mats=[ss_rot_dashpot_mat],
                                            dirs=[o3.cc.DOF2D_ROTZ])
    elif dtype == 'horz_dashpot':
        cxx = bd.xi * 2 * np.sqrt(bd.mass_eff * bd.k_eff)
        ss_rot_dashpot_mat = o3.uniaxial_material.Viscous(osi, cxx, alpha=1.)
        sfi_dashpot_ele = o3.element.ZeroLength(osi, [bot_ss_node, top_ss_node], mats=[ss_rot_dashpot_mat],
                                            dirs=[o3.cc.X])
    else:
        beta_k = 2 * bd.xi / omega
        o3.rayleigh.Rayleigh(osi, 0, 0, beta_k_init=beta_k, beta_k_comm=0.0)


    # Define the input motion for the dynamic analysis
    acc_series = o3.time_series.Path(osi, dt=asig.dt, values=-asig.values)  # should be negative
    o3.pattern.UniformExcitation(osi, dir=o3.cc.X, accel_series=acc_series)
    print('loaded gm')
    o3.wipe_analysis(osi)

    o3.algorithm.Newton(osi)
    o3.system.SparseGeneral(osi)
    o3.numberer.RCM(osi)
    o3.constraints.Transformation(osi)
    o3.integrator.Newmark(osi, 0.5, 0.25)
    o3.analysis.Transient(osi)

    o3.test_check.NormDispIncr(osi, tol=1.0e-6, max_iter=10)
    analysis_time = asig.time[-1]
    analysis_dt = 0.001

    # define outputs of analysis
    od = {
        "time": o3.recorder.TimeToArrayCache(osi),
        "rel_deck_disp": o3.recorder.NodeToArrayCache(osi, top_ss_node, [o3.cc.DOF2D_X], 'disp'),
        "deck_accel": o3.recorder.NodeToArrayCache(osi, top_ss_node, [o3.cc.DOF2D_X], 'accel'),
        "deck_rot": o3.recorder.NodeToArrayCache(osi, top_ss_node, [o3.cc.DOF2D_ROTZ], 'disp'),
        "chord_rots": o3.recorder.ElementToArrayCache(osi, vert_ele, arg_vals=['chordRotation']),
        "col_forces": o3.recorder.ElementToArrayCache(osi, vert_ele, arg_vals=['force']),
    }
    if dtype in ['rot_dashpot', 'horz_dashpot']:
        od['dashpot_force'] = o3.recorder.ElementToArrayCache(osi, sfi_dashpot_ele, arg_vals=['force'])

    o3.analyze(osi, int(analysis_time / analysis_dt), analysis_dt)

    o3.wipe(osi)

    for item in od:
        od[item] = od[item].collect()
    od['col_shear'] = -od['col_forces'][:, 0]
    od['col_moment'] = od['col_forces'][:, 2]
    od['hinge_rotation'] = od['chord_rots'][:, 1]
    od['hinge_rotation1'] = -od['chord_rots'][:, 2]
    del od['col_forces']
    del od['chord_rots']

    return od
def run(apply_diff):
    # If use_pload=true then apply point load at end, else apply distributed load along beam

    osi = o3.OpenSeesInstance(ndm=2, state=3)

    ele_len = 4.0

    # Establish nodes
    left_node = o3.node.Node(osi, 0, 0)
    right_node = o3.node.Node(osi, ele_len, 0)

    # Fix left node
    if apply_diff:
        o3.Fix3DOF(osi, left_node, o3.cc.FIXED, o3.cc.FREE, o3.cc.FREE)
        o3.Fix3DOF(osi, left_node, o3.cc.FREE, o3.cc.FIXED, o3.cc.FIXED)
    else:
        o3.Fix3DOF(osi, left_node, o3.cc.FIXED, o3.cc.FIXED, o3.cc.FIXED)
        o3.Fix3DOF(osi, left_node, o3.cc.FIXED, o3.cc.FIXED, o3.cc.FIXED)
    o3.Fix3DOF(osi, right_node, o3.cc.FREE, o3.cc.FREE, o3.cc.FREE)
    e_mod = 200.0e2
    i_sect = 0.1
    area = 0.5
    lp_i = 0.1
    lp_j = 0.1

    elastic = 0

    if elastic:
        left_sect = o3.section.Elastic2D(osi, e_mod, area, i_sect)
    else:
        m_cap = 14.80
        b = 0.05
        phi = m_cap / (e_mod * i_sect)
        # mat_flex = o3.uniaxial_material.Steel01(osi, m_cap, e0=e_mod * i_sect, b=b)
        mat_flex = o3.uniaxial_material.ElasticBilin(osi, e_mod * i_sect,
                                                     e_mod * i_sect * b, phi)
        mat_axial = o3.uniaxial_material.Elastic(osi, e_mod * area)
        left_sect = o3.section.Aggregator(osi,
                                          mats=[[mat_axial, o3.cc.P],
                                                [mat_flex, o3.cc.M_Z],
                                                [mat_flex, o3.cc.M_Y]])
    right_sect = o3.section.Elastic2D(osi, e_mod, area, i_sect)
    centre_sect = o3.section.Elastic2D(osi, e_mod, area, i_sect)
    integ = o3.beam_integration.HingeMidpoint(osi, left_sect, lp_i, right_sect,
                                              lp_j, centre_sect)
    beam_transf = o3.geom_transf.Linear2D(osi, )
    ele = o3.element.ForceBeamColumn(osi, [left_node, right_node], beam_transf,
                                     integ)
    use_pload = 1
    w_gloads = 1
    if w_gloads:
        # Apply gravity loads
        pload = 1.0 * ele_len
        udl = 2.0
        ts_po = o3.time_series.Linear(osi, factor=1)
        o3.pattern.Plain(osi, ts_po)
        if use_pload:
            o3.Load(osi, right_node, [0, -pload, 0])
        else:
            o3.EleLoad2DUniform(osi, ele, -udl)

        tol = 1.0e-3
        o3.constraints.Plain(osi)
        o3.numberer.RCM(osi)
        o3.system.BandGeneral(osi)
        n_steps_gravity = 10
        o3.integrator.LoadControl(osi, 1. / n_steps_gravity, num_iter=10)
        o3.test_check.NormDispIncr(osi, tol, 10)
        o3.algorithm.Linear(osi)
        o3.analysis.Static(osi)
        o3.analyze(osi, n_steps_gravity)
        o3.gen_reactions(osi)
        print('reactions: ', o3.get_ele_response(osi, ele, 'force')[:3])
        end_disp = o3.get_node_disp(osi, right_node, dof=o3.cc.Y)
        print(f'end_disp: {end_disp}')
        if use_pload:
            disp_expected = pload * ele_len**3 / (3 * e_mod * i_sect)
            print(f'v_expected: {pload}')
            print(f'm_expected: {pload * ele_len}')
            print(f'disp_expected: {disp_expected}')
        else:
            v_expected = udl * ele_len
            m_expected = udl * ele_len**2 / 2
            disp_expected = udl * ele_len**4 / (8 * e_mod * i_sect)
            print(f'v_expected: {v_expected}')
            print(f'm_expected: {m_expected}')
            print(f'disp_expected: {disp_expected}')
        rot_0 = o3.get_ele_response(osi,
                                    ele,
                                    'section',
                                    extra_args=['1', 'deformation'])[1]
        shear_0 = o3.get_ele_response(osi,
                                      ele,
                                      'section',
                                      extra_args=['1', 'deformation'])[2]
        print(
            o3.get_ele_response(osi,
                                ele,
                                'section',
                                extra_args=['2', 'deformation']))
예제 #16
0
def get_moment_curvature(axial_load=100., max_curve=0.001, num_incr=500):
    osi = o3.OpenSeesInstance(ndm=2, ndf=3, state=3)

    fc = 4.0
    # e_mod = 57000.0 * np.sqrt(fc * 1000.0) / 1e3

    conc_conf = o3.uniaxial_material.Concrete01(osi, fpc=-5.0, epsc0=-0.005, fpcu=-3.5, eps_u=-0.02)
    conc_unconf = o3.uniaxial_material.Concrete01(osi, fpc=-fc, epsc0=-0.002, fpcu=0.0, eps_u=-0.006)
    rebar = o3.uniaxial_material.Steel01(osi, fy=60.0, e0=30000.0, b=0.02)

    h = 18.0
    b = 18.0
    cover = 2.5
    gj = 1.0E10
    nf_core_y = 8
    nf_core_z = 8
    nf_cover_y = 10
    nf_cover_z = 10
    n_bars = 3
    bar_area = 0.79

    edge_y = h / 2.0
    edge_z = b / 2.0
    core_y = edge_y - cover
    core_z = edge_z - cover

    sect = o3.section.Fiber(osi, gj=gj)
    # define the core patch
    o3.patch.Quad(osi, conc_conf, nf_core_z, nf_core_y,  # core, counter-clockwise (diagonals at corners)
                  crds_i=[-core_y, core_z],
                  crds_j=[-core_y, -core_z],
                  crds_k=[core_y, -core_z],
                  crds_l=[core_y, core_z])

    o3.patch.Quad(osi, conc_unconf, 1, nf_cover_y,  # right cover, counter-clockwise (diagonals at corners)
                  crds_i=[-edge_y, edge_z],
                  crds_j=[-core_y, core_z],
                  crds_k=[core_y, core_z],
                  crds_l=[edge_y, edge_z])
    o3.patch.Quad(osi, conc_unconf, 1, nf_cover_y,  # left cover
                  crds_i=[-core_y, -core_z],
                  crds_j=[-edge_y, -edge_z],
                  crds_k=[edge_y, -edge_z],
                  crds_l=[core_y, -core_z])
    o3.patch.Quad(osi, conc_unconf, nf_cover_z, 1,  # bottom cover
                  crds_i=[-edge_y, edge_z],
                  crds_j=[-edge_y, -edge_z],
                  crds_k=[-core_y, -core_z],
                  crds_l=[-core_y, core_z])
    o3.patch.Quad(osi, conc_unconf, nf_cover_z, 1,  # top cover
                  crds_i=[core_y, core_z],
                  crds_j=[core_y, -core_z],
                  crds_k=[edge_y, -edge_z],
                  crds_l=[edge_y, edge_z])

    o3.layer.Straight(osi, rebar, n_bars, bar_area, start=[-core_y, core_z], end=[-core_y, -core_z])
    o3.layer.Straight(osi, rebar, n_bars, bar_area, start=[core_y, core_z], end=[core_y, -core_z])

    spacing_y = 2 * core_y / (n_bars - 1)
    remaining_bars = n_bars - 2
    o3.layer.Straight(osi, rebar, remaining_bars, bar_area,
                      start=[core_y - spacing_y, core_z],
                      end=[-core_y + spacing_y, core_z])
    o3.layer.Straight(osi, rebar, remaining_bars, bar_area,
                      start=[core_y - spacing_y, -core_z],
                      end=[-core_y + spacing_y, -core_z])

    n1 = o3.node.Node(osi, 0.0, 0.0)
    n2 = o3.node.Node(osi, 0.0, 0.0)
    o3.Fix3DOF(osi, n1, 1, 1, 1)
    o3.Fix3DOF(osi, n2, 0, 1, 0)
    ele = o3.element.ZeroLengthSection(osi, [n1, n2], sect)

    nd = o3.recorder.NodeToArrayCache(osi, n2, dofs=[3], res_type='disp')
    nm = o3.recorder.NodeToArrayCache(osi, n1, dofs=[3], res_type='reaction')

    ts = o3.time_series.Constant(osi)
    o3.pattern.Plain(osi, ts)
    o3.Load(osi, n2, load_values=[axial_load, 0.0, 0.0])

    o3.system.BandGeneral(osi)
    o3.numberer.Plain(osi)
    o3.constraints.Plain(osi)
    o3.test.NormUnbalance(osi, tol=1.0e-9, max_iter=10)
    o3.algorithm.Newton(osi)
    o3.integrator.LoadControl(osi, incr=0.0)
    o3.analysis.Static(osi)
    o3.analyze(osi, 1)

    #
    ts = o3.time_series.Linear(osi)
    o3.pattern.Plain(osi, ts)
    o3.Load(osi, n2, load_values=[0.0, 0.0, 1.0])

    d_cur = max_curve / num_incr

    o3.integrator.DisplacementControl(osi, n2, o3.cc.DOF2D_ROTZ, d_cur, 1, d_cur, d_cur)
    o3.analyze(osi, num_incr)
    o3.wipe(osi)
    curvature = nd.collect()
    moment = -nm.collect()
    return moment, curvature
예제 #17
0
def get_elastic_response(mass, k_spring, 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 motion: array_like,
        acceleration values
    :param dt: float, time step of acceleration values
    :param xi: damping ratio
    :param r_post: post-yield stiffness
    :return:
    """
    osi = o3.OpenSeesInstance(ndm=2, state=3)

    height = 5.
    # Establish nodes
    bot_node = o3.node.Node(osi, 0, 0)
    top_node = o3.node.Node(osi, 0, height)

    # Fix bottom node
    o3.Fix3DOF(osi, top_node, o3.cc.FREE, o3.cc.FIXED, o3.cc.FREE)
    o3.Fix3DOF(osi, bot_node, o3.cc.FIXED, o3.cc.FIXED, o3.cc.FIXED)
    # Set out-of-plane DOFs to be slaved
    o3.EqualDOF(osi, top_node, bot_node, [o3.cc.Y])

    # nodal mass (weight / g):
    o3.Mass(osi, top_node, mass, 0., 0.)

    # Define material
    transf = o3.geom_transf.Linear2D(osi, [])
    area = 1.0
    e_mod = 1.0e6
    iz = k_spring * height ** 3 / (3 * e_mod)
    ele_nodes = [bot_node, top_node]

    ele = o3.element.ElasticBeamColumn2D(osi, ele_nodes, area=area, e_mod=e_mod, iz=iz, transf=transf)
    # Define the dynamic analysis
    acc_series = o3.time_series.Path(osi, dt=dt, values=-motion)  # should be negative
    o3.pattern.UniformExcitation(osi, dir=o3.cc.X, accel_series=acc_series)

    # set damping based on first eigen mode
    angular_freq = o3.get_eigen(osi, solver='fullGenLapack', n=1)[0] ** 0.5
    response_period = 2 * np.pi / angular_freq
    print('response_period: ', response_period)
    beta_k = 2 * xi / angular_freq
    o3.rayleigh.Rayleigh(osi, alpha_m=0.0, beta_k=beta_k, beta_k_init=0.0, beta_k_comm=0.0)

    # Run the dynamic analysis

    o3.wipe_analysis(osi)

    o3.algorithm.Newton(osi)
    o3.system.SparseGeneral(osi)
    o3.numberer.RCM(osi)
    o3.constraints.Transformation(osi)
    o3.integrator.Newmark(osi, 0.5, 0.25)
    o3.analysis.Transient(osi)
    o3.extensions.to_py_file(osi, 'simple.py')

    o3.test_check.EnergyIncr(osi, tol=1.0e-10, max_iter=10)
    analysis_time = (len(motion) - 1) * dt
    analysis_dt = 0.001
    outputs = {
        "time": [],
        "rel_disp": [],
        "rel_accel": [],
        "rel_vel": [],
        "force": []
    }

    while o3.get_time(osi) < analysis_time:

        o3.analyze(osi, 1, analysis_dt)
        curr_time = o3.get_time(osi)
        outputs["time"].append(curr_time)
        outputs["rel_disp"].append(o3.get_node_disp(osi, top_node, o3.cc.X))
        outputs["rel_vel"].append(o3.get_node_vel(osi, top_node, o3.cc.X))
        outputs["rel_accel"].append(o3.get_node_accel(osi, top_node, o3.cc.X))
        o3.gen_reactions(osi)
        outputs["force"].append(o3.get_ele_response(osi, ele, 'force'))
    o3.wipe(osi)
    for item in outputs:
        outputs[item] = np.array(outputs[item])

    return outputs
예제 #18
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:
    """
    osi = o3.OpenSeesInstance(ndm=2)

    # Establish nodes
    bot_node = o3.node.Node(osi, 0, 0)
    top_node = o3.node.Node(osi, 0, 0)

    # Fix bottom node
    o3.Fix3DOF(osi, top_node, o3.cc.FREE, o3.cc.FIXED, o3.cc.FIXED)
    o3.Fix3DOF(osi, bot_node, o3.cc.FIXED, o3.cc.FIXED, o3.cc.FIXED)
    # Set out-of-plane DOFs to be slaved
    o3.EqualDOF(osi, top_node, bot_node, [o3.cc.Y, o3.cc.DOF2D_ROTZ])

    # nodal mass (weight / g):
    o3.Mass(osi, top_node, mass, 0., 0.)

    # Define material
    bilinear_mat = o3.uniaxial_material.Steel01(osi,
                                                fy=f_yield,
                                                e0=k_spring,
                                                b=r_post)

    # Assign zero length element, # Note: pass actual node and material objects into element
    o3.element.ZeroLength(osi, [bot_node, top_node],
                          mats=[bilinear_mat],
                          dirs=[o3.cc.DOF2D_X],
                          r_flag=1)

    # Define the dynamic analysis
    values = list(-1 * motion)  # should be negative
    acc_series = o3.time_series.Path(osi, dt, values)
    o3.pattern.UniformExcitation(osi, o3.cc.X, accel_series=acc_series)

    # set damping based on first eigen mode
    angular_freq2 = o3.get_eigen(osi, solver='fullGenLapack', n=1)
    if hasattr(angular_freq2, '__len__'):
        angular_freq2 = angular_freq2[0]
    angular_freq = angular_freq2**0.5
    beta_k = 2 * xi / angular_freq
    o3.rayleigh.Rayleigh(osi,
                         alpha_m=0.0,
                         beta_k=beta_k,
                         beta_k_init=0.0,
                         beta_k_comm=0.0)

    # Run the dynamic analysis

    o3.wipe_analysis(osi)
    newmark_gamma = 0.5
    newmark_beta = 0.25

    o3.algorithm.Newton(osi)
    o3.constraints.Transformation(osi)
    o3.algorithm.Newton(osi)
    o3.numberer.RCM(osi)
    o3.system.SparseGeneral(osi)
    o3.integrator.Newmark(osi, newmark_gamma, newmark_beta)
    o3.analysis.Transient(osi)

    o3.test_check.EnergyIncr(osi, tol=1.0e-10, max_iter=10)
    analysis_time = (len(values) - 1) * dt
    analysis_dt = 0.001
    outputs = {"time": [], "rel_disp": [], "rel_accel": [], "force": []}
    o3.record(osi)
    curr_time = o3.get_time(osi)
    while curr_time < analysis_time:
        outputs["time"].append(curr_time)
        outputs["rel_disp"].append(o3.get_node_disp(osi, top_node, o3.cc.X))
        outputs["rel_accel"].append(o3.get_node_accel(osi, top_node, o3.cc.X))
        o3.gen_reactions(osi)
        outputs["force"].append(-o3.get_node_reaction(
            osi, bot_node, o3.cc.X))  # Negative since diff node
        o3.analyze(osi, 1, analysis_dt)
        curr_time = o3.get_time(osi)
    o3.wipe(osi)
    for item in outputs:
        outputs[item] = np.array(outputs[item])

    return outputs
def run(use_pload):
    # If pload=true then apply point load at end, else apply distributed load along beam

    osi = o3.OpenSeesInstance(ndm=2, state=3)

    ele_len = 4.0

    # Establish nodes
    left_node = o3.node.Node(osi, 0, 0)
    right_node = o3.node.Node(osi, ele_len, 0)

    # Fix bottom node
    o3.Fix3DOF(osi, left_node, o3.cc.FIXED, o3.cc.FIXED, o3.cc.FIXED)
    o3.Fix3DOF(osi, right_node, o3.cc.FREE, o3.cc.FREE, o3.cc.FREE)
    e_mod = 200.0e2
    i_sect = 0.1
    area = 0.5
    lp_i = 0.1
    lp_j = 0.1

    elastic = 0

    if elastic:
        left_sect = o3.section.Elastic2D(osi, e_mod, area, i_sect)
    else:
        m_cap = 14.80
        b = 0.05
        phi = m_cap / (e_mod * i_sect)
        # mat_flex = o3.uniaxial_material.Steel01(osi, m_cap, e0=e_mod * i_sect, b=b)
        mat_flex = o3.uniaxial_material.ElasticBilin(osi, e_mod * i_sect,
                                                     e_mod * i_sect * b, phi)
        mat_axial = o3.uniaxial_material.Elastic(osi, e_mod * area)
        left_sect = o3.section.Aggregator(osi,
                                          mats=[[mat_axial, o3.cc.P],
                                                [mat_flex, o3.cc.M_Z],
                                                [mat_flex, o3.cc.M_Y]])
    right_sect = o3.section.Elastic2D(osi, e_mod, area, i_sect)
    centre_sect = o3.section.Elastic2D(osi, e_mod, area, i_sect)
    integ = o3.beam_integration.HingeMidpoint(osi, left_sect, lp_i, right_sect,
                                              lp_j, centre_sect)
    beam_transf = o3.geom_transf.Linear2D(osi, )
    ele = o3.element.ForceBeamColumn(osi, [left_node, right_node], beam_transf,
                                     integ)

    w_gloads = 1
    if w_gloads:
        # Apply gravity loads
        pload = 1.0 * ele_len
        udl = 2.0
        ts_po = o3.time_series.Linear(osi, factor=1)
        o3.pattern.Plain(osi, ts_po)
        if use_pload:
            o3.Load(osi, right_node, [0, -pload, 0])
        else:
            o3.EleLoad2DUniform(osi, ele, -udl)

        tol = 1.0e-3
        o3.constraints.Plain(osi)
        o3.numberer.RCM(osi)
        o3.system.BandGeneral(osi)
        n_steps_gravity = 10
        o3.integrator.LoadControl(osi, 1. / n_steps_gravity, num_iter=10)
        o3.test_check.NormDispIncr(osi, tol, 10)
        o3.algorithm.Linear(osi)
        o3.analysis.Static(osi)
        o3.analyze(osi, n_steps_gravity)
        o3.gen_reactions(osi)
        print('reactions: ', o3.get_ele_response(osi, ele, 'force')[:3])
        end_disp = o3.get_node_disp(osi, right_node, dof=o3.cc.Y)
        print(f'end_disp: {end_disp}')
        if use_pload:
            disp_expected = pload * ele_len**3 / (3 * e_mod * i_sect)
            print(f'v_expected: {pload}')
            print(f'm_expected: {pload * ele_len}')
            print(f'disp_expected: {disp_expected}')
        else:
            v_expected = udl * ele_len
            m_expected = udl * ele_len**2 / 2
            disp_expected = udl * ele_len**4 / (8 * e_mod * i_sect)
            print(f'v_expected: {v_expected}')
            print(f'm_expected: {m_expected}')
            print(f'disp_expected: {disp_expected}')

        # o3.extensions.to_py_file(osi, 'temp4.py')
    disp_load = 1
    if disp_load:
        # start displacement controlled
        d_inc = -0.01

        # opy.wipeAnalysis()
        o3.numberer.RCM(osi)
        o3.system.BandGeneral(osi)
        o3.test_check.NormUnbalance(osi, 2, max_iter=10, p_flag=0)
        # o3.test_check.FixedNumIter(osi, max_iter=10)
        # o3.test_check.NormDispIncr(osi, 0.002, 10, p_flag=0)
        o3.algorithm.Newton(osi)
        o3.integrator.DisplacementControl(osi, right_node, o3.cc.Y, d_inc)
        o3.analysis.Static(osi)
        ts_po = o3.time_series.Linear(osi, factor=1)
        o3.pattern.Plain(osi, ts_po)
        o3.Load(osi, right_node, [0.0, 1.0, 0])
        ok = o3.analyze(osi, 10)
        end_disp = o3.get_node_disp(osi, right_node, dof=o3.cc.Y)
        print(f'end_disp: {end_disp}')
        r = o3.get_ele_response(osi, ele, 'force')[:3]
        print('reactions: ', r)
        k = r[1] / -end_disp
        print('k: ', k)
        k_elastic_expected = 1. / (ele_len**3 / (3 * e_mod * i_sect))
        print('k_elastic_expected: ', k_elastic_expected)
예제 #20
0
def run_pm4sand_et(sl,
                   csr,
                   esig_v0=101.0e3,
                   static_bias=0.0,
                   n_lim=100,
                   k0=0.5,
                   strain_limit=0.03,
                   strain_inc=5.0e-6,
                   etype='implicit'):

    nu_init = k0 / (1 + k0)
    damp = 0.02
    omega0 = 0.2
    omega1 = 20.0
    a1 = 2. * damp / (omega0 + omega1)
    a0 = a1 * omega0 * omega1

    # Initialise OpenSees instance
    osi = o3.OpenSeesInstance(ndm=2, ndf=3, state=3)

    # Establish nodes
    h_ele = 1.
    bl_node = o3.node.Node(osi, 0, 0)
    br_node = o3.node.Node(osi, h_ele, 0)
    tr_node = o3.node.Node(osi, h_ele, h_ele)
    tl_node = o3.node.Node(osi, 0, h_ele)
    all_nodes = [bl_node, br_node, tr_node, tl_node]

    # Fix bottom node
    o3.Fix3DOF(osi, bl_node, o3.cc.FIXED, o3.cc.FIXED, o3.cc.FIXED)
    o3.Fix3DOF(osi, br_node, o3.cc.FIXED, o3.cc.FIXED, o3.cc.FIXED)
    o3.Fix3DOF(osi, tr_node, o3.cc.FREE, o3.cc.FREE, o3.cc.FIXED)
    o3.Fix3DOF(osi, tl_node, o3.cc.FREE, o3.cc.FREE, o3.cc.FIXED)
    # Set out-of-plane DOFs to be slaved
    o3.EqualDOF(osi, tr_node, tl_node, [o3.cc.X, o3.cc.Y])

    # Define material
    pm4sand = o3.nd_material.PM4Sand(osi,
                                     sl.relative_density,
                                     sl.g0_mod,
                                     sl.h_po,
                                     sl.unit_sat_mass,
                                     101.3,
                                     nu=nu_init)

    # Note water bulk modulus is irrelevant since constant volume test - so as soil skeleton contracts
    # the bulk modulus of the soil skeleton controls the change in effective stress
    water_bulk_mod = 2.2e6
    ele = o3.element.SSPquadUP(osi,
                               all_nodes,
                               pm4sand,
                               1.0,
                               water_bulk_mod,
                               1.,
                               sl.permeability,
                               sl.permeability,
                               sl.e_curr,
                               alpha=1.0e-5,
                               b1=0.0,
                               b2=0.0)

    o3.constraints.Transformation(osi)
    o3.test_check.NormDispIncr(osi, tol=1.0e-6, max_iter=35, p_flag=0)
    o3.numberer.RCM(osi)
    omegas = np.array(o3.get_eigen(osi, n=1))**0.5
    periods = 2 * np.pi / omegas
    periods = [0.001]
    if etype == 'implicit':
        o3.algorithm.Newton(osi)
        o3.system.FullGeneral(osi)
        o3.integrator.Newmark(osi, gamma=5. / 6, beta=4. / 9)
        dt = 0.01
    else:
        o3.algorithm.Linear(osi, factor_once=True)
        o3.system.FullGeneral(osi)
        if etype == 'newmark_explicit':
            o3.integrator.NewmarkExplicit(osi, gamma=0.5)
            explicit_dt = periods[0] / np.pi / 8
        elif etype == 'central_difference':
            o3.integrator.CentralDifference(osi)
            explicit_dt = periods[0] / np.pi / 16  # 0.5 is a factor of safety
        elif etype == 'hht_explicit':
            o3.integrator.HHTExplicit(osi, alpha=0.5)
            explicit_dt = periods[0] / np.pi / 8
        elif etype == 'explicit_difference':
            o3.integrator.ExplicitDifference(osi)
            explicit_dt = periods[0] / np.pi / 4
        else:
            raise ValueError(etype)
        print('explicit_dt: ', explicit_dt)
        dt = explicit_dt
    o3.analysis.Transient(osi)
    freqs = [0.5, 10]
    xi = 0.1
    use_modal_damping = 0
    if use_modal_damping:
        omega_1 = 2 * np.pi * freqs[0]
        omega_2 = 2 * np.pi * freqs[1]
        a0 = 2 * xi * omega_1 * omega_2 / (omega_1 + omega_2)
        a1 = 2 * xi / (omega_1 + omega_2)
        o3.rayleigh.Rayleigh(osi, a0, 0, a1, 0)
    else:
        o3.ModalDamping(osi, [xi])

    o3.update_material_stage(osi, pm4sand, stage=0)
    # print('here1: ', o3.get_ele_response(osi, ele, 'stress'), esig_v0, csr)

    all_stresses_cache = o3.recorder.ElementToArrayCache(osi,
                                                         ele,
                                                         arg_vals=['stress'])
    all_strains_cache = o3.recorder.ElementToArrayCache(osi,
                                                        ele,
                                                        arg_vals=['strain'])
    nodes_cache = o3.recorder.NodesToArrayCache(osi,
                                                all_nodes,
                                                dofs=[1, 2, 3],
                                                res_type='disp')
    o3.recorder.NodesToFile(osi,
                            'node_disp.txt',
                            all_nodes,
                            dofs=[1, 2, 3],
                            res_type='disp')

    # Add static vertical pressure and stress bias
    ttime = 30
    time_series = o3.time_series.Path(osi,
                                      time=[0, ttime, 1e10],
                                      values=[0, 1, 1])
    o3.pattern.Plain(osi, time_series)
    o3.Load(osi, tl_node, [0, -esig_v0 / 2, 0])
    o3.Load(osi, tr_node, [0, -esig_v0 / 2, 0])

    o3.analyze(osi, num_inc=int(ttime / dt) + 10, dt=dt)

    ts2 = o3.time_series.Path(osi,
                              time=[ttime, 80000, 1e10],
                              values=[1., 1., 1.],
                              factor=1)
    o3.pattern.Plain(osi, ts2, fact=1.)
    y_vert = o3.get_node_disp(osi, tr_node, o3.cc.Y)
    o3.SP(osi, tl_node, dof=o3.cc.Y, dof_values=[y_vert])
    o3.SP(osi, tr_node, dof=o3.cc.Y, dof_values=[y_vert])

    # Close the drainage valves
    for node in all_nodes:
        o3.remove_sp(osi, node, dof=3)
    o3.analyze(osi, int(5 / dt), dt=dt)
    print('here3: ', o3.get_ele_response(osi, ele, 'stress'), esig_v0, csr)

    o3.update_material_stage(osi, pm4sand, stage=1)
    o3.set_parameter(osi, value=0, eles=[ele], args=['FirstCall', pm4sand.tag])
    o3.analyze(osi, int(5 / dt), dt=dt)
    o3.set_parameter(osi,
                     value=sl.poissons_ratio,
                     eles=[ele],
                     args=['poissonRatio', pm4sand.tag])

    o3.extensions.to_py_file(osi)

    n_cyc = 0.0
    target_strain = 1.1 * strain_limit
    target_disp = target_strain * h_ele
    limit_reached = 0
    export = 1
    while n_cyc < n_lim:
        print('n_cyc: ', n_cyc)
        h_disp = o3.get_node_disp(osi, tr_node, o3.cc.X)
        curr_time = o3.get_time(osi)
        steps = target_strain / strain_inc
        ts0 = o3.time_series.Path(osi,
                                  time=[curr_time, curr_time + steps, 1e10],
                                  values=[h_disp, target_disp, target_disp],
                                  factor=1)
        pat0 = o3.pattern.Plain(osi, ts0)
        o3.SP(osi, tr_node, dof=o3.cc.X, dof_values=[1.0])
        curr_stress = o3.get_ele_response(osi, ele, 'stress')[2]
        if math.isnan(curr_stress):
            raise ValueError

        if export:
            o3.extensions.to_py_file(osi)
            export = 0
        while curr_stress < (csr - static_bias) * esig_v0:
            o3.analyze(osi, int(0.1 / dt), dt=dt)
            curr_stress = o3.get_ele_response(osi, ele, 'stress')[2]
            h_disp = o3.get_node_disp(osi, tr_node, o3.cc.X)
            print(h_disp, target_disp)
            if h_disp >= target_disp:
                print('STRAIN LIMIT REACHED - on load')
                limit_reached = 1
                break
        if limit_reached:
            break
        n_cyc += 0.25
        print('load reversal, n_cyc: ', n_cyc)
        curr_time = o3.get_time(osi)
        o3.remove_load_pattern(osi, pat0)
        o3.remove(osi, ts0)
        o3.remove_sp(osi, tr_node, dof=o3.cc.X)
        # Reverse cycle
        steps = (h_disp + target_disp) / (strain_inc * h_ele)
        ts0 = o3.time_series.Path(osi,
                                  time=[curr_time, curr_time + steps, 1e10],
                                  values=[h_disp, -target_disp, -target_disp],
                                  factor=1)
        pat0 = o3.pattern.Plain(osi, ts0)
        o3.SP(osi, tr_node, dof=o3.cc.X, dof_values=[1.0])
        i = 0
        while curr_stress > -(csr + static_bias) * esig_v0:
            o3.analyze(osi, int(0.1 / dt), dt=dt)
            curr_stress = o3.get_ele_response(osi, ele, 'stress')[2]
            h_disp = o3.get_node_disp(osi, tr_node, o3.cc.X)

            if -h_disp >= target_disp:
                print('STRAIN LIMIT REACHED - on reverse')
                limit_reached = 1
                break
            i += 1
            if i > steps:
                break
        if limit_reached:
            break
        n_cyc += 0.5
        print('reload, n_cyc: ', n_cyc)
        curr_time = o3.get_time(osi)
        o3.remove_load_pattern(osi, pat0)
        o3.remove(osi, ts0)
        o3.remove_sp(osi, tr_node, dof=o3.cc.X)
        # reload cycle
        steps = (-h_disp + target_disp) / (strain_inc * h_ele)
        ts0 = o3.time_series.Path(osi,
                                  time=[curr_time, curr_time + steps, 1e10],
                                  values=[h_disp, target_disp, target_disp],
                                  factor=1)
        pat0 = o3.pattern.Plain(osi, ts0)
        o3.SP(osi, tr_node, dof=o3.cc.X, dof_values=[1.0])
        while curr_stress < static_bias * esig_v0:
            o3.analyze(osi, int(0.1 / dt), dt=dt)
            curr_stress = o3.get_ele_response(osi, ele, 'stress')[2]
            h_disp = o3.get_node_disp(osi, tr_node, o3.cc.X)

            if h_disp >= target_disp:
                print('STRAIN LIMIT REACHED - on reload')
                limit_reached = 1
                break
        if limit_reached:
            break
        o3.remove_load_pattern(osi, pat0)
        o3.remove(osi, ts0)
        o3.remove_sp(osi, tr_node, dof=o3.cc.X)
        n_cyc += 0.25

    o3.wipe(osi)
    all_stresses = all_stresses_cache.collect()
    all_strains = all_strains_cache.collect()
    disps = nodes_cache.collect()
    stress = all_stresses[:, 2]
    strain = all_strains[:, 2]
    ppt = all_stresses[:, 1]

    return stress, strain, ppt, disps

    pass
def run_analysis(etype, asig, use_modal_damping=0):
    osi = o3.OpenSeesInstance(ndm=2, ndf=3)
    nodes = [
        o3.node.Node(osi, 0.0, 0.0),
        o3.node.Node(osi, 5.5, 0.0),
        o3.node.Node(osi, 0.0, 3.3),
        o3.node.Node(osi, 5.5, 3.3)
    ]
    o3.Mass2D(osi, nodes[2], 1e5, 1e5, 1e6)
    o3.Mass2D(osi, nodes[3], 1e5, 1e5, 1e6)
    o3.Fix3DOF(osi, nodes[0], o3.cc.FIXED, o3.cc.FIXED, o3.cc.FIXED)
    o3.Fix3DOF(osi, nodes[1], o3.cc.FIXED, o3.cc.FIXED, o3.cc.FIXED)

    steel_mat = o3.uniaxial_material.Steel01(osi, 300.0e6, 200.0e9, b=0.02)

    tran = o3.geom_transf.Linear2D(osi)
    o3.element.ElasticBeamColumn2D(osi, [nodes[2], nodes[3]],
                                   0.01,
                                   200.0e9,
                                   iz=1.0e-4,
                                   transf=tran)
    o3.element.ElasticBeamColumn2D(osi, [nodes[0], nodes[2]],
                                   0.01,
                                   200.0e9,
                                   iz=1.0e-4,
                                   transf=tran)
    o3.element.ElasticBeamColumn2D(osi, [nodes[1], nodes[3]],
                                   0.01,
                                   200.0e9,
                                   iz=1.0e-4,
                                   transf=tran)

    a_series = o3.time_series.Path(osi, dt=asig.dt, values=-1 *
                                   asig.values)  # should be negative
    o3.pattern.UniformExcitation(osi, dir=o3.cc.X, accel_series=a_series)

    xi = 0.1
    angular_freqs = np.array(o3.get_eigen(
        osi, n=5))**0.5  # There are vertical modes too!
    print('angular_freqs: ', angular_freqs)
    periods = 2 * np.pi / angular_freqs
    print('periods: ', periods)

    if use_modal_damping:  # Does not support modal damping
        freqs = [0.5, 5]
        omega_1 = 2 * np.pi * freqs[0]
        omega_2 = 2 * np.pi * freqs[1]
        a0 = 2 * xi * omega_1 * omega_2 / (omega_1 + omega_2)
        a1 = 2 * xi / (omega_1 + omega_2)
        o3.rayleigh.Rayleigh(osi, a0, 0, a1, 0)
    else:
        o3.ModalDamping(osi, [xi])

    o3.constraints.Transformation(osi)
    o3.test_check.NormDispIncr(osi, tol=1.0e-5, max_iter=35, p_flag=0)
    o3.numberer.RCM(osi)
    if use_modal_damping:
        o3_sys = o3.system.ProfileSPD  # not sure why don't need to use FullGen here? since matrix is full?
    else:
        o3_sys = o3.system.ProfileSPD
    if etype == 'implicit':
        o3.algorithm.Newton(osi)
        o3_sys(osi)
        o3.integrator.Newmark(osi, gamma=0.5, beta=0.25)
        dt = 0.001
    else:
        o3.algorithm.Linear(osi, factor_once=True)

        if etype == 'newmark_explicit':
            o3_sys(osi)
            o3.integrator.NewmarkExplicit(osi, gamma=0.5)
            explicit_dt = periods[-1] / np.pi / 2.01
        elif etype == 'central_difference':
            o3_sys(osi)
            o3.integrator.CentralDifference(osi)
            if use_modal_damping:
                explicit_dt = periods[
                    -1] / np.pi / 1.5  # 1.1 is a factor of safety
            else:
                explicit_dt = periods[-1] / np.pi / 1.5
        elif etype == 'explicit_difference':
            o3.system.Diagonal(osi)
            o3.integrator.ExplicitDifference(osi)
            explicit_dt = periods[-1] / np.pi / 1.6
        else:
            raise ValueError(etype)
        print('explicit_dt: ', explicit_dt)
        dt = explicit_dt
    o3.analysis.Transient(osi)

    roof_disp = o3.recorder.NodeToArrayCache(osi,
                                             nodes[2],
                                             dofs=[o3.cc.X],
                                             res_type='disp')
    time = o3.recorder.TimeToArrayCache(osi)
    ttotal = 15.0
    o3.analyze(osi, int(ttotal / dt), dt)
    o3.wipe(osi)
    return time.collect(), roof_disp.collect()