예제 #1
0
def test_write_obj_to_fis_str():
    sl = lq.num.flac.PM4Sand()
    sl.name = 'layer_1'
    sl.phi = 30.
    sl.g_mod = 50.0e3
    sl.specific_gravity = 2.65
    sl.e_curr = 0.55
    sl.poissons_ratio = 0.3
    sl.dilation_angle = 0.0
    sl.cohesion = 0.0
    sl.permeability = 1.0e-4
    sl.set_g0_mod_from_g_mod_at_v_eff_stress(20.0e6, 50.0e3)
    with pytest.raises(sm.ModelError):
        lq.num.flac.write_obj_to_fis_str(sl, sl.inputs, sl.required_parameters)
    sl.h_po = 0.5
    sl.relative_density = 0.5
    p_str = ''.join(
        lq.num.flac.write_obj_to_fis_str(sl, sl.inputs,
                                         sl.required_parameters))
    assert 'layer_1_relative_density=0.5' in p_str

    sp = sm.SoilProfile()
    sp.add_layer(0, sl)
    sp.height = 10.
    p_str = ''.join(lq.num.flac.write_soil_profile_obj_to_fis_str(sp))
    assert 'layer_1_relative_density=0.5' in p_str
예제 #2
0
def build_soil_profile_from_bi2014_w_layer_dict(bi2014, layers_dict):
    """
    Defined soil profile properties based on an equivalent soil profile define

    Parameters
    ----------
    bi2014: liquepy.trigger.BoulangerIdriss2014CPT
    esp: equivalent_soil object
        Equivalent soil profile of the triggering analysis

    Returns
    -------
    sm.SoilProfile
    """
    assert isinstance(bi2014, lq.trigger.BoulangerIdriss2014CPT)
    d_inc = bi2014.depth[3] - bi2014.depth[2]
    sp = sm.SoilProfile()
    sp.gwl = bi2014.gwl
    sp.height = bi2014.depth[-1]
    s_depths = []
    i_ths = []
    csr_n15 = []
    for crr in layers_dict:
        for depth in layers_dict[crr]:
            s_depths.append(depth)
            csr_n15.append(crr)
            i_ths.append((np.abs(bi2014.depth - depth - d_inc)).argmin())
    i_ths.append(len(bi2014.depth) - 1)
    s_depths.append(sp.height)
    csr_n15.append(-1)  # make same length

    i_ths = np.array(i_ths)
    s_depths = np.array(s_depths)
    csr_n15 = np.array(csr_n15)
    arr_inds = s_depths.argsort()
    i_ths = i_ths[arr_inds]
    s_depths = s_depths[arr_inds]
    csr_n15 = csr_n15[arr_inds]
    s_depths[0] = 0

    crr_values = lq.trigger.boulanger_and_idriss_2014.calc_crr_m7p5_from_qc1ncs(
        bi2014.q_c1n_cs)
    crr_values = np.clip(crr_values, None, 0.6)

    for i in range(len(s_depths) - 1):
        sl = sm.Soil()
        set_soil_props(sl,
                       bi2014,
                       i_top=i_ths[i] - 1,
                       i_bot=i_ths[i + 1],
                       gwl=sp.gwl)
        # if csr_n15[i]:
        #     sl.csr_n15 = csr_n15[i]
        #     sl.inputs.append("csr_n15")
        sl.csr_n15 = np.mean(crr_values[i_ths[i] - 1:i_ths[i + 1]])
        sl.inputs.append("csr_n15")
        sp.add_layer(s_depths[i], sl)

    sp.set_soil_ids_to_layers()
    return sp, i_ths
예제 #3
0
def test_two_d_mesh_w_1_profile():
    rho = 1.8
    sl1 = sm.Soil(g_mod=50, unit_dry_weight=rho * 9.8, poissons_ratio=0.3)
    sl2 = sm.Soil(g_mod=100, unit_dry_weight=rho * 9.8, poissons_ratio=0.3)
    sl3 = sm.Soil(g_mod=400, unit_dry_weight=rho * 9.8, poissons_ratio=0.3)
    sp = sm.SoilProfile()
    sp.add_layer(0, sl1)
    sp.add_layer(5, sl2)
    sp.add_layer(12, sl3)
    sp.x_angles = [0.0, 0.0, 0.0]
    sp.height = 18
    sp.x = 0

    tds = sm.TwoDSystem(4, 15)
    tds.add_sp(sp, x=0)
    tds.x_surf = np.array([0])
    tds.y_surf = np.array([0])

    x_scale_pos = np.array([0])
    x_scale_vals = np.array([2.])
    fc = sm.num.mesh.FiniteElementOrth2DMeshConstructor(
        tds, 0.3, x_scale_pos=x_scale_pos, x_scale_vals=x_scale_vals)
    femesh = fc.femesh
    ind = np.argmin(abs(femesh.y_nodes + 5.0))
    assert np.isclose(-5.0, femesh.y_nodes[ind])
    ind = np.argmin(abs(femesh.y_nodes + 12.0))
    assert np.isclose(-12.0, femesh.y_nodes[ind])
    ind = np.argmin(abs(femesh.y_nodes + 15.0))
    assert np.isclose(-15.0, femesh.y_nodes[ind])
예제 #4
0
def test_loc_to_dict():
    cpt = lq.field.load_mpa_cpt_file(TEST_DATA_DIR + "standard_1.csv")
    sp = sm.SoilProfile()
    loc = lq.field.transect.Loc(cpt=cpt)
    loc.soil_profile = sp
    pdict = loc.to_dict()
    assert 'id' in pdict
    assert 'soil_profile_id' in pdict
예제 #5
0
def _example_run():
    vs = 150.0
    rho = 1.8
    g_mod = vs**2 * rho
    import sfsimodels as sm
    sl = sm.Soil(g_mod=g_mod, unit_dry_weight=rho * 9.8, poissons_ratio=0.3)
    sp = sm.SoilProfile()
    sp.add_layer(0, sl)
    sp.add_layer(5, sl)
    sp.add_layer(12, sl)
    sp.height = 18
    sp.x = 0
    sp2 = sm.SoilProfile()
    sp2.add_layer(0, sl)
    sp2.add_layer(7, sl)
    sp2.add_layer(12, sl)
    sp2.height = 20
    sp.x_angles = [0.05, 0.0, 0.0]
    sp2.x_angles = [0.0, 0.00, 0.0]

    fd = sm.RaftFoundation()
    fd.width = 2
    fd.depth = 0
    fd.length = 100
    fd.ip_axis = 'width'
    tds = TwoDSystem(width=40, height=15)
    tds.add_sp(sp, x=0)
    tds.add_sp(sp2, x=14)
    tds.x_surf = np.array([0, 10, 12, 40])
    tds.y_surf = np.array([0, 0, 2, 2])
    bd = sm.NullBuilding()
    bd.set_foundation(fd, x=0.0)
    tds.add_bd(bd, x=8)

    x_scale_pos = np.array([0, 5, 15, 30])
    x_scale_vals = np.array([2., 1.0, 2.0, 3.0])
    fc = FiniteElementOrth2DMeshConstructor(tds,
                                            0.3,
                                            x_scale_pos=x_scale_pos,
                                            x_scale_vals=x_scale_vals)
    femesh = fc.femesh
예제 #6
0
def run():
    rho = 1.8
    sl1 = sm.Soil(g_mod=50, unit_dry_weight=rho * 9.8, poissons_ratio=0.3)
    sl2 = sm.Soil(g_mod=100, unit_dry_weight=rho * 9.8, poissons_ratio=0.3)
    sl3 = sm.Soil(g_mod=400, unit_dry_weight=rho * 9.8, poissons_ratio=0.3)
    sl4 = sm.Soil(g_mod=600, unit_dry_weight=rho * 9.8, poissons_ratio=0.3)
    sp = sm.SoilProfile()
    sp.add_layer(0, sl1)
    sp.add_layer(5, sl2)
    sp.add_layer(12, sl3)
    sp.height = 18
    sp.x = 0

    sp.x_angles = [0.0, 0.0, 0.0]

    fd = sm.RaftFoundation()
    fd.width = 4
    fd.height = 1.0
    fd.depth = 0.5
    fd.length = 100
    tds = sm.TwoDSystem(width=10, height=15)
    tds.add_sp(sp, x=0)
    tds.x_surf = np.array([0, 40])
    tds.y_surf = np.array([0, 0])
    bd = sm.NullBuilding()
    bd.set_foundation(fd, x=0)
    tds.add_bd(bd, x=5)

    x_scale_pos = np.array([0, 5, 15, 30])
    x_scale_vals = np.array([2., 1.0, 2.0, 3.0])
    femesh = sm.num.mesh.FiniteElement2DMesh(tds,
                                             0.3,
                                             x_scale_pos=x_scale_pos,
                                             x_scale_vals=x_scale_vals)

    import sys
    import pyqtgraph as pg
    from pyqtgraph.Qt import QtGui, QtCore
    import o3plot

    win = pg.plot()
    win.setWindowTitle('ECP definition')
    win.setXRange(0, femesh.tds.width)
    win.setYRange(-femesh.tds.height, max(femesh.tds.y_surf))

    o3plot.plot_finite_element_mesh(win, femesh)
    # o3_plot.plot_two_d_system(win, tds)

    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()
예제 #7
0
def test_save_and_load_2d_system():

    vs = 250.0

    sl = sm.Soil()
    unit_mass = 1700.0
    sl.g_mod = vs**2 * unit_mass
    sl.poissons_ratio = 0.0
    # sl.cohesion = sl.g_mod / 1000
    sl.cohesion = 30.0e3
    sl.id = 1
    sl.phi = 0.0
    sl.unit_dry_weight = unit_mass * 9.8
    sl.specific_gravity = 2.65
    sl.xi = 0.03  # for linear analysis
    sl.sra_type = 'hyperbolic'
    sl.inputs += ['sra_type', 'xi']
    sp = sm.SoilProfile()
    sp.add_layer(0, sl)
    sp.height = 1.0e3
    sp.id = 1
    sp.x_angles = [0.0, 0.0]
    fd = sm.RaftFoundation()
    fd.width = 2
    fd.depth = 0.8
    fd.height = 1
    fd.length = 100
    fd.ip_axis = 'width'
    bd = sm.SDOFBuilding()
    bd.h_eff = 8.
    bd.set_foundation(fd, x=0.0)
    sys_width = 6 * fd.width
    tds = sm.TwoDSystem(width=sys_width, height=10)
    tds.add_sp(sp, 0)
    tds.add_bd(bd, sys_width / 2)
    tds.id = 1
    ecp_out = sm.Output()
    ecp_out.add_to_dict(tds)
    # ecp_out.add_to_dict(sp)
    p_str = json.dumps(ecp_out.to_dict(), skipkeys=["__repr__"], indent=4)
    objs = sm.loads_json(p_str)
    building = objs["building"][1]
    system = objs["system"][1]
    assert np.isclose(building.h_eff, 8)
    assert np.isclose(building.fd.height, 1)
    assert isinstance(system, sm.TwoDSystem)
    assert system.sps[0].layer(1).xi == 0.03
