예제 #1
0
def test_save_load_w_diff_wmd():
    sl = lq.num.models.ManzariDafaliasModel(liq_mass_density=1., p_atm=101.)
    sl.e_curr = 0.8
    sl.g0 = 125
    sl.poissons_ratio = 0.3

    sl.m_c = 1.214  # From Cubrinovski 1998
    sl.c_c = 0.712
    sl.lambda_c = 0.019
    sl.e_0 = 0.934
    sl.ksi = 0.7
    sl.p_atm = 101
    sl.m_yield = 0.01
    sl.h_0 = 7.05
    sl.c_h = 0.968
    sl.n_b = 1.1
    sl.a_0 = 0.704
    sl.n_d = 3.5
    sl.z_max = 4
    sl.c_z = 600
    sl.specific_gravity = 2.65
    print(sl.unit_dry_weight)
    sl.cohesion = 0

    eo = sm.Output()
    eo.add_to_dict(sl)
    p_str = json.dumps(eo.to_dict(), indent=4)
    mods = sm.loads_json(
        p_str,
        {'soil-manzaridafalias_model': lq.num.models.ManzariDafaliasModel})
예제 #2
0
def test_save_and_load_building():
    number_of_storeys = 6
    interstorey_height = 3.4  # m
    masses = 40.0e3  # kg
    n_bays = 3

    fb = models.FrameBuilding(number_of_storeys, n_bays)
    fb.id = 1
    fb.interstorey_heights = interstorey_height * np.ones(number_of_storeys)
    fb.floor_length = 18.0  # m
    fb.floor_width = 16.0  # m
    fb.storey_masses = masses * np.ones(number_of_storeys)  # kg

    fb.bay_lengths = [6., 6.0, 6.0]
    fb.set_beam_prop("depth", [0.5, 0.5, 0.5], repeat="up")
    fb.set_beam_prop("width", [0.4, 0.4, 0.4], repeat="up")
    fb.set_column_prop("width", [0.5, 0.5, 0.5, 0.5], repeat="up")
    fb.set_column_prop("depth", [0.5, 0.5, 0.5, 0.5], repeat="up")
    fb.n_seismic_frames = 3
    fb.n_gravity_frames = 0

    ecp_output = sm.Output()
    ecp_output.add_to_dict(fb)

    ecp_output.name = "a single soil"
    ecp_output.units = "N, kg, m, s"
    ecp_output.comments = ""
    p_d = ecp_output.to_dict()
    p_str = json.dumps(ecp_output.to_dict(), skipkeys=["__repr__"], indent=4)
    mods = sm.loads_json(p_str)
    bd2 = mods['building'][1]
    print(bd2)
예제 #3
0
def test_save_and_load_soil():
    # Set the void ratio and specific gravity
    sl = sm.Soil()
    sl.id = 1
    sl.e_curr = 0.7
    assert sl.unit_dry_weight is None
    sl.specific_gravity = 2.95
    assert np.isclose(sl.unit_dry_weight, 17000, rtol=0.01)

    # set modulus parameters
    g_mod_set = 40e6
    sl.g_mod = g_mod_set
    sl.poissons_ratio = 0.4
    ecp_output = sm.Output()
    ecp_output.add_to_dict(sl)

    ecp_output.name = "a single soil"
    ecp_output.units = "N, kg, m, s"
    ecp_output.comments = ""
    p_str = json.dumps(ecp_output.to_dict(), skipkeys=["__repr__"], indent=4)
    a = open("temp.json", "w")
    a.write(p_str)
    a.close()
    objs = sm.loads_json(p_str, verbose=0)
    loaded_soil = objs['soils'][1]
    assert np.isclose(loaded_soil.g_mod, sl.g_mod)
예제 #4
0
def test_save_and_load_soil_w_diff_wmd():  # deprecated
    sl = models.Soil(wmd=1.0)
    sl.e_curr = 0.65
    sl.specific_gravity = 2.65
    ecp_output = sm.Output()
    ecp_output.add_to_dict(sl)
    p_str = json.dumps(ecp_output.to_dict(), indent=4)
    objs = sm.loads_json(p_str)

    sl = models.StressDependentSoil(wmd=1.0, p_atm=101.0)
    sl.e_curr = 0.65
    sl.specific_gravity = 2.65

    ecp_output = sm.Output()
    ecp_output.add_to_dict(sl)
    p_str = json.dumps(ecp_output.to_dict(), indent=4)
    objs = sm.loads_json(p_str)
