Skip to content

Commit a22f358

Browse files
committed
Monitor tests
1 parent c2cfd06 commit a22f358

File tree

1 file changed

+114
-13
lines changed

1 file changed

+114
-13
lines changed

tests/test_components/test_heat_charge.py

Lines changed: 114 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -252,18 +252,21 @@ def monitors():
252252

253253
energy_band_mnt1 = td.SteadyEnergyBandMonitor(size=(1.6, 2, 3), name="bandgap_test")
254254

255+
electric_field_mnt = td.SteadyElectricFieldMonitor(size=(1.6, 2, 3), name="electric_field_test")
256+
255257
return [
256-
temp_mnt1,
257-
temp_mnt2,
258-
temp_mnt3,
259-
temp_mnt4,
260-
volt_mnt1,
261-
volt_mnt2,
262-
volt_mnt3,
263-
volt_mnt4,
264-
capacitance_mnt1,
265-
free_carrier_mnt1,
266-
energy_band_mnt1,
258+
temp_mnt1, # 0
259+
temp_mnt2, # 1
260+
temp_mnt3, # 2
261+
temp_mnt4, # 3
262+
volt_mnt1, # 4
263+
volt_mnt2, # 5
264+
volt_mnt3, # 6
265+
volt_mnt4, # 7
266+
capacitance_mnt1, # 8
267+
free_carrier_mnt1, # 9
268+
energy_band_mnt1, # 10
269+
electric_field_mnt, # 11
267270
]
268271

269272

@@ -516,7 +519,10 @@ def temperature_monitor_data(monitors):
516519
@pytest.fixture(scope="module")
517520
def voltage_monitor_data(monitors):
518521
"""Creates different voltage monitor data."""
519-
_, _, _, _, volt_mnt1, volt_mnt2, volt_mnt3, volt_mnt4, _, _, _ = monitors
522+
volt_mnt1 = monitors[4]
523+
volt_mnt2 = monitors[5]
524+
volt_mnt3 = monitors[6]
525+
volt_mnt4 = monitors[7]
520526

521527
# SpatialDataArray
522528
nx, ny, nz = 9, 6, 5
@@ -642,6 +648,84 @@ def energy_band_monitor_data(monitors):
642648
return (eb_data1,)
643649

644650

651+
@pytest.fixture(scope="module")
652+
def electric_field_monitor_data(monitors):
653+
"""Creates different electric field monitor data."""
654+
monitor = monitors[11]
655+
656+
# TetrahedralGridDataset
657+
tet_grid_points = td.PointDataArray(
658+
[[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [1.0, 1.0, 0.0], [0.0, 0.0, 1.0]],
659+
dims=("index", "axis"),
660+
)
661+
662+
tet_grid_cells = td.CellDataArray(
663+
[[0, 1, 2, 4], [1, 2, 3, 4]],
664+
dims=("cell_index", "vertex_index"),
665+
)
666+
667+
tet_grid_values = td.IndexedDataArray(
668+
[1.0, 2.0, 3.0, 4.0, 5.0],
669+
dims=("index",),
670+
name="T",
671+
)
672+
673+
tet_grid = td.TetrahedralGridDataset(
674+
points=tet_grid_points,
675+
cells=tet_grid_cells,
676+
values=tet_grid_values,
677+
)
678+
679+
mnt_data1 = td.SteadyElectricFieldData(monitor=monitor, Ex=tet_grid, Ey=tet_grid, Ez=tet_grid)
680+
681+
# TriangularGridDataset
682+
tri_grid_points = td.PointDataArray(
683+
[[0.0, 0.0], [1.0, 0.0], [0.0, 1.0], [1.0, 1.0]],
684+
dims=("index", "axis"),
685+
)
686+
687+
tri_grid_cells = td.CellDataArray(
688+
[[0, 1, 2], [1, 2, 3]],
689+
dims=("cell_index", "vertex_index"),
690+
)
691+
692+
tri_grid_values = td.IndexedDataArray(
693+
[1.0, 2.0, 3.0, 4.0],
694+
dims=("index",),
695+
name="T",
696+
)
697+
698+
tri_grid = td.TriangularGridDataset(
699+
normal_axis=1,
700+
normal_pos=0,
701+
points=tri_grid_points,
702+
cells=tri_grid_cells,
703+
values=tri_grid_values,
704+
)
705+
706+
mnt_data2 = td.SteadyElectricFieldData(monitor=monitor, Ex=tri_grid, Ey=tri_grid, Ez=tri_grid)
707+
708+
mnt_data3 = td.SteadyElectricFieldData(monitor=monitor, Ex=None, Ey=None, Ez=None)
709+
710+
data_v = td.IndexedVoltageDataArray(
711+
[[0.0, 1.5], [1.5, 2], [2.5, 3.0], [3.5, -4.0]],
712+
coords={"index": np.arange(4), "voltage": [-1, 1]},
713+
name="test",
714+
)
715+
tri_grid_v = td.TriangularGridDataset(
716+
normal_axis=1,
717+
normal_pos=0,
718+
points=tri_grid_points,
719+
cells=tri_grid_cells,
720+
values=data_v,
721+
)
722+
mnt_data4 = td.SteadyElectricFieldData(
723+
monitor=monitor, Ex=tri_grid_v, Ey=tri_grid_v, Ez=tri_grid_v
724+
)
725+
726+
return (mnt_data1, mnt_data2, mnt_data3, mnt_data4)
727+
728+
645729
@pytest.fixture(scope="module")
646730
def simulation_data(
647731
heat_simulation,
@@ -797,11 +881,28 @@ def test_monitor_crosses_medium(mediums, structures, heat_simulation, conduction
797881

798882

799883
def test_heat_charge_mnt_data(
800-
temperature_monitor_data, voltage_monitor_data, capacitance_monitor_data
884+
temperature_monitor_data, voltage_monitor_data, electric_field_monitor_data
801885
):
802886
"""Tests whether different heat-charge monitor data can be created."""
803887
assert len(temperature_monitor_data) == 4, "Expected 4 temperature monitor data entries."
804888
assert len(voltage_monitor_data) == 4, "Expected 4 voltage monitor data entries."
889+
assert len(electric_field_monitor_data) == 4, "Expected 4 electric field monitor data entries."
890+
891+
for mnt_data in electric_field_monitor_data:
892+
assert "Ex" in mnt_data.field_components.keys()
893+
assert "Ey" in mnt_data.field_components.keys()
894+
assert "Ez" in mnt_data.field_components.keys()
895+
896+
symm_data = mnt_data.symmetry_expanded_copy
897+
assert symm_data.Ex == mnt_data.Ex
898+
assert symm_data.Ey == mnt_data.Ey
899+
assert symm_data.Ez == mnt_data.Ez
900+
901+
names = mnt_data.field_name("abs^2")
902+
print(names)
903+
assert names == "Ex², Ey², Ez²"
904+
names = mnt_data.field_name()
905+
assert names == "Ex, Ey, Ez"
805906

806907

807908
def test_grid_spec_validation(grid_specs):

0 commit comments

Comments
 (0)