예제 #8
0
def capacity_meyerhof_and_hanna_1978(sl_0, sl_1, h0, fd, gwl=1e6, verbose=0):
    """
    Calculates the two-layered foundation capacity according Meyerhof and Hanna (1978)

    :param sl_0: Top Soil object
    :param sl_1: Base Soil object
    :param h0: Height of top soil layer
    :param fd: Foundation object
    :param wtl: water table level
    :param verbose: verbosity
    :return: ultimate bearing stress
    """
    sp = sm.SoilProfile()
    sp.add_layer(0, sl_0)
    sp.add_layer(h0, sl_1)
    sp.gwl = gwl
    return capacity_sp_meyerhof_and_hanna_1978(sp, fd)
예제 #9
0
def build_soil_profile_from_bi2014(esp, bi2014):
    """
    Defined soil profile properties based on an equivalent soil profile define

    Parameters
    ----------
    bi2014: liquepy.trigger.BoulangerIdriss2014CPT
    esp: equivalent_soil object
        Equivalent soil profile of the triggering analysis

    Returns
    -------
    sm.SoilProfile
    """
    assert isinstance(bi2014, lq.trigger.BoulangerIdriss2014CPT)
    sp = sm.SoilProfile()
    sp.gwl = bi2014.gwl
    sp.height = bi2014.depth[-1]
    s_depths = [0, esp.h_crust]
    csr_n15 = [0]
    if esp.n_layers == 3:
        csr_n15 += [esp.csr_n15, 0]
        s_depths.append(esp.d_nonliq)
    else:
        s_depths.append(esp.d_nonliqs[0])
        s_depths.append(esp.d_liqs[1])
        s_depths.append(esp.d_nonliqs[1])
        csr_n15 += [esp.csr_n15s[0], 0, esp.csr_n15s[1], 0]
    s_depths.append(sp.height)

    for i in range(len(s_depths) - 1):
        if s_depths[i + 1] - s_depths[i] > 0:
            sl = sm.Soil()
            set_soil_props(sl,
                           bi2014,
                           i_top=esp.ith(s_depths[i]),
                           i_bot=esp.ith(s_depths[i + 1]),
                           gwl=sp.gwl)
            if csr_n15[i]:
                sl.csr_n15 = csr_n15[i]
                sl.inputs.append("csr_n15")
            sp.add_layer(s_depths[i], sl)

    sp.set_soil_ids_to_layers()
    return sp
예제 #10
0
def test_est_nses_millen_et_al_2019():
    # Define soil profile properties
    damp = 0.03
    sp = sm.SoilProfile()  # Soil profile object
    # Top layer
    sl1 = sm.Soil(g_mod=40.0e6, unit_dry_weight=20.0e3)
    sl1.xi = damp
    sp.add_layer(depth=0, soil=sl1)
    # Middle layer - with lower shear modulus
    sl2 = sm.Soil(g_mod=30.0e6, unit_dry_weight=20.0e3)
    sl2.xi = damp
    sp.add_layer(depth=10, soil=sl2)
    # Bottom layer
    sl3 = sm.Soil(g_mod=40.0e6, unit_dry_weight=20.0e3)
    sl3.xi = damp
    sp.add_layer(depth=20, soil=sl3)
    sp.height = 30  # m

    # Load ground motion
    acc = np.loadtxt(conftest.TEST_DATA_DIR + 'test_motion_dt0p01.txt',
                     skiprows=2)
    dt = 0.01

    in_signal = eqsig.AccSignal(acc / 2, dt)
    rho = sp.layer(3).unit_dry_weight / 9.8
    in_uke = eqsig.im.calc_unit_kinetic_energy(in_signal)[-1]
    in_cake = in_uke * rho

    # Estimate CASE and CAKE using the input motion with method from Millen et al. (2019)
    odepths = np.array([4.])
    pred_case = nses.est_case_1d_millen_et_al_2019(sp,
                                                   in_signal,
                                                   odepths,
                                                   xi=damp)[0, -1]
    pred_cake = nses.est_case_1d_millen_et_al_2019(sp,
                                                   in_signal,
                                                   odepths,
                                                   xi=damp,
                                                   nodal=False)[0, -1]
    assert np.isclose(pred_cake, 729.00213882), pred_cake  # v0.6.3
    assert np.isclose(pred_case, 40.094265976), pred_case  # v0.6.3
예제 #11
0
def run():
    xi = 0.03

    sl = sm.Soil()
    vs = 250.
    unit_mass = 1700.0
    sl.g_mod = vs**2 * unit_mass
    sl.poissons_ratio = 0.3
    sl.unit_dry_weight = unit_mass * 9.8
    sl.xi = xi  # for linear analysis

    sl_base = sm.Soil()
    vs = 350.
    unit_mass = 1700.0
    sl_base.g_mod = vs**2 * unit_mass
    sl_base.poissons_ratio = 0.3
    sl_base.unit_dry_weight = unit_mass * 9.8
    sl_base.xi = xi  # for linear analysis
    soil_profile = sm.SoilProfile()
    soil_profile.add_layer(0, sl)
    soil_profile.add_layer(10., sl_base)
    soil_profile.height = 20.0
    gm_scale_factor = 1.0

    import matplotlib.pyplot as plt
    from bwplot import cbox
    bf, sps = plt.subplots(ncols=3, figsize=(6, 8))

    ys = site_response(soil_profile, static=0)
    sps[0].plot(ys, c=cbox(0))
    ys = site_response(soil_profile, static=1)
    sps[0].plot(ys, c=cbox(1))

    sps[0].legend(prop={'size': 6})
    name = __file__.replace('.py', '')
    name = name.split("fig_")[-1]
    bf.suptitle(name)
    bf.savefig(f'figs/{name}.png', dpi=90)
    plt.show()
예제 #12
0
def test_mesh_vary_y():
    vs = 150.0
    rho = 1.8
    g_mod = vs**2 * rho

    sl0 = sm.Soil(g_mod=g_mod, unit_dry_weight=rho * 9.8, poissons_ratio=0.31)
    sl1 = sm.Soil(g_mod=g_mod, unit_dry_weight=rho * 9.8, poissons_ratio=0.32)
    sl2 = sm.Soil(g_mod=g_mod, unit_dry_weight=rho * 9.8, poissons_ratio=0.33)
    sl3 = sm.Soil(g_mod=g_mod, unit_dry_weight=rho * 9.8, poissons_ratio=0.34)
    sl4 = sm.Soil(g_mod=g_mod, unit_dry_weight=rho * 9.8, poissons_ratio=0.35)
    sl5 = sm.Soil(g_mod=g_mod, unit_dry_weight=rho * 9.8, poissons_ratio=0.36)
    sp = sm.SoilProfile()
    sp.add_layer(0, sl1)
    sp.add_layer(5, sl2)
    sp.add_layer(12, sl3)
    sp.height = 18
    sp.x = 0
    sp2 = sm.SoilProfile()
    sp2.add_layer(0, sl4)
    sp2.add_layer(7, sl5)
    sp2.add_layer(12, sl0)
    sp2.height = 20
    sp.x_angles = [None, 0.01, 0.05]
    sp2.x_angles = [None, 0.00, 0.0]

    fd = sm.RaftFoundation()
    fd.width = 2
    fd.depth = 0
    fd.ip_axis = 'width'
    fd.height = 1
    fd.length = 100
    tds = sm.TwoDSystem(width=40, height=15)
    tds.add_sp(sp, x=0)
    tds.add_sp(sp2, x=14)
    tds.x_surf = np.array([0, 10, 12, 25, 40])
    tds.y_surf = np.array([0, 0, 2, 2.5, 2])
    bd = sm.NullBuilding()
    bd.set_foundation(fd, x=0.0)
    tds.add_bd(bd, x=8)

    x_scale_pos = np.array([0, 5, 15, 30])
    x_scale_vals = np.array([2., 1.0, 2.0, 3.0])
    fc = mesh2d_vary_y.FiniteElementVary2DMeshConstructor(
        tds, 0.3, x_scale_pos=x_scale_pos, x_scale_vals=x_scale_vals)

    show = 0
    femesh = fc.femesh
    if show:

        import sys
        import pyqtgraph as pg
        from pyqtgraph.Qt import QtGui, QtCore
        import o3plot
        win = pg.plot()
        win.setWindowTitle('ECP definition')
        win.setXRange(0, tds.width)
        win.setYRange(-tds.height, max(tds.y_surf))

        o3plot.plot_finite_element_mesh_onto_win(win, femesh)

        xcs = list(fc.yd)
        xcs.sort()
        xcs = np.array(xcs)
        for i in range(len(xcs)):
            win.addItem(pg.InfiniteLine(xcs[i], angle=90,
                                        pen=(0, 255, 0, 100)))

        o3plot.plot_two_d_system(tds, win)

        for i, sd in enumerate(fc.sds):

            x0 = sd[0][0]
            x1 = sd[0][1]
            y0 = sd[1][0]
            y1 = sd[1][1]
            win.plot(sd[0], sd[1], pen='r')
            x0_ind = femesh.get_nearest_node_index_at_x(x0)
            x1_ind = femesh.get_nearest_node_index_at_x(x1)
            y0_ind = femesh.get_nearest_node_index_at_depth(y0, x0)
            y1_ind = femesh.get_nearest_node_index_at_depth(y1, x1)
            win.plot([femesh.x_nodes[x0_ind], femesh.x_nodes[x1_ind]], [
                femesh.y_nodes[x0_ind][y0_ind], femesh.y_nodes[x1_ind][y1_ind]
            ],
                     pen='b')
        if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
            QtGui.QApplication.instance().exec_()
    dhs = np.diff(femesh.y_nodes, axis=1)
    assert np.min(-dhs) > 0.3 * 0.5, np.min(-dhs)
    assert np.max(-dhs) < 0.3 * 2, np.min(-dhs)
    sds = fc.sds
    for sd in sds:
        x0 = sd[0][0]
        x1 = sd[0][1]
        y0 = sd[1][0]
        y1 = sd[1][1]
        y0_ind = femesh.get_nearest_node_index_at_depth(y0, x0)
        y1_ind = femesh.get_nearest_node_index_at_depth(y1, x1)
        if y0 == 0 and y1 == 2:
            assert y0_ind - 5 == y1_ind, (sd, y0_ind - 5, y1_ind)
        else:
            assert y0_ind == y1_ind, (sd, y0_ind, y1_ind)
