@@ -163,8 +163,8 @@ def test_each_reaction_overpotential(self):
163163 np .testing .assert_array_less (self .eta_r_n (t , x_n ), tol )
164164 np .testing .assert_array_less (- self .eta_r_p (t , x_p ), tol )
165165 elif self .operating_condition == "off" :
166- np .testing .assert_array_almost_equal (self .eta_r_n (t , x_n ), 0 )
167- np .testing .assert_array_almost_equal (- self .eta_r_p (t , x_p ), 0 )
166+ np .testing .assert_allclose (self .eta_r_n (t , x_n ), 0 , rtol = 1e-7 , atol = 1e-6 )
167+ np .testing .assert_allclose (- self .eta_r_p (t , x_p ), 0 , rtol = 1e-7 , atol = 1e-6 )
168168
169169 def test_overpotentials (self ):
170170 """Testing that all are:
@@ -183,8 +183,8 @@ def test_overpotentials(self):
183183 np .testing .assert_array_less (- self .delta_phi_s_av (self .t ), tol )
184184
185185 elif self .operating_condition == "off" :
186- np .testing .assert_array_almost_equal (self .eta_r_av (self .t ), 0 )
187- np .testing .assert_array_almost_equal (self .eta_e_av (self .t ), 0 , decimal = 11 )
186+ np .testing .assert_allclose (self .eta_r_av (self .t ), 0 , rtol = 1e-7 , atol = 1e-6 )
187+ np .testing .assert_allclose (self .eta_e_av (self .t ), 0 , rtol = 1e-12 , atol = 1e- 11 )
188188 np .testing .assert_allclose (
189189 self .delta_phi_s_av (self .t ), 0 , atol = 2e-14 , rtol = 1e-16
190190 )
@@ -204,8 +204,8 @@ def test_ocps(self):
204204 np .testing .assert_array_less (neg_end_vs_start , 0 )
205205 np .testing .assert_array_less (- pos_end_vs_start , 0 )
206206 elif self .operating_condition == "off" :
207- np .testing .assert_array_almost_equal (neg_end_vs_start , 0 )
208- np .testing .assert_array_almost_equal (pos_end_vs_start , 0 )
207+ np .testing .assert_allclose (neg_end_vs_start , 0 , rtol = 1e-7 , atol = 1e-6 )
208+ np .testing .assert_allclose (pos_end_vs_start , 0 , rtol = 1e-7 , atol = 1e-6 )
209209
210210 def test_ocv (self ):
211211 """Testing that:
@@ -221,7 +221,7 @@ def test_ocv(self):
221221 elif self .operating_condition == "charge" :
222222 np .testing .assert_array_less (- end_vs_start , 0 )
223223 elif self .operating_condition == "off" :
224- np .testing .assert_array_almost_equal (end_vs_start , 0 )
224+ np .testing .assert_allclose (end_vs_start , 0 , rtol = 1e-7 , atol = 1e-6 )
225225
226226 def test_voltage (self ):
227227 """Testing that:
@@ -236,32 +236,41 @@ def test_voltage(self):
236236 elif self .operating_condition == "charge" :
237237 np .testing .assert_array_less (- end_vs_start , 0 )
238238 elif self .operating_condition == "off" :
239- np .testing .assert_array_almost_equal (end_vs_start , 0 )
239+ np .testing .assert_allclose (end_vs_start , 0 , rtol = 1e-7 , atol = 1e-6 )
240240
241241 def test_consistent (self ):
242242 """Test voltage components are consistent with one another by ensuring they sum
243243 correctly"""
244244
245- np .testing .assert_array_almost_equal (
246- self .ocv (self .t ), self .ocp_p (self .t ) - self .ocp_n (self .t )
245+ np .testing .assert_allclose (
246+ self .ocv (self .t ),
247+ self .ocp_p (self .t ) - self .ocp_n (self .t ),
248+ rtol = 1e-7 ,
249+ atol = 1e-6 ,
247250 )
248- np .testing .assert_array_almost_equal (
249- self .eta_r_av (self .t ), self .eta_r_p_av (self .t ) - self .eta_r_n_av (self .t )
251+ np .testing .assert_allclose (
252+ self .eta_r_av (self .t ),
253+ self .eta_r_p_av (self .t ) - self .eta_r_n_av (self .t ),
254+ rtol = 1e-7 ,
255+ atol = 1e-6 ,
250256 )
251- np .testing .assert_array_almost_equal (
257+ np .testing .assert_allclose (
252258 self .eta_particle (self .t ),
253259 self .eta_particle_p (self .t ) - self .eta_particle_n (self .t ),
260+ rtol = 1e-7 ,
261+ atol = 1e-6 ,
254262 )
255263
256- np .testing .assert_array_almost_equal (
264+ np .testing .assert_allclose (
257265 self .voltage (self .t ),
258266 self .ocv (self .t )
259267 + self .eta_particle (self .t )
260268 + self .eta_r_av (self .t )
261269 + self .eta_e_av (self .t )
262270 + self .delta_phi_s_av (self .t )
263271 + self .eta_sei_av (self .t ),
264- decimal = 5 ,
272+ rtol = 1e-6 ,
273+ atol = 1e-5 ,
265274 )
266275
267276 def test_all (self ):
@@ -385,8 +394,8 @@ def test_concentration_increase_decrease(self):
385394 np .testing .assert_array_less (0 , neg_end_vs_start )
386395 np .testing .assert_array_less (pos_end_vs_start , 0 )
387396 elif self .operating_condition == "off" :
388- np .testing .assert_array_almost_equal (neg_diff , 0 )
389- np .testing .assert_array_almost_equal (pos_diff , 0 )
397+ np .testing .assert_allclose (neg_diff , 0 , rtol = 1e-7 , atol = 1e-6 )
398+ np .testing .assert_allclose (pos_diff , 0 , rtol = 1e-7 , atol = 1e-6 )
390399 np .testing .assert_allclose (neg_end_vs_start , 0 , rtol = 1e-16 , atol = 1e-5 )
391400 np .testing .assert_allclose (pos_end_vs_start , 0 , rtol = 1e-16 , atol = 1e-5 )
392401
@@ -455,7 +464,8 @@ def test_conservation(self):
455464 decimal = 9
456465 else :
457466 decimal = 14
458- np .testing .assert_array_almost_equal (diff , 0 , decimal = decimal )
467+ atol = 10 ** (- decimal + 1 )
468+ np .testing .assert_allclose (diff , 0 , rtol = 1e-7 , atol = atol )
459469
460470 def test_concentration_profile (self ):
461471 """Test that the concentration in the centre of the negative particles is
@@ -479,8 +489,8 @@ def test_fluxes(self):
479489 )
480490 if self .model .options ["particle" ] == "uniform profile" :
481491 # Fluxes are zero everywhere since the concentration is uniform
482- np .testing .assert_array_almost_equal (self .N_s_n (t , x_n , r_n ), 0 )
483- np .testing .assert_array_almost_equal (self .N_s_p (t , x_p , r_p ), 0 )
492+ np .testing .assert_allclose (self .N_s_n (t , x_n , r_n ), 0 , rtol = 1e-7 , atol = 1e-6 )
493+ np .testing .assert_allclose (self .N_s_p (t , x_p , r_p ), 0 , rtol = 1e-7 , atol = 1e-6 )
484494 else :
485495 if self .operating_condition == "discharge" :
486496 if self .model .options ["particle" ] == "quartic profile" :
@@ -498,11 +508,15 @@ def test_fluxes(self):
498508 np .testing .assert_array_less (self .N_s_n (t [1 :], x_n , r_n [1 :]), 1e-16 )
499509 np .testing .assert_array_less (- 1e-16 , self .N_s_p (t [1 :], x_p , r_p [1 :]))
500510 if self .operating_condition == "off" :
501- np .testing .assert_array_almost_equal (self .N_s_n (t , x_n , r_n ), 0 )
502- np .testing .assert_array_almost_equal (self .N_s_p (t , x_p , r_p ), 0 )
511+ np .testing .assert_allclose (
512+ self .N_s_n (t , x_n , r_n ), 0 , rtol = 1e-7 , atol = 1e-6
513+ )
514+ np .testing .assert_allclose (
515+ self .N_s_p (t , x_p , r_p ), 0 , rtol = 1e-7 , atol = 1e-6
516+ )
503517
504- np .testing .assert_array_almost_equal (0 , self .N_s_n (t , x_n , r_n [0 ]), decimal = 4 )
505- np .testing .assert_array_almost_equal (0 , self .N_s_p (t , x_p , r_p [0 ]), decimal = 4 )
518+ np .testing .assert_allclose (0 , self .N_s_n (t , x_n , r_n [0 ]), rtol = 1e-5 , atol = 1e- 4 )
519+ np .testing .assert_allclose (0 , self .N_s_p (t , x_p , r_p [0 ]), rtol = 1e-5 , atol = 1e- 4 )
506520
507521 def test_all (self ):
508522 self .test_concentration_increase_decrease ()
@@ -590,8 +604,8 @@ def test_fluxes(self):
590604 models (bug in implementation of boundary conditions?)"""
591605
592606 t , x = self .t , self .x_edge
593- np .testing .assert_array_almost_equal (self .N_e_hat (t , x [0 ]), 0 , decimal = 3 )
594- np .testing .assert_array_almost_equal (self .N_e_hat (t , x [- 1 ]), 0 , decimal = 3 )
607+ np .testing .assert_allclose (self .N_e_hat (t , x [0 ]), 0 , rtol = 1e-4 , atol = 1e- 3 )
608+ np .testing .assert_allclose (self .N_e_hat (t , x [- 1 ]), 0 , rtol = 1e-4 , atol = 1e- 3 )
595609
596610 def test_splitting (self ):
597611 """Test that when splitting the concentrations and fluxes by negative electrode,
@@ -604,7 +618,7 @@ def test_splitting(self):
604618
605619 # Loose tolerance since the different way that c_e and c_e_n/s/p are calculated
606620 # introduces some numerical error
607- np .testing .assert_array_almost_equal (self .c_e (t , x ), c_e_combined , decimal = 12 )
621+ np .testing .assert_allclose (self .c_e (t , x ), c_e_combined , rtol = 1e-13 , atol = 1e- 12 )
608622
609623 def test_all (self ):
610624 self .test_concentration_limit ()
@@ -660,7 +674,7 @@ def __init__(self, model, param, disc, solution, operating_condition):
660674 def test_negative_electrode_potential_profile (self ):
661675 """Test that negative electrode potential is zero on left boundary. Test
662676 average negative electrode potential is less than or equal to zero."""
663- np .testing .assert_array_almost_equal (self .phi_s_n (self .t , x = 0 ), 0 , decimal = 5 )
677+ np .testing .assert_allclose (self .phi_s_n (self .t , x = 0 ), 0 , rtol = 1e-6 , atol = 1e- 5 )
664678
665679 def test_positive_electrode_potential_profile (self ):
666680 """Test average positive electrode potential is less than the positive electrode
@@ -673,25 +687,35 @@ def test_potential_differences(self):
673687 potential and electrolyte potential"""
674688 t , x_n , x_p = self .t , self .x_n , self .x_p
675689
676- np .testing .assert_array_almost_equal (
677- self .phi_s_n (t , x_n ) - self .phi_e_n (t , x_n ), self .delta_phi_n (t , x_n )
690+ np .testing .assert_allclose (
691+ self .phi_s_n (t , x_n ) - self .phi_e_n (t , x_n ),
692+ self .delta_phi_n (t , x_n ),
693+ rtol = 1e-7 ,
694+ atol = 1e-6 ,
678695 )
679- np .testing .assert_array_almost_equal (
696+ np .testing .assert_allclose (
680697 self .phi_s_p (t , x_p ) - self .phi_e_p (t , x_p ),
681698 self .delta_phi_p (t , x_p ),
682- decimal = 5 ,
699+ rtol = 1e-6 ,
700+ atol = 1e-5 ,
683701 )
684702
685703 def test_average_potential_differences (self ):
686704 """Test that average potential differences are the difference between electrode
687705 potential and electrolyte potential"""
688706 t = self .t
689707
690- np .testing .assert_array_almost_equal (
691- self .phi_s_n_av (t ) - self .phi_e_n_av (t ), self .delta_phi_n_av (t ), decimal = 4
708+ np .testing .assert_allclose (
709+ self .phi_s_n_av (t ) - self .phi_e_n_av (t ),
710+ self .delta_phi_n_av (t ),
711+ rtol = 1e-5 ,
712+ atol = 1e-4 ,
692713 )
693- np .testing .assert_array_almost_equal (
694- self .phi_s_p_av (t ) - self .phi_e_p_av (t ), self .delta_phi_p_av (t ), decimal = 4
714+ np .testing .assert_allclose (
715+ self .phi_s_p_av (t ) - self .phi_e_p_av (t ),
716+ self .delta_phi_p_av (t ),
717+ rtol = 1e-5 ,
718+ atol = 1e-4 ,
695719 )
696720
697721 def test_gradient_splitting (self ):
@@ -802,10 +826,10 @@ def test_current_density_boundaries(self):
802826 current_param = self .model .param .current_density_with_time
803827
804828 i_cell = self .param .process_symbol (current_param ).evaluate (t = t )
805- np .testing .assert_array_almost_equal (self .i_s_n (t , x_n [0 ]), i_cell , decimal = 2 )
806- np .testing .assert_array_almost_equal (self .i_s_n (t , x_n [- 1 ]), 0 , decimal = 4 )
807- np .testing .assert_array_almost_equal (self .i_s_p (t , x_p [- 1 ]), i_cell , decimal = 3 )
808- np .testing .assert_array_almost_equal (self .i_s_p (t , x_p [0 ]), 0 , decimal = 4 )
829+ np .testing .assert_allclose (self .i_s_n (t , x_n [0 ]), i_cell , rtol = 1e-3 , atol = 1e- 2 )
830+ np .testing .assert_allclose (self .i_s_n (t , x_n [- 1 ]), 0 , rtol = 1e-5 , atol = 1e- 4 )
831+ np .testing .assert_allclose (self .i_s_p (t , x_p [- 1 ]), i_cell , rtol = 1e-4 , atol = 1e- 3 )
832+ np .testing .assert_allclose (self .i_s_p (t , x_p [0 ]), 0 , rtol = 1e-5 , atol = 1e- 4 )
809833
810834 def test_all (self ):
811835 self .test_conservation ()
@@ -827,8 +851,8 @@ def __init__(self, model, param, disc, solution, operating_condition):
827851 def test_velocity_boundaries (self ):
828852 """Test the boundary values of the current densities"""
829853 L_x = self .x_edge [- 1 ]
830- np .testing .assert_array_almost_equal (self .v_box (self .t , 0 ), 0 , decimal = 4 )
831- np .testing .assert_array_almost_equal (self .v_box (self .t , L_x ), 0 , decimal = 4 )
854+ np .testing .assert_allclose (self .v_box (self .t , 0 ), 0 , rtol = 1e-5 , atol = 1e- 4 )
855+ np .testing .assert_allclose (self .v_box (self .t , L_x ), 0 , rtol = 1e-5 , atol = 1e- 4 )
832856
833857 def test_vertical_velocity (self ):
834858 """Test the boundary values of the current densities"""
@@ -847,11 +871,11 @@ def test_velocity_vs_current(self):
847871 DeltaV_p = self .param .evaluate (DeltaV_p )
848872 F = pybamm .constants .F .value
849873
850- np .testing .assert_array_almost_equal (
851- self .v_box (t , x_n ), DeltaV_n * self .i_e (t , x_n ) / F
874+ np .testing .assert_allclose (
875+ self .v_box (t , x_n ), DeltaV_n * self .i_e (t , x_n ) / F , rtol = 1e-7 , atol = 1e-6
852876 )
853- np .testing .assert_array_almost_equal (
854- self .v_box (t , x_p ), DeltaV_p * self .i_e (t , x_p ) / F
877+ np .testing .assert_allclose (
878+ self .v_box (t , x_p ), DeltaV_p * self .i_e (t , x_p ) / F , rtol = 1e-7 , atol = 1e-6
855879 )
856880
857881 def test_all (self ):
@@ -889,12 +913,13 @@ def test_degradation_modes(self):
889913
890914 def test_lithium_lost (self ):
891915 """Test the two ways of measuring lithium lost give the same value"""
892- np .testing .assert_array_almost_equal (
916+ np .testing .assert_allclose (
893917 self .n_Li_lost (self .t ),
894918 self .n_Li_lost_rxn (self .t )
895919 + self .n_Li_lost_LAM_n (self .t )
896920 + self .n_Li_lost_LAM_p (self .t ),
897- decimal = 5 ,
921+ rtol = 1e-6 ,
922+ atol = 1e-5 ,
898923 )
899924
900925 def test_all (self ):
0 commit comments