calcRL.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. /***********************************************************/
  2. /*** ***/
  3. /*** Resistance and Inductance using Coifman wavelets ***/
  4. /*** for the method of moments ***/
  5. /*** ***/
  6. /*** by Zhichao Zhang ***/
  7. /*** 2001.3 ***/
  8. /*** ***/
  9. /***********************************************************/
  10. /***********************************************************
  11. Abstract:
  12. The frequency-dependent resistance and inductance of uniform
  13. transmission lines are calculated with a hybrid technique that
  14. combines a cross-section coupled circuit method with a surface
  15. integral equation approach. The coupled circuit approach is
  16. most applicble for low-frequency calculations, while the
  17. integral equation approach is best for high frequencies. The
  18. low-frequency method consists in subdividing the cross section
  19. of each conductor into triangular filaments, each with an
  20. assumed uniform currect distribution. The resistance and
  21. mutual inductance between the filaments are clculated, and a
  22. matrix is inverted to give the overall resistance and
  23. inductance of the conductors. The high-frequency method
  24. expresses the resistance and inductance of each conductor in
  25. terms of the current at the surface of that conductor and the
  26. derivative of that current normal to the surface. A coupled
  27. integral equation is then derived to relate these qualities
  28. through the diffusion equation inside the conductors and
  29. La;lace's equation outside. The method of moments with
  30. pulse basis functions is used to solve the integral equations.
  31. An interpolation between the results of these two methods gives
  32. very good results over the entire frequency range, even when few
  33. basis functions are used. Results for a variety of configurations
  34. are shown and are compared with experimental data and other
  35. numerical techniques.
  36. **************************************************************/
  37. #include "stdafx.h"
  38. #ifdef HAVE_SYS_TIMES_H
  39. #include <sys/times.h>
  40. #endif
  41. #include <time.h>
  42. #include <stdio.h>
  43. /********************** Global variables *******************/
  44. int Nc, Die, Rec, Cir, Tri, Ell, Pol, Gnd, Tra;
  45. Matrix Gnddi, Recdi, Cirdi, Tradix, Tradiy; /* dimension matrix */
  46. Vector ag, bg, cg; /* gnd parameters **************/
  47. Vector a, b, c; /* rec parameters **************/
  48. Vector at, bt, ct; /* tra parameters **************/
  49. Vector Circum; /* Circumference of conductors */
  50. Vector Diec; /* circum of die conductors ****/
  51. Vector Recc; /* circum of rec conductors ****/
  52. Vector Circ; /* circum of cir conductors ****/
  53. Vector Trac; /* circum of tra conductors ****/
  54. Vector Tric; /* circum of tri conductors ****/
  55. Vector Ellc; /* circum of ell conductors ****/
  56. Vector Polc; /* circum of pol conductors ****/
  57. Vector Gndc; /* circum of gnd conductors ****/
  58. double freq, sqrtoms, sigma;
  59. double omega, oms, omegamu, sft;
  60. double tmp1, tmp2, tmp3, tmp4;
  61. int matr, Mt, Np;
  62. int Ns, Nsr, Ngx, Ngy, Nxt, Nyt, Ngr, Nrt;
  63. int Nh, Nc4, Nit, J, Nw, Nwx, Nwy, Nws;
  64. double hsrw, EPS, Uniti;
  65. double Pi = 4.0*atan(1.0);
  66. double Pih, Pit, wn, mu, cf;
  67. double step_w, hw, hwh, mmax;
  68. Complex Ic;
  69. Vector Iq_sq;
  70. /********************** Main program ***********************/
  71. char fileIn[1024];
  72. int append;
  73. int main ( int argc, char *argv[] )
  74. {
  75. /************ to setup global parameters *********/
  76. char fileName[1024], fileOut[1024], fileRL[1024], fileXmgrR[1024];
  77. char fileXmgrL[1024], strg[20];
  78. //---------------------------------------------------------------
  79. // Get the input and output file names from the command-line.
  80. //---------------------------------------------------------------
  81. if ( argc > 0)
  82. strcpy (fileName, argv[1]);
  83. else
  84. strcpy (fileName, "data");
  85. append = 0;
  86. if ( argc > 1 )
  87. {
  88. if ( ! strcmp (argv[2], "append") )
  89. {
  90. append = 1;
  91. cout << "Append to existing data in file" << endl;
  92. }
  93. }
  94. if ( strlen(fileName) < 2 )
  95. strcpy (fileName, "data");
  96. sprintf (fileIn, "%s.in", fileName);
  97. sprintf (fileOut, "%s.out", fileName);
  98. sprintf (fileRL, "%s.out.rl", fileName);
  99. sprintf (fileXmgrR, "%s.out.resistance", fileName);
  100. sprintf (fileXmgrL, "%s.out.inductance", fileName);
  101. cout << "Input file : " << fileIn << endl;
  102. cout << "Output file: " << fileOut << endl;
  103. cout << "R file : " << fileRL << endl;
  104. cout << "Xmgr files : " << fileXmgrR << endl;
  105. cout << " : " << fileXmgrL << endl;
  106. cout << " " << endl;
  107. //----------------------------------------------------------------
  108. // Get the data.
  109. //----------------------------------------------------------------
  110. getparam();
  111. time_t start_time, end_time;
  112. time_t tme1, tme2;
  113. time(&start_time);
  114. tme1 = start_time;
  115. /************ define variables *******************/
  116. const int NN = 2*Nc*Nw+Nc;
  117. int i, j, m, n, k, n0, j1, i1, ix, i2, j2, k2;
  118. int jn, kn, jm, km, jx, iy;
  119. double t, tp, xt, yt, dlu;
  120. Complex tmp, tmp0, sum, sum0, tmpsum, suc;
  121. Vector xcnt(Nws), ycnt(Nws);
  122. Vector ptr(Ngr), whr(Ngr), tr(Nrt), wr(Nrt);
  123. Vector twr(Nrt), wwr(Nrt);
  124. Vector twx(Nwx), wwx(Nwx), twy(Nwy), wwy(Nwy);
  125. Vector ptwx(Nwx), whwx(Nwx), ptwy(Nwy), whwy(Nwy);
  126. Vector sxc4(Nc4), sc4(Nc4), wxc4(Nc4), wc4(Nc4);
  127. Vector ts(Nw), tn(Nw), Indx;
  128. Matrix uns(3, Nw);
  129. CmplxVector Rhsw(NN), Jnj(NN), xc;
  130. CmplxMatrix Pw(NN, NN), Pwt(NN, NN);
  131. Vector Res(Nc), Ind(Nc), sum1(Nc);
  132. Matrix Res1(Nc, Nc), Ind1(Nc, Nc), matout;
  133. CmplxVector sum2(Nc);
  134. double rsum, isum, tmpsum1, tmpsum2, tst, tempc;
  135. Complex tmpv0, tmpvi, tmpu0, tmpui, tmp0v0, tmp0vi, tmp0u0, tmp0ui;
  136. Complex sumv0, sumvi, sumu0, sumui, temsum;
  137. ofstream *xmgrRdata;
  138. ofstream *xmgrLdata;
  139. ofstream *rldata;
  140. ofstream *outdata;
  141. // Check if the file exists. If it doesn't, the xmgr files must be
  142. // initialized.
  143. int init = 0;
  144. if ( ! fopen (fileXmgrR, "r") )
  145. {
  146. cout << fileXmgrR << " does not exist so must initialize" << endl;
  147. init = 1;
  148. }
  149. if ( append )
  150. {
  151. outdata = new ofstream(fileOut, ios::app | ios::out);
  152. rldata = new ofstream(fileRL, ios::app | ios::out);
  153. xmgrRdata = new ofstream(fileXmgrR, ios::app | ios::out);
  154. xmgrLdata = new ofstream(fileXmgrL, ios::app | ios::out);
  155. }
  156. else
  157. {
  158. init = 1;
  159. outdata = new ofstream( fileOut, ios::out);
  160. rldata = new ofstream( fileRL, ios::out);
  161. xmgrRdata = new ofstream( fileXmgrR, ios::out);
  162. xmgrLdata = new ofstream( fileXmgrR, ios::out);
  163. }
  164. if ( init )
  165. {
  166. cout << "Initializing the xmgr files" << endl;
  167. *xmgrRdata << "@ title \"Resistance\"" << endl;
  168. *xmgrRdata << "@ subtitle \"" << fileXmgrR << "\"" << endl;
  169. *xmgrRdata << "@ yaxis label \"Ohm/m\"" << endl;
  170. *xmgrRdata << "@ xaxis label \"Frequency (Hz)\"" << endl;
  171. *xmgrRdata << "@ legend string 0 \"Signal1,Signal1\"" << endl;
  172. *xmgrRdata << "@ legend string 1 \"Signal1,Signal2\"" << endl;
  173. *xmgrRdata << "@ legend string 2 \"Signal2,Signal1\"" << endl;
  174. *xmgrRdata << "@ legend string 3 \"Signal2,Signal2\"" << endl;
  175. *xmgrRdata << "@ type nxy" << endl;
  176. cout << "@ title \"Resistance\"" << endl;
  177. cout << "@ subtitle \"" << fileXmgrR << "\"" << endl;
  178. cout << "@ yaxis label \"nH/m\"" << endl;
  179. cout << "@ xaxis label \"Frequency (Hz)\"" << endl;
  180. cout << "@ legend string 0 \"Signal1,Signal1\"" << endl;
  181. cout << "@ legend string 1 \"Signal1,Signal2\"" << endl;
  182. cout << "@ legend string 2 \"Signal2,Signal1\"" << endl;
  183. cout << "@ legend string 3 \"Signal2,Signal2\"" << endl;
  184. cout << "@ type nxy" << endl;
  185. *xmgrLdata << "@ title \"Inductance\"" << endl;
  186. *xmgrLdata << "@ subtitle \"" << fileXmgrL << "\"" << endl;
  187. *xmgrLdata << "@ yaxis label \"Ohm/m\"" << endl;
  188. *xmgrLdata << "@ legend string 0 \"Signal1,Signal1\"" << endl;
  189. *xmgrLdata << "@ legend string 1 \"Signal1,Signal2\"" << endl;
  190. *xmgrLdata << "@ legend string 2 \"Signal2,Signal1\"" << endl;
  191. *xmgrLdata << "@ legend string 3 \"Signal2,Signal2\"" << endl;
  192. *xmgrLdata << "@ type nxy" << endl;
  193. cout << "@ subtitle \"" << fileXmgrL << "\"" << endl;
  194. cout << "@ yaxis label \"nH/m\"" << endl;
  195. cout << "@ legend string 0 \"Signal1,Signal1\"" << endl;
  196. cout << "@ legend string 1 \"Signal1,Signal2\"" << endl;
  197. cout << "@ legend string 2 \"Signal2,Signal1\"" << endl;
  198. cout << "@ legend string 3 \"Signal2,Signal2\"" << endl;
  199. cout << "@ type nxy" << endl;
  200. }
  201. // cout << "start" << endl;
  202. getcoif4( sxc4, sc4, wxc4, wc4, Nit );
  203. getsbs( uns );
  204. /** points and weights for Gauss the method */
  205. gauleg( -1.0, 1.0, ptwx, whwx );
  206. gauleg( -1.0, 1.0, ptwy, whwy );
  207. for(i = 0; i < Nw; i++) {
  208. tn[i] = i*step_w;
  209. }
  210. // time(&tme2);
  211. // cout << "time 1: " << tme2 - tme1 << endl;
  212. // tme1 = tme2;
  213. int idx, idx2, jdx, jdx2;
  214. /***** to create system matrix **************/
  215. for(i1 = 0; i1 < Nc; i1 ++) {
  216. // cout << i1 << endl;
  217. double hcircum = 0.5 * Circum[i1];
  218. for(i = 0; i < Nw; i ++) {
  219. idx = i1*Nw+i;
  220. idx2 =(Nc+i1)*Nw+i;
  221. for(j1 = 0; j1 < Nc; j1 ++) {
  222. tmp2 = step_w*Circum[j1];
  223. for(j = 0; j < Nw; j ++) {
  224. jdx = j1*Nw+j;
  225. jdx2 = (Nc+j1)*Nw+j;
  226. sumv0 = 0.0;
  227. sumu0 = 0.0;
  228. sumvi = 0.0;
  229. sumui = 0.0;
  230. if(i1 == j1 && i == j) {
  231. for(m = 0; m < Nws; m ++) {
  232. tmp3 = double(m) + 0.5;
  233. tmp3 *= hw;
  234. // xcnt[m] = uns(1,j) + hw * tmp3;
  235. // ycnt[m] = uns(1,i) + hw * tmp3;
  236. xcnt[m] = uns(1,j) + tmp3;
  237. ycnt[m] = uns(1,i) + tmp3;
  238. }
  239. for(iy = 0; iy < Nws; iy ++) {
  240. for(jx = 0; jx < Nws; jx ++) {
  241. intpnt( xcnt[jx], twx, wwx, ptwx, whwx,
  242. ycnt[iy], twy, wwy, ptwy, whwy,
  243. hwh );
  244. tmpv0 = 0.0;
  245. tmpu0 = 0.0;
  246. tmpvi = 0.0;
  247. tmpui = 0.0;
  248. for(m = 0; m < Nwy; m ++) {
  249. tmp0v0 = 0.0;
  250. tmp0u0 = 0.0;
  251. tmp0vi = 0.0;
  252. tmp0ui = 0.0;
  253. for( n = 0; n < Nwx; n++ ) {
  254. tmp3 = wwx[n] * scalcoif4( twx[n], J, j, sc4 );
  255. tmp0v0 += kernel_v0( twy[m], twx[n], i1, j1 ) *
  256. tmp3;
  257. tmp0u0 += kernel_u0( twy[m], twx[n], i1, j1 ) *
  258. tmp3;
  259. tmp0vi += kernel_vi( twy[m], twx[n], i1, j1 ) *
  260. tmp3;
  261. tmp0ui += kernel_ui( twy[m], twx[n], i1, j1 ) *
  262. tmp3;
  263. }
  264. tmp3 = wwy[m] * scalcoif4( twy[m], J, i, sc4 );
  265. tmpv0 += tmp0v0 * tmp3;
  266. tmpu0 += tmp0u0 * tmp3;
  267. tmpvi += tmp0vi * tmp3;
  268. tmpui += tmp0ui * tmp3;
  269. }
  270. sumv0 += tmpv0;
  271. sumu0 += tmpu0;
  272. sumvi += tmpvi;
  273. sumui += tmpui;
  274. }
  275. }
  276. tmp1 = Circum[j1] * Circum[i1];
  277. sumv0 = sumv0 * tmp1;
  278. sumvi = sumvi * tmp1;
  279. sumu0 = sumu0 * tmp1 - hcircum;
  280. sumui = sumui * tmp1 + hcircum;
  281. } else if (i1 == j1 && i != j) {
  282. tmp3 = tmp2 * Circum[i1];
  283. sumv0 = kernel_v0( tn[i], tn[j], i1, j1 ) * tmp3;
  284. sumvi = kernel_vi( tn[i], tn[j], i1, j1 ) * tmp3;
  285. sumu0 = kernel_u0( tn[i], tn[j], i1, j1 ) * tmp3;
  286. sumui = kernel_ui( tn[i], tn[j], i1, j1 ) * tmp3;
  287. } else {
  288. tmp3 = tmp2 * Circum[i1];
  289. sumv0 = kernel_v0( tn[i], tn[j], i1, j1 ) * tmp3;
  290. sumvi = 0.0;
  291. sumu0 = kernel_u0( tn[i], tn[j], i1, j1 ) * tmp3;
  292. sumui = 0.0;
  293. }
  294. Pwt(idx, jdx) = sumv0;
  295. Pwt(idx2, jdx) = sumvi;
  296. Pwt(idx, jdx2) = -sumu0;
  297. Pwt(idx2, jdx2) = -sumui;
  298. }
  299. }
  300. }
  301. }
  302. // time(&tme2);
  303. // cout << "time 2: " << tme2 - tme1 << endl;
  304. // tme1 = tme2;
  305. for(i = 0; i < Nc; i ++) {
  306. if(i < Gnd) {
  307. tempc = Gndc[i];
  308. } else if(i >= Gnd && i < (Gnd + Rec)) {
  309. tempc = Recc[i-Gnd];
  310. } else if(i >= (Gnd + Rec) && i < (Gnd + Rec + Cir)) {
  311. tempc = Circ[i-Gnd-Rec];
  312. } else if(i >= (Gnd + Rec + Cir) && i < (Gnd + Rec + Cir + Tra)) {
  313. tempc = Trac[i-Gnd-Rec-Cir];
  314. }
  315. for(j = 0; j < Nw; j ++) {
  316. Pwt(2*Nw*Nc+i, i*Nw+j) = tempc * tempc;
  317. Pwt(i*Nw+j, 2*Nw*Nc+i) = tempc / power(2.0, double(J)/2.0);
  318. }
  319. }
  320. // time(&tme2);
  321. // cout << "time 3: " << tme2 - tme1 << endl;
  322. // tme1 = tme2;
  323. // cout << NN
  324. // << "X"
  325. // << NN
  326. // << " System Matrix Created !!! "
  327. // << endl;
  328. /* Solve equation for different current combination */
  329. for(i2 = 1; i2 < Nc; i2 ++) {
  330. for(j2 = i2; j2 < Nc; j2 ++) {
  331. /// cout << i2 << endl;
  332. // cout << j2 <<endl;
  333. if(i2 == j2) {
  334. Iq_sq[0] = -1.0;
  335. for (k2 = 1; k2 < Nc; k2 ++) {
  336. if(k2 == j2) {
  337. Iq_sq[k2] = 1.0;
  338. } else {
  339. Iq_sq[k2] = 0.0;
  340. }
  341. }
  342. } else {
  343. for (k2 = 0; k2 < Nc; k2 ++) {
  344. if(k2 == i2) {
  345. Iq_sq[k2] = 1.0;
  346. } else if(k2 == j2){
  347. Iq_sq[k2] = -1.0;
  348. } else {
  349. Iq_sq[k2] = 0.0;
  350. }
  351. }
  352. }
  353. for(i = 0; i < 2*Nc*Nw; i ++) {
  354. Rhsw[i] = 0.0;
  355. }
  356. for(i = 0; i < Nc; i ++) {
  357. if(i < Gnd) {
  358. tempc = Gndc[i];
  359. } else if(i >= Gnd && i < (Gnd + Rec)) {
  360. tempc = Recc[i-Gnd];
  361. } else if(i >= (Gnd + Rec) && i < (Gnd + Rec + Cir)) {
  362. tempc = Circ[i-Gnd-Rec];
  363. } else if(i >= (Gnd + Rec + Cir) && i < (Gnd + Rec + Cir + Tra)) {
  364. tempc = Trac[i-Gnd-Rec-Cir];
  365. }
  366. Rhsw[2*Nc*Nw+i] = (-1.0)*Ic*Iq_sq[i]*oms*tempc/power(2.0,double(J)/2.0);
  367. }
  368. // time(&tme2);
  369. // cout << "time 4: " << tme2 - tme1 << endl;
  370. // tme1 = tme2;
  371. // cout << endl
  372. // << "Right hand side vector created!! "
  373. // << endl;
  374. for(i = 0; i < NN; i ++) {
  375. for(j = 0; j < NN; j ++) {
  376. Pw(i,j) = Pwt(i,j);
  377. }
  378. }
  379. /* By Using LU Decomposition */
  380. if(matr == 1) {
  381. ludcmp( Pw, Indx, dlu );
  382. lubksb( Pw, Rhsw, Indx );
  383. }
  384. /* By Using Stab */
  385. if(matr == 2) {
  386. xc.resize(NN);
  387. bi_cgstab_c( Pw, xc, Rhsw, EPS );
  388. Rhsw = xc;
  389. }
  390. // cout << " System of linear equations for N = "
  391. // << NN
  392. // << " solved !!! "
  393. // << endl;
  394. /* To calculate the resistance and inductance ****/
  395. for(i = 0; i < Nw; i ++) {
  396. ts[i] = double(i)/double(Nw);
  397. }
  398. for(ix = 0; ix < Nc; ix ++) {
  399. for(i = 0; i < Nw; i ++) {
  400. tmp = 0.0;
  401. tmp0 = 0.0;
  402. for(j = i-7; j <= i+4; j ++) {
  403. if(j < 0) {
  404. tst = ts[i] + 1.0;
  405. j1 = j + Nw;
  406. } else if (j > Nw-1) {
  407. tst = ts[i] - 1.0;
  408. j1 = j - Nw;
  409. } else {
  410. tst = ts[i];
  411. j1 = j;
  412. }
  413. tmp += scalcoif4( tst, J, j1, sc4 ) * Rhsw[ix*Nw+j1];
  414. tmp0 += scalcoif4( tst, J, j1, sc4 ) * Rhsw[(ix+Nc)*Nw+j1];
  415. }
  416. Jnj[ix*Nw+i] = tmp;
  417. Jnj[(ix+Nc)*Nw+i] = tmp0;
  418. }
  419. }
  420. for (i = 0; i < Nc; i ++) {
  421. Jnj[2*Nc*Nw+i] = Rhsw[2*Nc*Nw+i];
  422. }
  423. for (i = 0; i < Nc; i ++) {
  424. sum1[i] = 0.0;
  425. Res[i] = 0.0;
  426. Ind[i] = 0.0;
  427. }
  428. // time(&tme2);
  429. // cout << "time 5: " << tme2 - tme1 << endl;
  430. // tme1 = tme2;
  431. rsum = 0.0;
  432. isum = 0.0;
  433. for (i = 0; i < Nc; i ++) {
  434. tmp4 = Circum[i] / double(Nw);
  435. tmpsum1 = 0.0;
  436. tmpsum2 = 0.0;
  437. sum2[i] = cmplx( 0.0, 0.0 );
  438. for (j = 0; j < Nw; j ++) {
  439. tmpsum1 += imag(Jnj[(i+Nc)*Nw+j] * conjg(Jnj[i*Nw+j])) * tmp4;
  440. tmpsum2 += real(Jnj[2*Nc*Nw+i] * conjg(Jnj[i*Nw+j])) * tmp4;
  441. sum2[i] += Jnj[i*Nw+j] * Circum[i] / double(Nw);
  442. }
  443. rsum += tmpsum1;
  444. isum += tmpsum2;
  445. tmp4 = cabs(sum2[i]);
  446. sum1[i] = tmp4 * tmp4;
  447. }
  448. for (i = 0; i < Nc; i++) {
  449. Res[i] = omegamu * rsum / sum1[i];
  450. Ind[i] = (-1) * mu * isum / sum1[i];
  451. }
  452. if(i2 == j2) {
  453. Res1(i2,i2) = Res[i2];
  454. Ind1(i2,i2) = Ind[i2];
  455. } else {
  456. Res1(i2,j2) = Res[i2];
  457. Ind1(i2,j2) = Ind[i2];
  458. Res1(j2,i2) = Res[j2];
  459. Ind1(j2,i2) = Ind[j2];
  460. }
  461. }
  462. }
  463. // time(&tme2);
  464. // cout << "time 6: " << tme2 - tme1 << endl;
  465. // tme1 = tme2;
  466. /* Generate mutual resistance and inductance */
  467. for(i2 = 1; i2 < Nc; i2 ++) {
  468. for(j2 = 1; j2 < Nc; j2 ++) {
  469. if(i2 != j2) {
  470. Res1(i2,j2) = (Res1(i2,i2)+Res1(j2,j2)-Res1(i2,j2))/2.0;
  471. Ind1(i2,j2) = (Ind1(i2,i2)+Ind1(j2,j2)-Ind1(i2,j2))/2.0;
  472. }
  473. }
  474. }
  475. time(&end_time);
  476. // cout << "time 7: " << end_time - tme1 << endl;
  477. // tme1 = tme2;
  478. // cout << "Start-time: " << start_time << endl;
  479. // cout << " End-time: " << end_time << endl;
  480. cout << " Run-time: " << (end_time - start_time) << " seconds" << endl;
  481. #ifdef HAVE_SYS_TIMES_H
  482. tms run_times;
  483. times(&run_times);
  484. cout << "User CPU time: " << run_times.tms_utime/CLOCKS_PER_SEC << endl;
  485. cout << " Sys CPU time: " << run_times.tms_stime/CLOCKS_PER_SEC << endl;
  486. #endif
  487. /* output data into file */
  488. *outdata << "--------------------------------------------------------"
  489. << endl;
  490. *outdata << "Resistance/Inductance Values" << endl;
  491. *outdata << "Input file: " << fileIn << endl;
  492. *outdata << "--------------------------------------------------------"
  493. << endl;
  494. *outdata << "Frequency: " << freq << " Conductivity: " <<
  495. sigma << "\n" << endl;
  496. *outdata << Nc-1 << ""
  497. << "X" << ""
  498. << Nc-1 << ""
  499. << " Resistance Matrix (Ohm/m):" << endl;
  500. *outdata <<endl;
  501. for(i2 = 1; i2 < Nc; i2++) {
  502. for(j2 = 1; j2 < Nc; j2++) {
  503. *outdata << Res1(i2,j2) << " ";
  504. *rldata << freq << " " << (Ind1(i2,j2) * 1e9) << " " <<
  505. Res1(i2,j2) << endl;
  506. }
  507. *outdata << endl;
  508. *outdata << endl;
  509. *xmgrRdata << freq;
  510. for(i2 = 1; i2 < Nc; i2++)
  511. {
  512. for(j2 = 1; j2 < Nc; j2++)
  513. *xmgrRdata << " " << Res1(i2,j2);
  514. }
  515. *xmgrRdata << endl;
  516. }
  517. *outdata << Nc-1 << ""
  518. << "X" << ""
  519. << Nc-1 << ""
  520. << " Inductance Matrix (H/m):" << endl;
  521. *outdata <<endl;
  522. for(i2 = 1; i2 < Nc; i2 ++) {
  523. for(j2 = 1; j2 < Nc; j2 ++) {
  524. *outdata << Ind1(i2,j2) << " ";
  525. }
  526. *outdata << endl;
  527. *outdata << endl;
  528. }
  529. *outdata << endl;
  530. *outdata << endl;
  531. *xmgrLdata << freq;
  532. for(i2 = 1; i2 < Nc; i2++)
  533. {
  534. for(j2 = 1; j2 < Nc; j2++)
  535. *xmgrLdata << " " << Ind1(i2,j2) * 1e9;
  536. }
  537. *xmgrLdata << endl;
  538. *outdata << endl;
  539. #ifdef HAVE_SYS_TIMES_H
  540. *outdata << "User CPU time: " << run_times.tms_utime/CLOCKS_PER_SEC << endl;
  541. *outdata << " Sys CPU time: " << run_times.tms_stime/CLOCKS_PER_SEC << endl;
  542. #endif
  543. outdata->close();
  544. rldata->close();
  545. xmgrRdata->close();
  546. xmgrLdata->close();
  547. cout << "Calculation Completed." << endl;
  548. return 0;
  549. }