def run(show=0):
    record_filename = 'test_motion_dt0p01.txt'
    asig = eqsig.load_asig(ap.MODULE_DATA_PATH + 'gms/' + record_filename,
                           m=0.5)

    period = 1.0

    from eqsig import sdof
    import matplotlib.pyplot as plt
    import engformat as ef
    bf, ax = plt.subplots(nrows=2)
    xi = 0.05
    outputs = gen_response(period, xi, asig, etype='implicit')
    ax[0].plot(outputs['time'], outputs['rel_disp'], label='implicit', ls='--')
    outputs = gen_response(period,
                           xi,
                           asig,
                           etype='central_difference',
                           fos_for_dt=5)
    ax[0].plot(outputs['time'],
               outputs['rel_disp'],
               label='central_difference',
               ls='--')
    ef.text_at_rel_pos(ax[0], 0.05, 0.95, f'$\\xi$ = {xi*100:.0f}%')
    periods = np.array([period])

    # Compare closed form elastic solution
    resp_u, resp_v, resp_a = sdof.response_series(motion=asig.values,
                                                  dt=asig.dt,
                                                  periods=periods,
                                                  xi=xi)
    ax[0].plot(asig.time, resp_u[0], ls='-', label='Elastic', zorder=0)

    xi = 0.0
    outputs = gen_response(period, xi, asig, etype='implicit')
    ax[1].plot(outputs['time'], outputs['rel_disp'], label='implicit', ls='--')
    outputs = gen_response(period,
                           xi,
                           asig,
                           etype='central_difference',
                           fos_for_dt=5)
    ax[1].plot(outputs['time'],
               outputs['rel_disp'],
               label='central_difference',
               ls='--')
    ef.text_at_rel_pos(ax[1], 0.05, 0.95, f'$\\xi$ = {xi*100:.0f}%')
    periods = np.array([period])

    # Compare closed form elastic solution
    resp_u, resp_v, resp_a = sdof.response_series(motion=asig.values,
                                                  dt=asig.dt,
                                                  periods=periods,
                                                  xi=xi)
    ax[1].plot(asig.time, resp_u[0], ls='-', label='Elastic', zorder=0)
    plt.legend()
    plt.show()
Example #2
0
def test_sdof():
    """
    Create a plot of an elastic analysis, nonlinear analysis and closed form elastic

    :return:
    """

    record_filename = 'short_motion_dt0p01.txt'
    asig = eqsig.load_asig(ap.MODULE_DATA_PATH + 'gms/' + record_filename, m=0.5)
    period = 1.0
    xi = 0.05
    mass = 1.0
    f_yield = 1.5  # Reduce this to make it nonlinear
    r_post = 0.0

    periods = np.array([period])
    resp_u, resp_v, resp_a = sdof.response_series(motion=asig.values, dt=asig.dt, periods=periods, xi=xi)

    k_spring = 4 * np.pi ** 2 * mass / period ** 2
    outputs = get_elastic_response(mass, k_spring, asig.values, asig.dt, xi=xi, r_post=r_post)
    acc_opensees_elastic = np.interp(asig.time, outputs["time"], outputs["rel_accel"]) - asig.values
    time = asig.time

    run = 1
    if run:
        import matplotlib.pyplot as plt
        bf, sps = plt.subplots(nrows=3)
        sps[0].plot(time, resp_u[0], lw=0.7, c='r')
        sps[0].plot(outputs["time"], outputs["rel_disp"], ls='--')
        sps[1].plot(outputs['rel_disp'], outputs['force'][:, 2])
        sps[2].plot(time, resp_a[0], lw=0.7, c='r')
        sps[2].plot(outputs["time"], outputs["rel_accel"], ls='--')
        sps[2].plot(time, acc_opensees_elastic, ls='--', c='g')
        plt.show()
