2 Commits b8ea8fdc45 ... 3c00389570

Author SHA1 Message Date
  Saravanan Dayalan 3c00389570 feat: add normalized differentiated gaussian pulse source 1 month ago
  Saravanan Dayalan bfd6b45564 refactor: replace time_step with t 1 month ago
2 changed files with 25 additions and 9 deletions
  1. 2 2
      src/fdtdpy/simulation.py
  2. 23 7
      src/fdtdpy/sources.py

+ 2 - 2
src/fdtdpy/simulation.py

@@ -28,12 +28,12 @@ def simulate(ke: int, ex: np.ndarray, hy: np.ndarray) -> tuple[np.ndarray, np.nd
     Hy = np.empty((0, hy.shape[0]))
 
     # FDTD simulation loop
-    for time_step in range(1, nsteps + 1):
+    for t in range(1, nsteps + 1):
         # calculate the Ex field
         ex[1:ke] = ex[1:ke] + 0.5 * (hy[0:ke-1] - hy[1:ke])
 
         # sinusoidal wave source (frequency 1900 MHz)
-        ex[1] = ex[1] + sources.sinusoidal(time_step, freq=1900e6)
+        ex[1] = ex[1] + sources.sinusoidal(t, freq=1900e6)
 
         # absorbing boundary conditions
         ex[0], lbound[0], lbound[1] = lbound[0], lbound[1], ex[1]

+ 23 - 7
src/fdtdpy/sources.py

@@ -4,27 +4,43 @@
 import numpy as np
 
 
-def gaussian(time_step: int, t0: int = 40, spread: float = 12) -> float:
+def gaussian(t: int, t0: int = 70, sigma: float = 12) -> float:
     """
     Gaussian pulse source
 
-    :param int time_step: an integer counter that serves as the temporal index
+    :param int t: an integer counter that serves as the temporal index
     :param int t0: time step at which gaussian function is maximum, default 40
-    :param float spread: width of the gaussian pulse, default 12
+    :param float sigma: width of the gaussian pulse, default 12
 
     :return: gaussian pulse
     :rtype: float
 
     """
 
-    return np.exp(-0.5 * ((t0 - time_step) / spread) ** 2)
+    return np.exp(-0.5 * ((t - t0) / sigma) ** 2)
 
 
-def sinusoidal(time_step: int, ddx: float = 0.01, freq: float = 700e6) -> float:
+def normalized_gaussian(t: int, t0: int = 40, sigma: float = 12) -> float:
+    """
+    Normalized differentiated Gaussian pulse source
+
+    :param int t: an integer counter that serves as the temporal index
+    :param int t0: time step at which gaussian function is maximum, default 40
+    :param float sigma: width of the gaussian pulse, default 12
+
+    :return: normalized differentiated gaussian pulse
+    :rtype: float
+
+    """
+
+    return -(t - t0) / sigma * np.exp(-0.5 * ((t - t0) / sigma) ** 2)
+
+
+def sinusoidal(t: int, ddx: float = 0.01, freq: float = 700e6) -> float:
     """
     Sinusoidal wave source
 
-    :param int time_step: an integer counter that serves as the temporal index
+    :param int t: an integer counter that serves as the temporal index
     :param float ddx: the cell size (m), default 0.01 m
     :param float freq: frequency of the sinusoidal wave source, default 700 MHz
 
@@ -35,4 +51,4 @@ def sinusoidal(time_step: int, ddx: float = 0.01, freq: float = 700e6) -> float:
 
     dt: float = ddx / 6e8  # time step
 
-    return np.sin(2 * np.pi * freq * dt * time_step)
+    return np.sin(2 * np.pi * freq * dt * t)