From 39873c9ef3e844209247c47148b80829081302bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dieter=20Werthm=C3=BCller?= Date: Thu, 19 Aug 2021 15:14:11 +0200 Subject: [PATCH] Undo a thing from previous commit; add test (#240) --- emg3d/simulations.py | 2 +- tests/test_simulations.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/emg3d/simulations.py b/emg3d/simulations.py index 21a46fea..bf6aacf5 100644 --- a/emg3d/simulations.py +++ b/emg3d/simulations.py @@ -1087,7 +1087,7 @@ def print_solver_info(self, field='efield', verb=1, return_info=False): cinfo = info[src][freq] # Print if verbose or not converged. - if verb > 0 or cinfo['exit'] != 0: + if cinfo is not None and (verb > 0 or cinfo['exit'] != 0): # Initial message. if not out: diff --git a/tests/test_simulations.py b/tests/test_simulations.py index ef641950..8bc22dec 100644 --- a/tests/test_simulations.py +++ b/tests/test_simulations.py @@ -422,6 +422,22 @@ def test_print_solver(self, capsys): out, _ = capsys.readouterr() assert "= Source TxED-1; Frequency 1.0 Hz = CONVERGED" in out + # Two sources, only compute 1, assure printing works. + sources = [emg3d.TxElectricDipole((x, 0, 0, 0, 0)) for x in [0, 10]] + survey = emg3d.Survey( + name='Test', sources=sources, + receivers=receivers, + frequencies=1.0, noise_floor=1e-15, relative_error=0.05, + ) + + inp = {'name': 'Test', 'survey': survey, 'model': model, + 'gridding': 'same'} + simulation = simulations.Simulation(**inp, solver_opts={'verb': 0}) + _ = simulation.get_efield('TxED-2', 'f-1') + simulation.print_solver_info(verb=1) + out, _ = capsys.readouterr() + assert "= Source TxED-2; Frequency 1.0 Hz = CONVERGED" in out + def test_rel_abs_rec(self): # Sources sources = emg3d.surveys.txrx_coordinates_to_dict(