MCPcopy Create free account
hub / github.com/NanoComp/meep / FilteredSource

Class FilteredSource

python/adjoint/filter_source.py:10–188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8
9
10class FilteredSource(CustomSource):
11 def __init__(
12 self,
13 center_frequency: float,
14 frequencies: np.ndarray,
15 frequency_response,
16 dt,
17 time_src=None,
18 ):
19 # divide by two to compensate for staggered E, H time interval
20 dt = dt / 2
21 self.dt = dt
22 self.frequencies = frequencies
23 self.center_frequencies = frequencies
24
25 # For now, the basis functions cannot overlap much in the frequency
26 # domain. Otherwise, the resulting nodes are wildly large and induce
27 # numerical precision errors. We can always produce a safe result
28 # by forcing the length of each basis function to meet the minimum
29 # frequency requirements. This method still minimizes storage
30 # requirements.
31 self.T = np.max(np.abs(1 / np.diff(frequencies)))
32 self.N = np.rint(self.T / self.dt)
33 self.t = np.arange(0, dt * (self.N), dt)
34 self.n = np.arange(self.N)
35 f = self.func()
36
37 # frequency bandwidth of the Nuttall window function
38 fwidth = self.nuttall_bandwidth()
39
40 self.bf = [
41 lambda t, i=i: 0
42 if t > self.T
43 else (
44 self.nuttall(t, self.center_frequencies)
45 / (self.dt / np.sqrt(2 * np.pi))
46 )[i]
47 for i in range(len(self.center_frequencies))
48 ]
49 self.time_src_bf = [
50 CustomSource(
51 src_func=bfi,
52 center_frequency=center_frequency,
53 is_integrated=False,
54 end_time=self.T,
55 fwidth=fwidth,
56 )
57 for bfi in self.bf
58 ]
59
60 if time_src:
61 # get the cutoff of the input signal
62 signal_t = np.array(
63 [time_src.swigobj.current(ti, dt) for ti in self.t]
64 ) # time domain signal
65 signal_dtft = self.dtft(signal_t, self.frequencies)
66 else:
67 signal_dtft = 1

Callers 4

place_adjoint_sourceMethod · 0.85
place_adjoint_sourceMethod · 0.85
place_adjoint_sourceMethod · 0.85
place_adjoint_sourceMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected