Skip to content

Commit

Permalink
adds function to generate dictionary with number of tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto-o committed Dec 17, 2024
1 parent 69be1b3 commit 3a3ebec
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
25 changes: 24 additions & 1 deletion test/pyWrapper/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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

11 changes: 11 additions & 0 deletions test/pyWrapper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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))

0 comments on commit 3a3ebec

Please sign in to comment.