def test_hh_param_multi_layer__ensure_identical_objects_from_file_or_array(
         self):
     HH_x = HH_Param_Multi_Layer(_join(f_dir, 'HH_X_FKSH14.txt'))
     HH_x_array = np.genfromtxt(_join(f_dir, 'HH_X_FKSH14.txt'))
     HH_x_from_array = HH_Param_Multi_Layer(HH_x_array)
     self.assertTrue(
         np.allclose(HH_x.serialize_to_2D_array(),
                     HH_x_from_array.serialize_to_2D_array()))
    def test_nonlinear(self):
        accel_data = np.genfromtxt('./files/sample_accel.txt')
        accel_downsample = accel_data[::50]  # for faster testing speed
        gm = Ground_Motion(accel_downsample, unit='gal')
        prof = Vs_Profile('./files/profile_FKSH14.txt')
        hh_g = HH_Param_Multi_Layer('./files/HH_G_FKSH14.txt')
        hh_x = HH_Param_Multi_Layer('./files/HH_X_FKSH14.txt')
        sim = Nonlinear_Simulation(prof, gm, G_param=hh_g, xi_param=hh_x)

        batch_sim = Batch_Simulation([sim])
        options = dict(show_fig=False, save_txt=False, remove_sim_dir=True)

        non_par_results = batch_sim.run(parallel=False, options=options)
        par_results = batch_sim.run(parallel=True, n_cores=2, options=options)

        accel_out_0_non_par = non_par_results[0].accel_on_surface.accel
        accel_out_0_par = par_results[0].accel_on_surface.accel

        self.assertTrue(
            np.allclose(accel_out_0_non_par,
                        accel_out_0_par,
                        atol=0.0,
                        rtol=1e-3))
    def test_check_layer_count(self):
        # Case 1(a): normal case, with parameters
        vs_profile = Vs_Profile('./files/profile_FKSH14.txt')
        HH_G = HH_Param_Multi_Layer('./files/HH_G_FKSH14.txt')
        HH_x = HH_Param_Multi_Layer('./files/HH_X_FKSH14.txt')
        sim.check_layer_count(vs_profile, G_param=HH_G, xi_param=HH_x)

        # Case 1(b): normal case, with curves
        curves_data = np.genfromtxt('./files/curve_FKSH14.txt')
        mgdc = Multiple_GGmax_Damping_Curves(data=curves_data)
        sim.check_layer_count(vs_profile, GGmax_and_damping_curves=mgdc)

        # Case 2(a): abnormal case, with parameters
        del HH_G[-1]
        with self.assertRaises(ValueError,
                               msg='Not enough sets of parameters'):
            sim.check_layer_count(vs_profile, G_param=HH_G)

        # Case 2(b): abnormal case, with curves
        curves_data_ = curves_data[:, :-4]
        with self.assertRaises(ValueError, msg='Not enough sets of curves'):
            mgdc_ = Multiple_GGmax_Damping_Curves(data=curves_data_)
            sim.check_layer_count(vs_profile, GGmax_and_damping_curves=mgdc_)
Exemplo n.º 4
0
    def test_construct_curves(self):
        HH_G = HH_Param_Multi_Layer('./files/HH_G_FKSH14.txt')
        mgc, _ = HH_G.construct_curves()
        curves = mgc.get_curve_matrix()
        self.assertEqual(mgc.n_layer, HH_G.n_layer)
        self.assertEqual(curves.shape[1], HH_G.n_layer * 4)

        HH_x = HH_Param_Multi_Layer('./files/HH_X_FKSH14.txt')
        _, mdc = HH_x.construct_curves()
        curves = mdc.get_curve_matrix()
        self.assertEqual(mdc.n_layer, HH_x.n_layer)
        self.assertEqual(curves.shape[1], HH_x.n_layer * 4)

        H4_G = MKZ_Param_Multi_Layer('./files/H4_G_IWTH04.txt')
        mgc, _ = H4_G.construct_curves()
        curves = mgc.get_curve_matrix()
        self.assertEqual(mgc.n_layer, H4_G.n_layer)
        self.assertEqual(curves.shape[1], H4_G.n_layer * 4)

        H4_x = MKZ_Param_Multi_Layer('./files/H4_x_IWTH04.txt')
        mgc, mdc = H4_x.construct_curves()
        curves = mdc.get_curve_matrix()
        self.assertEqual(mdc.n_layer, H4_x.n_layer)
        self.assertEqual(curves.shape[1], H4_x.n_layer * 4)
 def test_serialize_to_2D_array__from_HH_x_parameters(self):
     HH_x = HH_Param_Multi_Layer(_join(f_dir, 'HH_X_FKSH14.txt'))
     HH_x_2D_array = HH_x.serialize_to_2D_array()
     HH_x_2D_array_bench = np.genfromtxt(_join(f_dir, 'HH_X_FKSH14.txt'))
     self.assertTrue(np.allclose(HH_x_2D_array, HH_x_2D_array_bench))
 def test_construct_curves__from_HH_x_parameters(self):
     HH_x = HH_Param_Multi_Layer(_join(f_dir, 'HH_X_FKSH14.txt'))
     _, mdc = HH_x.construct_curves()
     curves = mdc.get_curve_matrix()
     self.assertEqual(mdc.n_layer, HH_x.n_layer)
     self.assertEqual(curves.shape[1], HH_x.n_layer * 4)
 def test_construct_curves__from_HH_G_parameters(self):
     HH_G = HH_Param_Multi_Layer(_join(f_dir, 'HH_G_FKSH14.txt'))
     mgc, _ = HH_G.construct_curves()
     curves = mgc.get_curve_matrix()
     self.assertEqual(mgc.n_layer, HH_G.n_layer)
     self.assertEqual(curves.shape[1], HH_G.n_layer * 4)
 def test_hh_param_multi_layer__test_list_operations(self):
     HH_x = HH_Param_Multi_Layer(_join(f_dir, 'HH_X_FKSH14.txt'))
     del HH_x[3]
     self.assertEqual(len(HH_x), 4)
     self.assertEqual(len(HH_x), 4)
 def test_hh_param_multi_layer__can_initiate_an_object_from_a_2D_array(
         self):
     HH_x_array = np.genfromtxt(_join(f_dir, 'HH_X_FKSH14.txt'))
     HH_x_from_array = HH_Param_Multi_Layer(HH_x_array)
     self.assertEqual(len(HH_x_from_array), 5)
     self.assertEqual(HH_x_from_array.n_layer, 5)
 def test_hh_param_multi_layer__can_initiate_an_object_from_a_file(self):
     HH_x = HH_Param_Multi_Layer(_join(f_dir, 'HH_X_FKSH14.txt'))
     self.assertEqual(len(HH_x), 5)
     self.assertEqual(HH_x.n_layer, 5)