forked from purdue-onchip/gds2Para
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestMain.cpp
executable file
·368 lines (340 loc) · 17.9 KB
/
TestMain.cpp
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
/**
* @file TestMain.cpp
* @author Michael R. Hayashi
* @date 18 October 2018
* @brief Primary Function for Input/Solver/Output Control Modes
*/
#define _USE_MATH_DEFINES // Place before including <cmath> for e, log2(e), log10(e), ln(2), ln(10), pi, pi/2, pi/4, 1/pi, 2/pi, 2/sqrt(pi), sqrt(2), and 1/sqrt(2)
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <ctime>
#include <limbo/parsers/gdsii/stream/GdsReader.h>
#include <parser-spef/parser-spef.hpp>
#include <Eigen/Sparse>
#include "limboint.h"
#include "solnoutclass.h"
using std::cerr;
using std::cout;
using std::endl;
/// @brief main function
/// @param argc number of arguments
/// @param argv values of arguments
/// @return 0 if succeed
int main(int argc, char** argv)
{
if (argc == 2)
{
if (strcmp(argv[1], "--help") == 0)
{
cout << "Help for Test Limbo Interface binary" << endl;
cout << "Usage: Test_$@ [options] file1 [file2..file3]" << endl;
cout << "Options:" << endl;
cout << " --help Display this information." << endl;
cout << " --version Print the version number." << endl;
cout << " -r, --read Read given GDSII file into memory." << endl;
cout << " -p, --parrot Immediately output given GDSII file after reading." << endl;
cout << " -w, --write Write database in memory to given SPEF file." << endl;
cout << " -i, --imp Read given interconnect modeling platform file and write GDSII file with name also given." << endl;
//cout << " -s, --simulate Read GDSII file and sim input file into memory, simulate, and write solution to SPEF file." << endl;
cout << " -s, --simulate Read GDSII file and sim input file into memory, simulate, and write solution to Xyce (SPICE) subcircuit file." << endl;
cout << endl << "Comments:" << endl;
cout << "The file passed after -r, --read, -p, or --parrot must be a Calma GDSII stream file." << endl;
cout << " The file passed after -w or --write must be a blank SPEF file." << endl;
cout << " The first file passed after -i or --imp must be a 3D description .imp file, and the second must be a blank .gds file." << endl;
//cout << " The first file passed after -s or --simulate must be a Calma GDSII stream file, the second must be a sim_input file, and the third must be a blank SPEF file." << endl;
cout << " The first file passed after -s or --simulate must be a Calma GDSII stream file, the second must be a sim_input file, and the third must be a blank Xyce file." << endl;
cout << endl << "Bug reporting:" << endl;
cout << "Visit <https://github.com/purdue-onchip/gdsii-interface>" << endl;
}
else if (strcmp(argv[1], "--version") == 0)
{
cout << "Version Number for Test Limbo Interface binary: " << "1.0" << endl;
}
else
{
cerr << "Only \"--help\" or \"--version\" flags allowed without files passed" << endl;
}
}
else if (argc == 3)
{
if ((strcmp(argv[1], "-r") == 0) || (strcmp(argv[1], "--read") == 0))
{
AsciiDataBase adb;
string fName = argv[2];
adb.setFileName(fName);
std::ifstream inFile(fName.c_str());
GdsParser::GdsReader adbReader(adb);
bool adbIsGood = adbReader(inFile);
vector<size_t> indCellPrint = { adb.getNumCell() - 1 };
adb.print(indCellPrint);
/*EnumDataBase edb;
GdsParser::GdsReader edbReader(edb);
bool edbIsGood = edbReader(inFile);
cout << "Test Enum API: " << edbIsGood << endl;
//cout << "Test Enum API: " << GdsParser::read(edb, argv[1]) << endl;*/
}
else if ((strcmp(argv[1], "-p") == 0) || (strcmp(argv[1], "--parrot") == 0))
{
// Read and print existing file
AsciiDataBase adb;
string fName = argv[2];
size_t indExtension = fName.find(".", 1);
adb.setFileName(fName.substr(0, indExtension) + "_parrot" + fName.substr(indExtension, string::npos));
GdsParser::GdsReader adbReader(adb);
bool adbIsGood = adbReader(fName.c_str());
adb.print({ adb.getNumCell() - 1 });
// Dump to parroted file immediately
adb.dump();
cout << "Dumped parroted file" << endl;
}
else if ((strcmp(argv[1], "-w") == 0) || (strcmp(argv[1], "--write") == 0))
{
// Load sample information in memory
string design = "test_out";
Waveforms blank;
// Setup the port information vector
vector<Port> ports = {};
ports.emplace_back(Port("inp1", 'I', 50., vector<double>(6, 0), -1));
ports.emplace_back(Port("u1:a", 'I', 50., vector<double>(6, 0), -1));
ports.emplace_back(Port("inp2", 'I', 50., vector<double>(6, 0), -1));
ports.emplace_back(Port("u1:b", 'I', 50., vector<double>(6, 0), -1));
ports.emplace_back(Port("out", 'O', 50., vector<double>(6, 0), -1));
ports.emplace_back(Port("u3:o", 'O', 50., vector<double>(6, 0), -1));
ports.emplace_back(Port("u1:o", 'O', 50., vector<double>(6, 0), -1));
ports.emplace_back(Port("u4:a", 'I', 50., vector<double>(6, 0), -1));
ports.emplace_back(Port("u4:o", 'O', 50., vector<double>(6, 0), -1));
ports.emplace_back(Port("f1:d", 'I', 50., vector<double>(6, 0), -1));
ports.emplace_back(Port("f1:a", 'O', 50., vector<double>(6, 0), -1));
ports.emplace_back(Port("u2:a", 'I', 50., vector<double>(6, 0), -1));
ports.emplace_back(Port("u4:b", 'I', 50., vector<double>(6, 0), -1));
// Setup the Eigen sparse conductance matrix
spMat matG(13, 13); // Initialize sparse conductance matrix (S)
vector<dTriplet> listG; // Initialize triplet list for conductance matrix
listG.reserve(3); // Reserve room for 3 nonzero entries in each row
listG.push_back(dTriplet(0, 0, 1. / (10.5e3)));
listG.push_back(dTriplet(0, 1, -1. / (10.5e3)));
listG.push_back(dTriplet(1, 0, -1. / (10.5e3)));
listG.push_back(dTriplet(1, 1, 1. / (10.5e3)));
listG.push_back(dTriplet(2, 2, 1. / (4.5e3)));
listG.push_back(dTriplet(2, 3, -1. / (4.5e3)));
listG.push_back(dTriplet(3, 2, -1. / (4.5e3)));
listG.push_back(dTriplet(3, 3, 1. / (4.5e3)));
listG.push_back(dTriplet(4, 4, 1. / (1.4e3)));
listG.push_back(dTriplet(4, 5, -1. / (1.4e3)));
listG.push_back(dTriplet(5, 4, -1. / (1.4e3)));
listG.push_back(dTriplet(5, 5, 1. / (1.4e3)));
listG.push_back(dTriplet(6, 6, 1. / (2.1e3)));
listG.push_back(dTriplet(6, 7, -1. / (2.1e3)));
listG.push_back(dTriplet(7, 6, -1. / (2.1e3)));
listG.push_back(dTriplet(7, 7, 1. / (2.1e3)));
listG.push_back(dTriplet(8, 8, 1. / (2.1e3)));
listG.push_back(dTriplet(8, 9, -1. / (2.1e3)));
listG.push_back(dTriplet(9, 8, -1. / (2.1e3)));
listG.push_back(dTriplet(9, 9, 1. / (2.1e3)));
listG.push_back(dTriplet(10, 10, 1. / (1.2e3 + 2.3e3 + 3.4e3) + 1. / (1.2e3 + 7.8e3 + 5.6e3)));
listG.push_back(dTriplet(10, 11, -1. / (1.2e3 + 2.3e3 + 3.4e3)));
listG.push_back(dTriplet(10, 12, -1. / (1.2e3 + 7.8e3 + 5.6e3)));
listG.push_back(dTriplet(11, 10, -1. / (3.4e3 + 2.3e3 + 1.2e3)));
listG.push_back(dTriplet(11, 11, 1. / (3.4e3 + 2.3e3 + 1.2e3) + 1. / (3.4e3 + 2.3e3 + 7.8e3 + 5.6e3)));
listG.push_back(dTriplet(11, 12, -1. / (3.4e3 + 2.3e3 + 7.8e3 + 5.6e3)));
listG.push_back(dTriplet(12, 10, -1. / (5.6e3 + 7.8e3 + 1.2e3)));
listG.push_back(dTriplet(12, 11, -1. / (5.6e3 + 7.8e3 + 2.3e3 + 3.4e3)));
listG.push_back(dTriplet(12, 12, 1. / (5.6e3 + 7.8e3 + 1.2e3) + 1. / (5.6e3 + 7.8e3 + 2.3e3 + 3.4e3)));
matG.setFromTriplets(listG.begin(), listG.end()); // Assign nonzero entries to sparse conductance matrix
matG.makeCompressed(); // Conductance matrix in compressed sparse row (CSR) format
// Setup the Eigen sparse capacitance matrix
spMat matC(13, 13); // Initialize sparse capacitance matrix (F)
vector<dTriplet> listC; // Initialize triplet list for capacitance matrix
listC.reserve(1); // Reserve room for 1 nonzero entry in each row
listC.push_back(dTriplet(0, 0, 2.5e-15));
listC.push_back(dTriplet(1, 1, 2.9e-15));
listC.push_back(dTriplet(2, 2, 0.7e-15));
listC.push_back(dTriplet(3, 3, 1.3e-15));
listC.push_back(dTriplet(4, 4, 0.5e-15));
listC.push_back(dTriplet(5, 5, 0.2e-15));
listC.push_back(dTriplet(6, 6, 0.35e-15));
listC.push_back(dTriplet(7, 7, 0.65e-15));
listC.push_back(dTriplet(8, 8, 0.7e-15));
listC.push_back(dTriplet(9, 9, 0.5e-15));
listC.push_back(dTriplet(10, 10, 8.9e-15));
listC.push_back(dTriplet(11, 11, 6.7e-15));
listC.push_back(dTriplet(12, 12, 7.8e-15));
matC.setFromTriplets(listC.begin(), listC.end()); // Assign nonzero entries to sparse capacitance matrix
matC.makeCompressed(); // Capactiance matrix in compressed sparse row (CSR) format
// Create variables of custom classes
Parasitics sample(ports, matG, matC);
SolverDataBase sdb(design, blank, sample);
// Prepare to write to file
string fName = argv[2];
sdb.setOutSPEF(fName);
bool couldDump = sdb.printDumpSPEF();
}
else
{
cerr << "Must pass a file after \"-r\", \"-p\", or \"-w\" flags, rerun with \"--help\" flag for details" << endl;
}
}
else if (argc == 4)
{
if ((strcmp(argv[1], "-i") == 0) || (strcmp(argv[1], "--imp") == 0))
{
// Read interconnect modeling platform (IMP) file and write to GDSII file
SolverDataBase sdb;
string inIMPFile = argv[2];
string outGDSIIFile = argv[3];
bool sdbIsGood = sdb.readIMPwriteGDSII(inIMPFile, outGDSIIFile);
cout << "File ready at " << outGDSIIFile << endl;
}
else
{
cerr << "Must pass a .imp file to read and blank GDSII file to write after \"-i\" flag, rerun with \"--help\" flag for details" << endl;
}
}
else if (argc == 5)
{
if ((strcmp(argv[1], "-s") == 0) || (strcmp(argv[1], "--simulate") == 0))
{
// Get file names
string inGDSIIFile = argv[2];
string inSimFile = argv[3];
size_t indExtension = inGDSIIFile.find(".", 1);
string inStackFile = inGDSIIFile.substr(0, indExtension) + "_stack.txt";
//string inStackFile = inGDSIIFile; // Use stack information contained within sim_input file
// Initialize SolverDataBase, mesh, and other useful variables
SolverDataBase sdb;
fdtdMesh sys;
int status;
clock_t t1 = clock();
// Read GDSII file
AsciiDataBase adb;
adb.setFileName(inGDSIIFile);
GdsParser::GdsReader adbReader(adb);
bool adbIsGood = adbReader(inGDSIIFile.c_str());
vector<size_t> indCellPrint = { adb.getNumCell() - 1 };
adb.print(indCellPrint, &sys);
cout << "GDSII file read" << endl;
// Read simulation input file
bool sdbIsGood = sdb.readSimInput(inSimFile);
cout << "Simulation input file read" << endl;
// Set the number of input conductors
sys.numCdtRow = adb.getNumCdtIn();
clock_t t2 = clock();
// Read the input file
unordered_map<double, int> xi, yi, zi;
status = readInput(inStackFile.c_str(), &sys, xi, yi, zi);
if (status == 0){
cout << "readInput Success!" << endl;
cout << "readInput time is " << (clock() - t2) * 1.0 / CLOCKS_PER_SEC << endl;
}
else {
cout << "readInput Fail!" << endl;
return status;
}
// Set D_eps and D_sig
clock_t t3 = clock();
status = matrixConstruction(&sys);
if (status == 0) {
cout << "matrixConstruction Success!" << endl;
cout << "matrixConstruction time is " << (clock() - t3) * 1.0 / CLOCKS_PER_SEC << endl;
}
else {
cout << "matrixConstruction Fail!" << endl;
return status;
}
// Set port
clock_t t4 = clock();
status = portSet(&sys, xi, yi, zi);
if (status == 0){
cout << "portSet Success!\n";
cout << "portSet time is " << (clock() - t4) * 1.0 / CLOCKS_PER_SEC << endl;
}
else {
cout << "portSet Fail!\n";
return status;
}
// Generate Stiffness Matrix
clock_t t5 = clock();
status = generateStiff(&sys);
if (status == 0){
cout << "generateStiff Success!" << endl;
cout << "generateStiff time is " << (clock() - t5) * 1.0 / CLOCKS_PER_SEC << endl;
}
else {
cout << "generateStiff Fail!" << endl;
return status;
}
// Parameter generation
t5 = clock();
status = paraGenerator(&sys, xi, yi, zi);
if (status == 0){
cout << "paraGenerator Success!" << endl;
cout << "paraGenerator time is " << (clock() - t5) * 1.0 / CLOCKS_PER_SEC << endl;
}
else {
cout << "paraGenerator Fail!" << endl;
return status;
}
cout << "Engine time to this point: " << (clock() - t2) * 1.0 / CLOCKS_PER_SEC << endl;
cout << "Total time to this point: " << (clock() - t1) * 1.0 / CLOCKS_PER_SEC << endl;
// Parameter storage
spMat matG(sys.numPorts, sys.numPorts); // Initialize Eigen sparse conductance matrix (S)
spMat matC(sys.numPorts, sys.numPorts); // Initialize Eigen sparse capacitance matrix (F)
vector<dTriplet> listG; // Initialize triplet list for conductance matrix
vector<dTriplet> listC;
listG.reserve(sys.numPorts); // Reserve room so matrix could be dense
listC.reserve(sys.numPorts);
for (size_t indi = 0; indi < sys.numPorts; indi++) // Loop over excitation ports
{
double sumG = 0.;
double sumC = 0.;
for (size_t indj = 0; indj < sys.numPorts; indj++) // Loop over response ports
{
// Symmetrize diagonal components before saving entry
double symgij = 0.5 * (sys.Y[indi * sys.numPorts + indj].real() + sys.Y[indj * sys.numPorts + indi].real());
double symcij = 0.5 * (sys.Y[indi * sys.numPorts + indj].imag() + sys.Y[indj * sys.numPorts + indi].imag()) / (2 * M_PI * sys.freqStart * sys.freqUnit);
listG.push_back(dTriplet(indj, indi, symgij));
listC.push_back(dTriplet(indj, indi, symcij));
/*if (indi != indj) // Off-diagonal entries are negated node-to-node admittances
{
listG.push_back(dTriplet(indi, indj, sys.Y[indi * sys.numPorts + indj].real()));
listC.push_back(dTriplet(indi, indj, sys.Y[indi * sys.numPorts + indj].imag() / (2 * M_PI* sys.freqStart * sys.freqUnit)));
}
// Diagonal entries need to have sum of all attached admittances, so note them
sumG += sys.Y[indi * sys.numPorts + indj].real();
sumC += sys.Y[indi * sys.numPorts + indj].imag() / (2 * M_PI* sys.freqStart * sys.freqUnit);*/
}
// Record diagonal entries
listG.push_back(dTriplet(indi, indi, sumG));
listC.push_back(dTriplet(indi, indi, sumC));
}
matG.setFromTriplets(listG.begin(), listG.end()); // Assign nonzero entries to sparse conductance matrix
matC.setFromTriplets(listC.begin(), listC.end()); // Do not put in compressed sparse row (CSR) format due to density
Parasitics oldPara = sdb.getParasitics(); // Get outdated parastics structure to update
sdb.setParasitics(Parasitics(oldPara.getPorts(), matG, matC));
/*// Output SPEF file
string outSPEFFile = argv[4];
sdb.setDesignName(adb.findNames().back());
sdb.setOutSPEF(outSPEFFile);
bool sdbCouldDump = sdb.printDumpSPEF();
cout << "File ready at " << outSPEFFile << endl; */
// Output Xyce subcircuit file
string outXyceFile = argv[4];
sdb.setDesignName(adb.findNames().back());
sdb.setOutXyce(outXyceFile);
bool sdbCouldDump = sdb.printDumpXyce();
cout << "File ready at " << outXyceFile << endl;
}
else
{
//cerr << "Must pass a GDSII file, sim_input file, and blank SPEF file to write after \"-s\" flag, rerun with \"--help\" flag for details" << endl;
cerr << "Must pass a GDSII file, sim_input file, and blank Xyce file to write after \"-s\" flag, rerun with \"--help\" flag for details" << endl;
}
}
else
{
cerr << "Between 1 and 4 arguments are required, use \"--help\" flag for details" << endl;
}
return 0;
}