diff --git a/test/pyWrapper/test_integration.py b/test/pyWrapper/test_integration.py index 0bac80d4..623c5a2d 100644 --- a/test/pyWrapper/test_integration.py +++ b/test/pyWrapper/test_integration.py @@ -164,4 +164,27 @@ def test_sgbc_can_launch(tmp_path): solver = FDTD(input_filename = fn, path_to_exe=SEMBA_EXE) solver.run() - assert solver.hasFinishedSuccessfully() == True \ No newline at end of file + assert solver.hasFinishedSuccessfully() == True + +def test_sgbc_vtk_tags(tmp_path): + case = 'sgbc' + input_json = getCase(case) + input_json['general']['numberOfSteps'] = 1 + fn = tmp_path._str + '/' + case + '.fdtd.json' + with open(fn, 'w') as modified_json: + json.dump(input_json, modified_json) + + solver = FDTD(input_filename = fn, path_to_exe=SEMBA_EXE, flags=['-mapvtk']) + solver.run() + + assert solver.hasFinishedSuccessfully() == True + + vtkmapfile = solver.getVTKMap() + + assert os.path.isfile(vtkmapfile) + + d = createFaceTagDictionary(vtkmapfile) + assert d[64] == 4 + assert d[128] == 4 + assert d[192] == 4 + \ No newline at end of file diff --git a/test/pyWrapper/utils.py b/test/pyWrapper/utils.py index f40f920f..e452c7f0 100644 --- a/test/pyWrapper/utils.py +++ b/test/pyWrapper/utils.py @@ -3,6 +3,7 @@ import json import numpy as np import matplotlib.pyplot as plt +import pyvista as pv # Use of absolute path to avoid conflicts when changing directory. SEMBA_EXE = os.getcwd() + '/build/bin/semba-fdtd' @@ -63,3 +64,13 @@ def readSpiceFile(spice_file): val = np.append(val, float(l.split()[1])) return t, val +def createFaceTagDictionary(vtkfile): + ugrid = pv.UnstructuredGrid(vtkfile) + quads = np.argwhere(ugrid.celltypes == 9) #[i][0] + tags = np.array([]) + tagnumber_array = ugrid.cell_data['tagnumber'] + for i in range(quads[0][0], quads[-1][0]+1): + tags = np.append(tags, tagnumber_array[i]) + + unique, counts = np.unique(tags, return_counts=True) + return dict(zip(unique, counts))