diff --git a/test/Element/Allen_Cahn/test_allen_cahn_element.py b/test/Element/Allen_Cahn/test_allen_cahn_element.py index 08b23b8..d999591 100644 --- a/test/Element/Allen_Cahn/test_allen_cahn_element.py +++ b/test/Element/Allen_Cahn/test_allen_cahn_element.py @@ -96,7 +96,8 @@ def right(x): return np.isclose(x[0], a) # Compare the computed total energy with the theoretical energy energy_simulation = S.energy_files["total.energy"]["gamma"][0] - assert np.isclose(energy_simulation, energy_theory, atol=1e-3), f"Simulated energy {energy_simulation} does not match theoretical energy {energy_theory}" + + np.testing.assert_allclose(energy_simulation, energy_theory, rtol=1e-3, atol=1e-3, err_msg=f"Simulated energy {energy_simulation} does not match theoretical energy {energy_theory}") # Clean up: remove the generated files if os.path.exists(Data.results_folder_name): diff --git a/test/Element/Phase_Field/test_phase_field_element.py b/test/Element/Phase_Field/test_phase_field_element.py index 15b4205..3785dbe 100644 --- a/test/Element/Phase_Field/test_phase_field_element.py +++ b/test/Element/Phase_Field/test_phase_field_element.py @@ -98,14 +98,16 @@ def left(x): W_gradphi = 0.5 * tanh_a_div_l - 0.5 * a_div_l * (1.0 - tanh_a_div_l**2) W = np.tanh(a_div_l) - assert np.isclose(S.energy_files["total.energy"]["gamma_phi"][0], 0.5 * W_phi, atol=1e-6), \ - f"Computed phi energy {S.energy_files["total.energy"]["gamma_phi"][0]} does not match theoretical energy {W_phi}" + + np.testing.assert_allclose(S.energy_files["total.energy"]["gamma_phi"][0], 0.5 * W_phi, rtol=1e-3, atol=1e-6, + err_msg=f"Computed phi energy {S.energy_files['total.energy']['gamma_phi'][0]} does not match theoretical energy {W_phi}") - assert np.isclose(S.energy_files["total.energy"]["gamma_gradphi"][0], 0.5 * W_gradphi, atol=1e-6), \ - f"Computed gradphi energy {S.energy_files["total.energy"]["gamma_gradphi"][0]} does not match theoretical energy {W_gradphi}" + np.testing.assert_allclose(S.energy_files["total.energy"]["gamma_gradphi"][0], 0.5 * W_gradphi, rtol=1e-3, atol=1e-6, + err_msg=f"Computed gradphi energy {S.energy_files['total.energy']['gamma_gradphi'][0]} does not match theoretical energy {W_gradphi}") + + np.testing.assert_allclose(S.energy_files["total.energy"]["gamma"][0], 0.5 * W, rtol=1e-3, atol=1e-6, + err_msg=f"Computed energy {S.energy_files['total.energy']['gamma'][0]} does not match theoretical energy {W}") - assert np.isclose(S.energy_files["total.energy"]["gamma"][0], 0.5 * W, atol=1e-6), \ - f"Computed energy {S.energy_files["total.energy"]["gamma"][0]} does not match theoretical energy {W}" # Clean up: Remove generated files if os.path.exists(Data.results_folder_name): diff --git a/test/Element/Phase_Field_Fracture/test_phase_field_fracture_element.py b/test/Element/Phase_Field_Fracture/test_phase_field_fracture_element.py index f8ba0ba..b0e1bae 100644 --- a/test/Element/Phase_Field_Fracture/test_phase_field_fracture_element.py +++ b/test/Element/Phase_Field_Fracture/test_phase_field_fracture_element.py @@ -125,8 +125,9 @@ def update_boundary_conditions(bcs, time): phi_t = 2 * psi_t / (Data.Gc / Data.l + 2 * psi_t) sigma_t = displacement * (Data.lambda_ + 2 * Data.mu) * (1 - phi_t)**2 - assert np.allclose(S.reaction_files["top.reaction"]["Ry"], sigma_t, atol=1e-8), \ - f"Computed reaction force {S.reaction_files["top.reaction"]["Ry"]} does not match theoretical reaction {sigma_t}" + np.testing.assert_allclose(S.reaction_files["top.reaction"]["Ry"], sigma_t, rtol=1e-3, atol=1e-8, + err_msg=f"Computed reaction force {S.reaction_files['top.reaction']['Ry']} does not match theoretical reaction {sigma_t}") + # Clean up: Remove generated files if os.path.exists(Data.results_folder_name): import shutil diff --git a/test/Element/Phase_Field_Fracture/test_phase_field_fracture_element_anisotropic.py b/test/Element/Phase_Field_Fracture/test_phase_field_fracture_element_anisotropic.py index 63405a6..90bb561 100644 --- a/test/Element/Phase_Field_Fracture/test_phase_field_fracture_element_anisotropic.py +++ b/test/Element/Phase_Field_Fracture/test_phase_field_fracture_element_anisotropic.py @@ -146,8 +146,8 @@ def update_boundary_conditions(bcs, time): else: raise ValueError(f"Invalid value for split_energy: {Data.split_energy}. Expected 'spectral' or 'deviatoric'.") - assert np.allclose(S.reaction_files["top.reaction"]["Ry"], sigma_t, atol=1e-8), \ - f"Computed reaction force {S.reaction_files["top.reaction"]["Ry"]} does not match theoretical reaction {sigma_t} for {Data.split_energy}" + np.testing.assert_allclose(S.reaction_files["top.reaction"]["Ry"], sigma_t, rtol=1e-3, atol=1e-8, + err_msg=f"Computed reaction force {S.reaction_files['top.reaction']['Ry']} does not match theoretical reaction {sigma_t} for {Data.split_energy}") # Clean up: Remove generated files if os.path.exists(Data.results_folder_name):