Example #3
0
def test_sdof():
    """
    Create a plot of an elastic analysis, nonlinear analysis and closed form elastic

    :return:
    """

    from tests.conftest import TEST_DATA_DIR

    record_path = TEST_DATA_DIR
    record_filename = 'test_motion_dt0p01.txt'
    dt = 0.01
    rec = np.loadtxt(record_path + record_filename)
    acc_signal = eqsig.AccSignal(rec, dt)
    period = 1.0
    xi = 0.05
    mass = 1.0
    f_yield = 1.5  # Reduce this to make it nonlinear
    r_post = 0.0

    periods = np.array([period])
    resp_u, resp_v, resp_a = sdof.response_series(motion=rec,
                                                  dt=dt,
                                                  periods=periods,
                                                  xi=xi)

    k_spring = 4 * np.pi**2 * mass / period**2
    outputs = get_inelastic_response(mass,
                                     k_spring,
                                     f_yield,
                                     rec,
                                     dt,
                                     xi=xi,
                                     r_post=r_post)
    outputs_elastic = get_inelastic_response(mass,
                                             k_spring,
                                             f_yield * 100,
                                             rec,
                                             dt,
                                             xi=xi,
                                             r_post=r_post)
    ux_opensees = outputs["rel_disp"]
    disp_inelastic_final = ux_opensees[-1]

    time = acc_signal.time
    acc_opensees_elastic = np.interp(time, outputs_elastic["time"],
                                     outputs_elastic["rel_accel"]) - rec
    ux_opensees_elastic = np.interp(time, outputs_elastic["time"],
                                    outputs_elastic["rel_disp"])
    diff_disp = abs(np.sum(ux_opensees_elastic - resp_u[0]))
    diff_acc = abs(np.sum(acc_opensees_elastic - resp_a[0]))
    assert diff_disp < 1.0e-4
    assert diff_acc < 5.0e-4
    assert np.isclose(disp_inelastic_final, 0.018651987846)
Example #4
0
 def response_series(self, response_times=None, xi=-1):
     """
     Generate the response time series for a set of elastic SDOFs for a given
     damping (xi).
     """
     if self.verbose:
         print('Generating response series')
     if response_times is not None:
         self.response_times = response_times
     if xi == -1:
         xi = self._cached_xi
     resp_u, resp_v, resp_a = dh.response_series(self.values, self.dt,
                                                 self.response_times, xi)
     return resp_u, resp_v, resp_a
Example #5
0
def show_nigam_and_jennings_vs_duhamels():
    record_path = TEST_DATA_DIR
    record_filename = 'test_motion_dt0p01.txt'
    dt = 0.01
    rec = np.loadtxt(record_path + record_filename, skiprows=2)
    periods = np.array([0.0, 0.05])
    xi = 0.05
    resp_u, resp_v, sdof_acc = sdof.response_series(rec, dt, periods, xi)

    import matplotlib.pyplot as plt
    bf, sps = plt.subplots(figsize=(9, 5))
    plt.plot(sdof_acc[0], lw=0.7)
    plt.plot(sdof_acc[1], lw=0.7)
    plt.show()
Example #6
0
def cumulative_response_spectra(acc_signal, fun_name, periods=None, xi=None):

    if periods is None:
        periods = acc_signal.response_times
    else:
        periods = np.array(periods)
    if xi is None:
        xi = 0.05
    resp_u, resp_v, resp_a = sdof.response_series(acc_signal.values, acc_signal.dt, periods, xi)
    if fun_name == "arias_intensity":
        rs = _raw_calc_arias_intensity(resp_a, acc_signal.dt)
    else:
        raise ValueError
    return rs
Example #7
0
def test_nigam_and_jennings_vs_duhamels():
    record_path = TEST_DATA_DIR
    record_filename = 'test_motion_dt0p01.txt'
    dt = 0.01
    rec = np.loadtxt(record_path + record_filename, skiprows=2)
    periods = np.linspace(0.1, 2.5, 2)
    xi = 0.05
    resp_u, resp_v, sdof_acc = sdof.response_series(rec, dt, periods, xi)
    i = 0
    duhamel_u = sdof.single_elastic_response(rec, dt, periods[i], xi)
    diff_disp = np.sum(abs(resp_u[i] - duhamel_u))
    assert diff_disp < 2.0e-2, diff_disp
    i = 1
    duhamel_u = sdof.single_elastic_response(rec, dt, periods[i], xi)
    diff_disp = np.sum(abs(resp_u[i] - duhamel_u))
    assert diff_disp < 3.0e-2, diff_disp