def run():
    sl = sm.Soil()
    sl.o3_type = 'pimy'
    vs = 250.
    unit_mass = 1700.0
    sl.cohesion = 120.0e3
    sl.phi = 0.0
    sl.g_mod = vs**2 * unit_mass
    sl.poissons_ratio = 0.3
    sl.unit_dry_weight = unit_mass * 9.8
    sl.specific_gravity = 2.65
    sl.xi = 0.03  # for linear analysis
    sl.sra_type = 'linear'
    assert np.isclose(vs, sl.get_shear_vel(saturated=False))
    soil_profile = sm.SoilProfile()
    soil_profile.add_layer(0, sl)
    soil_profile.height = 30.0

    sl_base = sm.Soil()
    sl_base.o3_type = 'pimy'
    vs = 450.
    unit_mass = 1700.0
    sl_base.g_mod = vs**2 * unit_mass
    sl_base.poissons_ratio = 0.3
    sl_base.cohesion = 120.0e3
    sl_base.phi = 0.0
    sl_base.unit_dry_weight = unit_mass * 9.8
    sl_base.specific_gravity = 2.65
    sl_base.xi = 0.03  # for linear analysis
    sl_base.sra_type = 'linear'
    soil_profile.add_layer(10.1, sl_base)
    soil_profile.height = 20.0
    gm_scale_factor = 1.5
    record_filename = 'short_motion_dt0p01.txt'
    in_sig = eqsig.load_asig(ap.MODULE_DATA_PATH + 'gms/' + record_filename,
                             m=gm_scale_factor)

    # analysis with pysra
    od = lq.sra.run_pysra(soil_profile, in_sig, odepths=np.array([0.0, 2.0]))
    pysra_surf_sig = eqsig.AccSignal(od['ACCX'][0], in_sig.dt)

    outputs = site_response(soil_profile, in_sig)
    resp_dt = outputs['time'][2] - outputs['time'][1]
    o3_surf_sig = eqsig.AccSignal(outputs['ACCX'][0], resp_dt)

    o3_surf_vals = np.interp(pysra_surf_sig.time, o3_surf_sig.time,
                             o3_surf_sig.values)

    show = 1

    if show:
        import matplotlib.pyplot as plt
        from bwplot import cbox

        in_sig.smooth_fa_frequencies = in_sig.fa_frequencies[1:]
        o3_surf_sig.smooth_fa_frequencies = in_sig.fa_frequencies[1:]
        pysra_surf_sig.smooth_fa_frequencies = in_sig.fa_frequencies[1:]

        bf, sps = plt.subplots(nrows=3)

        sps[0].plot(in_sig.time, in_sig.values, c='k', label='Input')
        sps[0].plot(pysra_surf_sig.time, o3_surf_vals, c=cbox(0), label='o3')
        sps[0].plot(pysra_surf_sig.time,
                    pysra_surf_sig.values,
                    c=cbox(1),
                    label='pysra')

        sps[1].plot(in_sig.fa_frequencies, abs(in_sig.fa_spectrum), c='k')
        sps[1].plot(o3_surf_sig.fa_frequencies,
                    abs(o3_surf_sig.fa_spectrum),
                    c=cbox(0))
        sps[1].plot(pysra_surf_sig.fa_frequencies,
                    abs(pysra_surf_sig.fa_spectrum),
                    c=cbox(1))
        sps[1].set_xlim([0, 20])
        in_sig.smooth_fa_frequencies = in_sig.fa_frequencies
        pysra_surf_sig.smooth_fa_frequencies = in_sig.fa_frequencies
        o3_surf_sig.smooth_fa_frequencies = in_sig.fa_frequencies
        h = o3_surf_sig.smooth_fa_spectrum / in_sig.smooth_fa_spectrum
        sps[2].plot(o3_surf_sig.smooth_fa_frequencies, h, c=cbox(0))
        pysra_h = pysra_surf_sig.smooth_fa_spectrum / in_sig.smooth_fa_spectrum
        sps[2].plot(pysra_surf_sig.smooth_fa_frequencies, pysra_h, c=cbox(1))
        sps[2].axhline(1, c='k', ls='--')
        sps[0].legend()
        name = __file__.replace('.py', '')
        name = name.split("fig_")[-1]
        bf.savefig(f'figs/{name}.png', dpi=90)
        plt.show()

    assert np.isclose(o3_surf_vals, pysra_surf_sig.values, atol=0.01,
                      rtol=100).all()
def run():
    soil_profile = sm.SoilProfile()
    soil_profile.height = 30.0

    sl = sm.Soil()
    vs = 250.
    unit_mass = 1700.0
    sl.g_mod = vs**2 * unit_mass
    sl.poissons_ratio = 0.3
    sl.unit_dry_weight = unit_mass * 9.8
    sl.xi = 0.01  # for linear analysis
    soil_profile.add_layer(0, sl)

    sl_base = sm.Soil()
    vs = 350.
    unit_mass = 1700.0
    sl_base.g_mod = vs**2 * unit_mass
    sl_base.poissons_ratio = 0.3
    sl_base.unit_dry_weight = unit_mass * 9.8
    sl_base.xi = 0.01  # for linear analysis
    soil_profile.add_layer(19., sl_base)
    soil_profile.height = 20.0

    record_filename = 'short_motion_dt0p01.txt'
    in_sig = eqsig.load_asig(ap.MODULE_DATA_PATH + 'gms/' + record_filename,
                             m=0.5)

    # analysis with pysra
    od = lq.sra.run_pysra(soil_profile,
                          in_sig,
                          odepths=np.array([0.0]),
                          wave_field='outcrop')
    pysra_sig = eqsig.AccSignal(od['ACCX'][0], in_sig.dt)

    bf, sps = plt.subplots(nrows=3)

    sps[0].plot(in_sig.time, in_sig.values, c='k', label='Input')

    sps[0].plot(pysra_sig.time,
                pysra_sig.values,
                c=cbox('mid grey'),
                label='pysra')

    sps[1].plot(in_sig.fa_frequencies, abs(in_sig.fa_spectrum), c='k')

    sps[1].plot(pysra_sig.fa_frequencies,
                abs(pysra_sig.fa_spectrum),
                c=cbox('mid grey'))
    sps[1].set_xlim([0, 20])
    in_sig.smooth_fa_frequencies = in_sig.fa_frequencies[1:]
    pysra_sig.smooth_fa_frequencies = in_sig.fa_frequencies[1:]
    pysra_h = pysra_sig.smooth_fa_spectrum / in_sig.smooth_fa_spectrum
    sps[2].plot(pysra_sig.smooth_fa_frequencies, pysra_h, c=cbox('mid grey'))

    # Normal 1d analysis with tied boundaries
    outputs = site_response(soil_profile,
                            in_sig,
                            freqs=(0.5, 10),
                            xi=0.02,
                            analysis_dt=0.005,
                            x_eles=1,
                            ff_bc=False)
    resp_dt = outputs['time'][2] - outputs['time'][1]
    surf_sig = eqsig.AccSignal(outputs['ACCX'][0], resp_dt)
    sps[0].plot(surf_sig.time, surf_sig.values, c=cbox(0), label='o3 - 1D')
    sps[1].plot(surf_sig.fa_frequencies, abs(surf_sig.fa_spectrum), c=cbox(0))
    surf_sig.smooth_fa_frequencies = in_sig.fa_frequencies[1:]
    h = surf_sig.smooth_fa_spectrum / in_sig.smooth_fa_spectrum
    sps[2].plot(surf_sig.smooth_fa_frequencies, h, c=cbox(0))

    # 2d analysis with tied boundaries
    outputs = site_response(soil_profile,
                            in_sig,
                            freqs=(0.5, 10),
                            xi=0.02,
                            analysis_dt=0.005,
                            x_eles=20,
                            ff_bc=False)
    resp_dt = outputs['time'][2] - outputs['time'][1]
    surf_sig = eqsig.AccSignal(outputs['ACCX'][0], resp_dt)
    sps[0].plot(surf_sig.time,
                surf_sig.values,
                c=cbox(1),
                label='o3 - 2D tied',
                ls='--')
    sps[1].plot(surf_sig.fa_frequencies,
                abs(surf_sig.fa_spectrum),
                c=cbox(1),
                ls='--')
    surf_sig.smooth_fa_frequencies = in_sig.fa_frequencies
    h = surf_sig.smooth_fa_spectrum / in_sig.smooth_fa_spectrum
    sps[2].plot(surf_sig.smooth_fa_frequencies, h, c=cbox(1), ls='--')

    # 2d analysis with free-field columns
    outputs = site_response(soil_profile,
                            in_sig,
                            freqs=(0.5, 10),
                            xi=0.02,
                            analysis_dt=0.005,
                            x_eles=20,
                            ff_bc=True)
    resp_dt = outputs['time'][2] - outputs['time'][1]
    surf_sig = eqsig.AccSignal(outputs['ACCX'][0], resp_dt)
    sps[0].plot(surf_sig.time,
                surf_sig.values,
                c=cbox(2),
                label='o3 - 2D FF columns',
                ls=':')
    sps[1].plot(surf_sig.fa_frequencies,
                abs(surf_sig.fa_spectrum),
                c=cbox(2),
                ls=':')
    surf_sig.smooth_fa_frequencies = in_sig.fa_frequencies
    h = surf_sig.smooth_fa_spectrum / in_sig.smooth_fa_spectrum
    sps[2].plot(surf_sig.smooth_fa_frequencies, h, c=cbox(2), ls=':')

    sps[0].set_ylabel('Acc [m/s2]')
    sps[1].set_ylabel('FA')

    sps[2].set_ylabel('H')
    sps[2].set_xlabel('Freq [Hz]')

    sps[2].axhline(1, c='k', ls='--')
    sps[0].legend()
    plt.show()
