Skip to content

Commit

Permalink
Added test for dielectric refraction
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianarce-elemwave committed Jan 9, 2025
1 parent b0b1867 commit 8644e80
Show file tree
Hide file tree
Showing 3 changed files with 30,110 additions and 7 deletions.
72 changes: 72 additions & 0 deletions test/pyWrapper/test_full_system.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from utils import *
from typing import Dict


@no_mtln_skip
Expand Down Expand Up @@ -268,3 +269,74 @@ def test_sgbc_shielding_effectiveness(tmp_path):
anal_s21_db = 20*np.log10(np.abs(slab.s[:, 0, 1]))

assert np.allclose(fdtd_s21_db, anal_s21_db, rtol=0.05)

def test_dielectric_refraction(tmp_path):
_FIELD_TOLERANCE = 0.05
_RELATIVE_PERMITTIVITY = 4

def getIncidentField(probe:Probe) -> Dict:
idx = probe.df['field'].argmin()
time = probe.df['time'][idx]
value = probe.df['field'][idx]
return {"time":time, "value": value}

def getReflectedField(probe:Probe) -> Dict:
idx = probe.df['field'].argmax()
time = probe.df['time'][idx]
value = probe.df['field'][idx]
return {"time":time, "value": value}

def getRefractedField(probe:Probe) -> Dict:
idx = probe.df['field'].argmin()
time = probe.df['time'][idx]
value = probe.df['field'][idx]
return {"time":time, "value": value}

def getReflectedDelay(incidentTime:float, reflectedTime:float):
timeToSurface:float = ((reflectedTime-incidentTime)/2) + incidentTime
reflectedDelay:float = reflectedTime - timeToSurface
return reflectedDelay

def getRefractedDelay(incidentTime:float, reflectedTime:float, refractedTime:float):
timeToSurface:float = ((reflectedTime-incidentTime)/2) + incidentTime
refractedDelay = refractedTime - timeToSurface
return refractedDelay

materialRelativeImpedance = np.sqrt(1/_RELATIVE_PERMITTIVITY)
expectedReflectedCoeff = (materialRelativeImpedance - 1) / (materialRelativeImpedance + 1)
expectedRefractedCoeff = (1 + expectedReflectedCoeff)

expectedDelayRatio = 1/np.sqrt(_RELATIVE_PERMITTIVITY)

fn = CASES_FOLDER + "dielectric_refraction/dielectricRefraction.fdtd.json"
solver = FDTD(fn, path_to_exe=SEMBA_EXE, run_in_folder=tmp_path)

solver.run()
assert solver.hasFinishedSuccessfully()

outsideProbe = Probe(solver.getSolvedProbeFilenames("outside")[0])
insideProbe = Probe(solver.getSolvedProbeFilenames("inside")[0])

time = outsideProbe.df['time']
dt = time[1] - time[0]
fq = fftfreq(len(time))/dt

incidentField = getIncidentField(outsideProbe)
reflectedField = getReflectedField(outsideProbe)
refractedField = getRefractedField(insideProbe)

assert (incidentField['value'] - refractedField['value'] + reflectedField['value']) < _FIELD_TOLERANCE
assert np.allclose(reflectedField["value"]/incidentField["value"], expectedReflectedCoeff, rtol=_FIELD_TOLERANCE)
assert np.allclose(refractedField["value"]/incidentField["value"], expectedRefractedCoeff, rtol=_FIELD_TOLERANCE)

reflectedDelay:float = getReflectedDelay(incidentField['time'], reflectedField['time'])
refractedDelay:float = getRefractedDelay(incidentField['time'], reflectedField['time'], refractedField['time'])

assert np.allclose(reflectedDelay/refractedDelay, expectedDelayRatio, rtol=_FIELD_TOLERANCE)







44 changes: 37 additions & 7 deletions testData/cases/dielectric_refraction/dielectricRefraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,45 @@
plt.legend()

# %%
getMaxTimeOutside = outside.df['field'].argmin()
getMaxTimeOutside
incidentPulseIndex = outside.df['field'].argmin()
reflectedPulseIndex = outside.df['field'].argmax()
refractedPulseIndex = inside.df['field'].argmin()

# %%
outside.df['field'][getMaxTimeOutside]
incidentPulse = outside.df['field'][incidentPulseIndex]
reflectedPulse = outside.df['field'][reflectedPulseIndex]
refractedPulse = inside.df['field'][refractedPulseIndex]
pulses = [
incidentPulse,
reflectedPulse,
refractedPulse
]

incidentTime = outside.df['time'][incidentPulseIndex]
reflectedTime = outside.df['time'][reflectedPulseIndex]
refractedTime = inside.df['time'][refractedPulseIndex]

times = [
incidentTime,
reflectedTime,
refractedTime
]

for i in range(len(pulses)):
print(pulses[i])
print(times[i])
print()

# %%
outside.df['time'][getMaxTimeOutside]

print(pulses[0] + pulses[1] - pulses[2])
# %%
getMaxTimeInside = inside.df['field'].argmin()
inside.df['field'][getMaxTimeInside]
inside.df['time'][getMaxTimeInside]

timeToDielectricSurface = (times[1] - times[0])/2 + times[0]

reflectedDelay = times[1] - timeToDielectricSurface
refractedDelay = times[2] - timeToDielectricSurface
print(reflectedDelay)
print(refractedDelay)
print(reflectedDelay/refractedDelay)
# %%
Loading

0 comments on commit 8644e80

Please sign in to comment.