def test_soil_profile_vertical_total_stress_w_surface_layer(): soil_1 = models.Soil() soil_1.phi = 33. soil_1.cohesion = 50000 soil_1.unit_dry_weight = 18000 soil_profile = models.SoilProfile() soil_profile.add_layer(-3, sm.Soil()) soil_profile.add_layer(-1, soil_1) sl = soil_profile.layer(1) assert np.isclose(soil_profile.get_v_total_stress_at_depth(5), 5 * 18000, rtol=0.0001) soil_profile.gwl = 3. assert np.isclose(soil_profile.get_v_total_stress_at_depth(3), 3 * 18000, rtol=0.0001) with pytest.raises(exceptions.AnalysisError): soil_profile.get_v_eff_stress_at_depth(4) sl_id = soil_profile.get_layer_index_by_depth(1.5) soil_profile.layer(sl_id).unit_sat_weight = 21000 expected = 3 * 18000 + 2 * 21000 assert np.isclose(soil_profile.get_v_total_stress_at_depth(5), expected, rtol=0.0001) soil_2 = models.Soil() soil_2.phi = 33. soil_2.cohesion = 50000 soil_2.unit_dry_weight = 16000 # CONSIDER TWO LAYER SOIL PROFILE soil_profile.add_layer(4., soil_2) soil_profile.gwl = 10000 # Dry first assert np.isclose(soil_profile.get_v_total_stress_at_depth(5), 4 * 18000 + 1 * 16000, rtol=0.0001) soil_profile.gwl = 3. with pytest.raises(exceptions.AnalysisError): soil_profile.get_v_eff_stress_at_depth(5) sl_id = soil_profile.get_layer_index_by_depth(4.5) soil_profile.layer(sl_id).unit_sat_weight = 20000 expected = 3 * 18000 + 1 * 21000 + 1 * 20000 assert np.isclose(soil_profile.get_v_total_stress_at_depth(5), expected, rtol=0.0001)
def test_can_move_layer(): sl1 = models.Soil() sl2 = models.Soil() sp = models.SoilProfile() sp.add_layer(0.0, sl1) sp.add_layer(3.0, sl2) assert sp.get_layer_depth(2) == 3.0 sp.move_layer(4.0, 2) assert sp.get_layer_depth(2) == 4.0
def test_set_soil_ids_in_soil_profile(): sl1 = models.Soil() sl2 = models.Soil() sp = models.SoilProfile() sp.add_layer(0, sl1) sp.add_layer(3, sl2) assert sp.layer(2).id is None sp.set_soil_ids_to_layers() assert sp.layer(2).id == 2
def test_karamitros(): # Load ground motion fpath = TEST_DATA_DIR + "input_acc.his" acc_file = np.loadtxt(fpath, skiprows=4) acc = acc_file[:, 1] # define the soils and soil profile sl_0 = sm.Soil() sl_0.phi = 0 sl_0.cohesion = 50000 sl_0.unit_dry_weight = 19600 sl_0.unit_sat_weight = 21000 sl_1 = sm.Soil() sl_1.phi = 33. sl_1.cohesion = 0 sl_1.unit_dry_weight = 19700 sl_1.unit_sat_weight = 21000 soil_profile = sm.SoilProfile() soil_profile.add_layer(0, sl_0) soil_profile.add_layer(4.0, sl_1) soil_profile.gwl = 2. # Define a foundation length = 1000000. fd = sm.Foundation() fd.length = length fd.width = 10.0 fd.depth = 0.0 q = 80000 # applied load z_c = lqs.cal_z_c(fd, z_liq=4, h0=2) vertical_effective_stress = soil_profile.get_v_eff_stress_at_depth(z_c) phi_deg = lqs.calc_degraded_phi(sl_1.phi, vertical_effective_stress, q=q) assert np.isclose(phi_deg, 9.9275389), phi_deg # Not validated sl_1.phi = phi_deg q_ult = gf.capacity_meyerhof_and_hanna_1978(sl_0, sl_1, h0=2, fd=fd, verbose=0) assert np.isclose(q_ult, 107350.07398), q_ult # Not validated dt = 0.005 sett_dyn = lqs.karamitros_settlement(fd, z_liq=4, q=80000, q_ult=q_ult, acc=acc, dt=dt) assert np.isclose( sett_dyn, 0.03242937, rtol=0.001), sett_dyn # 0.03242937 Not validated, liquepy 0.1.11
def test_get_layer_index_by_depth(): sl1 = models.Soil() sl2 = models.Soil() sp = models.SoilProfile() sp.add_layer(0, sl1) sp.add_layer(3, sl2) assert sp.get_layer_index_by_depth(0) == 1 assert sp.get_layer_index_by_depth(1) == 1 assert sp.get_layer_index_by_depth(3) == 2 assert sp.get_layer_index_by_depth(4) == 2
def test_non_water_liquid(): sl0 = models.Soil(liq_mass_density=1.0e3, unit_dry_weight=16000., e_curr=0.55) sl1 = models.Soil(liq_mass_density=1.1e3, liq_sg=1.1, unit_dry_weight=16000., e_curr=0.55) assert np.isclose(sl0.specific_gravity, sl1.specific_gravity), (sl0.specific_gravity, sl1.specific_gravity) assert not np.isclose(sl0.unit_sat_weight, sl1.unit_sat_weight), (sl0.unit_sat_weight, sl1.unit_sat_weight) sl1.override('liq_sg', 1.0) assert np.isclose(sl0.unit_sat_weight, sl1.unit_sat_weight), (sl0.unit_sat_weight, sl1.unit_sat_weight) sl0 = models.Soil(liq_mass_density=1.0e3, unit_sat_weight=20000., e_curr=0.55) sl1 = models.Soil(liq_mass_density=1.1e3, unit_sat_weight=20000., e_curr=0.55) assert not np.isclose(sl0.specific_gravity, sl1.specific_gravity), (sl0.specific_gravity, sl1.specific_gravity) assert not np.isclose(sl0.unit_dry_weight, sl1.unit_dry_weight), (sl0.unit_sat_weight, sl1.unit_sat_weight)
def test_poissons_ratio_again(): soil = models.Soil() g_mod = 60000000.0 bulk_mod = 87142857.14285 poissons_ratio = 0.22 soil.g_mod = g_mod soil.bulk_mod = bulk_mod soil.poissons_ratio = poissons_ratio soil2 = models.Soil() soil2.bulk_mod = bulk_mod soil2.g_mod = g_mod soil2.poissons_ratio = poissons_ratio
def test_can_replace_layers(): sl1 = models.Soil() sl2 = models.Soil() sl2.g_mod = 2.0 sl3 = models.Soil() sl3.g_mod = 3.0 sp = models.SoilProfile() sp.add_layer(0.0, sl1) sp.add_layer(3.0, sl2) assert np.isclose(sp.layer(2).g_mod, 2.0) sp.replace_layer(2, sl3) assert np.isclose(sp.layer(2).g_mod, 3.0)
def test_get_parameter_at_depth_in_soil_profile(): sl1 = models.Soil() sl1_gmod = 30e6 sl1.g_mod = sl1_gmod sl2 = models.Soil() sl2_cohesion = 20e3 sl2.cohesion = sl2_cohesion sp = models.SoilProfile() sp.add_layer(0, sl1) sp.add_layer(3, sl2) assert np.isclose(sp.get_parameter_at_depth(2, 'g_mod'), sl1_gmod) assert sp.get_parameter_at_depth(4, 'g_mod') is None assert np.isclose(sp.get_parameter_at_depth(4, 'cohesion'), sl2_cohesion) assert sp.get_parameter_at_depth(2, 'cohesion') is None
def test_moist_weight_setter(): sl = models.Soil() sl.unit_dry_weight = 17000 sl.e_curr = 0.7 assert sl.saturation is None sl.unit_moist_weight = 18000 assert np.isclose(sl.saturation, 0.248, 0.01)
def test_inputs_soil(): sl = models.Soil() assert "g_mod" in sl.inputs assert "e_cr0" not in sl.inputs crit_sl = models.CriticalSoil() assert "g_mod" in crit_sl.inputs assert "e_cr0" in crit_sl.inputs
def test_soil_profile_split_complex_stress_dependent(): sl1 = models.Soil() sl1_gmod = 40e6 sl1_unit_dry_weight = 16000 sl1.g_mod = sl1_gmod sl1.unit_dry_weight = sl1_unit_dry_weight sl2 = models.StressDependentSoil() sl2.poissons_ratio = 0.33 sp = models.SoilProfile() sp.add_layer(0, sl1) sp.add_layer(3, sl2) sp.height = 5 with pytest.raises(ValueError): sp.gen_split(props=["shear_vel"]) sl2.unit_dry_weight = 17000 sp.gen_split(props=["shear_vel"]) assert len(sp.split['thickness']) == len(sp.split['shear_vel']) assert None in sp.split['shear_vel'] sl2.g0_mod = 501 sp.layer(2).unit_dry_weight = sl1_unit_dry_weight sp.gen_split(props=["shear_vel"]) assert None not in sp.split['shear_vel']
def test_void_ratio_setter(): sl = models.Soil() sl.unit_dry_weight = 17000 assert sl.specific_gravity is None sl.e_curr = 0.7 assert np.isclose(sl.specific_gravity, 2.949, rtol=0.01) # check that unit_dry_weight is still consistent sl.unit_dry_weight = 17000
def test_load_nan(): sl = models.Soil(pw=None) sl.g_mod = "" sl.bulk_mod = "" sl.g_mod = None for item in sl.inputs: setattr(sl, item, "") setattr(sl, item, None)
def test_relative_density_to_e_min_setter(): sl = models.Soil() sl.e_max = 1.0 sl.e_curr = 0.76 assert sl.e_min is None sl.relative_density = 0.4 e_min = 0.4 assert np.isclose(sl.e_min, e_min, rtol=0.01), sl.e_min # reverse sl = models.Soil() sl.e_max = 1.0 sl.e_curr = 0.76 assert sl.relative_density is None relative_density = 0.4 sl.e_min = 0.4 assert np.isclose(sl.relative_density, relative_density, rtol=0.01), sl.relative_density
def test_saturation_setter_on_soil(): sl = models.Soil() sl.unit_dry_weight = 17000 sl.e_curr = 0.7 assert np.isclose(sl.unit_sat_weight, 21035.3, rtol=0.01) assert sl.saturation is None assert sl.unit_moist_weight is None sl.saturation = 1.0 assert np.isclose(sl.unit_moist_weight, 21035.3, rtol=0.01)
def test_specific_gravity_setter(): # void ratio then specific gravity sl = models.Soil() 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) # check that void ratio is still consistent sl.e_curr = 0.7 # specific gravity then void ratio sl = models.Soil() sl.specific_gravity = 2.95 assert sl.unit_dry_weight is None sl.e_curr = 0.7 assert np.isclose(sl.unit_dry_weight, 17000, rtol=0.01) # check that specific gravity is still consistent sl.specific_gravity = 2.95
def test_reset_all(): from tests import load_test_data as ltd soil = models.Soil() ltd.load_soil_test_data(soil) soil.reset_all() exception_list = ["base_type", "type", "stype"] for item in soil.inputs: if item not in exception_list: assert getattr(soil, item) is None
def test_relative_density_to_e_curr_setter(): sl = models.Soil() sl.e_max = 1.0 sl.e_min = 0.4 assert sl.e_curr is None sl.relative_density = 0.4 # expected_void_ratio = sl.e_max - sl.relative_density * (sl.e_max - sl.e_min) expected_void_ratio = 0.76 assert np.isclose(sl.e_curr, expected_void_ratio, rtol=0.01), sl.e_curr # reverse sl = models.Soil() sl.e_max = 1.0 sl.e_min = 0.4 assert sl.relative_density is None sl.e_curr = 0.76 # expected_void_ratio = sl.e_max - sl.relative_density * (sl.e_max - sl.e_min) expected_relative_density = 0.4 assert np.isclose(sl.relative_density, expected_relative_density, rtol=0.01), sl.e_curr
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)
def test_hydrostatic_pressure(): soil_1 = models.Soil() soil_1.phi = 33. soil_1.cohesion = 50000 soil_1.unit_dry_weight = 18000 soil_2 = models.Soil() soil_2.phi = 33. soil_2.cohesion = 50000 soil_2.unit_dry_weight = 18000 soil_profile = models.SoilProfile() soil_profile.add_layer(0, soil_1) soil_profile.add_layer(5., soil_2) z_c = 5.0 gwl = 4.0 soil_profile.gwl = gwl assert soil_1.unit_sat_weight is None assert np.isclose(soil_profile.get_hydrostatic_pressure_at_depth(2), 0.0, rtol=0.0001) assert np.isclose(soil_profile.get_hydrostatic_pressure_at_depth(z_c), 9800, rtol=0.0001)
def test_relative_density_to_e_max_setter(): sl = models.Soil() sl.e_min = 0.4 sl.e_curr = 0.76 assert sl.e_max is None sl.relative_density = 0.4 e_max = 1.0 actual = sl.e_max assert np.isclose(sl.e_max, e_max, rtol=0.01), actual # reverse sl = models.Soil() sl.e_min = 0.4 sl.e_curr = 0.76 assert sl.relative_density is None relative_density = 0.4 sl.e_max = 1.0 actual = sl.relative_density assert np.isclose(sl.relative_density, relative_density, rtol=0.01), actual
def test_add_layer_to_soil_profile(): soil_profile = models.SoilProfile() soil = models.Soil() soil_profile.add_layer(3, soil) soil_profile.add_layer(5, soil) soil_profile.add_layer(2.5, soil) layer_order = [2.5, 3, 5] ind = 0 for layer in soil_profile.layers: assert layer == layer_order[ind] ind += 1
def test_soil_profile_split_simple_prop(): 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.add_layer(0, sl1) sp.add_layer(3, sl2) sp.height = 5 sp.gen_split(props=["cohesion"]) assert len(sp.split['thickness']) == len(sp.split['cohesion']) assert None in sp.split['cohesion'] sl1.cohesion = 0.0 sp.gen_split(props=["cohesion"]) assert np.max(sp.split["cohesion"]) == 20e3
def test_get_soil_at_depth_in_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.add_layer(0, sl1) sp.add_layer(3, sl2) sl_at_2 = sp.get_soil_at_depth(2) sl_at_4 = sp.get_soil_at_depth(4) assert np.isclose(sl_at_2.g_mod, sl1_gmod) assert np.isclose(sl_at_2.unit_dry_weight, sl1_unit_dry_weight) assert sl_at_2.cohesion is None assert sl_at_4.g_mod is None assert sl_at_4.unit_dry_weight is None assert np.isclose(sl_at_4.cohesion, sl2_cohesion)
def test_get_parameters_at_depth_in_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.add_layer(0, sl1) sp.add_layer(3, sl2) vals_at_2 = sp.get_parameters_at_depth(2, ['g_mod', 'unit_dry_weight', 'cohesion']) vals_at_4 = sp.get_parameters_at_depth(4, ['g_mod', 'unit_dry_weight', 'cohesion']) assert np.isclose(vals_at_2['g_mod'], sl1_gmod) assert np.isclose(vals_at_2['unit_dry_weight'], sl1_unit_dry_weight) assert vals_at_2['cohesion'] is None assert vals_at_4['g_mod'] is None assert vals_at_4['unit_dry_weight'] is None assert np.isclose(vals_at_4['cohesion'], sl2_cohesion)
def test_can_override_all(): from tests import load_test_data as ltd soil = models.Soil() ltd.load_soil_test_data(soil) soil.reset_all() for item in soil.inputs: soil2 = soil.deepcopy() value = getattr(soil, item) if value is not None and not isinstance(value, str): soil2.override(item, value * 1.3) assert getattr(soil2, item) == value * 1.3
def test_model_inputs(): p_models = [ dm.SeismicHazard(), dm.FrameBuilding(1, 2), dm.WallBuilding(1), dm.Soil(), dm.materials.ReinforcedConcreteMaterial() ] for model in p_models: for parameter in model.inputs: assert hasattr(model, parameter), parameter
def test_saturation_set_in_soil_profile(): sl = models.Soil() sl.id = 1 sl.relative_density = .40 # [decimal] sl.unit_dry_weight = 17000 # [N/m3] sp = models.SoilProfile() sp.hydrostatic = True sp.gwl = 4.0 sp.add_layer(0, sl) sp.add_layer(6, sl.deepcopy()) assert np.isclose(sp.layer(1).saturation, 0.00) assert np.isclose(sp.layer(2).saturation, 1.00) # Add a layer in between sl = models.Soil() sl.id = 2 sl.relative_density = .50 # [decimal] sl.unit_dry_weight = 18000 # [N/m3] sp.add_layer(2, sl) assert np.isclose(sp.layer(2).saturation, 0.50)
def test_e_max_to_saturated_weight_setter(): sl = models.Soil() sl.e_min = 0.4 sl.e_max = 1.0 sl.unit_dry_weight = 16000 assert sl.unit_sat_weight is None sl.e_curr = 0.76 assert sl.unit_sat_weight is not None sl.relative_density = 0.4 unit_sat_weight = 20231.818 assert np.isclose(sl.unit_sat_weight, unit_sat_weight, rtol=0.01), sl.unit_sat_weight