aboutsummaryrefslogtreecommitdiff
path: root/src/devices/directional_coupler.cpp
blob: da0872b499374eaa8f1b564c6c4a6a62dfe6c1ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
#include "specs.h"
#include <directional_coupler.h>

using namespace std;

void DirectionalCouplerUni::on_port_in1_changed()
{
    m_through_power_dB = 10*log10(m_dc_through_coupling_power) - m_dc_loss;
    m_cross_power_dB = 10*log10(1.0 - m_dc_through_coupling_power) - m_dc_loss;

    m_memory_in1[0] = 0; // initializing for nan wavelength

    const double transmission_through = pow(10.0, m_through_power_dB / 20.0);
    const double transmission_cross = pow(10.0, m_cross_power_dB / 20.0);

    // Pre-calculate S-parameters
    OpticalSignal::field_type S13, S14, S23, S24;
    S13 = polar(transmission_through, m_through_phase_rad);
    S24 = polar(transmission_through, m_through_phase_rad);
    S14 = polar(transmission_cross, m_cross_phase_rad);
    S23 = polar(transmission_cross, m_cross_phase_rad);

    if (specsGlobalConfig.verbose_component_initialization)
    {
        cout << name() << ":" << endl;
        cout << "through_power = " << norm(S13) << " W/W" << endl;
        cout << "cross_power = " << norm(S14)<< " W/W" << endl;
        cout << "through_field = " << abs(S13) << "" << endl;
        cout << "cross_field = " << abs(S14)<< "" << endl;
        cout << "insertion loss = " << m_dc_loss << "dB" << endl;
        cout << (dynamic_cast<spx::oa_signal_type *>(p_in1.get_interface()))->name();
        cout << " --,__,-> ";
        cout << (dynamic_cast<spx::oa_signal_type *>(p_out1.get_interface()))->name();
        cout << endl;

        cout << (dynamic_cast<spx::oa_signal_type *>(p_in2.get_interface()))->name();
        cout << " --'  '-> ";
        cout << (dynamic_cast<spx::oa_signal_type *>(p_out2.get_interface()))->name();
        cout << endl;

        cout << endl;
    }

    OpticalSignal p_in1_read;

    while (true) {
        // Wait for a new input signal
        wait();

        // Read current inputs
        p_in1_read = p_in1->read();

        auto cur_wavelength_id = p_in1_read.m_wavelength_id;
        // Updating the field memory
        m_memory_in1[cur_wavelength_id] = p_in1_read.m_field;

        auto s3 = OpticalSignal(m_memory_in1[cur_wavelength_id] * S13 +
                        m_memory_in2[cur_wavelength_id] * S23
                        , cur_wavelength_id);

        auto s4 = OpticalSignal(m_memory_in1[cur_wavelength_id] * S14 +
                                m_memory_in2[cur_wavelength_id] * S24
                                , cur_wavelength_id);

        m_out1_writer.delayedWrite(s3, sc_time(m_delay_ns, SC_NS));
        m_out2_writer.delayedWrite(s4, sc_time(m_delay_ns, SC_NS));
    }
}

void DirectionalCouplerUni::on_port_in2_changed()
{
    m_through_power_dB = 10*log10(m_dc_through_coupling_power) - m_dc_loss;
    m_cross_power_dB = 10*log10(1.0 - m_dc_through_coupling_power) - m_dc_loss;

    m_memory_in2[0] = 0; // initializing for nan wavelength

    const double transmission_through = pow(10.0, m_through_power_dB / 20.0);
    const double transmission_cross = pow(10.0, m_cross_power_dB / 20.0);

    // Pre-calculate S-parameters
    OpticalSignal::field_type S13, S14, S23, S24;
    S13 = polar(transmission_through, m_through_phase_rad);
    S24 = polar(transmission_through, m_through_phase_rad);
    S14 = polar(transmission_cross, m_cross_phase_rad);
    S23 = polar(transmission_cross, m_cross_phase_rad);

    OpticalSignal p_in2_read;

    while (true) {
        // Wait for a new input signal
        wait();

        // Read current inputs
        p_in2_read = p_in2->read();

        auto cur_wavelength_id = p_in2_read.m_wavelength_id;
        // Updating the field memory
        m_memory_in2[cur_wavelength_id] = p_in2_read.m_field;

        auto s3 = OpticalSignal(m_memory_in1[cur_wavelength_id] * S13 +
                                m_memory_in2[cur_wavelength_id] * S23
                        , cur_wavelength_id);

        auto s4 = OpticalSignal(m_memory_in1[cur_wavelength_id] * S14 +
                                m_memory_in2[cur_wavelength_id] * S24
                                , cur_wavelength_id);

        m_out1_writer.delayedWrite(s3, sc_time(m_delay_ns, SC_NS));
        m_out2_writer.delayedWrite(s4, sc_time(m_delay_ns, SC_NS));
    }
}


void DirectionalCouplerBi::on_p0_in_changed()
{
    m_through_power_dB = 10*log10(m_dc_through_coupling_power) - m_dc_loss;
    m_cross_power_dB = 10*log10(1.0 - m_dc_through_coupling_power) - m_dc_loss;

    m_memory_in0[0] = 0; // initializing for nan wavelength

    const double transmission_through = pow(10.0, m_through_power_dB / 20.0);
    const double transmission_cross = pow(10.0, m_cross_power_dB / 20.0);

    // Pre-calculate S-parameters
    OpticalSignal::field_type S02, S13, S03, S12;
    S02 = polar(transmission_through, m_through_phase_rad);
    S13 = polar(transmission_through, m_through_phase_rad);
    S03 = polar(transmission_cross, m_cross_phase_rad);
    S12 = polar(transmission_cross, m_cross_phase_rad);

    if (specsGlobalConfig.verbose_component_initialization)
    {
        cout << name() << ":" << endl;
        cout << "through_power = " << norm(S02) << " W/W" << endl;
        cout << "cross_power = " << norm(S03)<< " W/W" << endl;
        cout << "through_field = " << abs(S02) << "" << endl;
        cout << "cross_field = " << abs(S03)<< "" << endl;
        cout << "insertion loss = " << m_dc_loss << "dB" << endl;
        cout << (dynamic_cast<spx::oa_signal_type *>(p0_in.get_interface()))->name();

        cout << " --,__,-> ";
        cout << (dynamic_cast<spx::oa_signal_type *>(p2_out.get_interface()))->name();
        cout << endl;
        cout << (dynamic_cast<spx::oa_signal_type *>(p1_in.get_interface()))->name();
        cout << " --'  '-> ";
        cout << (dynamic_cast<spx::oa_signal_type *>(p3_out.get_interface()))->name();
        cout << endl;

        cout << (dynamic_cast<spx::oa_signal_type *>(p0_out.get_interface()))->name();
        cout << " <-,__,-- ";
        cout << (dynamic_cast<spx::oa_signal_type *>(p2_in.get_interface()))->name();
        cout << endl;
        cout << (dynamic_cast<spx::oa_signal_type *>(p1_out.get_interface()))->name();
        cout << " <-'  '-- ";
        cout << (dynamic_cast<spx::oa_signal_type *>(p3_in.get_interface()))->name();
        cout << endl;

        cout << endl;
    }

    OpticalSignal p0_in_read;

    while (true) {
        // Wait for a new input signal
        wait();

        // Read current inputs
        p0_in_read = p0_in->read();

        auto cur_wavelength_id = p0_in_read.m_wavelength_id;

        // Updating the field memory
        m_memory_in0[cur_wavelength_id] = p0_in_read.m_field;

        auto s2 = OpticalSignal(m_memory_in0[cur_wavelength_id] * S02 +
                                m_memory_in1[cur_wavelength_id] * S12
                                , cur_wavelength_id);

        auto s3 = OpticalSignal(m_memory_in0[cur_wavelength_id] * S03 +
                                m_memory_in1[cur_wavelength_id] * S13
                                , cur_wavelength_id);

        m_p2_out_writer.delayedWrite(s2, sc_time(m_delay_ns, SC_NS));
        m_p3_out_writer.delayedWrite(s3, sc_time(m_delay_ns, SC_NS));
    }
}

