Skip to content

Commit

Permalink
Adds test to check movie is created in test sphere
Browse files Browse the repository at this point in the history
  • Loading branch information
lmdiazangulo committed Nov 9, 2024
1 parent 4934733 commit efb237e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
14 changes: 4 additions & 10 deletions src_pyWrapper/pyWrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,11 @@ class Probe():

def __init__(self, probe_filename):
self.filename = probe_filename

# with open(probe_filename, 'r') as file:
# data = file.read()
# data = data.replace('/', '-')
# with open(probe_filename, 'w') as file:
# file.write(data)

mtln_probe_tags = ['_V_','_I_']
current_probe_tags = ['_Wx_', '_Wy_', '_Wz_']
far_field_tag = ['_FF_']
movie_tags = ['_ExC_', '_EyC_', '_EzC_', '_HxC_', '_HyC_', '_HzC_']
movie_tags = ['_ExC_', '_EyC_', '_EzC_', '_HxC_', '_HyC_', '_HzC_', '_ME_', '_MH_']
all_tags = current_probe_tags + far_field_tag + movie_tags + mtln_probe_tags


Expand All @@ -48,14 +42,14 @@ def __init__(self, probe_filename):
elif tag in far_field_tag:
self.type = 'farField'
self.name, positions_str = basename_with_no_case_name.split(tag)
init_str, end_str = pos = positions_str.split('__')
init_str, end_str = positions_str.split('__')
self.cell_init = positionStrToCell(init_str)
self.cell_end = positionStrToCell(end_str)
self.df = pd.read_csv(self.filename, sep='\s+')
elif tag in movie_tags:
self.type = 'movie'
self.name, positions_str = basename_with_no_case_name.split(tag)
init_str, end_str = pos = positions_str.split('__')
init_str, end_str = positions_str.split('__')
self.cell_init = positionStrToCell(init_str)
self.cell_end = positionStrToCell(end_str)
elif tag in mtln_probe_tags:
Expand Down Expand Up @@ -101,7 +95,7 @@ def getSolvedProbeFilenames(self, probe_name):
if not "probes" in input_json:
raise ValueError('Solver does not contain probes.')

file_extensions = ('*.dat', '*.bin')
file_extensions = ('*.dat', '*.xdmf', '*.bin', '*.h5')
probeFiles = []
for ext in file_extensions:
newProbes = [x for x in glob.glob(ext) if re.match(self.case + '_' + probe_name, x)]
Expand Down
28 changes: 17 additions & 11 deletions test/pyWrapper/test_full_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,27 +91,33 @@ def test_towelHanger(tmp_path):
for i in range(3):
p_solved = Probe(probe_files[i])
assert np.allclose(p_expected[i].df.to_numpy()[:,0:3], p_solved.df.to_numpy()[:,0:3], rtol = 5e-2, atol=5e-2)



def test_sphere(tmp_path):
case = 'sphere'
input_json = getCase(case)
input_json['general']['numberOfSteps'] = 200
input_json['probes'][0]['domain']['numberOfFrequencies'] = 100
input_json['general']['numberOfSteps'] = 20
input_json['probes'][0]['domain']['initialFrequency'] = 1e8
input_json['probes'][0]['domain']['finalFrequency'] = 1e9

fn = tmp_path._str + '/' + case + '.fdtd.json'
with open(fn, 'w') as modified_json:
json.dump(input_json, modified_json)
with open(fn, 'w') as modified_json_file:
json.dump(input_json, modified_json_file)

makeCopy(tmp_path, EXCITATIONS_FOLDER+'gauss.exc')

solver = FDTD(input_filename = fn, path_to_exe=SEMBA_EXE)
solver.run()
probe_files = solver.getSolvedProbeFilenames("Far") # semba-fdtd seems to always use the name Far for "far field" probes.
assert solver.hasFinishedSuccessfully()

far_field_probe_files = solver.getSolvedProbeFilenames("Far") # semba-fdtd seems to always use the name Far for "far field" probes.
assert solver.hasFinishedSuccessfully() == True
assert len(probe_files) == 1

p = Probe(probe_files[0])
assert p.type == 'farField'
assert len(far_field_probe_files) == 1
p = Probe(far_field_probe_files[0])
assert p.type == 'farField'

electric_field_movie_files = solver.getSolvedProbeFilenames("electric_field_movie")
assert solver.hasFinishedSuccessfully() == True
assert len(electric_field_movie_files) == 3
p = Probe(electric_field_movie_files[0])
assert p.type == 'movie'

9 changes: 8 additions & 1 deletion test/pyWrapper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ def copyInputFiles(temp_dir, input, excitation, executable):
makeCopy(temp_dir, executable)

def getProbeFile(prefix, probe_name):
return ([x for x in glob.glob('*dat') if re.match(prefix + '_' + probe_name + '.*dat',x)])[0]
extensions = ["dat", "xdmf", "h5", "bin"]

probeFiles = []
for ext in extensions:
newFiles = ([x for x in glob.glob('*'+ext) if re.match(prefix + '_' + probe_name + '.*'+ext, x)])[0]
probeFiles.append(newFiles)

return probeFiles

def countLinesInFile(probe_fn):
with open(probe_fn, 'r') as f:
Expand Down

0 comments on commit efb237e

Please sign in to comment.