예제 #5
0
def test_save_and_load_soil_w_diff_liq_mass_density():
    sl = models.Soil(liq_mass_density=1.0)
    sl.e_curr = 0.65
    sl.specific_gravity = 2.65
    ecp_output = sm.Output()
    ecp_output.add_to_dict(sl)
    p_str = json.dumps(ecp_output.to_dict(), indent=4)
    print(p_str)
    objs = sm.loads_json(p_str)
예제 #6
0
def test_can_set_more_than_two_positional_args():
    c3 = Custom3Req(1, 3, 5)
    c3.id = 1
    ecp_output = sm.Output()
    ecp_output.add_to_dict(c3)
    p_str = json.dumps(ecp_output.to_dict(), skipkeys=["__repr__"], indent=4)
    objs = sm.loads_json(p_str, custom={"custom_object-custom3": Custom3Req})
    cus = objs["custom_object"][1]
    assert cus.p2 == 3
    assert cus.p3 == 5
예제 #7
0
def test_save_and_load_an_element():
    ele = models.buildings.BeamColumnElement()
    ele.sections = [models.sections.RCBeamSection()]
    ele.set_section_prop('width', 0.5)
    ecp_output = sm.Output()
    ecp_output.add_to_dict(ele)
    p_str = json.dumps(ecp_output.to_dict(), skipkeys=["__repr__"], indent=4)
    mods = sm.loads_json(p_str)
    ele2 = mods['beam_column_element'][1]
    s2 = mods['section'][1]
    assert ele2.s[0].width == 0.5, ele2.s[0].width
    assert s2.width == 0.5
예제 #8
0
def test_save_and_load_two_soil_profiles():
    sl = models.Soil(liq_mass_density=1.0)
    sl.e_curr = 0.65
    sl.specific_gravity = 2.65
    sp = models.SoilProfile()
    sp.add_layer(0, sl)
    sp.add_layer(2, sl)
    sp2 = sp.deepcopy()
    sp2.move_layer(3, 2)
    ecp_output = sm.Output()
    ecp_output.add_to_dict(sp)
    ecp_output.add_to_dict(sp2)
    p_str = json.dumps(ecp_output.to_dict(), indent=4)
    objs = sm.loads_json(p_str)
    assert len(objs['soil_profile']) == 2
예제 #9
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
예제 #10
0
def test_save_and_load_2d_frame_building():
    number_of_storeys = 6
    interstorey_height = 3.4  # m
    masses = 40.0e3  # kg
    n_bays = 3

    fb2d = models.FrameBuilding2D(number_of_storeys, n_bays)
    fb2d.n_storeys = 6
    fb2d.id = 1
    fb2d.interstorey_heights = interstorey_height * np.ones(number_of_storeys)
    fb2d.floor_length = 18.0  # m
    fb2d.floor_width = 16.0  # m
    fb2d.storey_masses = masses * np.ones(number_of_storeys)  # kg

    fb2d.bay_lengths = [6., 6.0, 6.0]
    fb2d.set_beam_prop("depth", [0.5, 0.6, 0.5], repeat="up")
    fb2d.set_beam_prop("width", [0.4, 0.4, 0.4], repeat="up")
    fb2d.set_column_prop("width", [0.5, 0.5, 0.5, 0.5], repeat="up")
    fb2d.set_column_prop("depth", [0.5, 0.5, 0.5, 0.5], repeat="up")
    fb2d.beams[0][0].set_section_prop('a_custom_property', 11)
    fb2d.beams[0][0].add_inputs_to_section(["a_custom_property"])

    ecp_output = sm.Output()
    ecp_output.add_to_dict(fb2d)

    ecp_output.name = "a single building"
    ecp_output.units = "N, kg, m, s"
    ecp_output.comments = ""
    p_d = ecp_output.to_dict()
    p_str = json.dumps(ecp_output.to_dict(), skipkeys=["__repr__"], indent=4)
    a = open("temp.json", "w")
    a.write(p_str)
    a.close()

    objs = sm.loads_json(p_str)
    building = objs["buildings"][1]
    assert np.isclose(building.beams[0][0].sections[0].depth,
                      0.5), building.beams[0][0].sections[0].depth
    assert np.isclose(building.beams[0][1].sections[0].depth, 0.6)

    assert building.beams[0][0].s[0].a_custom_property == 11, building.beams[
        0][0].sections[0].a_custom_property
    assert np.isclose(building.columns[0][0].sections[0].depth, 0.5)