예제 #15
0
def run():
    forder = 1.0e3
    sl = sm.Soil()
    sl.o3_type = 'pimy'
    vs = 100.
    xi = 0.03
    unit_mass = 1700.0
    sl.cohesion = 120.0e3
    sl.phi = 0.0
    sl.g_mod = vs ** 2 * unit_mass
    sl.poissons_ratio = 0.0
    sl.unit_dry_weight = unit_mass * 9.8
    sl.specific_gravity = 2.65
    sl.xi = 0.03  # for linear analysis
    sl.xi_min = 0.03  # for eqlin analysis
    sl.peak_strain = 0.1

    sl.o3_mat = o3.nd_material.PressureIndependMultiYield(None, 2, unit_mass / forder, sl.g_mod / forder,
                                                          sl.bulk_mod / forder, sl.cohesion / forder, 0.1,
                                                          0.0, 101.0e3 / forder, 0.0, 25)

    assert np.isclose(vs, sl.get_shear_vel(saturated=False))
    soil_profile = sm.SoilProfile()
    soil_profile.add_layer(0, sl)

    sl_base = sm.Soil()
    sl_base.o3_type = 'pimy'
    vs = 150.
    unit_mass = 1700.0
    sl_base.g_mod = vs ** 2 * unit_mass
    sl_base.poissons_ratio = 0.0
    sl_base.cohesion = 120.0e3
    sl_base.phi = 0.0
    sl_base.unit_dry_weight = unit_mass * 9.8
    sl_base.specific_gravity = 2.65
    sl_base.xi = xi  # for linear analysis
    sl_base.xi_min = 0.03  # for eqlin analysis
    sl_base.peak_strain = 0.1
    e_mod = 2 * sl_base.g_mod * (1 + sl_base.poissons_ratio)
    sl_base.o3_mat = o3.nd_material.PressureIndependMultiYield(None, 2, unit_mass / forder, sl_base.g_mod / forder,
                                                          sl_base.bulk_mod / forder, sl_base.cohesion / forder, 0.1, 0.0,
                                                          101.0e3 / forder, 0.0, 25)
    soil_profile.add_layer(5.1, sl_base)
    soil_profile.height = 10.0
    gm_scale_factor = 0.5
    record_filename = 'short_motion_dt0p01.txt'
    in_sig = eqsig.load_asig(ap.MODULE_DATA_PATH + 'gms/' + record_filename, m=gm_scale_factor)

    # analysis with pysra
    sl.sra_type = 'hyperbolic'
    sl_base.sra_type = 'hyperbolic'
    od = lq.sra.run_pysra(soil_profile, in_sig, odepths=np.array([0.0]), wave_field='within')
    pysra_sig = eqsig.AccSignal(od['ACCX'][0], in_sig.dt)

    import matplotlib.pyplot as plt
    from bwplot import cbox
    bf, sps = plt.subplots(nrows=3, figsize=(6, 8))

    in_sig.smooth_fa_frequencies = in_sig.fa_frequencies[1:]
    pysra_sig.smooth_fa_frequencies = in_sig.fa_frequencies[1:]
    sps[0].plot(in_sig.time, in_sig.values, c='k', label='Input')
    sps[0].plot(pysra_sig.time, pysra_sig.values, c='r', label='pysra')
    sps[1].plot(in_sig.fa_frequencies, abs(in_sig.fa_spectrum), c='k')
    sps[1].semilogx(pysra_sig.fa_frequencies, abs(pysra_sig.fa_spectrum), c='r')
    pysra_h = pysra_sig.smooth_fa_spectrum / in_sig.smooth_fa_spectrum
    sps[2].semilogx(pysra_sig.smooth_fa_frequencies, pysra_h, c='r')

    # analysis with O3
    etypes = ['implicit', 'explicit_difference', 'central_difference', 'newmark_explicit']
    # etypes = ['central_difference']
    # etypes = ['implicit', 'explicit_difference']
    ls = ['-', '--', ':', '-.']

    for i, etype in enumerate(etypes):
        outputs_exp = site_response(soil_profile, in_sig, freqs=(0.5, 10), xi=xi, etype=etype, forder=forder,
                                    rec_dt=in_sig.dt, analysis_time=in_sig.time[-1] + 3)
        resp_dt = (outputs_exp['time'][-1] - outputs_exp['time'][0]) / (len(outputs_exp['time']) - 1)
        abs_surf_sig = outputs_exp['ACCX'][0] + np.interp(np.arange(len(outputs_exp['ACCX'][0])) * resp_dt, in_sig.time,
                                                          in_sig.values)
        surf_sig = eqsig.AccSignal(abs_surf_sig, resp_dt)

        surf_sig.smooth_fa_frequencies = in_sig.fa_frequencies[1:]
        sps[0].plot(surf_sig.time, surf_sig.values, c=cbox(i), label=etype, ls=ls[i])
        sps[1].plot(surf_sig.fa_frequencies, abs(surf_sig.fa_spectrum), c=cbox(i), ls=ls[i])
        h = surf_sig.smooth_fa_spectrum / in_sig.smooth_fa_spectrum
        sps[2].plot(surf_sig.smooth_fa_frequencies, h, c=cbox(i), ls=ls[i])

    sps[2].axhline(1, c='k', ls='--')

    sps[0].legend(prop={'size': 6})
    name = __file__.replace('.py', '')
    name = name.split("fig_")[-1]
    bf.suptitle(name)
    bf.savefig(f'figs/{name}.png', dpi=90)
    plt.show()
def run():
    sl = sm.Soil()
    sl.type = 'pimy'
    vs = 160.
    unit_mass = 1700.0
    sl.cohesion = 58.0e3
    sl.phi = 0.0
    sl.g_mod = vs**2 * unit_mass
    sl.poissons_ratio = 0.0
    sl.phi = 0.0
    sl.unit_dry_weight = unit_mass * 9.8
    sl.specific_gravity = 2.65
    sl.strain_peak = 0.1  # set additional parameter required for PIMY model
    sl.xi = 0.03  # for linear analysis
    sl.sra_type = 'hyperbolic'
    assert np.isclose(vs, sl.get_shear_vel(saturated=False))
    soil_profile = sm.SoilProfile()
    soil_profile.add_layer(0, sl)

    sl = sm.Soil()
    sl.type = 'pimy'
    vs = 400.
    unit_mass = 1700.0
    sl.g_mod = vs**2 * unit_mass
    sl.poissons_ratio = 0.0
    sl.cohesion = 395.0e3
    sl.phi = 0.0
    sl.unit_dry_weight = unit_mass * 9.8
    sl.specific_gravity = 2.65
    sl.strain_peak = 0.1  # set additional parameter required for PIMY model
    sl.xi = 0.03  # for linear analysis
    sl.sra_type = 'hyperbolic'
    soil_profile.add_layer(9.5, sl)
    soil_profile.height = 20.0
    ecp_out = sm.Output()
    ecp_out.add_to_dict(soil_profile)
    ofile = open('ecp.json', 'w')
    ofile.write(json.dumps(ecp_out.to_dict(), indent=4))
    ofile.close()

    record_path = TEST_DATA_DIR
    record_filename = 'short_motion_dt0p01.txt'
    in_sig = eqsig.load_asig(record_filename)

    # linear analysis with pysra
    od = run_pysra(soil_profile, in_sig, odepths=np.array([0.0, 2.0]))
    pysra_sig = eqsig.AccSignal(od['ACCX_d0'], in_sig.dt)

    outputs = o3soil.sra.site_response(soil_profile, in_sig)
    resp_dt = outputs['time'][2] - outputs['time'][1]
    surf_sig = eqsig.AccSignal(outputs['ACCX'][0], resp_dt)

    o3_surf_vals = np.interp(pysra_sig.time, surf_sig.time, surf_sig.values)

    show = 1

    if show:
        import matplotlib.pyplot as plt
        from bwplot import cbox

        bf, sps = plt.subplots(nrows=3)

        sps[0].plot(in_sig.time, in_sig.values, c='k', label='Input')
        sps[0].plot(pysra_sig.time, o3_surf_vals, c=cbox(0), label='o3')
        sps[0].plot(pysra_sig.time, pysra_sig.values, c=cbox(1), label='pysra')

        sps[1].plot(in_sig.fa_frequencies, abs(in_sig.fa_spectrum), c='k')
        sps[1].plot(surf_sig.fa_frequencies,
                    abs(surf_sig.fa_spectrum),
                    c=cbox(0))
        sps[1].plot(pysra_sig.fa_frequencies,
                    abs(pysra_sig.fa_spectrum),
                    c=cbox(1))
        sps[1].set_xlim([0, 20])
        h = surf_sig.smooth_fa_spectrum / in_sig.smooth_fa_spectrum
        sps[2].plot(surf_sig.smooth_fa_frequencies, h, c=cbox(0))
        pysra_h = pysra_sig.smooth_fa_spectrum / in_sig.smooth_fa_spectrum
        sps[2].plot(pysra_sig.smooth_fa_frequencies, pysra_h, c=cbox(1))
        sps[2].axhline(1, c='k', ls='--')
        sps[0].plot(pysra_sig.time, (o3_surf_vals - pysra_sig.values) * 10,
                    c='r',
                    label='Error x10')
        sps[0].legend()
        plt.show()

    assert np.isclose(o3_surf_vals, pysra_sig.values, atol=0.01,
                      rtol=100).all()
예제 #17
0
import sys
import pyqtgraph as pg
from pyqtgraph.Qt import QtGui, QtCore
import o3plot

#%%
vs = 150.0
rho = 1.8
g_mod = vs ** 2 * rho

sl1 = sm.Soil(g_mod=g_mod, unit_dry_weight=rho * 9.8, poissons_ratio=0.32)
sl2 = sm.Soil(g_mod=g_mod, unit_dry_weight=rho * 9.8, poissons_ratio=0.33)
sl3 = sm.Soil(g_mod=g_mod, unit_dry_weight=rho * 9.8, poissons_ratio=0.34)
sl4 = sm.Soil(g_mod=g_mod, unit_dry_weight=rho * 9.8, poissons_ratio=0.35)
sl5 = sm.Soil(g_mod=g_mod, unit_dry_weight=rho * 9.8, poissons_ratio=0.36)
sp = sm.SoilProfile()
h_face = 1.8
sp.add_layer(0, sl1)
sp.add_layer(3.4, sl2)
sp.add_layer(5.7, sl3)
sp2 = sm.SoilProfile()
sp2.add_layer(0, sl4)
sp2.add_layer(3.9, sl2)
sp2.add_layer(6.5, sl5)
sp2.height = 20
sp.x_angles = [None, 0.07, 0.0]
sp2.x_angles = [None, 0.00, 0.0]


tds = sm.TwoDSystem(width=45, height=7.5)
tds.add_sp(sp, x=0)
예제 #18
0
def run():
    soil_profile = sm.SoilProfile()
    soil_profile.height = 30.0
    xi = 0.03

    sl = sm.Soil()
    vs = 250.
    unit_mass = 1700.0
    sl.g_mod = vs**2 * unit_mass
    sl.poissons_ratio = 0.3
    sl.unit_dry_weight = unit_mass * 9.8
    sl.xi = xi  # for linear analysis
    soil_profile.add_layer(0, sl)

    sl_base = sm.Soil()
    vs = 350.
    unit_mass = 1700.0
    sl_base.g_mod = vs**2 * unit_mass
    sl_base.poissons_ratio = 0.3
    sl_base.unit_dry_weight = unit_mass * 9.8
    sl_base.xi = xi  # for linear analysis
    soil_profile.add_layer(19., sl_base)
    soil_profile.height = 20.0
    gm_scale_factor = 1.5
    record_filename = 'short_motion_dt0p01.txt'
    in_sig = eqsig.load_asig(ap.MODULE_DATA_PATH + 'gms/' + record_filename,
                             m=gm_scale_factor)

    # analysis with pysra
    od = lq.sra.run_pysra(soil_profile,
                          in_sig,
                          odepths=np.array([0.0]),
                          wave_field='within')
    pysra_sig = eqsig.AccSignal(od['ACCX'][0], in_sig.dt)

    # Implicit analysis with O3
    outputs_imp = site_response(soil_profile,
                                in_sig,
                                freqs=(0.5, 10),
                                xi=xi,
                                analysis_dt=0.001)
    resp_dt = outputs_imp['time'][2] - outputs_imp['time'][1]
    surf_sig_imp = eqsig.AccSignal(outputs_imp['ACCX'][0], resp_dt)

    # Explicit analysis with O3
    outputs_exp = site_response(soil_profile,
                                in_sig,
                                freqs=(0.5, 10),
                                xi=xi,
                                analysis_dt=0.0001,
                                use_explicit=1)
    resp_dt = outputs_exp['time'][2] - outputs_exp['time'][1]
    surf_sig = eqsig.AccSignal(outputs_exp['ACCX'][0], resp_dt)

    show = 1

    if show:
        import matplotlib.pyplot as plt
        from bwplot import cbox

        in_sig.smooth_fa_frequencies = in_sig.fa_frequencies[1:]
        surf_sig.smooth_fa_frequencies = in_sig.fa_frequencies[1:]
        pysra_sig.smooth_fa_frequencies = in_sig.fa_frequencies[1:]
        surf_sig_imp.smooth_fa_frequencies = in_sig.fa_frequencies[1:]

        bf, sps = plt.subplots(nrows=3)

        sps[0].plot(in_sig.time, in_sig.values, c='k', label='Input')
        sps[0].plot(pysra_sig.time, pysra_sig.values, c=cbox(1), label='pysra')
        sps[0].plot(surf_sig_imp.time,
                    surf_sig_imp.values,
                    c=cbox(0),
                    label='o3-imp')
        sps[0].plot(surf_sig.time,
                    surf_sig.values,
                    c=cbox(2),
                    label='o3-exp',
                    ls='--')

        sps[1].plot(in_sig.fa_frequencies, abs(in_sig.fa_spectrum), c='k')
        sps[1].plot(pysra_sig.fa_frequencies,
                    abs(pysra_sig.fa_spectrum),
                    c=cbox(1))
        sps[1].plot(surf_sig_imp.fa_frequencies,
                    abs(surf_sig_imp.fa_spectrum),
                    c=cbox(0))
        sps[1].plot(surf_sig.fa_frequencies,
                    abs(surf_sig.fa_spectrum),
                    c=cbox(2),
                    ls='--')
        sps[1].set_xlim([0, 20])
        pysra_h = pysra_sig.smooth_fa_spectrum / in_sig.smooth_fa_spectrum
        sps[2].plot(pysra_sig.smooth_fa_frequencies, pysra_h, c=cbox(1))

        h = surf_sig_imp.smooth_fa_spectrum / in_sig.smooth_fa_spectrum
        sps[2].plot(in_sig.smooth_fa_frequencies, h, c=cbox(0))
        h = surf_sig.smooth_fa_spectrum / in_sig.smooth_fa_spectrum
        sps[2].plot(surf_sig.smooth_fa_frequencies, h, c=cbox(2), ls='--')

        sps[2].axhline(1, c='k', ls='--')

        sps[0].legend()
        plt.show()
