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
|
#include <ctime>
#include <iomanip>
#include <tb/crow_tb.h>
#include <cstdlib>
#include <unistd.h>
#include <chrono>
#include <waveguide.h>
#include <directional_coupler.h>
#include <probe.h>
#include <crow.h>
#include <specs.h>
#include "time_monitor.h"
#include "general_utils.h"
using namespace std;
using namespace std::chrono;
/* ----------------------------------------------------------------------------- *
This testbench is called freqsweep because it is capable of this
type of simulation, but it is also possible to set it as a time-domain
simulation depending on the mode chosen when calling SPECS. Example:
specs -t ac_add_drop -m fd -> will perform the frequency sweep
specs -t ac_add_drop -m td -> will perform the time domain simulation
/ ----------------------------------------------------------------------------- */
// ---------------- Use this variable to change the size of the CROW -----------
size_t nrings_crow = 3;
// -----------------------------------------------------------------------------
void crow_tb::run_td()
{
bool verbose = true;
if (specsGlobalConfig.simulation_mode == OpticalOutputPortMode::TIME_DOMAIN)
{
int npulses = 4;
double lambda = 1554.3719e-9;
lambda = 1.561931948453715e-6;
lambda = 1538.3277504e-9;
lambda = 1543e-9;
lambda = 1556.5742279e-9;
lambda = 1556.32782563158025368466e-9;
lambda = 1556e-9;
lambda = 1553e-9;
//lambda = 1550e-9;
double tpulse = 1e-9;
double deadtime = tpulse;
// Wait one tick that all sc_threads are started and on their first `wait` call
wait(SC_ZERO_TIME);
if (verbose)
{
cout << "----------------------------" <<endl;
cout << "Starting time-domain simulation" << endl;
}
for (int i = 0; i < npulses; ++i)
{
IN->write(OpticalSignal(1, lambda));
wait(tpulse, SC_SEC);
// //ADD.write(OpticalSignal(polar<double>(1, M_PI_2), lambda));
// //ADD.write(OpticalSignal(polar<double>(0,0), lambda));
IN->write(OpticalSignal(0, lambda));
// ADD.write(OpticalSignal(0, lambda));
wait(deadtime, SC_SEC);
}
}
while (true) { wait(); }
}
void crow_tb::run_fd()
{
bool verbose = true;
if (specsGlobalConfig.simulation_mode == OpticalOutputPortMode::FREQUENCY_DOMAIN)
{
auto lambda_center = 1550e-9;
auto lambda_span = 2e-9;
auto dlambda = 0.001e-9;
auto lambda_min = lambda_center - lambda_span/2;
auto lambda_max = lambda_center + lambda_span/2;
// lambda_min = 1545e-9;
// lambda_max = 1569e-9;
lambda_min = 299792458.0/195e12;
lambda_max = 299792458.0/190e12;
lambda_min = 1556e-9;
lambda_span = lambda_max - lambda_min;
dlambda = lambda_span / 10000;
// Wait one tick that all sc_threads are started and on their first `wait` call
wait(SC_ZERO_TIME);
//wait(lambda_min, SC_SEC);
auto tic = high_resolution_clock::now();
auto toc = high_resolution_clock::now();
if (verbose)
{
cout << "----------------------------" <<endl;
cout << "Starting sweep" << endl;
}
int i = 0;
int n = ceil(lambda_span / dlambda);
for (auto lambda = lambda_min; lambda < lambda_max + dlambda; lambda += dlambda)
{
++i;
if (true || (verbose && i % (int)(n/20) == 0))
{
toc = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(toc - tic);
tic = toc;
cout << duration.count()/1000.0 << "ms" << endl;
cout << endl;
cout << fixed << setprecision(1) << (lambda-lambda_min)/lambda_span * 100.0 << "%" << endl;
cout << setprecision(20) << lambda * 1e9 << "nm" << endl;
}
IN->write(OpticalSignal(sqrt(1), lambda));
ADD->write(OpticalSignal(0, lambda));
//ADD.write(OpticalSignal(polar<double>(0, 0), lambda));
//ADD.write(OpticalSignal(polar<double>(sqrt(0.5), -M_PI_2), lambda));
wait(dlambda, SC_SEC);
}
if (verbose)
{
cout << "----------------------------" <<endl;
cout << "Sweep over (" << n << " points)" << endl;
}
}
while (true) { wait(); }
}
void crow_tb::monitor()
{
unsigned long long event_counter = 0;
while(true)
{
wait();
continue;
event_counter++;
std::cout << sc_time_stamp() << ":" << std::endl
<< "\tIN: " << IN->read() << std::endl
<< "\tADD: " << ADD->read() << std::endl
<< "\tTHROUGH: " << THROUGH->read() << std::endl
<< "\tDROP: " << DROP->read() << std::endl
<< "\tCOUNT: " << event_counter << std::endl;
}
}
void crow_tb_run()
{
specsGlobalConfig.applyEngineResolution();
spx::oa_signal_type IN("IN"), THROUGH("THROUGH"), DROP("DROP"), ADD("ADD");
crow_tb tb1("tb1");
tb1.IN(IN);
tb1.ADD(ADD);
tb1.THROUGH(THROUGH);
tb1.DROP(DROP);
// pid_t pid = fork();
CROW *pc;
// if(pid)
pc = new CROW("crow", nrings_crow);
// else
// pc = new Crow("crow", 5);
pc->p_in(IN);
pc->p_add(ADD);
pc->p_out_t(THROUGH);
pc->p_out_d(DROP);
pc->setRingLength(2*30e-6);
pc->m_loss_db_cm = 2.0;
pc->m_coupling_through = 1 - pow(0.83645, 2.0);
// pc->m_coupling_through = 0.5;
pc->m_neff = 2.6391;
pc->m_ng = 4.3416;
pc->m_ring_length = 500.0*1.55e-6 + 1.55e-6/2.0;
pc->m_loss_db_cm = 2.0;
pc->m_coupling_through = 1 - 0.2;
pc->m_neff = 1;
pc->m_ng = 2;
pc->init(); //instantiating all nets
Probe pthrough("pthrough", true, true, false, true);
pthrough.p_in(THROUGH);
//
Probe pcross("pcross", true, true, false, false);
pcross.p_in(DROP);
specsGlobalConfig.trace_filename = "traces/crow_tb";
// Apply SPECS options specific to the testbench
// specsGlobalConfig.simulation_mode = OpticalOutputPortMode::EVENT_DRIVEN;
specsGlobalConfig.trace_all_optical_nets = 0;
// Run SPECS pre-simulation code
specsGlobalConfig.prepareSimulation();
// Start simulation
sc_start(50e-9, SC_SEC);
std::cout << std::endl << std::endl;
std::cout << ".vcd trace file: " << specsGlobalConfig.trace_filename << std::endl;
sc_close_vcd_trace_file(specsGlobalConfig.default_trace_file);
}
|