예제 #11
0
def test_save_and_load_soil_profile():
    sl1 = models.Soil()
    sl1_gmod = 30e6
    sl1_unit_dry_weight = 16000
    sl1.g_mod = sl1_gmod
    sl1.unit_dry_weight = sl1_unit_dry_weight
    sl2 = models.Soil()
    sl2_cohesion = 20e3
    sl2.cohesion = sl2_cohesion
    sp = models.SoilProfile()
    sp.id = 0
    sp.add_layer(0, sl1)
    sp.add_layer(3, sl2)
    sp.set_soil_ids_to_layers()
    ecp_output = sm.Output()
    ecp_output.add_to_dict(sp, export_none=False)
    p_str = ecp_output.to_str()
    objs = sm.loads_json(p_str, verbose=0)
    loaded_soil = objs['soils'][1]
    load_soil_from_profile = sp.layer(1)
    assert np.isclose(loaded_soil.g_mod, sl1.g_mod)
    assert np.isclose(load_soil_from_profile.g_mod, sl1.g_mod)
예제 #12
0
def test_save_and_load_w_linked_building_and_soil():
    number_of_storeys = 6
    interstorey_height = 3.4  # m

    wb = models.WallBuilding(number_of_storeys)
    wb.id = 1
    wb.interstorey_heights = interstorey_height * np.ones(number_of_storeys)
    wb.floor_length = 18.0  # m
    wb.floor_width = 16.0  # m

    fd = models.RaftFoundation()
    fd.length = 4
    fd.width = 6
    fd.height = 0.0
    fd.density = 3
    fd.id = 1

    # link building to foundation
    fd.set_building(wb, two_way=False)
    assert fd.building.n_storeys == number_of_storeys
    assert wb.foundation is None
    fd.set_building(wb, two_way=True)
    assert wb.foundation.length == 4

    ecp_output = sm.Output()
    ecp_output.add_to_dict(wb)
    ecp_output.add_to_dict(fd)

    ecp_output.name = "a single wall building"
    ecp_output.units = "N, kg, m, s"
    ecp_output.comments = ""
    p_str = json.dumps(ecp_output.to_dict(), skipkeys=["__repr__"], indent=4)
    objs = sm.loads_json(p_str)
    building = objs["building"][1]
    foundation = objs["foundation"][1]
    assert foundation.width == 6
    assert building.foundation.width == 6, building.fd
    assert np.isclose(building.floor_length, 18.0)
예제 #13
0
def test_save_and_load_wall_building():
    number_of_storeys = 6
    interstorey_height = 3.4  # m
    masses = 40.0e3  # kg
    n_bays = 3

    fb = models.WallBuilding(number_of_storeys)
    fb.id = 1
    fb.interstorey_heights = interstorey_height * np.ones(number_of_storeys)
    fb.floor_length = 18.0  # m
    fb.floor_width = 16.0  # m
    fb.storey_masses = masses * np.ones(number_of_storeys)  # kg

    ecp_output = sm.Output()
    ecp_output.add_to_dict(fb)

    ecp_output.name = "a single wall building"
    ecp_output.units = "N, kg, m, s"
    ecp_output.comments = ""
    p_str = json.dumps(ecp_output.to_dict(), skipkeys=["__repr__"], indent=4)
    objs = sm.loads_json(p_str)
    building = objs["buildings"][1]
    assert np.isclose(building.floor_length, 18.0)
예제 #14
0
def test_save_and_load_soil_profile_w_and_wo_none():
    sl1 = models.Soil()
    sl1_gmod = 30e6
    sl1_unit_dry_weight = 16000
    sl1.g_mod = sl1_gmod
    sl1.unit_dry_weight = sl1_unit_dry_weight
    sl2 = models.Soil()
    sl2_cohesion = 20e3
    sl2.cohesion = sl2_cohesion
    sp = models.SoilProfile()
    sp.id = 0
    sp.add_layer(0, sl1)
    sp.add_layer(3, sl2)
    sp.set_soil_ids_to_layers()
    ecp_output_verby = sm.Output()
    ecp_output_verby.add_to_dict(sp, export_none=True)
    p_str = json.dumps(ecp_output_verby.to_dict(),
                       skipkeys=["__repr__"],
                       indent=4)
    assert 'e_min' in p_str
    ecp_output = sm.Output()
    ecp_output.add_to_dict(sp, export_none=False)

    ecp_output.name = "a single soil"
    ecp_output.units = "N, kg, m, s"
    ecp_output.comments = ""
    p_str = json.dumps(ecp_output.to_dict(), skipkeys=["__repr__"], indent=4)
    assert 'e_min' not in p_str
    a = open("temp.json", "w")
    a.write(p_str)
    a.close()
    objs = sm.loads_json(p_str, verbose=0)
    loaded_soil = objs['soils'][1]
    load_soil_from_profile = sp.layer(1)
    assert np.isclose(loaded_soil.g_mod, sl1.g_mod)
    assert np.isclose(load_soil_from_profile.g_mod, sl1.g_mod)