예제 #19
0
def run():
    soil_profile = sm.SoilProfile()
    soil_profile.height = 30.0
    xi = 0.03

    sl = sm.Soil()
    vs = 250.
    unit_mass = 1700.0
    sl.g_mod = vs**2 * unit_mass
    sl.poissons_ratio = 0.3
    sl.unit_dry_weight = unit_mass * 9.8
    sl.xi = xi  # for linear analysis
    soil_profile.add_layer(0, sl)

    sl_base = sm.Soil()
    vs = 350.
    unit_mass = 1700.0
    sl_base.g_mod = vs**2 * unit_mass
    sl_base.poissons_ratio = 0.0
    sl_base.unit_dry_weight = unit_mass * 9.8
    sl_base.xi = xi  # for linear analysis
    soil_profile.add_layer(19., sl_base)
    soil_profile.height = 20.0
    gm_scale_factor = 1.5
    record_filename = 'short_motion_dt0p01.txt'
    in_sig = eqsig.load_asig(ap.MODULE_DATA_PATH + 'gms/' + record_filename,
                             m=gm_scale_factor)

    # analysis with pysra
    sl.sra_type = 'linear'
    sl_base.sra_type = 'linear'
    od = run_pysra(soil_profile,
                   in_sig,
                   odepths=np.array([0.0, 2.0]),
                   wave_field='outcrop')
    pysra_sig = eqsig.AccSignal(od['ACCX'][0], in_sig.dt)

    dtype = 'rayleigh'
    dtype = 'modal'
    outputs = site_response(soil_profile,
                            in_sig,
                            freqs=(0.5, 10),
                            xi=xi,
                            analysis_dt=0.001,
                            dtype=dtype)
    resp_dt = (outputs['TIME'][-1] -
               outputs['TIME'][0]) / (len(outputs['TIME']) - 1)
    surf_sig = eqsig.AccSignal(outputs['ACCX'][0], resp_dt)

    o3_surf_vals = np.interp(pysra_sig.time, surf_sig.time, surf_sig.values)

    show = 1

    if show:
        import matplotlib.pyplot as plt
        from bwplot import cbox

        in_sig.smooth_fa_frequencies = in_sig.fa_frequencies[1:]
        surf_sig.smooth_fa_frequencies = in_sig.fa_frequencies[1:]
        pysra_sig.smooth_fa_frequencies = in_sig.fa_frequencies[1:]

        bf, sps = plt.subplots(nrows=3)

        sps[0].plot(in_sig.time, in_sig.values, c='k', label='Input')
        sps[0].plot(surf_sig.time, surf_sig.values, c=cbox(0), label='o3')
        sps[0].plot(pysra_sig.time, pysra_sig.values, c=cbox(1), label='pysra')
        sps[0].plot(pysra_sig.time, (o3_surf_vals - pysra_sig.values) * 10,
                    c='r',
                    label='Error x10')

        sps[1].plot(in_sig.fa_frequencies, abs(in_sig.fa_spectrum), c='k')
        sps[1].plot(surf_sig.fa_frequencies,
                    abs(surf_sig.fa_spectrum),
                    c=cbox(0))
        sps[1].plot(pysra_sig.fa_frequencies,
                    abs(pysra_sig.fa_spectrum),
                    c=cbox(1))
        sps[1].set_xlim([0, 20])
        h = surf_sig.smooth_fa_spectrum / in_sig.smooth_fa_spectrum
        sps[2].plot(surf_sig.smooth_fa_frequencies, h, c=cbox(0))
        pysra_h = pysra_sig.smooth_fa_spectrum / in_sig.smooth_fa_spectrum
        sps[2].plot(pysra_sig.smooth_fa_frequencies, pysra_h, c=cbox(1))
        sps[2].axhline(1, c='k', ls='--')
        sps[0].legend()
        plt.show()

    assert np.isclose(o3_surf_vals, pysra_sig.values, atol=0.01,
                      rtol=100).all()
def run(out_folder, dytime=None):

    xi = 0.05

    sl = sm.Soil()
    sl.type = 'pimy'
    vs = 160.
    unit_mass = 1700.0
    sl.cohesion = 58.0e3
    sl.phi = 0.0
    sl.g_mod = vs**2 * unit_mass
    sl.poissons_ratio = 0.0
    sl.phi = 0.0
    sl.unit_dry_weight = unit_mass * 9.8
    sl.specific_gravity = 2.65
    sl.peak_strain = 0.01  # set additional parameter required for PIMY model
    ref_press = 100.e3
    sl.xi = 0.03  # for linear analysis
    sl.sra_type = 'hyperbolic'
    o3soil.backbone.set_params_from_op_pimy_model(sl, ref_press)
    sl.inputs += [
        'strain_curvature', 'xi_min', 'sra_type', 'strain_ref', 'peak_strain'
    ]
    assert np.isclose(vs, sl.get_shear_vel(saturated=False))
    sp = sm.SoilProfile()
    sp.add_layer(0, sl)

    sl = sm.Soil()
    sl.type = 'pimy'
    vs = 350.
    unit_mass = 1700.0
    sl.g_mod = vs**2 * unit_mass
    sl.poissons_ratio = 0.0
    sl.cohesion = 395.0e3
    sl.phi = 0.0
    sl.unit_dry_weight = unit_mass * 9.8
    sl.specific_gravity = 2.65
    sl.peak_strain = 0.1  # set additional parameter required for PIMY model
    sl.xi = 0.03  # for linear analysis
    sl.sra_type = 'hyperbolic'
    o3soil.backbone.set_params_from_op_pimy_model(sl, ref_press)
    sl.inputs += [
        'strain_curvature', 'xi_min', 'sra_type', 'strain_ref', 'peak_strain'
    ]
    sp.add_layer(8.5, sl)
    sp.height = 14.0

    ecp_out = sm.Output()
    ecp_out.add_to_dict(sp)
    ecp_out.to_file(out_folder + 'ecp.json')

    asig = eqsig.load_asig(ap.MODULE_DATA_PATH + 'gms/short_motion_dt0p01.txt',
                           m=2.5)
    if dytime is None:
        ind = None
    else:
        ind = int(dytime / asig.dt)
    asig = eqsig.AccSignal(asig.values[:ind], asig.dt)

    outs = {'ACCX': 'all', 'TAU': 'all', 'STRS': 'all'}
    # cache = 0
    # if not cache:
    #     outputs = site_response(soil_profile, asig, xi=xi, out_folder=out_folder, outs=outs, rec_dt=asig.dt, analysis_time=dytime, fixed_base=1)
    # else:
    #     o3sra_outs = o3ptools.O3SRAOutputs()
    #     outputs = o3sra_outs.load_results_from_files()

    show = 1
    if show:
        import matplotlib.pyplot as plt
        bf, sps = plt.subplots(nrows=3)
        # TODO: Show loads on playback
        # TODO: add material to playback, and show legend with material type, set material.__str__ as basetype, params[2:]
        sra1d = o3soil.sra.run_sra(sp,
                                   asig,
                                   xi=xi,
                                   cache_path=out_folder,
                                   outs=outs,
                                   analysis_time=dytime,
                                   base_imp=-1,
                                   playback=True)
        outputs = sra1d.out_dict
        import pandas as pd
        df = pd.DataFrame.from_dict(outputs['TAU'])
        df.to_csv('tau.csv', index=False)
        ind_3m = sra1d.get_nearest_ele_layer_at_depth(3)
        ind_6m = sra1d.get_nearest_ele_layer_at_depth(6)
        ind_12m = sra1d.get_nearest_ele_layer_at_depth(12)
        sps[0].plot(outputs["time"], outputs["TAU"][ind_3m], ls='--')
        sps[0].plot(outputs["time"], outputs["TAU"][ind_6m], ls='--', c='r')
        sps[0].plot(outputs["time"], outputs["TAU"][ind_12m], ls='--')
        sps[2].plot(outputs["time"], outputs["STRS"][ind_6m], ls='--', c='r')
        sps[1].plot(outputs['STRS'][ind_6m], outputs['TAU'][ind_6m], c='r')
        # sps[1].plot(outputs['STRS'][3], sl.g_mod / 1e3 * outputs['STRS'][3], ls='--')
        # sps[2].plot(outputs["time"], outputs["ACCX"][5], ls='--')
        plt.show()