void DirectionalCouplerBi::on_p1_in_changed()
{
    m_through_power_dB = 10*log10(m_dc_through_coupling_power) - m_dc_loss;
    m_cross_power_dB = 10*log10(1.0 - m_dc_through_coupling_power) - m_dc_loss;

    m_memory_in1[0] = 0; // initializing for nan wavelength

    const double transmission_through = pow(10.0, m_through_power_dB / 20.0);
    const double transmission_cross = pow(10.0, m_cross_power_dB / 20.0);

    // Pre-calculate S-parameters
    OpticalSignal::field_type S02, S13, S03, S12;
    S02 = polar(transmission_through, m_through_phase_rad);
    S13 = polar(transmission_through, m_through_phase_rad);
    S03 = polar(transmission_cross, m_cross_phase_rad);
    S12 = polar(transmission_cross, m_cross_phase_rad);

    OpticalSignal p1_in_read;

    while (true) {
        // Wait for a new input signal
        wait();

        // Read current inputs
        p1_in_read = p1_in->read();

        auto cur_wavelength_id = p1_in_read.m_wavelength_id;

        // Updating the field memory
        m_memory_in1[cur_wavelength_id] = p1_in_read.m_field;

        auto s2 = OpticalSignal(m_memory_in0[cur_wavelength_id] * S02 +
                                m_memory_in1[cur_wavelength_id] * S12
                                , cur_wavelength_id);

        auto s3 = OpticalSignal(m_memory_in0[cur_wavelength_id] * S03 +
                                m_memory_in1[cur_wavelength_id] * S13
                                , cur_wavelength_id);

        m_p2_out_writer.delayedWrite(s2, sc_time(m_delay_ns, SC_NS));
        m_p3_out_writer.delayedWrite(s3, sc_time(m_delay_ns, SC_NS));
    }
}

void DirectionalCouplerBi::on_p2_in_changed()
{
    m_through_power_dB = 10*log10(m_dc_through_coupling_power) - m_dc_loss;
    m_cross_power_dB = 10*log10(1.0 - m_dc_through_coupling_power) - m_dc_loss;

    m_memory_in2[0] = 0; // initializing for nan wavelength

    const double transmission_through = pow(10.0, m_through_power_dB / 20.0);
    const double transmission_cross = pow(10.0, m_cross_power_dB / 20.0);

    // Pre-calculate S-parameters
    OpticalSignal::field_type S02, S13, S03, S12;
    S02 = polar(transmission_through, m_through_phase_rad);
    S13 = polar(transmission_through, m_through_phase_rad);
    S03 = polar(transmission_cross, m_cross_phase_rad);
    S12 = polar(transmission_cross, m_cross_phase_rad);

    OpticalSignal p2_in_read;

    while (true) {
        // Wait for a new input signal
        wait();

        // Read current inputs
        p2_in_read = p2_in->read();

        auto cur_wavelength_id = p2_in_read.m_wavelength_id;

        // Updating the field memory
        m_memory_in2[cur_wavelength_id] = p2_in_read.m_field;

        auto s0 = OpticalSignal(m_memory_in2[cur_wavelength_id] * S02 +
                                m_memory_in3[cur_wavelength_id] * S03
                                , cur_wavelength_id);

        auto s1 = OpticalSignal(m_memory_in2[cur_wavelength_id] * S12 +
                                m_memory_in3[cur_wavelength_id] * S13
                                , cur_wavelength_id);

        m_p0_out_writer.delayedWrite(s0, sc_time(m_delay_ns, SC_NS));
        m_p1_out_writer.delayedWrite(s1, sc_time(m_delay_ns, SC_NS));
    }
}

void DirectionalCouplerBi::on_p3_in_changed()
{
    m_through_power_dB = 10*log10(m_dc_through_coupling_power) - m_dc_loss;
    m_cross_power_dB = 10*log10(1.0 - m_dc_through_coupling_power) - m_dc_loss;

    m_memory_in3[0] = 0; // initializing for nan wavelength

    const double transmission_through = pow(10.0, m_through_power_dB / 20.0);
    const double transmission_cross = pow(10.0, m_cross_power_dB / 20.0);

    // Pre-calculate S-parameters
    OpticalSignal::field_type S02, S13, S03, S12;
    S02 = polar(transmission_through, m_through_phase_rad);
    S13 = polar(transmission_through, m_through_phase_rad);
    S03 = polar(transmission_cross, m_cross_phase_rad);
    S12 = polar(transmission_cross, m_cross_phase_rad);

    OpticalSignal p3_in_read;

    while (true) {
        // Wait for a new input signal
        wait();

        // Read current inputs
        p3_in_read = p3_in->read();

        auto cur_wavelength_id = p3_in_read.m_wavelength_id;

        // Updating the field memory
        m_memory_in3[cur_wavelength_id] = p3_in_read.m_field;

        auto s0 = OpticalSignal(m_memory_in2[cur_wavelength_id] * S02 +
                                m_memory_in3[cur_wavelength_id] * S03
                                , cur_wavelength_id);

        auto s1 = OpticalSignal(m_memory_in2[cur_wavelength_id] * S12 +
                                m_memory_in3[cur_wavelength_id] * S13
                                , cur_wavelength_id);

        m_p0_out_writer.delayedWrite(s0, sc_time(m_delay_ns, SC_NS));
        m_p1_out_writer.delayedWrite(s1, sc_time(m_delay_ns, SC_NS));
    }
}