(self)
| 689 | self.assertAlmostEqual(result[0], -0.0599602798684155) |
| 690 | |
| 691 | def test_timing_data(self): |
| 692 | resolution = 20 |
| 693 | cell_size = mp.Vector3(10, 10) |
| 694 | pml = [mp.PML(1)] |
| 695 | center = mp.Vector3(2, -1) |
| 696 | result = [] |
| 697 | fcen = 0.15 |
| 698 | df = 0.1 |
| 699 | |
| 700 | sources = [ |
| 701 | mp.Source( |
| 702 | src=mp.GaussianSource(fcen, fwidth=df), |
| 703 | component=mp.Ez, |
| 704 | center=mp.Vector3(), |
| 705 | ) |
| 706 | ] |
| 707 | geometry = [ |
| 708 | mp.Block( |
| 709 | center=mp.Vector3(), |
| 710 | size=mp.Vector3(mp.inf, 3, mp.inf), |
| 711 | material=mp.Medium(epsilon=12), |
| 712 | ) |
| 713 | ] |
| 714 | |
| 715 | sim = mp.Simulation( |
| 716 | resolution=resolution, |
| 717 | cell_size=cell_size, |
| 718 | boundary_layers=pml, |
| 719 | sources=sources, |
| 720 | geometry=geometry, |
| 721 | geometry_center=center, |
| 722 | ) |
| 723 | sim.run(until=50) |
| 724 | timing_data = sim.get_timing_data() |
| 725 | |
| 726 | # Non-exhaustive collection of steps where some time should be spent: |
| 727 | EXPECTED_NONZERO_TIMESINKS = ( |
| 728 | mp.Stepping, |
| 729 | mp.Boundaries, |
| 730 | mp.FieldUpdateB, |
| 731 | mp.FieldUpdateH, |
| 732 | mp.FieldUpdateD, |
| 733 | mp.FieldUpdateE, |
| 734 | ) |
| 735 | # Due to the problem setup, no time should be spent on these steps: |
| 736 | EXPECTED_ZERO_TIMESINKS = (mp.MPBTime, mp.GetFarfieldsTime) |
| 737 | |
| 738 | for sink in itertools.chain( |
| 739 | EXPECTED_NONZERO_TIMESINKS, EXPECTED_ZERO_TIMESINKS |
| 740 | ): |
| 741 | self.assertIn(sink, timing_data.keys()) |
| 742 | self.assertEqual(len(timing_data[sink]), mp.count_processors()) |
| 743 | np.testing.assert_array_equal(sim.time_spent_on(sink), timing_data[sink]) |
| 744 | |
| 745 | for sink in EXPECTED_NONZERO_TIMESINKS: |
| 746 | for t in timing_data[sink]: |
| 747 | self.assertGreater(t, 0) |
| 748 |
nothing calls this directly
no test coverage detected