def run():
    soil_profile = sm.SoilProfile()
    soil_profile.height = 30.0
    xi = 0.03

    sl = sm.Soil()
    vs = 250.
    unit_mass = 1700.0
    sl.g_mod = vs**2 * unit_mass
    sl.poissons_ratio = 0.3
    sl.unit_dry_weight = unit_mass * 9.8
    sl.xi = xi  # for linear analysis
    sl.sra_type = 'linear'
    soil_profile.add_layer(0, sl)

    sl_base = sm.Soil()
    vs = 350.
    unit_mass = 1700.0
    sl_base.g_mod = vs**2 * unit_mass
    sl_base.poissons_ratio = 0.0
    sl_base.unit_dry_weight = unit_mass * 9.8
    sl_base.xi = xi  # for linear analysis
    sl_base.sra_type = 'linear'
    soil_profile.add_layer(10., sl_base)
    soil_profile.height = 20.0
    gm_scale_factor = 1.5
    record_filename = 'test_motion_dt0p01.txt'
    in_sig = eqsig.load_asig(ap.MODULE_DATA_PATH + 'gms/' + record_filename,
                             m=gm_scale_factor)

    # analysis with pysra
    od = lq.sra.run_pysra(soil_profile,
                          in_sig,
                          odepths=np.array([0.0]),
                          wave_field='within')
    ind = in_sig.npts
    pysra_sig = eqsig.AccSignal(od['ACCX'][0][:ind], in_sig.dt)

    dtype = 'rayleigh'
    dtype = 'modal'
    outputs = site_response(soil_profile,
                            in_sig,
                            freqs=(0.5, 10),
                            xi=xi,
                            analysis_dt=0.005,
                            dtype=dtype)
    resp_dt = outputs['time'][2] - outputs['time'][1]
    surf_sig = eqsig.AccSignal(outputs['ACCX'][0], resp_dt)

    o3_surf_vals = np.interp(pysra_sig.time, surf_sig.time,
                             surf_sig.values) + in_sig.values
    surf_sig = eqsig.AccSignal(
        surf_sig.values + np.interp(surf_sig.time, in_sig.time, in_sig.values),
        surf_sig.dt)

    show = 1

    if show:
        import matplotlib.pyplot as plt
        from bwplot import cbox

        in_sig.smooth_fa_frequencies = in_sig.fa_frequencies[1:]
        surf_sig.smooth_fa_frequencies = in_sig.fa_frequencies[1:]
        pysra_sig.smooth_fa_frequencies = in_sig.fa_frequencies[1:]

        bf, sps = plt.subplots(nrows=3)

        sps[0].plot(in_sig.time, in_sig.values, c='k', label='Input')
        sps[0].plot(surf_sig.time, surf_sig.values, c=cbox(0), label='o3')
        sps[0].plot(pysra_sig.time, pysra_sig.values, c=cbox(1), label='pysra')

        sps[1].plot(in_sig.fa_frequencies, abs(in_sig.fa_spectrum), c='k')
        sps[1].plot(surf_sig.fa_frequencies,
                    abs(surf_sig.fa_spectrum),
                    c=cbox(0))
        sps[1].plot(pysra_sig.fa_frequencies,
                    abs(pysra_sig.fa_spectrum),
                    c=cbox(1))

        h = surf_sig.smooth_fa_spectrum / in_sig.smooth_fa_spectrum
        sps[2].plot(surf_sig.smooth_fa_frequencies, h, c=cbox(0))
        pysra_h = pysra_sig.smooth_fa_spectrum / in_sig.smooth_fa_spectrum
        sps[2].plot(pysra_sig.smooth_fa_frequencies, pysra_h, c=cbox(1))
        sps[2].axhline(1, c='k', ls='--')
        sps[1].set_xlim([0, 20])
        sps[2].set_xlim([0, 20])
        sps[0].legend()
        name = __file__.replace('.py', '')
        name = name.split("fig_")[-1]
        bf.suptitle(name)
        bf.savefig(f'figs/{name}.png', dpi=90)
        plt.show()

    assert np.isclose(o3_surf_vals, pysra_sig.values, atol=0.01,
                      rtol=100).all()
def create():
    sl = sm.Soil()
    vs = 200.
    unit_mass = 1700.0
    sl.cohesion = 68.0e3
    # sl.cohesion = 0.0
    sl.phi = 0.0
    sl.g_mod = 68.0e6
    print('G_mod: ', sl.g_mod)
    sl.unit_dry_weight = unit_mass * 9.8
    sl.specific_gravity = 2.65
    k0 = 1.0
    # sl.poissons_ratio = k0 / (1 + k0) - 0.01
    sl.poissons_ratio = 0.3
    strain_max = 0.01
    strains = np.logspace(-4, -1.5, 40)
    esig_v0 = 100.0e3
    ref_press = 100.e3
    ndm = 2
    # TODO: phi and cohesion are not used as you would expect for user defined surfaces !!! recalculated: tau_max calculated the
    set_params_from_op_pimy_model(sl, strain_max, ref_press)
    sl.inputs += ['strain_curvature', 'xi_min', 'sra_type', 'strain_ref']

    sp = sm.SoilProfile()
    sp.id = 1
    sp.add_layer(0, sl)
    sp.height = 30.0
    ecp_out = sm.Output()
    ecp_out.add_to_dict(sp)
    ofile = open('ecp.json', 'w')
    # ofile.write(json.dumps(ecp_out.to_dict(), indent=4))
    ofile.close()

    compare_backbone = 1
    if compare_backbone:
        dss_eq = np.sqrt(3. / 2)
        pysra_sl = pysra.site.ModifiedHyperbolicSoilType(
            "",
            1,
            strain_ref=sl.strain_ref * dss_eq,
            curvature=sl.strain_curvature,
            damping_min=sl.xi_min,
            strains=strains)
        pysra_tau = pysra_sl.mod_reduc.values * sl.g_mod * pysra_sl.mod_reduc.strains
        taus = calc_backbone_op_pimy_model(sl,
                                           strain_max,
                                           strains,
                                           ref_press,
                                           ndm=ndm,
                                           esig_v0=esig_v0)
        osi = o3.OpenSeesInstance(ndm=2, ndf=2, state=3)
        # See example: https://opensees.berkeley.edu/wiki/index.php/PressureIndependMultiYield_Material
        base_mat = o3.nd_material.PressureIndependMultiYield(
            osi,
            nd=2,
            rho=sl.unit_sat_mass,
            g_mod_ref=sl.g_mod_ref,
            bulk_mod_ref=sl.bulk_mod_ref,
            peak_strain=strain_max,
            cohesion=sl.cohesion,
            phi=sl.phi,
            p_ref=sl.p_ref,
            d=0.0,
            n_surf=25)

        disps = np.array(
            [0.0, 0.00003, -0.00003, 0.0004, 0.0001, 0.0009, -0.0009]) * 10
        disps = np.linspace(0.0, 0.02, 100)
        k0_init = sl.poissons_ratio / (1 - sl.poissons_ratio)
        print(k0_init)
        stress, strain, v_eff, h_eff, exit_code = d2d.run_2d_strain_driver_iso(
            osi,
            base_mat,
            esig_v0=esig_v0,
            disps=disps,
            handle='warn',
            verbose=1,
            target_d_inc=0.00001)
        bf, sps = plt.subplots(nrows=2)
        sps[0].plot(strain, stress, c='r')
        sps[0].plot(strains, taus, label='approx PIMY')
        sps[0].plot(pysra_sl.mod_reduc.strains,
                    pysra_tau,
                    ls='--',
                    label='PySRA Hyperbolic')
        # sps[1].plot(stress)
        sps[1].plot(v_eff)
        sps[1].plot(h_eff)
        sps[0].axhline(sl.cohesion, c='k')
        plt.legend()
        plt.show()
def run():

    vs = 250.
    sp = sm.SoilProfile()
    sp.height = 30.
    sl = sm.Soil()

    sl.type = 'elastic'
    sl.poissons_ratio = 0.
    sl.unit_dry_weight = 2.202e3 * 9.8
    sl.g_mod = vs ** 2 * sl.unit_dry_mass
    sl.xi = 0.01  # for linear analysis
    sp.add_layer(0, sl)

    rock = sm.Soil()
    vs = 450.
    unit_mass = 1700.0
    rock.g_mod = vs ** 2 * unit_mass
    rock.unit_dry_weight = unit_mass * 9.8
    rock.poissons_ratio = 0.
    rock.xi = 0.01
    sp.add_layer(sp.height, rock)
    sp.height = sp.height + 1

    in_sig = eqsig.load_asig(ap.MODULE_DATA_PATH + 'gms/short_motion_dt0p01.txt', m=0.05)

    opfile = __file__[:-3] + 'op.py'
    fixed_base = 0
    if fixed_base:
        base_imp = -1
        wave_field = 'within'
    else:
        base_imp = 0
        wave_field = 'outcrop'

    outputs = o3soil.sra.site_response(sp, in_sig, outs={'ACCX': 'all'}, dy=0.5, opfile=opfile,
                                       base_imp=base_imp, freqs=(0.5, 20), xi=0.02, analysis_dt=0.005)
    resp_dt = outputs['time'][2] - outputs['time'][1]
    o3_surf_sig = eqsig.AccSignal(outputs['ACCX'][0], resp_dt)

    pysra_outs_full = lq.sra.run_pysra(sp, in_sig, [0], wave_field=wave_field)
    pysra_surf_sig = eqsig.AccSignal(pysra_outs_full['ACCX'][0], in_sig.dt)

    show = 1

    if show:
        import matplotlib.pyplot as plt
        from bwplot import cbox

        bf, sps = plt.subplots(nrows=3)

        sps[0].plot(in_sig.time, in_sig.values, c='k', label='Input', lw=1)
        sps[0].plot(o3_surf_sig.time, o3_surf_sig.values, c=cbox(0), label='o3-surf-direct', lw=1)
        sps[0].plot(pysra_surf_sig.time, pysra_surf_sig.values, c=cbox(4), label='pysra-surf-direct', lw=1, ls='--')

        sps[1].loglog(o3_surf_sig.fa_frequencies, abs(o3_surf_sig.fa_spectrum), c=cbox(0), lw=1)

        sps[1].loglog(pysra_surf_sig.fa_frequencies, abs(pysra_surf_sig.fa_spectrum), c=cbox(4), lw=1)
        in_sig.smooth_fa_frequencies = in_sig.fa_frequencies
        pysra_surf_sig.smooth_fa_frequencies = in_sig.fa_frequencies
        o3_surf_sig.smooth_fa_frequencies = in_sig.fa_frequencies
        in_sig.generate_smooth_fa_spectrum(band=80)
        pysra_surf_sig.generate_smooth_fa_spectrum(band=80)
        o3_surf_sig.generate_smooth_fa_spectrum(band=80)

        sps[2].plot(in_sig.smooth_fa_frequencies, o3_surf_sig.smooth_fa_spectrum / in_sig.smooth_fa_spectrum,
                    c=cbox(0), label='O3 - smoothed')
        sps[2].plot(in_sig.smooth_fa_frequencies, pysra_surf_sig.smooth_fa_spectrum / in_sig.smooth_fa_spectrum,
                    c=cbox(4), label='Pysra - smoothed')
        pysra_sp = lq.sra.sm_profile_to_pysra(sp)
        freqs, tfs = lq.sra.calc_pysra_tf(pysra_sp, in_sig.fa_frequencies, absolute=True)
        sps[2].plot(freqs, tfs,  c='k', label='Pysra - exact')
        sps[0].legend(loc='lower right')

        vs_damped = lq.sra.theory.calc_damped_vs_dormieux_1990(sl.get_shear_vel(saturated=False), sl.xi)
        vs_br_damped = lq.sra.theory.calc_damped_vs_dormieux_1990(rock.get_shear_vel(saturated=False), rock.xi)
        h = sp.height
        omega = in_sig.fa_frequencies * np.pi * 2
        imp = lq.sra.theory.calc_impedance(sl.unit_dry_mass, vs_damped, rock.unit_dry_mass, vs_br_damped)
        tfs = lq.sra.theory.calc_tf_elastic_br(h, vs_damped, omega, imp, absolute=True)
        sps[2].semilogx(in_sig.fa_frequencies, tfs, label='Theoretical Elastic BR', c='r', ls='--')

        sps[2].set_xlim([0.1, 30])
        sps[0].set_ylabel('Acc [m/s2]')
        sps[1].set_ylabel('FAS')
        sps[2].set_ylabel('H')
        sps[0].set_xlabel('Time [s]')
        sps[1].set_xlabel('Freq [Hz]')
        sps[2].set_xlabel('Freq [Hz]')
        sps[2].legend()
        plt.show()
