Skip to content

Commit 65902a4

Browse files
authored
Merge pull request #8 from purdue-onchip/layerFdtd
Integrate layeredFD with VoVh and para-extraction in linux
2 parents 26d1315 + d9fb66e commit 65902a4

File tree

5 files changed

+95
-30
lines changed

5 files changed

+95
-30
lines changed

layeredFD_setup.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# How to Setup Layered Finite-Difference Solver
2+
Please follow these instructions for running layered FD solver in Linux system or Windows system. Please direct all questions, bug reports, and issues to the primary maintainer:
3+
* [Shuzhan Sun](mailto:sun630@purdue.edu?subject=Inquiry%20for%20gds2Para), Graduate Research Assistant, School of ECE, Purdue University
4+
5+
## Linux System
6+
The macro `SKIP_LAYERED_FD` in head file `fdtd.hpp` switches between layeredFD solver and V0Vh solver. Setup for each is:
7+
* Case 1: run V0Vh solver in Linux
8+
```C++
9+
#define SKIP_LAYERED_FD
10+
```
11+
12+
* Case 2: run layeredFD solver in Linux
13+
```C++
14+
// #define SKIP_LAYERED_FD
15+
```
16+
17+
Everything else is the same as [V0Vh solver](https://github.com/purdue-onchip/gds2Para/blob/master/purdue_install.md), including commands, final parameters, and storage styles.
18+
19+
## Windows System
20+
Currently, only layeredFD solver is supported in Win32 system, and above macro `SKIP_LAYERED_FD` no longer changes anything in Win32 system.
21+
### How to Setup in Visual Studio (tested in Visual Studio 2017):
22+
1. Create a visual studio project inside the parent directory of folder `gds2Para`, and only include these files in project:
23+
```bash
24+
fdtd.hpp
25+
generateStiff.cpp
26+
layeredFdtd.hpp
27+
mapIndex.hpp
28+
matrixTypeDef.hpp
29+
mesh.cpp
30+
pardisoSolver.hpp
31+
sysInfoIO.hpp
32+
```
33+
2. Edit the `configuration` of the visual studio project to include Intel MKL. A simple way is to install [Intel Parallel Studio XE](https://software.intel.com/en-us/parallel-studio-xe/choose-download), which is free for student.
34+
3. Write a main function to call the layeredFD solver and put it next to the VS project solution (.sln). Example main function is `layeredFD.cpp`:
35+
```C++
36+
#include "gds2Para/src/layeredFdtd.hpp"
37+
int main(void) {
38+
layeredFdtd();
39+
return 0;
40+
}
41+
```
42+
### How to Run in Visual Studio
43+
1. Run the layeredFD solver in Linux (could stop ealier with `Ctrl+Z`) to generate a folder `temp_sysInfoIO` inside the parent directory of folder `gds2Para`. This step exports the structure information to a few txt files. This step is necessary because many codes for loading gds files cannot be compiled in Windows system.
44+
2. Back to Visual Studio, under mode `Debug x64`, run `Local Windows Debugger` in VS to get the parameters.

src/TestMain.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -351,13 +351,21 @@ int main(int argc, char** argv)
351351
#endif
352352

353353
// Write object sys to files
354-
#ifndef SKIP_WRITE_SYS_TO_FILE
354+
#ifndef SKIP_LAYERED_FD
355355
WriteSysToFile(sys);
356356
#endif
357357

358358
// Parameter generation
359359
clock_t t6 = clock();
360+
#ifndef SKIP_LAYERED_FD // Run layered Finite-Difference solver
361+
cout << endl << endl << "Results from Layered Finite-Difference Solver: " << endl;
362+
status = solveE_Zpara_layered(&sys);
363+
//cout << endl << endl << "Results from Reference (direct backslash with PARDISO): " << endl;
364+
//solveE_Zpara_reference(&sys);
365+
#else // Run VoVh solver
366+
cout << endl << endl << "Results from V0Vh Solver: " << endl;
360367
status = paraGenerator(&sys, xi, yi, zi);
368+
#endif
361369
if (status == 0)
362370
{
363371
cout << "paraGenerator Success!" << endl;

src/fdtd.hpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@
2424
#include <algorithm>
2525
#include <utility>
2626

27+
//#define SKIP_LAYERED_FD // Comment out if you want to run layered FD code in Linux, doesn't matter for Windows system
28+
2729
// HYPRE and MKL data type control
28-
#define LARGE_SYSTEM (1) // Must leave defined with the current makefile. Comment out in windows system
29-
#ifdef LARGE_SYSTEM
30-
#define MKL_ILP64 (1) // Must define before including mkl.h if using long long int
30+
#define LARGE_SYSTEM (1) // Must leave defined with the current makefile
31+
#if defined(LARGE_SYSTEM) && defined(__linux__)
32+
#define MKL_ILP64 (1) // Must define before including mkl.h if using long long int, MKL_ILP64 only works for Linux not for Windows
3133
typedef long long int myint;
3234
#else
3335
typedef int myint;
@@ -74,10 +76,6 @@ using namespace std;
7476
//#define SKIP_GENERATE_STIFF
7577
#define SKIP_STIFF_REFERENCE
7678

77-
// Disable layered FDTD code (comment out if you want to test layered FDTD)
78-
#define SKIP_WRITE_SYS_TO_FILE // Skip writing sys obj to txt files
79-
#define SKIP_LAYERED_FDTD // Skip the main function's calling layeredFdtd code
80-
8179
// Function-like macros
8280
#define NELEMENT(x) ((sizeof x) / (sizeof x[0]))
8381

src/pardisoSolver.hpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ int eliminateVolumE(const vector<BlockType> &layerS, myint N_surfE, myint N_volE
111111
/*denseB21B23.writeToFile("blockB21B23.txt");
112112
denseD0sD1s.writeToFile("blockD.txt");*/
113113

114-
denseB21B23.~denseFormatOfMatrix(); // free combined dense [B21, B23]
114+
//denseB21B23.~denseFormatOfMatrix(); // free combined dense [B21, B23]
115115

116116
// Convert B12, B32 to mkl internal CSR matrix handles
117117
sparse_matrix_t csrB12_mklHandle, csrB32_mklHandle;
@@ -148,7 +148,7 @@ int eliminateVolumE(const vector<BlockType> &layerS, myint N_surfE, myint N_volE
148148
(preducedS + 2)->writeToFile("block_C2.txt");
149149
(preducedS + 3)->writeToFile("block_C3.txt");*/
150150

151-
denseD0sD1s.~denseFormatOfMatrix(); // free combined dense [D0s, D1s]
151+
//denseD0sD1s.~denseFormatOfMatrix(); // free combined dense [D0s, D1s]
152152
return 0;
153153
}
154154

@@ -634,7 +634,7 @@ denseFormatOfMatrix reconstruct_e(fdtdMesh *psys, const mapIndex &indexMap, cons
634634
}
635635

636636
// Solve E field and Z-parameters in Pardiso, solve layer by layer. (under developing)
637-
void solveE_Zpara_layered(fdtdMesh *psys) {
637+
int solveE_Zpara_layered(fdtdMesh *psys) {
638638

639639
// Initilize Z-parameters for all frequencies
640640
psys->x.assign(psys->numPorts * psys->numPorts * psys->nfreq, complex<double>(0., 0.));
@@ -666,6 +666,7 @@ void solveE_Zpara_layered(fdtdMesh *psys) {
666666
// Print Z-parameters
667667
psys->print_z_V0_Vh();
668668

669+
return 0;
669670
}
670671

671672
// Solve E field and Z-parameters in Pardiso, solve the whole structure as reference

src/sysInfoIO.hpp

+33-19
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
#include "fdtd.hpp"
55

6+
#include <sys/types.h>
7+
#include <sys/stat.h> // "mkdir" in linux
8+
69
using namespace std;
710

811
inline void WriteVectorIn1Line(ofstream &file_obj, const vector<double> &vec_x) {
@@ -23,12 +26,23 @@ void Write2DVectorIn1Line(ofstream &file_obj, const vector<vector<myint>> &vec_2
2326
file_obj << endl;
2427
}
2528

26-
// Write object sys to files
29+
// Write object sys to files (only works for Linux system due to paths)
2730
void WriteSysToFile(const fdtdMesh &sys) {
2831
ofstream file_obj;
32+
33+
// Create folder (if not exists) to store txt files, only in linux system
34+
#ifdef __linux__
35+
struct stat st = { 0 };
36+
if (stat("../temp_sysInfoIO", &st) == -1) {
37+
if (mkdir("../temp_sysInfoIO", 0777) == -1) {
38+
cerr << "Error in creating folder /temp_sysInfoIO!" << endl;
39+
exit(2);
40+
}
41+
}
42+
#endif
2943

3044
// Write primitive types like a bool, int, or float in one txt file
31-
file_obj.open("sys_PrimitiveType.txt", ios::out);
45+
file_obj.open("../temp_sysInfoIO/sys_PrimitiveType.txt", ios::out);
3246
file_obj << sys.numCdtRow << endl;
3347
file_obj << sys.lengthUnit << endl;
3448
file_obj << sys.freqUnit << endl;
@@ -48,34 +62,34 @@ void WriteSysToFile(const fdtdMesh &sys) {
4862
file_obj.close();
4963

5064
// Write each vector in independent file
51-
file_obj.open("sys_vec_stackEps.txt", ios::out);
65+
file_obj.open("../temp_sysInfoIO/sys_vec_stackEps.txt", ios::out);
5266
for (const auto& i : sys.stackEps)
5367
file_obj << i << endl;
5468
file_obj.close();
5569

56-
file_obj.open("sys_vec_stackSig.txt", ios::out);
70+
file_obj.open("../temp_sysInfoIO/sys_vec_stackSig.txt", ios::out);
5771
for (const auto& i : sys.stackSig)
5872
file_obj << i << endl;
5973
file_obj.close();
6074

61-
file_obj.open("sys_vec_stackBegCoor.txt", ios::out);
75+
file_obj.open("../temp_sysInfoIO/sys_vec_stackBegCoor.txt", ios::out);
6276
for (const auto& i : sys.stackBegCoor)
6377
file_obj << i << endl;
6478
file_obj.close();
6579

66-
file_obj.open("sys_vec_stackEndCoor.txt", ios::out);
80+
file_obj.open("../temp_sysInfoIO/sys_vec_stackEndCoor.txt", ios::out);
6781
for (const auto& i : sys.stackEndCoor)
6882
file_obj << i << endl;
6983
file_obj.close();
7084

71-
file_obj.open("sys_vec_stackName.txt", ios::out);
85+
file_obj.open("../temp_sysInfoIO/sys_vec_stackName.txt", ios::out);
7286
for (const auto& i : sys.stackName)
7387
file_obj << i << endl;
7488
file_obj.close();
7589

7690
// Write sys.portCoor. Every object of class fdtdPort takes n lines, being one element of vector portCoor
7791
// output format: multiplicity ~ 1st line; x1 ~ 2nd line; ... someattri ~ n-th line.
78-
file_obj.open("sys_vec_portCoor.txt", ios::out);
92+
file_obj.open("../temp_sysInfoIO/sys_vec_portCoor.txt", ios::out);
7993
for (int i = 0; i < sys.portCoor.size(); i++) {
8094
const fdtdPort &ofdtdPort = sys.portCoor[i];
8195

@@ -94,7 +108,7 @@ void WriteSysToFile(const fdtdMesh &sys) {
94108
file_obj.close();
95109

96110
// Write sys.conductorIn, only export what is used by function meshAndMark
97-
file_obj.open("sys_vec_conductorIn.txt", ios::out);
111+
file_obj.open("../temp_sysInfoIO/sys_vec_conductorIn.txt", ios::out);
98112
for (int i = 0; i < sys.conductorIn.size(); i++) {
99113
const fdtdOneCondct &ofdtdOneCondct = sys.conductorIn[i];
100114

@@ -114,7 +128,7 @@ void WriteSysToFile(const fdtdMesh &sys) {
114128

115129

116130
// Write *pointer to file
117-
file_obj.open("sys_ptr_stackCdtMark.txt", ios::out);
131+
file_obj.open("../temp_sysInfoIO/sys_ptr_stackCdtMark.txt", ios::out);
118132
for (int i = 0; i < sys.numStack; i++)
119133
file_obj << sys.stackCdtMark[i] << endl;
120134
file_obj.close();
@@ -186,7 +200,7 @@ void ReadSysFromFile(fdtdMesh *psys) {
186200
ifstream file_obj;
187201

188202
// Read primitive types like a bool, int, or float
189-
file_obj.open("sys_PrimitiveType.txt", ios::in);
203+
file_obj.open("temp_sysInfoIO/sys_PrimitiveType.txt", ios::in);
190204
if (!file_obj.is_open()) {
191205
perror("Error open");
192206
exit(EXIT_FAILURE);
@@ -210,39 +224,39 @@ void ReadSysFromFile(fdtdMesh *psys) {
210224
file_obj.close();
211225

212226
// Read each vector from independent file
213-
file_obj.open("sys_vec_stackEps.txt", ios::in);
227+
file_obj.open("temp_sysInfoIO/sys_vec_stackEps.txt", ios::in);
214228
while (file_obj >> doubVecValue) {
215229
psys->stackEps.push_back(doubVecValue);
216230
}
217231
file_obj.close();
218232

219-
file_obj.open("sys_vec_stackSig.txt", ios::in);
233+
file_obj.open("temp_sysInfoIO/sys_vec_stackSig.txt", ios::in);
220234
while (file_obj >> doubVecValue) {
221235
psys->stackSig.push_back(doubVecValue);
222236
}
223237
file_obj.close();
224238

225-
file_obj.open("sys_vec_stackBegCoor.txt", ios::in);
239+
file_obj.open("temp_sysInfoIO/sys_vec_stackBegCoor.txt", ios::in);
226240
while (file_obj >> doubVecValue) {
227241
psys->stackBegCoor.push_back(doubVecValue);
228242
}
229243
file_obj.close();
230244

231-
file_obj.open("sys_vec_stackEndCoor.txt", ios::in);
245+
file_obj.open("temp_sysInfoIO/sys_vec_stackEndCoor.txt", ios::in);
232246
while (file_obj >> doubVecValue) {
233247
psys->stackEndCoor.push_back(doubVecValue);
234248
}
235249
file_obj.close();
236250

237-
file_obj.open("sys_vec_stackName.txt", ios::in);
251+
file_obj.open("temp_sysInfoIO/sys_vec_stackName.txt", ios::in);
238252
while (file_obj >> strVecValue) {
239253
psys->stackName.push_back(strVecValue);
240254
}
241255
file_obj.close();
242256

243257
// Read sys.portCoor. Every object of class fdtdPort takes n lines, being one element of vector portCoor
244258
// Input format: multiplicity ~ 1st line; x1 ~ 2nd line; ... someattri ~ n-th line.
245-
file_obj.open("sys_vec_portCoor.txt", ios::in);
259+
file_obj.open("temp_sysInfoIO/sys_vec_portCoor.txt", ios::in);
246260

247261
num_line = 0;
248262
while (getline(file_obj, line)) {
@@ -275,7 +289,7 @@ void ReadSysFromFile(fdtdMesh *psys) {
275289
file_obj.close();
276290

277291
// Read sys.conductorIn, only input what is used by function meshAndMark
278-
file_obj.open("sys_vec_conductorIn.txt", ios::in);
292+
file_obj.open("temp_sysInfoIO/sys_vec_conductorIn.txt", ios::in);
279293

280294
num_line = 0;
281295
while (getline(file_obj, line)) {
@@ -300,7 +314,7 @@ void ReadSysFromFile(fdtdMesh *psys) {
300314

301315

302316
// Read *pointer from file
303-
file_obj.open("sys_ptr_stackCdtMark.txt", ios::in);
317+
file_obj.open("temp_sysInfoIO/sys_ptr_stackCdtMark.txt", ios::in);
304318
psys->stackCdtMark = (double *)malloc(psys->numStack * sizeof(double));
305319
for (int i = 0; i < psys->numStack; i++) {
306320
file_obj >> psys->stackCdtMark[i];

0 commit comments

Comments
 (0)