Skip to content

Commit 53fc640

Browse files
committed
Fix calculation error in MaxwellGarnettEMA
1 parent 1c6daa7 commit 53fc640

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/elli/materials.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,20 @@ def get_tensor_fraction(self, lbda: npt.ArrayLike, fraction: float) -> npt.NDArr
375375
e_h = self.host_material.get_tensor(lbda)
376376
e_g = self.guest_material.get_tensor(lbda)
377377

378-
# fmt: off
379-
epsilon = e_h \
380-
* (2 * fraction * (e_g - e_h) + e_g + 2 * e_h) \
378+
# Catch calculation warnings
379+
old_settings = np.geterr()
380+
np.seterr(invalid="ignore")
381+
382+
maxwell_garnett = (
383+
e_h
384+
* (2 * fraction * (e_g - e_h) + e_g + 2 * e_h)
381385
/ (2 * e_h + e_g - fraction * (e_g - e_h))
382-
# fmt: on
386+
)
387+
388+
# Reset numpy settings
389+
np.seterr(**old_settings)
390+
391+
epsilon = np.where(np.logical_and(e_h == 0, e_g == 0), e_h, maxwell_garnett)
383392
return epsilon
384393

385394

0 commit comments

Comments
 (0)