예제 #24
0
def run():
    xi = 0.03

    sl = sm.Soil()
    vs = 250.
    unit_mass = 1700.0
    sl.g_mod = vs**2 * unit_mass
    sl.poissons_ratio = 0.3
    sl.unit_dry_weight = unit_mass * 9.8
    sl.xi = xi  # for linear analysis

    sl_base = sm.Soil()
    vs = 350.
    unit_mass = 1700.0
    sl_base.g_mod = vs**2 * unit_mass
    sl_base.poissons_ratio = 0.3
    sl_base.unit_dry_weight = unit_mass * 9.8
    sl_base.xi = xi  # for linear analysis
    soil_profile = sm.SoilProfile()
    soil_profile.add_layer(0, sl)
    soil_profile.add_layer(10., sl_base)
    soil_profile.height = 20.0
    gm_scale_factor = 1.0
    record_filename = 'short_motion_dt0p01.txt'
    in_sig = eqsig.load_asig(ap.MODULE_DATA_PATH + 'gms/' + record_filename,
                             m=gm_scale_factor)
    # in_sig = eqsig.AccSignal(np.pad(in_sig.values, (500, 500), mode='constant', constant_values=0), in_sig.dt)
    # in_sig.butter_pass([0.1, None])
    # analysis with pysra
    sl.sra_type = 'linear'
    sl_base.sra_type = 'linear'
    od = lq.sra.run_pysra(soil_profile,
                          in_sig,
                          odepths=np.array([0.0]),
                          wave_field='within')
    pysra_sig = eqsig.AccSignal(od['ACCX'][0], in_sig.dt)

    import matplotlib.pyplot as plt
    from bwplot import cbox
    bf, sps = plt.subplots(nrows=3, figsize=(6, 8))

    in_sig.smooth_fa_frequencies = in_sig.fa_frequencies[1:]
    pysra_sig.smooth_fa_frequencies = in_sig.fa_frequencies[1:]
    sps[0].plot(in_sig.time, in_sig.values, c='k', label='Input')
    sps[0].plot(pysra_sig.time, pysra_sig.values, c='r', label='pysra')
    sps[1].plot(in_sig.fa_frequencies, abs(in_sig.fa_spectrum), c='k')
    sps[1].semilogx(pysra_sig.fa_frequencies,
                    abs(pysra_sig.fa_spectrum),
                    c='r')
    pysra_h = pysra_sig.smooth_fa_spectrum / in_sig.smooth_fa_spectrum
    sps[2].semilogx(pysra_sig.smooth_fa_frequencies, pysra_h, c='r')

    # analysis with O3
    etypes = [
        'implicit', 'explicit_difference', 'central_difference',
        'newmark_explicit'
    ]
    # etypes = ['implicit']
    ls = ['-', '--', ':', '-.']

    for i, etype in enumerate(etypes):
        outputs_exp = site_response(soil_profile,
                                    in_sig,
                                    freqs=(0.5, 10),
                                    xi=xi,
                                    etype=etype,
                                    rec_dt=0.01)
        resp_dt = (outputs_exp['TIME'][-1] -
                   outputs_exp['TIME'][0]) / (len(outputs_exp['TIME']) - 1)
        abs_surf_sig = outputs_exp['ACCX'][0] + np.interp(
            np.arange(len(outputs_exp['ACCX'][0])) * resp_dt, in_sig.time,
            in_sig.values)
        surf_sig = eqsig.AccSignal(abs_surf_sig, resp_dt)

        surf_sig.smooth_fa_frequencies = in_sig.fa_frequencies[1:]
        sps[0].plot(surf_sig.time,
                    surf_sig.values,
                    c=cbox(i),
                    label=etype,
                    ls=ls[i])
        sps[1].plot(surf_sig.fa_frequencies,
                    abs(surf_sig.fa_spectrum),
                    c=cbox(i),
                    ls=ls[i])
        h = surf_sig.smooth_fa_spectrum / in_sig.smooth_fa_spectrum
        sps[2].plot(surf_sig.smooth_fa_frequencies, h, c=cbox(i), ls=ls[i])

    sps[2].axhline(1, c='k', ls='--')

    sps[0].legend(prop={'size': 6})
    name = __file__.replace('.py', '')
    name = name.split("fig_")[-1]
    bf.suptitle(name)
    bf.savefig(f'figs/{name}.png', dpi=90)
    plt.show()
예제 #25
0
def run(show=0, export=0):
    sl = sm.Soil()

    vs = 160.
    unit_mass = 1700.0
    sl.cohesion = 58.0e3
    sl.phi = 0.0
    sl.g_mod = vs ** 2 * unit_mass
    sl.poissons_ratio = 0.0
    sl.phi = 0.0
    sl.unit_dry_weight = unit_mass * 9.8
    sl.strain_peak = 0.1  # set additional parameter required for PIMY model
    sl.xi = 0.03  # for linear analysis
    assert np.isclose(vs, sl.get_shear_vel(saturated=False))
    soil_profile = sm.SoilProfile()
    soil_profile.add_layer(0, sl)

    sl = sm.Soil()
    vs = 400.
    unit_mass = 1700.0
    sl.g_mod = vs ** 2 * unit_mass
    sl.poissons_ratio = 0.0
    sl.cohesion = 395.0e3
    sl.phi = 0.0
    sl.unit_dry_weight = unit_mass * 9.8
    sl.strain_peak = 0.1  # set additional parameter required for PIMY model
    sl.xi = 0.03  # for linear analysis
    soil_profile.add_layer(9.5, sl)
    soil_profile.height = 20.0
    ecp_out = sm.Output()
    ecp_out.add_to_dict(soil_profile)
    if export:
        import json
        ofile = open('ecp.json', 'w')
        ofile.write(json.dumps(ecp_out.to_dict(), indent=4))
        ofile.close()
    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) / 2
    acc_signal = eqsig.AccSignal(rec, dt)

    outputs = site_response(soil_profile, acc_signal, linear=0)
    tot_acc = np.sum(abs(outputs['rel_accel']))
    assert np.isclose(tot_acc, 515.76262984), tot_acc  # v3.1.0.11
    resp_dt = outputs['time'][2] - outputs['time'][1]
    surf_sig = eqsig.AccSignal(outputs['rel_accel'], resp_dt)

    if show:
        lw = 0.7
        import matplotlib.pyplot as plt
        from bwplot import cbox
        bf, sps = plt.subplots(nrows=3)

        # linear analysis with pysra
        od = run_pysra(soil_profile, acc_signal, odepths=np.array([0.0, 2.0]))
        pysra_sig = eqsig.AccSignal(od['ACCX_d0'], acc_signal.dt)

        sps[0].plot(acc_signal.time, acc_signal.values, c='k', lw=lw)
        sps[0].plot(surf_sig.time, surf_sig.values, c=cbox(0), lw=lw)
        sps[0].plot(acc_signal.time, pysra_sig.values, c=cbox(1), lw=lw)

        sps[1].plot(acc_signal.fa_frequencies, abs(acc_signal.fa_spectrum), c='k', label='Input', lw=lw)
        sps[1].plot(surf_sig.fa_frequencies, abs(surf_sig.fa_spectrum), c=cbox(0), label='O3', lw=lw)
        sps[1].plot(pysra_sig.fa_frequencies, abs(pysra_sig.fa_spectrum), c=cbox(1), label='pysra', lw=lw)
        sps[1].set_xlim([0, 20])
        h = surf_sig.smooth_fa_spectrum / acc_signal.smooth_fa_spectrum
        sps[2].plot(surf_sig.smooth_fa_frequencies, h, c=cbox(0))
        pysra_h = pysra_sig.smooth_fa_spectrum / acc_signal.smooth_fa_spectrum
        sps[2].plot(pysra_sig.smooth_fa_frequencies, pysra_h, c=cbox(1))
        # o3_nl_h = nl_surf_sig.smooth_fa_spectrum / acc_signal.smooth_fa_spectrum
        # sps[2].plot(nl_surf_sig.smooth_fa_frequencies, o3_nl_h, c=cbox(2))
        sps[2].axhline(1, c='k', ls='--')
        sps[1].legend()
        plt.show()
        print(outputs)
예제 #26
0
def test_two_d_mesh():
    rho = 1.8
    sl1 = sm.Soil(g_mod=50, unit_dry_weight=rho * 9.8, poissons_ratio=0.3)
    sl2 = sm.Soil(g_mod=100, unit_dry_weight=rho * 9.8, poissons_ratio=0.3)
    sl3 = sm.Soil(g_mod=400, unit_dry_weight=rho * 9.8, poissons_ratio=0.3)
    sl4 = sm.Soil(g_mod=600, unit_dry_weight=rho * 9.8, poissons_ratio=0.3)
    sp = sm.SoilProfile()
    sp.add_layer(0, sl1)
    sp.add_layer(5, sl2)
    sp.add_layer(12, sl3)
    sp.height = 18
    sp.x = 0
    sp2 = sm.SoilProfile()
    sp2.add_layer(0, sl1)
    sp2.add_layer(7, sl4)
    sp2.add_layer(12, sl3)
    sp2.height = 20
    sp.x_angles = [0.0, 0.05, 0.0]
    sp2.x_angles = [0.0, 0.00, 0.0]

    fd = sm.RaftFoundation()
    fd.width = 2
    fd.depth = 0
    fd.height = 0
    fd.length = 100
    fd.ip_axis = 'width'
    tds = sm.TwoDSystem(40, 15)
    tds.add_sp(sp, x=0)
    tds.add_sp(sp2, x=14)
    tds.x_surf = np.array([0, 10, 12, 40])
    tds.y_surf = np.array([0, 0, 2, 2])
    bd = sm.NullBuilding()
    bd.set_foundation(fd, x=0.0)
    bd_x = 8.
    tds.add_bd(bd, x=bd_x)

    x_scale_pos = np.array([0, 5, 15, 30])
    x_scale_vals = np.array([2., 1.0, 2.0, 3.0])
    fc = sm.num.mesh.FiniteElementOrth2DMeshConstructor(
        tds, 0.3, x_scale_pos=x_scale_pos, x_scale_vals=x_scale_vals)
    femesh = fc.femesh

    x_ind = femesh.get_indexes_at_xs([4.])[0]
    y_ind = femesh.get_indexes_at_depths([1.99])[0]
    sl_ind = femesh.soil_grid[x_ind][y_ind]
    assert sl_ind == 1000000
    assert femesh.get_active_nodes()[x_ind][y_ind] == 0
    p_ind = fc.x_index_to_sp_index[x_ind]
    assert p_ind == 0
    y_ind = femesh.get_indexes_at_depths([-3])[0]
    sl_ind = femesh.soil_grid[x_ind][y_ind]
    assert femesh.soils[sl_ind].g_mod == 50
    y_ind = femesh.get_indexes_at_depths([-8])[0]
    sl_ind = femesh.soil_grid[x_ind][y_ind]
    assert femesh.soils[sl_ind].g_mod == 100
    y_ind = femesh.get_indexes_at_depths([-12.5])[0]
    sl_ind = femesh.soil_grid[x_ind][y_ind]
    assert femesh.soils[sl_ind].g_mod == 400
    assert femesh.get_active_nodes()[x_ind][y_ind] == 1

    x_ind = femesh.get_indexes_at_xs([16.])[0]
    p_ind = fc.x_index_to_sp_index[x_ind]
    assert p_ind == 1
    y_ind = femesh.get_indexes_at_depths([1.99])[0]
    sl_ind = femesh.soil_grid[x_ind][y_ind]
    assert femesh.soils[sl_ind].g_mod == 50
    y_ind = femesh.get_indexes_at_depths([-3])[0]
    sl_ind = femesh.soil_grid[x_ind][y_ind]
    assert femesh.soils[sl_ind].g_mod == 50
    y_ind = femesh.get_indexes_at_depths([-8])[0]
    sl_ind = femesh.soil_grid[x_ind][y_ind]
    assert femesh.soils[sl_ind].g_mod == 600
    y_ind = femesh.get_indexes_at_depths([-12.5])[0]
    sl_ind = femesh.soil_grid[x_ind][y_ind]
    assert femesh.soils[sl_ind].g_mod == 400

    # check foundation
    lhs_ind = np.argmin(abs(femesh.x_nodes - (bd_x - fd.width / 2)))
    assert np.isclose(bd_x - fd.width / 2,
                      femesh.x_nodes[lhs_ind]), (bd_x - fd.width / 2,
                                                 femesh.x_nodes[lhs_ind])
    rhs_ind = np.argmin(abs(femesh.x_nodes - (bd_x + fd.width / 2)))
    assert np.isclose(bd_x + fd.width / 2, femesh.x_nodes[rhs_ind])