def run(show):
    period = 0.5
    xi = 0.05
    f_yield = 5.5  # Reduce this to make it nonlinear
    f_yield = 1.5  # Reduce this to make it nonlinear
    record_filename = 'test_motion_dt0p01.txt'
    asig = eqsig.load_asig(ap.MODULE_DATA_PATH + 'gms/' + record_filename,
                           m=0.5)
    etypes = [
        'implicit', 'newmark_explicit', 'explicit_difference',
        'central_difference'
    ]
    cs = ['k', 'b', 'g', 'orange', 'm']
    ls = ['-', '--', '-.', ':', '--']
    for i in range(len(etypes)):
        etype = etypes[i]
        od = run_analysis(asig, period, xi, f_yield, etype=etype)

        if show:
            import matplotlib.pyplot as plt
            plt.plot(od['time'],
                     od['rel_disp'],
                     label=etype,
                     c=cs[i],
                     ls=ls[i])
            periods = np.array([period])
    if show:
        # 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', c='r', lw=1)
        plt.legend()
        plt.show()
Example #9
0
def test_sdof(show=0):
    """
    Create a plot of an elastic analysis, nonlinear analysis and closed form elastic
    """

    folder_path = os.path.dirname(os.path.abspath(__file__))
    record_filename = folder_path + '/test_motion_dt0p01.txt'
    dt = 0.01
    rec = np.loadtxt(record_filename)
    period = 1.0
    xi = 0.05
    mass = 1.0
    f_yield = 1.5  # Reduce this to make it nonlinear
    r_post = 0.0

    periods = np.array([period])
    resp_u, resp_v, resp_a = sdof.response_series(motion=rec,
                                                  dt=dt,
                                                  periods=periods,
                                                  xi=xi)

    k_spring = 4 * np.pi**2 * mass / period**2
    outputs = get_inelastic_response(mass,
                                     k_spring,
                                     f_yield,
                                     rec,
                                     dt,
                                     xi=xi,
                                     r_post=r_post)
    outputs_elastic = get_inelastic_response(mass,
                                             k_spring,
                                             f_yield * 100,
                                             rec,
                                             dt,
                                             xi=xi,
                                             r_post=r_post)
    ux_opensees = outputs["rel_disp"]
    disp_inelastic_final = ux_opensees[-1]

    time = np.arange(len(rec)) * dt

    acc_opensees_elastic = np.interp(time, outputs_elastic["time"],
                                     outputs_elastic["rel_accel"]) - rec
    acc_opensees_inelastic = np.interp(time, outputs["time"],
                                       outputs["rel_accel"]) - rec
    ux_opensees_elastic = np.interp(time, outputs_elastic["time"],
                                    outputs_elastic["rel_disp"])
    diff_disp = np.sum(abs(ux_opensees_elastic - resp_u[0]))
    diff_acc = np.sum(abs(acc_opensees_elastic - resp_a[0]))
    assert diff_disp < 1.0e-2, diff_disp
    assert diff_acc < 5.0e-1, diff_acc
    assert np.isclose(disp_inelastic_final, 0.0186556)
    if show:
        import matplotlib.pyplot as plt
        bf, sps = plt.subplots(nrows=3, sharex='col')
        sps[0].plot(outputs_elastic["time"],
                    outputs_elastic["rel_disp"],
                    label='O3 Elastic',
                    lw=0.7,
                    c='b')
        sps[0].plot(outputs["time"],
                    outputs["rel_disp"],
                    label='O3 Inelastic',
                    lw=0.7,
                    c='r')
        sps[0].plot(time,
                    resp_u[0],
                    label='Closed form',
                    lw=1.4,
                    c='g',
                    ls='--')
        sps[1].plot(outputs_elastic["time"], outputs_elastic["rel_vel"])
        sps[1].plot(time, resp_v[0], lw=1.4, c='g', ls='--')
        sps[2].plot(time, acc_opensees_elastic, c='b')
        sps[2].plot(time, resp_a[0], lw=1.4, c='g', ls='--')
        sps[2].plot(time, acc_opensees_inelastic, c='r')
        sps[2].plot(time, rec, lw=0.7, c='k', label='Input', zorder=0)
        sps[2].axhline(f_yield,
                       c=(0.4, 0.4, 0.4),
                       label='$f_{yield}$',
                       ls='--',
                       lw=0.5,
                       zorder=-1)
        sps[2].axhline(-f_yield, c=(0.4, 0.4, 0.4), ls='--', lw=0.5, zorder=-1)
        sps[0].set_ylabel('Disp. [m]')
        sps[1].set_ylabel('Vel. [m/s]')
        sps[2].set_ylabel('Accel. [m/s2]')
        sps[-1].set_xlabel('Time [s]')
        sps[-1].set_xlim([0, time[-1]])
        sps[0].legend(loc='upper right')
        sps[2].legend(loc='upper right')
        plt.show()
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()