@@ -169,9 +169,11 @@ def test_new(self):
169
169
self .assert_all_close (self .elastic_tensor_1 , ElasticTensor (self .ft ))
170
170
non_symm = self .ft
171
171
non_symm [0 , 1 , 2 , 2 ] += 1.0
172
- with warnings .catch_warnings (record = True ) as w :
172
+ with pytest .warns (
173
+ UserWarning , match = "Input elastic tensor does not satisfy standard Voigt symmetries"
174
+ ) as warns :
173
175
ElasticTensor (non_symm )
174
- assert len (w ) == 1
176
+ assert len (warns ) == 1
175
177
bad_tensor1 = np .zeros ((3 , 3 , 3 ))
176
178
bad_tensor2 = np .zeros ((3 , 3 , 3 , 2 ))
177
179
with pytest .raises (ValueError , match = "ElasticTensor input must be rank 4" ):
@@ -185,7 +187,11 @@ def test_new(self):
185
187
def test_from_pseudoinverse (self ):
186
188
strain_list = [Strain .from_deformation (def_matrix ) for def_matrix in self .def_stress_dict ["deformations" ]]
187
189
stress_list = list (self .def_stress_dict ["stresses" ])
188
- with warnings .catch_warnings (record = True ):
190
+ with pytest .warns (
191
+ UserWarning ,
192
+ match = "Pseudo-inverse fitting of Strain/Stress lists may yield questionable results from "
193
+ "vasp data, use with caution" ,
194
+ ):
189
195
et_fl = - 0.1 * ElasticTensor .from_pseudoinverse (strain_list , stress_list ).voigt
190
196
self .assert_all_close (
191
197
et_fl .round (2 ),
@@ -202,8 +208,9 @@ def test_from_pseudoinverse(self):
202
208
def test_from_independent_strains (self ):
203
209
strains = self .toec_dict ["strains" ]
204
210
stresses = self .toec_dict ["stresses" ]
205
- with warnings . catch_warnings ( record = True ) :
211
+ with pytest . warns ( UserWarning , match = "No eq state found, returning zero voigt stress" ) as warns :
206
212
et = ElasticTensor .from_independent_strains (strains , stresses )
213
+ assert len (warns ) == 2
207
214
self .assert_all_close (et .voigt , self .toec_dict ["C2_raw" ], decimal = - 1 )
208
215
209
216
def test_energy_density (self ):
@@ -429,9 +436,8 @@ def test_get_strain_state_dict(self):
429
436
def test_find_eq_stress (self ):
430
437
test_strains = deepcopy (self .strains )
431
438
test_stresses = deepcopy (self .pk_stresses )
432
- with warnings .catch_warnings (record = True ):
433
- no_eq = find_eq_stress (test_strains , test_stresses )
434
- self .assert_all_close (no_eq , np .zeros ((3 , 3 )))
439
+ no_eq = find_eq_stress (test_strains , test_stresses )
440
+ self .assert_all_close (no_eq , np .zeros ((3 , 3 )))
435
441
test_strains [3 ] = Strain .from_voigt (np .zeros (6 ))
436
442
eq_stress = find_eq_stress (test_strains , test_stresses )
437
443
self .assert_all_close (test_stresses [3 ], eq_stress )
@@ -445,15 +451,7 @@ def test_get_diff_coeff(self):
445
451
self .assert_all_close (forward_13 , [- 11 / 6 , 3 , - 3 / 2 , 1 / 3 ])
446
452
self .assert_all_close (
447
453
backward_26 ,
448
- [
449
- 137 / 180 ,
450
- - 27 / 5 ,
451
- 33 / 2 ,
452
- - 254 / 9 ,
453
- 117 / 4 ,
454
- - 87 / 5 ,
455
- 203 / 45 ,
456
- ],
454
+ [137 / 180 , - 27 / 5 , 33 / 2 , - 254 / 9 , 117 / 4 , - 87 / 5 , 203 / 45 ],
457
455
)
458
456
self .assert_all_close (central_29 , central_diff_weights (9 , 2 ))
459
457
@@ -468,12 +466,11 @@ def test_fit(self):
468
466
reduced = [(e , pk ) for e , pk in zip (self .strains , self .pk_stresses ) if not (abs (abs (e ) - 0.05 ) < 1e-10 ).any ()]
469
467
# Get reduced dataset
470
468
r_strains , r_pk_stresses = zip (* reduced )
471
- with warnings .catch_warnings (record = True ):
472
- c2 = diff_fit (r_strains , r_pk_stresses , self .data_dict ["eq_stress" ], order = 2 )
473
- c2 , c3 , c4 = diff_fit (r_strains , r_pk_stresses , self .data_dict ["eq_stress" ], order = 4 )
474
- c2 , c3 = diff_fit (self .strains , self .pk_stresses , self .data_dict ["eq_stress" ], order = 3 )
475
- c2_red , c3_red = diff_fit (r_strains , r_pk_stresses , self .data_dict ["eq_stress" ], order = 3 )
476
- self .assert_all_close (c2 .voigt , self .data_dict ["C2_raw" ])
477
- self .assert_all_close (c3 .voigt , self .data_dict ["C3_raw" ], decimal = 5 )
478
- self .assert_all_close (c2 , c2_red , decimal = 0 )
479
- self .assert_all_close (c3 , c3_red , decimal = - 1 )
469
+ c2 = diff_fit (r_strains , r_pk_stresses , self .data_dict ["eq_stress" ], order = 2 )
470
+ c2 , c3 , c4 = diff_fit (r_strains , r_pk_stresses , self .data_dict ["eq_stress" ], order = 4 )
471
+ c2 , c3 = diff_fit (self .strains , self .pk_stresses , self .data_dict ["eq_stress" ], order = 3 )
472
+ c2_red , c3_red = diff_fit (r_strains , r_pk_stresses , self .data_dict ["eq_stress" ], order = 3 )
473
+ self .assert_all_close (c2 .voigt , self .data_dict ["C2_raw" ])
474
+ self .assert_all_close (c3 .voigt , self .data_dict ["C3_raw" ], decimal = 5 )
475
+ self .assert_all_close (c2 , c2_red , decimal = 0 )
476
+ self .assert_all_close (c3 , c3_red , decimal = - 1 )
0 commit comments