예제 #27
0
def run():
    soil_profile = sm.SoilProfile()
    soil_profile.height = 30.0
    xi = 0.03

    sl = sm.Soil()
    sl.o3_type = 'lin'  # Use linear soil model
    vs = 250.
    unit_mass = 1700.0
    sl.g_mod = vs**2 * unit_mass
    sl.poissons_ratio = 0.3
    sl.unit_dry_weight = unit_mass * 9.8
    sl.xi = xi  # for linear analysis
    soil_profile.add_layer(0, sl)

    sl_base = sm.Soil()
    vs = 350.
    unit_mass = 1700.0
    sl_base.g_mod = vs**2 * unit_mass
    sl_base.poissons_ratio = 0.3
    sl_base.unit_dry_weight = unit_mass * 9.8
    sl_base.xi = xi  # for linear analysis
    soil_profile.add_layer(10., sl_base)
    soil_profile.height = 20.0
    gm_scale_factor = 1.5
    record_filename = 'short_motion_dt0p01.txt'
    in_sig = eqsig.load_asig(ap.MODULE_DATA_PATH + 'gms/' + record_filename,
                             m=gm_scale_factor)

    # analysis with pysra
    od = lq.sra.run_pysra(soil_profile,
                          in_sig,
                          odepths=np.array([0.0]),
                          wave_field='outcrop')
    pysra_sig = eqsig.AccSignal(od['ACCX'][0], in_sig.dt)
    freqs = (0.5, 10)

    # outputs_imp = site_response(soil_profile, in_sig, freqs=(0.5, 10), xi=xi, analysis_dt=0.001)
    # resp_dt = outputs_imp['time'][2] - outputs_imp['time'][1]
    # surf_sig_imp = eqsig.AccSignal(outputs_imp['ACCX'][0], resp_dt)

    outputs_exp = site_response(soil_profile,
                                in_sig,
                                freqs=freqs,
                                xi=xi,
                                analysis_dt=0.0001,
                                use_explicit=1)
    resp_dt = outputs_exp['time'][2] - outputs_exp['time'][1]
    surf_sig = eqsig.AccSignal(outputs_exp['ACCX'][0], resp_dt)
    surf_sig_imp = surf_sig

    show = 1

    if show:
        import matplotlib.pyplot as plt
        from bwplot import cbox

        in_sig.smooth_fa_frequencies = in_sig.fa_frequencies[1:]
        surf_sig.smooth_fa_frequencies = in_sig.fa_frequencies[1:]
        pysra_sig.smooth_fa_frequencies = in_sig.fa_frequencies[1:]
        surf_sig_imp.smooth_fa_frequencies = in_sig.fa_frequencies[1:]

        bf, sps = plt.subplots(nrows=3)

        sps[0].plot(in_sig.time, in_sig.values, c='k', label='Input')
        sps[0].plot(pysra_sig.time, pysra_sig.values, c=cbox(1), label='pysra')
        sps[0].plot(surf_sig_imp.time,
                    surf_sig_imp.values,
                    c=cbox(0),
                    label='o3-imp')
        sps[0].plot(surf_sig.time,
                    surf_sig.values,
                    c=cbox(2),
                    label='o3-exp',
                    ls='--')

        sps[1].plot(in_sig.fa_frequencies, abs(in_sig.fa_spectrum), c='k')
        sps[1].plot(pysra_sig.fa_frequencies,
                    abs(pysra_sig.fa_spectrum),
                    c=cbox(1))
        sps[1].plot(surf_sig_imp.fa_frequencies,
                    abs(surf_sig_imp.fa_spectrum),
                    c=cbox(0))
        sps[1].plot(surf_sig.fa_frequencies,
                    abs(surf_sig.fa_spectrum),
                    c=cbox(2),
                    ls='--')
        sps[1].set_xlim([0, 20])
        pysra_h = pysra_sig.smooth_fa_spectrum / in_sig.smooth_fa_spectrum
        sps[2].plot(pysra_sig.smooth_fa_frequencies, pysra_h, c=cbox(1))

        h = surf_sig_imp.smooth_fa_spectrum / in_sig.smooth_fa_spectrum
        sps[2].plot(in_sig.smooth_fa_frequencies, h, c=cbox(0))
        h = surf_sig.smooth_fa_spectrum / in_sig.smooth_fa_spectrum
        sps[2].plot(surf_sig.smooth_fa_frequencies, h, c=cbox(2), ls='--')

        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)

        xi_min, fmin = lq.num.flac.calc_rayleigh_damping_params(f1=freqs[0],
                                                                f2=freqs[1],
                                                                d=xi)
        omega_min = 2 * np.pi * fmin
        alpha = xi_min * 2 * np.pi * fmin  # mass proportional term
        beta = xi_min / omega_min  # stiffness proportional term
        fs = np.logspace(-1, 1.3, 30)
        omgs = 2 * np.pi * fs
        xi_vals = 0.5 * (alpha / omgs + beta * omgs)
        sps[2].plot(fs, xi_vals * 100, c='k')
        sps[2].axhline(1, c='k', ls='--')
        sps[2].set_ylim([0, 2])
        sps[0].legend()
        plt.show()
예제 #28
0
def run():
    soil_profile = sm.SoilProfile()
    soil_profile.height = 10.0
    xi = 0.03

    sl = gen_mz_toyoura_sand_dafalias_and_manzari_2004()
    sl.relative_density = 0.6
    sl.sra_type = 'linear'  # set hyperbolic
    soil_profile.add_layer(0.0, sl)
    sl.xi = xi

    # Define o3 soil object
    nu_init = 0.05
    f_order = 1.0
    soil_mat = o3.nd_material.ManzariDafalias(None,
                                              g0=sl.g0,
                                              nu=nu_init,
                                              e_init=sl.e_curr,
                                              m_c=sl.m_c,
                                              c_c=sl.c_c,
                                              lambda_c=sl.lambda_c,
                                              e_0=sl.e_0,
                                              ksi=sl.ksi,
                                              p_atm=sl.p_atm / f_order,
                                              m_yield=sl.m_yield,
                                              h_0=sl.h_0,
                                              c_h=sl.c_h,
                                              n_b=sl.n_b,
                                              a_0=sl.a_0,
                                              n_d=sl.n_d,
                                              z_max=sl.z_max,
                                              c_z=sl.c_z,
                                              den=sl.unit_dry_mass / f_order)
    sl.o3_mat = soil_mat

    sl_base = sm.Soil()
    vs = 350.
    unit_mass = 1700.0
    sl_base.g_mod = vs**2 * unit_mass
    sl_base.poissons_ratio = 0.0
    sl_base.unit_dry_weight = unit_mass * 9.8
    sl_base.xi = xi  # for linear analysis
    e_mod = 2 * sl_base.g_mod * (1 + sl_base.poissons_ratio)
    sl_base.sra_type = 'linear'
    sl_base.o3_mat = o3.nd_material.ElasticIsotropic(None,
                                                     e_mod=e_mod,
                                                     nu=sl_base.poissons_ratio,
                                                     rho=sl_base.unit_dry_mass)
    soil_profile.add_layer(8., sl_base)
    gm_scale_factor = 0.5
    record_filename = 'short_motion_dt0p01.txt'
    in_sig = eqsig.load_asig(ap.MODULE_DATA_PATH + 'gms/' + record_filename,
                             m=gm_scale_factor)

    # analysis with pysra
    od = lq.sra.run_pysra(soil_profile,
                          in_sig,
                          odepths=np.array([0.0]),
                          wave_field='within')
    pysra_sig = eqsig.AccSignal(od['ACCX'][0], in_sig.dt)

    import matplotlib.pyplot as plt
    from bwplot import cbox
    bf, sps = plt.subplots(nrows=3, figsize=(6, 8))

    in_sig.smooth_fa_frequencies = in_sig.fa_frequencies[1:]
    pysra_sig.smooth_fa_frequencies = in_sig.fa_frequencies[1:]
    sps[0].plot(in_sig.time, in_sig.values, c='k', label='Input')
    sps[0].plot(pysra_sig.time, pysra_sig.values, c='r', label='pysra')
    sps[1].plot(in_sig.fa_frequencies, abs(in_sig.fa_spectrum), c='k')
    sps[1].plot(pysra_sig.fa_frequencies, abs(pysra_sig.fa_spectrum), c='r')
    # pysra_h = pysra_sig.smooth_fa_spectrum / in_sig.smooth_fa_spectrum
    # sps[2].plot(pysra_sig.smooth_fa_frequencies, pysra_h, c='r')

    # analysis with O3
    etypes = [
        'implicit', 'explicit_difference', 'central_difference',
        'newmark_explicit'
    ]
    # etypes = ['central_difference']
    etypes = ['implicit']
    # etypes = ['explicit_difference']
    ls = ['-', '--', ':', '-.']
    outs = {'ACCX': [0], 'TAUXY': 'all', 'STRS': 'all'}
    for i, etype in enumerate(etypes):
        outputs_exp = site_response(soil_profile,
                                    in_sig,
                                    freqs=(0.5, 10),
                                    xi=xi,
                                    etype=etype,
                                    outs=outs)
        resp_dt = outputs_exp['time'][2] - outputs_exp['time'][1]
        surf_sig = eqsig.AccSignal(outputs_exp['ACCX'][0], resp_dt)
        surf_sig.smooth_fa_frequencies = in_sig.fa_frequencies[1:]
        sps[0].plot(surf_sig.time,
                    surf_sig.values,
                    c=cbox(i),
                    label=etype,
                    ls=ls[i])
        sps[1].plot(surf_sig.fa_frequencies,
                    abs(surf_sig.fa_spectrum),
                    c=cbox(i),
                    ls=ls[i])
        # h = surf_sig.smooth_fa_spectrum / in_sig.smooth_fa_spectrum
        # sps[2].plot(surf_sig.smooth_fa_frequencies, h, c=cbox(i), ls=ls[i])
        sps[2].plot(outputs_exp['STRS'][6], outputs_exp['TAUXY'][6])

    # sps[2].axhline(1, c='k', ls='--')
    sps[1].set_xlim([0, 20])

    sps[0].legend(prop={'size': 6})
    plt.show()