def compute_enriched_elements_new_pseudo(self, delta_t): """ Compute the new artificial viscosity of the enriched_cells :param delta_t: time_step """ mask = self.enriched if not mask.any(): return # Left part : density_left = self.density.current_value[mask] density_left_new = self.density.new_value[mask] sound_velocity_left = self.sound_velocity.current_value[mask] size_left = self.left_part_size.new_value[mask] pseudo_left = OneDimensionCell.compute_pseudo( delta_t, density_left, density_left_new, size_left, sound_velocity_left, self.data.numeric.a_pseudo, self.data.numeric.b_pseudo) # Right part : density_right = self.enr_density.current_value[mask] density_right_new = self.enr_density.new_value[mask] sound_velocity_right = self.enr_sound_velocity.current_value[mask] size_right = self.right_part_size.new_value[mask] pseudo_right = OneDimensionCell.compute_pseudo( delta_t, density_right, density_right_new, size_right, sound_velocity_right, self.data.numeric.a_pseudo, self.data.numeric.b_pseudo) self.pseudo.new_value[mask] = pseudo_left self.enr_artificial_viscosity.new_value[mask] = pseudo_right
def compute_enriched_elements_new_time_step(self): """ Compute the new local time step. The calculation is equivalent to a remeshing time step and thus underestimates the time step for the enriched cells """ cfl = self.data.numeric.cfl cfl_pseudo = self.data.numeric.cfl_pseudo mask = self.enriched # Left part density_left = self.density.current_value[mask] density_left_new = self.density.new_value[mask] sound_velocity_left_new = self.sound_velocity.new_value[mask] pseudo_left = self.pseudo.current_value[mask] pseudo_left_new = self.pseudo.new_value[mask] dt_g = OneDimensionCell.compute_time_step( cfl, cfl_pseudo, density_left, density_left_new, self.left_part_size.new_value[mask], sound_velocity_left_new, pseudo_left, pseudo_left_new) # Right part density_right = self.enr_density.current_value[mask] density_right_new = self.enr_density.new_value[mask] sound_velocity_right_new = self.enr_sound_velocity.new_value[mask] pseudo_right = self.enr_artificial_viscosity.current_value[mask] pseudo_right_new = self.enr_artificial_viscosity.new_value[mask] dt_d = OneDimensionCell.compute_time_step( cfl, cfl_pseudo, density_right, density_right_new, self.right_part_size.new_value[mask], sound_velocity_right_new, pseudo_right, pseudo_right_new) if mask.any(): self._dt[mask] = np.min(np.array([dt_g, dt_d]), axis=0)
def setUp(self): """ Test set up """ self.nbr_cells = 4 self.my_cells = OneDimensionCell(self.nbr_cells) self.my_cells.cell_in_target = np.ones(self.nbr_cells, dtype='bool') self.test_data = DataContainer() # pylint: disable=no-value-for-parameter
class OneDimensionCellInternalLibTest(unittest.TestCase): """ A class to test the call of eos solver with internal lib """ @classmethod def setUpClass(cls): """ Tests setup for class """ data_file_path = os.path.join( os.path.dirname(__file__), "../../../tests/0_UNITTEST/XDATA_hydro.json") DataContainer(data_file_path) @classmethod def tearDownClass(cls): DataContainer.clear() print("\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n") def setUp(self): self.test_cell = Cell(3) def tearDown(self): pass def test_compute_new_pressure_internal(self): """ Test of compute_new_pressure method with internal solver """ self.test_cell._external_library = None self.test_cell.energy.current_value = np.array( [1.e+06, 0.5e+05, 2.4e+07]) self.test_cell.pressure.current_value = np.array( [1.5e+09, 0.5e+08, 1.2e+10]) self.test_cell.density.current_value = np.array([8000., 8500., 9500.]) self.test_cell.pseudo.current_value = np.array([1.e+08, 0., 2.4e+09]) self.test_cell.density.new_value = np.array([8120., 8440., 9620.]) self.test_cell.energy.new_value = np.array([0., 0., 0.]) self.test_cell.pressure.new_value = np.array([0., 0., 0.]) self.test_cell.sound_velocity.new_value = np.array([0., 0., 0.]) self.test_cell.compute_new_pressure(np.array([True, True, True]), 1.e-6) # Function to vanish delta_v = 1. / self.test_cell.density.new_value - 1. / self.test_cell.density.current_value func = (self.test_cell.energy.new_value + self.test_cell.pressure.new_value * delta_v / 2. + (self.test_cell.pressure.current_value + 2. * self.test_cell.pseudo.current_value) * delta_v / 2. - self.test_cell.energy.current_value) np.testing.assert_allclose( func, np.array([-1001570.197044, -49979.091163, -24011029.653135]))
class OneDimensionCellExternalLibTest(unittest.TestCase): """ Unittest of the OneDimensionCell class (external lib use case) """ @classmethod def setUpClass(cls): """ Tests setup for class """ data_file_path = os.path.join(os.path.dirname(__file__), "../../../tests/0_UNITTEST/XDATA.json") DataContainer(data_file_path) @classmethod def tearDownClass(cls): DataContainer.clear() print("\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n") def setUp(self): self.test_cell = Cell(3) def tearDown(self): pass @unittest.skip("No yet ready") def test_compute_new_pressure_external(self): """ Test of compute_new_pressure method with external solver """ self.test_cell._external_library = "" #Â pylint:disable=protected-access self.test_cell.energy.current_value = np.array( [1.e+06, 0.5e+05, 2.4e+07]) self.test_cell.pressure.current_value = np.array( [1.5e+09, 0.5e+08, 1.2e+10]) self.test_cell.density.current_value = np.array([8000., 8500., 9500.]) self.test_cell.pseudo.current_value = np.array([1.e+08, 0., 2.4e+09]) self.test_cell.density.new_value = np.array([8120., 8440., 9620.]) self.test_cell.energy.new_value = np.array([0., 0., 0.]) self.test_cell.pressure.new_value = np.array([0., 0., 0.]) self.test_cell.sound_velocity.new_value = np.array([0., 0., 0.]) self.test_cell.cell_in_target = np.array([True, True, True]) self.test_cell.compute_new_pressure(np.array([True, True, True]), 1.e-6) # Function to vanish delta_v = 1. / self.test_cell.density.new_value - 1. / self.test_cell.density.current_value func = (self.test_cell.energy.new_value + self.test_cell.pressure.new_value * delta_v / 2. + (self.test_cell.pressure.current_value + 2. * self.test_cell.pseudo.current_value) * delta_v / 2. - self.test_cell.energy.current_value) np.testing.assert_allclose(func, [0., 0., 0.])
def test_apply_equation_of_state(self): """ Test of apply_equation_of_state class method """ density_current = np.ones(self.nbr_cells) * 8930. pressure_current = np.ones(self.nbr_cells) * 1.e+05 energy_current = np.ones(self.nbr_cells) * 6.719465 density_new = np.array([9000., 8900., 8915., 8920.]) cson_new = np.zeros([self.nbr_cells]) pressure_new = np.zeros([self.nbr_cells]) energy_new = np.zeros([self.nbr_cells]) pseudo = np.zeros([self.nbr_cells]) eos = self.test_data.material_target.constitutive_model.eos.build_eos_obj() energy_new_value, pressure_new_value, sound_velocity_new_value = \ OneDimensionCell.apply_equation_of_state(self.my_cells, eos, density_current, density_new, pressure_current, pressure_new, energy_current, energy_new, pseudo, cson_new) expected_energy = np.array([487.425148, 94.274747, 28.598207, 16.438778]) expected_pressure = np.array([1.103738e+09, -4.640087e+08, -2.323383e+08, -1.549395e+08]) expected_sound_speed = np.array([4000.877516, 3926.583447, 3933.306654, 3935.541937]) np.testing.assert_allclose(energy_new_value, expected_energy, rtol=1.e-5) np.testing.assert_allclose(pressure_new_value, expected_pressure, rtol=1.e-5) np.testing.assert_allclose(sound_velocity_new_value, expected_sound_speed)
def test_general_method_deviator_strain_rate(self): """ Test of general_method_deviator_strain_rate """ mask = np.ones([self.nbr_cells], dtype=np.bool) mask[0] = False mask[1] = False delta_t = 1. x_new = np.array([[-0.5, ], [0.1, ], [0.2, ], [0.35, ], [0.65, ]]) u_new = np.array([[0.1, ], [-0.05, ], [0., ], [0.2, ], [0.3, ]]) # Reconstruction des array donn�s par la topologie position_new = np.array([[x_new[0], x_new[1]], [x_new[1], x_new[2]], [x_new[2], x_new[3]], [x_new[3], x_new[4]]]).reshape((4, 2)) vitesse_new = np.array([[u_new[0], u_new[1]], [u_new[1], u_new[2]], [u_new[2], u_new[3]], [u_new[3], u_new[4]]]).reshape((4, 2)) expected_result = np.array([[0., 0., 0.], [0., 0., 0.], [2.666667, -1.333333, -1.333333], [0.266667, -0.133333, -0.133333]]) dev_strain_rate = np.zeros((self.nbr_cells, 3)) D = OneDimensionCell.general_method_deviator_strain_rate(delta_t, position_new, vitesse_new) dev_strain_rate[mask] = D[mask] np.testing.assert_allclose(dev_strain_rate, expected_result, rtol=1.e-05)
def compute_enriched_elements_new_pressure(self, delta_t): """ Compute pressure, internal energy and sound velocity in left and right parts of the enriched elements :param delta_t: time step """ target_model = self.data.material_target.constitutive_model # Fracture cannot occur on the projectile => check only the target model to know if # elasticity or plasticity is activated elasticity_activated = (target_model.elasticity_model is not None) plasticity_activated = (target_model.plasticity_model is not None) mask = self.enriched if elasticity_activated or plasticity_activated: self.enr_energy.current_value[mask] += \ OneDimensionCell.add_elastic_energy_method( delta_t, self.enr_density.current_value[mask], self.enr_density.new_value[mask], self.enr_deviatoric_stress_current[mask], self.enr_deviatoric_stress_new[mask], self.enr_deviatoric_strain_rate[mask]) # Initialize local parameters : density_right = self.enr_density.current_value[mask] density_right_new = self.enr_density.new_value[mask] pressure_right = self.enr_pressure.current_value[mask] pressure_right_new = self.enr_pressure.new_value[mask] energy_right = self.enr_energy.current_value[mask] energy_right_new = self.enr_energy.new_value[mask] pseudo_right = self.enr_artificial_viscosity.current_value[mask] cson_right_new = self.enr_sound_velocity.new_value[mask] # Call EOS : energy_new_right_value, pressure_new_right_value, sound_velocity_new_right_value = \ OneDimensionCell.apply_equation_of_state( self, self._target_eos, density_right, density_right_new, pressure_right, pressure_right_new, energy_right, energy_right_new, pseudo_right, cson_right_new) # Save results : self.enr_pressure.new_value[mask] = pressure_new_right_value self.enr_energy.new_value[mask] = energy_new_right_value self.enr_sound_velocity.new_value[ mask] = sound_velocity_new_right_value
def setUp(self) -> None: """ Preparation of the test """ # Creation of a fake DataContainer : data_file_path = os.path.join( os.path.dirname(__file__), "../../../tests/0_UNITTEST/XDATA_hydro.json") self.test_datacontainer = DataContainer(data_file_path) # Preparation of the test self._pressure = 0. self.my_imposed_pressure = ImposedPressure(self._pressure) self.cells = OneDimensionCell(1000) self.cells.pressure_field[:] = 1. self.ruptured_cells = np.ndarray([1000], dtype=np.bool, order='C') self.ruptured_cells[:] = False self.ruptured_cells[500] = True
def compute_enriched_deviatoric_strain_rate( self, dt: float, # pylint: disable=invalid-name node_coord_new: np.array, node_velocity_new: np.array) -> None: """ Compute the deviatoric strain rate for enriched cells :param dt: time step :param node_coord_new: array, new nodes coordinates :param node_velocity_new: array, new nodes velocity """ disc_list = Discontinuity.discontinuity_list() if not disc_list: return mask_nodes_in = Discontinuity.in_nodes.flatten() mask_nodes_out = Discontinuity.out_nodes.flatten() mask_cells_arr = Discontinuity.ruptured_cell_id.flatten() eps_arr = Discontinuity.discontinuity_position.flatten() u2g_arr = Discontinuity.enr_velocity_new[:, 0].flatten() u1d_arr = Discontinuity.enr_velocity_new[:, 1].flatten() u_noeuds_new_in_arr = node_velocity_new[mask_nodes_in] u_noeuds_new_out_arr = node_velocity_new[mask_nodes_out] x_noeuds_new_in_arr = node_coord_new[mask_nodes_in] x_noeuds_new_out_arr = node_coord_new[mask_nodes_out] xg_new_arr = np.concatenate( (x_noeuds_new_in_arr, x_noeuds_new_in_arr + self.left_part_size.new_value[mask_cells_arr][np.newaxis].T), axis=1) xd_new_arr = np.concatenate( (x_noeuds_new_out_arr - self.right_part_size.new_value[mask_cells_arr][np.newaxis].T, x_noeuds_new_out_arr), axis=1) x_new_arr = np.concatenate((xg_new_arr, xd_new_arr)) u_discg_new_arr, u_discd_new_arr = self._compute_discontinuity_borders_velocity( eps_arr, u_noeuds_new_in_arr[:, 0], u1d_arr, u2g_arr, u_noeuds_new_out_arr[:, 0]) ug_new_arr = np.concatenate( (u_noeuds_new_in_arr, u_discg_new_arr[np.newaxis].T), axis=1) ud_new_arr = np.concatenate( (u_discd_new_arr[np.newaxis].T, u_noeuds_new_out_arr), axis=1) u_new_arr = np.concatenate((ug_new_arr, ud_new_arr)) deviator_left, deviator_right = np.split( OneDimensionCell.general_method_deviator_strain_rate( dt, x_new_arr, u_new_arr), 2) self._deviatoric_strain_rate[mask_cells_arr] = deviator_left self._enr_deviatoric_strain_rate[mask_cells_arr] = deviator_right
def test_compute_pseudo(self): """ Test of compute_pseudo class method """ rho_new = np.array([8500., 3500, 2175]) rho_old = np.array([8700., 3200, 2171]) new_size = np.array([0.025, 0.01, 0.005]) sound_speed = np.array([4400, 3200, 1140]) delta_t = 1.2e-08 pseudo_a, pseudo_b = 1.2, 0.25 result = OneDimensionCell.compute_pseudo(delta_t, rho_old, rho_new, new_size, sound_speed, pseudo_a, pseudo_b) np.testing.assert_allclose(result, [0.00000000e+00, 2.25427729e+13, 2.00897590e+09])
class ImposedPressureTest(unittest.TestCase): """ Test case utilis� pour test les fonctions du module 'Imposed Pressure' Marche bien mais appelle des m�thodes de Cell et OneDimensionCell non v�rifi�es """ def setUp(self) -> None: """ Preparation of the test """ # Creation of a fake DataContainer : data_file_path = os.path.join( os.path.dirname(__file__), "../../../tests/0_UNITTEST/XDATA_hydro.json") self.test_datacontainer = DataContainer(data_file_path) # Preparation of the test self._pressure = 0. self.my_imposed_pressure = ImposedPressure(self._pressure) self.cells = OneDimensionCell(1000) self.cells.pressure_field[:] = 1. self.ruptured_cells = np.ndarray([1000], dtype=np.bool, order='C') self.ruptured_cells[:] = False self.ruptured_cells[500] = True def tearDown(self) -> None: """ End of the tests """ DataContainer.clear() def test_apply_treatment(self) -> None: """ Teste la m�thode apply_treatment for ImposedPressure """ self.my_imposed_pressure.apply_treatment(self.cells, self.ruptured_cells) self.cells.increment_variables() self.assertAlmostEqual(self.cells.pressure_field[500], self._pressure)
def test_compute_time_step(self): """ Test of compute_time_step class method """ cfl, cfl_pseudo = 0.25, 0.1 rho_new = np.array([8500., 2175., 3500.]) rho_old = np.array([8700., 2174.9, 3200]) new_size = np.array([0.025, 0.01, 0.005]) sound_speed = np.array([4400., 3200., 1140.]) pseudo_old = np.array([1.0e+09, 0.5e+08, 0.3e+08]) pseudo_new = np.array([1.5e+09, 1.5e+08, 0.]) result = OneDimensionCell.compute_time_step(cfl, cfl_pseudo, rho_old, rho_new, new_size, sound_speed, pseudo_old, pseudo_new) np.testing.assert_allclose(result, [1.41137110e-06, 7.81250000e-07, 1.09649123e-06])
def test_add_elastic_energy_method(self): """ Test de la m�thode add_elastic_energy_method """ delta_t = 1. density_current = np.ones(self.nbr_cells) * 8930. density_new = np.ones(self.nbr_cells) * 8950. stress_dev_current = np.array([[2, -1, -1], [4, -2, -2], [10., -5., -5.], [40., -20., -20.]]) stress_dev_new = np.array([[20., -10, -10.], [5., -2.5, -2.5], [10., -5., -5.], [40., -20., -20.]]) strain_rate_dev = np.array([[1., -0.5, -0.5], [2., -1, -1], [3., -1.5, -1.5], [4., -2., -2.]]) energy_new = OneDimensionCell.add_elastic_energy_method(delta_t, density_current, density_new, stress_dev_current, stress_dev_new, strain_rate_dev) expected_energy = np.array([0.001846, 0.00151, 0.005034, 0.026846]) np.testing.assert_allclose(energy_new, expected_energy, rtol=1.e-3)
def setUp(self): self.nbr_cells = 4 self.my_cells = OneDimensionCell(self.nbr_cells) self.my_cells.cell_in_target = np.ones(self.nbr_cells, dtype='bool') self.mask = np.array([True, True, False, False]) self.test_data = DataContainer() # pylint: disable=no-value-for-parameter
def setUp(self): self.test_cell = Cell(3)
class OneDimensionCellEPPTest(unittest.TestCase): """ A class to test the module OneDimensionCell with elasticity and plasticity """ @classmethod def setUpClass(cls): """ Tests setup for class """ data_file_path = os.path.join( os.path.dirname(__file__), "../../../tests/0_UNITTEST/XDATA_epp.json") DataContainer(data_file_path) @classmethod def tearDownClass(cls): """ Actions after all the tests of the class """ DataContainer.clear() print("\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n") def setUp(self): """ Test set up """ self.nbr_cells = 4 self.my_cells = OneDimensionCell(self.nbr_cells) self.my_cells.cell_in_target = np.ones(self.nbr_cells, dtype='bool') self.test_data = DataContainer() # pylint: disable=no-value-for-parameter def test_apply_plastic_corrector_on_deviatoric_stress_tensor(self): """ Test of the method apply_plastic_corrector_on_deviatoric_stress_tensor """ mask = np.array([True, True, False, False]) deviatoric_stress_new = np.array([[8e+9, -4e+9, -4e+9], [5e+8, -2.5e+8, -2.5e+8], [1.e+2, -5e+1, -5e+1], [4e+9, -2e+9, -2e+9]]) j2 = np.sqrt(compute_second_invariant(deviatoric_stress_new)) yield_stress = np.ones( self.nbr_cells ) * self.test_data.material_target.initial_values.yield_stress_init radial_return = self.my_cells._compute_radial_return(j2, yield_stress) deviatoric_stress_new[mask] *= radial_return[mask][np.newaxis].T expected_value = np.array( [[8.000000e+07, -4.000000e+07, -4.000000e+07], [8.000000e+07, -4.000000e+07, -4.000000e+07], [1.e+2, -5e+1, -5e+1], [4e+9, -2e+9, -2e+9]]) np.testing.assert_allclose(deviatoric_stress_new, expected_value) def test_compute_yield_stress(self): """ Test of the method compute_yield_stress """ target_model = self.test_data.material_target self.my_cells.compute_yield_stress( target_model.constitutive_model.plasticity_model. build_yield_stress_obj(), np.array([True, True, True, True])) expected_value = target_model.initial_values.yield_stress_init np.testing.assert_allclose(self.my_cells.yield_stress.new_value, np.ones([self.nbr_cells]) * expected_value) def test_compute_equivalent_plastic_strain_rate(self): """ Test of the method compute_equivalent_plastic_strain_rate """ mask = np.array([True, True, False, False]) delta_t = 1. deviatoric_stress = np.array([[8e+9, -4e+9, -4e+9], [5e+8, -2.5e+8, -2.5e+8], [1.e+2, -5e+1, -5e+1], [4e+9, -2e+9, -2e+9]]) j2 = np.sqrt(compute_second_invariant(deviatoric_stress)) shear_modulus = np.ones( self.nbr_cells ) * self.test_data.material_target.initial_values.shear_modulus_init yield_stress = np.ones( self.nbr_cells ) * self.test_data.material_target.initial_values.yield_stress_init obtained = self.my_cells._compute_equivalent_plastic_strain_rate( j2[mask], shear_modulus[mask], yield_stress[mask], delta_t) np.testing.assert_allclose(obtained, np.array([0.08301887, 0.00440252]), rtol=1.e-5)
class OneDimensionCellElastoTest(unittest.TestCase): """ A class to test the OneDimensionCell module with elasticity physic """ @classmethod def setUpClass(cls): """ Tests setup for class """ data_file_path = os.path.join(os.path.dirname(__file__), "../../../tests/0_UNITTEST/XDATA_elasto.json") DataContainer(data_file_path) @classmethod def tearDownClass(cls): DataContainer.clear() print("\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n") def setUp(self): self.nbr_cells = 4 self.my_cells = OneDimensionCell(self.nbr_cells) self.my_cells.cell_in_target = np.ones(self.nbr_cells, dtype='bool') self.mask = np.array([True, True, False, False]) self.test_data = DataContainer() # pylint: disable=no-value-for-parameter def tearDown(self): pass def test_compute_new_pressure_with_elasticity(self): """ Test de la m�thode compute_new_pressure """ mask_classic = np.array([True, True, False, False]) self.my_cells.density.current_value = np.ones(self.nbr_cells) * 8930. self.my_cells.pressure.current_value = np.ones(self.nbr_cells) * 1.e+5 self.my_cells.energy.current_value = np.ones(self.nbr_cells) * 7.5 self.my_cells._deviatoric_stress_new = np.array([[200., -100, -100.], [5., -2.5, -2.5], [100., -50., -50.], [400., -200., -200.]]) self.my_cells._deviatoric_strain_rate = \ np.array([[-0.235294, 0.117647, 0.117647], [0.4444444, -0.2222222, -0.2222222], [0., 0., 0.], [0., 0., 0.]]) self.my_cells.density.new_value = np.array([8940., 8970, 8920., 9000.]) self.my_cells.sound_velocity.new_value = np.zeros([self.nbr_cells]) self.my_cells.pressure.new_value = np.zeros([self.nbr_cells]) self.my_cells.energy.new_value = np.zeros([self.nbr_cells]) self.my_cells.pseudo.new_value = np.zeros([self.nbr_cells]) delta_t = 1. self.my_cells.compute_new_pressure(mask_classic, delta_t) np.testing.assert_allclose(self.my_cells.pressure.new_value, np.array([1.557157e+08, 6.266033e+08, 0.000000e+00, 0.000000e+00]), rtol=1.e-5) np.testing.assert_allclose(self.my_cells.energy.new_value, np.array([17.254756, 163.9763, 0., 0.])) np.testing.assert_allclose(self.my_cells.sound_velocity.new_value, np.array([3948.726929, 3974.84139, 0., 0.])) def test_compute_shear_modulus(self): """ Test of the method compute_shear_modulus """ target_model = self.test_data.material_target self.my_cells.compute_shear_modulus( target_model.constitutive_model.elasticity_model.build_shear_modulus_obj(), np.array([True, True, True, True])) expected_value = target_model.initial_values.shear_modulus_init np.testing.assert_allclose(self.my_cells.shear_modulus.new_value, np.ones([self.nbr_cells]) * expected_value) def test_compute_complete_stress_tensor(self): """ Test of the method compute_complete_stress_tensor """ self.my_cells._stress = np.array([[2000., -1000, -1000.], [50., -25., -25.], [1000., -500., -500.], [4000., -2000., -2000.]]) self.my_cells._deviatoric_stress_new = np.array([[200., -100, -100.], [5., -2.5, -2.5], [100., -50., -50.], [400., -200., -200.]]) self.my_cells.pressure.new_value = np.array([1000, 25, 500, 2000]) self.my_cells.pseudo.new_value = np.array([-1, -2, -3, 4]) self.my_cells.compute_complete_stress_tensor() expected_result = np.array([[-799., -1099, -1099.], [-18, -25.5, -25.5], [-397., -547., -547.], [-1604., -2204., -2204.]]) np.testing.assert_allclose(self.my_cells.stress, expected_result) @mock.patch.object(OneDimensionCell, "general_method_deviator_strain_rate", spec=classmethod, new_callable=mock.MagicMock) def test_compute_deviatoric_stress_tensor(self, mock_compute_d): """ Test of the method compute_deviatoric_stress_tensor """ mock_compute_d.return_value = np.array([[1., -0.5, -0.5], [3., -1.5, -1.5], [2., -1., -1.], [0., 0., 0.]]) mask = np.array([True, True, True, False]) delta_t = 1. coord_noeud_new = np.array([[-0.25, ], [0.1, ], [0.2, ], [0.45, ], [0.85, ]]) vitesse_noeud_new = np.array([[0.1, ], [-0.05, ], [0., ], [0.2, ], [0.3, ]]) topo_ex = Topology1D(5, 4) self.my_cells._deviatoric_stress_current = np.array([[2000., -1000, -1000.], [50., -25., -25.], [1000., -500., -500.], [4000., -2000., -2000.]]) self.my_cells._deviatoric_strain_rate = np.array([[1., -0.5, -0.5], [3., -1.5, -1.5], [2., -1., -1.], [1., -0.5, -0.5]]) self.my_cells.shear_modulus.new_value = np.array([2., 4., 6., 8.]) self.my_cells.compute_deviatoric_stress_tensor(mask, topo_ex, coord_noeud_new, vitesse_noeud_new, delta_t) np.testing.assert_allclose(self.my_cells._deviatoric_stress_new, np.array([[2004, -1002., -1002.], [74., -37., -37.], [1024., -512., -512.], [0., 0., 0.]]), rtol=1.e-05) def test_compute_deviator_strain_rate(self): """ Test of the method compute_deviatoric_strain_rate """ # input data mask = np.array([True, True, False, False]) delta_t = 1. coord_noeud_new = np.array([[-0.25, ], [0.1, ], [0.2, ], [0.45, ], [0.85, ]]) vitesse_noeud_new = np.array([[0.1, ], [-0.05, ], [0., ], [0.2, ], [0.3, ]]) topo_ex = Topology1D(5, 4) # Test of the method compute_deviator D = self.my_cells.compute_deviator_strain_rate(delta_t, topo_ex, coord_noeud_new, vitesse_noeud_new) self.my_cells._deviatoric_strain_rate[mask] = D[mask] np.testing.assert_allclose(self.my_cells._deviatoric_strain_rate, np.array([[-0.235294, 0.117647, 0.117647], [0.4444444, -0.2222222, -0.2222222], [0., 0., 0.], [0., 0., 0.]]), rtol=1.e-05)