-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathresolves.cpp
1991 lines (1941 loc) · 82.7 KB
/
resolves.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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* resolves.cpp - source text to Coil64 - Radio frequency inductor and choke calculator
Copyright (C) 2019 Kustarev V.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses
*/
#include "resolves.h"
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///ROUTINE FUNCTIONS
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma pack(push,1)
struct _Elliptic{
double Fk;
double Ek;
};
#pragma pack(pop)
#pragma pack(push,1)
struct _MagCoreConst{
double C1;
double C2;
};
#pragma pack(pop)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double odCalc(double id){
//Calculating the outer diameter (od) of the wire with insulation from the internal diameter (id) without insulation
const double M = 0.96344;
const double b = -0.19861;
double od1 = exp(M * log(id) + b);
double od2 = 1.09 * id;
double od = qMax(od1, od2);
return od;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double convertfromAWG(QString AWG, bool *isOK){
QRegularExpression awgrule(AWG_REG_EX);
double result = 0;
if (awgrule.match(AWG).hasMatch()){
QStringList captured = awgrule.match(AWG).capturedTexts();
QString cap = captured[0];
if (AWG == cap){
if (AWG == "0000") result = 11.684;
else if (AWG == "000") result = 10.40384;
else if (AWG == "00") result = 9.26592;
else {
double awg = AWG.toDouble();
result = 0.127 * pow(92, (36 - awg) / 39);
}
if (isOK != NULL) *isOK = true;
} else if (isOK != NULL) *isOK = false;
} else if (isOK != NULL) *isOK = false;
return result;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
QString converttoAWG(double d, bool *isOK){
QString result ="";
if (!(d > 12)){
if ((d <= 12) && (d >= 11)) result = "0000";
else if ((d < 11) && (d >= 10)) result = "000";
else if ((d < 10) && (d >= 8.6)) result = "00";
else if ((d < 8.6) && (d >= 0.00785)){
double AWG = round(-39 * log(d / 0.127) / log(92) + 36);
result = QString::number(AWG);
}
if (isOK != NULL) *isOK = true;
} else if (isOK != NULL) *isOK = false;
return result;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double find_Archimedean_spiral_length(int n, double a) {
//function to calculate the Archimedean spiral length
double phi = 2 * n * M_PI;
double l = (a / (4 * M_PI)) * (phi * sqrt(1 + phi * phi) + log(phi + sqrt(1 + phi * phi)));
return l;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double find_actual_spiral_length(int N, double Din, double k) {
//Find the spiral length
int ni = ceil(Din / (2 * k));
double Lin = find_Archimedean_spiral_length(ni, k);
int n = ni + N;
double Lt = find_Archimedean_spiral_length(n, k);
return (Lt - Lin);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double getToroidEqMagLength(double OD, double ID){
return M_PI * log(OD / ID) / (1.0 / ID - 1.0 / OD);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double getToroidEqCrossSec(double OD, double ID, double he){
return 0.5 * he * pow(log(OD / ID), 2) / (1.0 / ID - 1.0 / OD);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double getSaturationCurrent(double Bs, double le, double mu, double N){
return 1e-4 * Bs * le / (mu0 * mu * N); // le [mm], Bs [Gs], return value in [mA]
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double find_Helix_turn_length(double r, double p){
return sqrt(pow(2 * M_PI * r, 2) + p * p);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double rosaKm(double n){
//Rosa's round wire mutual inductance correction
double n2 = n * n;
double n3 = n2 * n;
double n5 = n3 * n2;
double n7 = n5 * n2;
double n9 = n7 * n2;
return (log(2 * M_PI) - 1.5 - log(n) / (6 * n) - 0.33084236 / n - 1 / (120 * n3) + 1 / (504 * n5) - 0.0011923 / n7 + 0.0005068 / n9);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double rosaKs(double x){
//Rosa's round wire self inductance correction
return (1.25 - log(2 * x));
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void EF(double c, _Elliptic *result){
//the complete elliptic integrals of the first and second kind
double a = 1;
double b = sqrt(1 - pow(c, 2));
double E = 1 - pow(c, 2) / 2;
double i = 1;
while (fabs(a - b) > 1e-15) {
double a1 = (a + b) / 2;
double b1 = sqrt(a * b);
E = E - i * pow((a - b) / 2, 2);
i = 2 * i;
a = a1;
b = b1;
}
double Fk = M_PI / (2 * a);
double Ek = E * Fk;
result->Ek = Ek;
result->Fk = Fk;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double Mut(double r1, double r2, double x, double g){
//Mutual inductance of two coaxial circular filaments
//r1,r2 - radii of the two circular filaments
//x - distance between the centres of the circular filaments
//g - Geometric Mean Distance
double l = sqrt(pow(r2 - r1, 2) + pow(x, 2));
double c = 2 * sqrt(r1 * r2) / sqrt(pow(r1 + r2, 2) + pow(l - g, 2));
_Elliptic Ec;
EF(c, &Ec);
double result = -0.004 * M_PI * sqrt(r1 * r2) * ((c - 2 / c) * Ec.Fk + (2 / c) * Ec.Ek);
return (result);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double SelfInductanceStraightWire(double l, double dw){
double r = 0.5 * dw * exp(0.25);
double result = 0.002 * (l * log((l + sqrt(l * l + r * r)) / r) - sqrt(l * l + r * r) + l / 4 + r);
return result;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double MutInductanceStraightWire(double L1, double l2, double D){
double tmpLength = 0;
L1 = L1 / 2;
l2 = l2 / 2;
if (L1 < l2){
tmpLength = L1;
L1 = l2;
l2 = tmpLength;
}
double result = 0.002 * (2 * L1 * log((L1 + l2 + sqrt((L1 + l2) * (L1 + l2) + D * D)) / D) + (L1 - l2) *
log((L1 + l2 + sqrt((L1 + l2) * (L1 + l2) + D * D)) / (L1 - l2 + sqrt((L1 - l2) * (L1 - l2) + D * D))) +
sqrt((L1 - l2) * (L1 - l2) + D * D) - sqrt((L1 + l2) * (L1 + l2) + D * D));
return result;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double Ingrnd(double phi, double kphitheta, double sinpsi, double cos2psi, double rr, double y){
// by Robert Weaver from http://electronbunker.ca/eb/CalcMethods2d.html
//Integrand function called by HeliCoilS()
double result = (1 + cos2psi * (cos(kphitheta) - 1)) / sqrt(2 * rr * (1 - cos(kphitheta)) + (sinpsi * phi - y) *
(sinpsi * phi - y));
return result;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double HeliCoilS(double Lw, double psi, double r, double dw, double w, double t, bool isRoundWire, unsigned int accuracy){
// by Robert Weaver from http://electronbunker.ca/eb/CalcMethods2d.html (Version 1.0, 2011-03-25)
// edited by Valery Kustarev 2018-12-16
// Uses helical filament mutual inductance formula
// evaluated using Simpson's rule, and conductor gmd
// Lw = total length of wire
// psi = pitch angle of winding
// r = radius of winding
// dw = wire diameter
// MaxErr = max allowable error (set to 10000)
//
//px = p/(2pi) = lCOIL/(2piN)
//psi = Arctan(px/(piD)) = Arctan(p/(2pi^2*D))
//lW = piND/cos psi
//where:
//D is coil diameter = 2r;
//p is centre to centre turns spacing;
//lCOIL is length of coil.
// If Lw>2*pi*r, check that pitch angle >= psi-c (close wound pitch)
double sinpsic, psic, g, rr, psio, ThetaO, Y0, cosThetaO, k1, k2, t1, t0, c2s, ss, k, a, b, grandtotal;
double dx, MaxErr, CurrentErr, kat, kbt, Sum2, LastIntg, Sum, phi, kpt, Integral, aaa, bbb, ccc, ddd;
int m;
int err = ceil((float)accuracy / 2);
MaxErr = pow(10,-err);
Integral = 0;
// grandtotal = 0;
if (Lw > 2 * M_PI * r) {
if (isRoundWire){
sinpsic = dw / (2 * M_PI * r);
} else {
sinpsic = w / (2 * M_PI * r);
}
psic = atan(sinpsic / sqrt(1 - sinpsic * sinpsic));
if (psi < psic) {
// pitch angle is too small, // so set value of function to an illegal value and exit
return -1;
}
}
// gmd of solid round conductor. Other values may be substituted
// for different conductor geometries
if (isRoundWire){
g = exp(-0.25) * dw / 2;
} else {
g = 0.2235*(w + t);
}
rr = r * r;
psio = 0.5 * M_PI - psi;
// Calculate Filament 2 offset angle
// Trap for psi=0 condition in which case ThetaO=0 and Y0=g
// Trap for psio=0 condition in which case use simplified formula for ThetaO and Y0=0
// which happens with circular (non-helical) filament
if (psi == 0) {
ThetaO = 0;
Y0 = g;
} else if (psio == 0) {
cosThetaO = 1 - (g * g / (2 * rr));
ThetaO = -fabs(atan(sqrt(1 - cosThetaO * cosThetaO) / cosThetaO));
Y0 = 0;
} else {
// Use Newton-Raphson method
k1 = (g * g) / (2 * r * r) - 1;
k2 = tan(psio);
k2 = 0.5 * k2 * k2;
t1 = g / r * sin(psi);
do {
t0 = t1;
t1 = t0 - (k1 + cos(t0) - k2 * t0 * t0) / (-sin(t0) - 2 * k2 * t0);
} while (fabs(t1 - t0) > 1e-12);
ThetaO = -fabs(t1);
// Calculate Filament 2 Y-offset, using formula (29)
Y0 = sqrt(g * g - 2 * rr * (1 - cos(ThetaO)));
}
// Psi constants
c2s = cos(psi) * cos(psi);
ss = sin(psi);
k = cos(psi) / r;
// Start of Simpson's rule code
a = 0;
b = Lw / 32768;
if (b > Lw) {
b = Lw;
}
grandtotal = 0;
while (a < Lw) {
dx = b - a;
m = 1;
CurrentErr = 2 * MaxErr;
kat = k * a;
kbt = k * b;
aaa = (Lw - a) * (Ingrnd(-a, -kat - ThetaO, ss, c2s, rr, Y0));
bbb = Ingrnd(a, kat - ThetaO, ss, c2s, rr, Y0);
ccc = (Lw - b) * (Ingrnd(-b, -kbt - ThetaO, ss, c2s, rr, Y0));
ddd = Ingrnd(b, kbt - ThetaO, ss, c2s, rr, Y0);
Sum2 = aaa + bbb + ccc + ddd;
// Initialize LastResult to trapezoidal area for test purposes
LastIntg = Sum2 / 2 * dx;
while ((CurrentErr > MaxErr) || (m < 1024)) {
m = 2 * m;
dx = dx / 2;
Sum = 0;
int max= round((float)m/2);
for (int i = 1; i <= max; i++){
phi = 2 * i * dx + a;
kpt = k * phi;
Sum = Sum + (Lw - phi) * (Ingrnd(-phi, -kpt - ThetaO, ss, c2s, rr, Y0) + Ingrnd(phi, kpt - ThetaO, ss, c2s, rr, Y0));
}
Integral = (4 * (Sum) + Sum2) * dx / 3;
CurrentErr = fabs((Integral) / (LastIntg) - 1);
LastIntg = Integral;
Sum2 = Sum2 + Sum * 2;
}
grandtotal += Integral;
a = b;
b = b * 2;
if (b > Lw) {
b = Lw;
}
}
double result = 1e-1 * grandtotal;
return result;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double solveHelicalInductance(double N, double _p, double _Dk, double _dw, double _w, double _t, double *lw, bool isRoundWire, unsigned int accuracy){
double lW, dw = 0, w = 0, t = 0;
double psi;
double sinpsi;
double p = _p / 1000;
double Dk = _Dk / 1000;
double Result;
if (isRoundWire){
dw = _dw / 1000;
} else {
w = _w / 1000;
t = _t / 1000;
}
//psi= atan(p/(2*pi*pi*Dk));
sinpsi = p / (M_PI * Dk);
psi = atan(sinpsi / sqrt(1 - sinpsi * sinpsi));
lW = M_PI * N * Dk / cos(psi);
if (isRoundWire){
Result = HeliCoilS(lW, psi, Dk / 2, dw, 0, 0, isRoundWire, accuracy);
} else {
Result = HeliCoilS(lW, psi, Dk / 2, 0, w, t, isRoundWire, accuracy);
}
*lw = lW;
return (Result);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double deriveOneLayerPoligonalN(double Dk, double dw, double p, double n, double I, double *lw, double *iDk, unsigned int accuracy){
double Ind, N_max, N_min, N, k, Kw, rA, rP;
k = 2;
N_min = 0;
rA = sqrt((1 / M_PI) * (0.5 * n * pow(0.5 * Dk,2) * sin(2 * M_PI / n)));
rP = (0.5 / M_PI) * (Dk * n * sin(M_PI / n));
Kw = sqrt(1 / 369.0);
*iDk = 2 * (((Kw * pow(rP,2)) + ((2 - Kw) * pow(rA,2))) / (2 * rA));
N = sqrt(I / (0.0002 * M_PI * *iDk * (log(1 + M_PI / (2 * k)) + 1 / (2.3004 + 3.437 * k + 1.763 * k * k - 0.47 /
pow((0.755 + 1 / k), 1.44)))));
_CoilResult res;
getOneLayerI_Poligonal(Dk, dw, p, N, n, &res, accuracy);
Ind = res.sec;
while (Ind < I){
N_min = N;
N_max = 2 * N;
N = (N_max + N_min) / 2;
getOneLayerI_Poligonal(Dk, dw, p, N, n, &res, accuracy);
Ind = res.sec;
}
N_max = N;
while (fabs(1 - (Ind / I)) > 0.001){
N = (N_min + N_max) / 2;
getOneLayerI_Poligonal(Dk, dw, p, N, n, &res, accuracy);
Ind = res.sec;
if (Ind > I)
N_max = N;
else
N_min = N;
}
*lw = res.thd;
return N;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double getOneLayerN_Poligonal(double I, double Dk, double dw, double p, double n, _CoilResult *result, unsigned int accuracy){
double N, lw, iDk;
N = deriveOneLayerPoligonalN(Dk, dw, p, n, I, &lw, &iDk, accuracy);
result->sec = p * N;
result->thd = lw;
result->seven = iDk;
return N;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void getOneLayerI_Poligonal(double Dk, double dw, double p, double N, double n, _CoilResult *result, unsigned int accuracy){
double Kw, rA, rP, lk, iDk, lw;
lk = N * p;
rA = sqrt((1 / M_PI) * (0.5 * n * pow(0.5 * Dk,2) * sin(2.0 * M_PI / n)));
rP = (0.5 / M_PI) * (Dk * n * sin(M_PI / n));
Kw = sqrt(1 / (1 + 368.0 * (lk / Dk)));
iDk = 2.0 * (((Kw * pow(rP, 2)) + ((2.0 - Kw) * pow(rA, 2))) / (2.0 * rA));
result->sec = solveHelicalInductance(N, p, iDk, dw, 0, 0, &lw, true, accuracy);
result->thd = lw;
result->seven = iDk;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void getFerriteCoreMagConst(double l1, double l2, double l3, double l4, double l5,
double A1, double A2, double A3, double A4, double A5, _MagCoreConst *c)
{
//auxiliary function to get the constants C1 & C2 of a ferrite core with the close magnetic circuit
double sum11 = l1 / A1;
double sum21 = l1 / (A1 * A1);
double sum12 = l2 / A2;
double sum22 = l2 / (A2 * A2);
double sum13 = l3 / A3;
double sum23 = l3 / (A3 * A3);
double sum14 = l4 / A4;
double sum24 = l4 / (A4 * A4);
double sum15 = l5 / A5;
double sum25 = l5 / (A5 * A5);
c->C1 = sum11 + sum12 + sum13 + sum14 + sum15;
c->C2 = sum21 + sum22 + sum23 + sum24 + sum25;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// PUBLIC FUNCTIONS REALIZATION
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double getOneLayerN_withRoundWire(double Dk, double dw, double p, double I, double *lw, unsigned int accuracy){
double ind, N_max, N_min, N, k;
k = 2;
N_min = 0;
N = sqrt(I / (0.0002 * M_PI * Dk * (log(1 + M_PI / (2 * k)) + 1 / (2.3004 + 3.437 * k + 1.763 * k * k - 0.47 / pow((0.755 + 1 / k), 1.44)))));
ind = solveHelicalInductance(N, p, Dk, dw, 0, 0, lw, true, accuracy);
while (ind < I) {
N_min = N;
N_max = 2 * N;
N = (N_max + N_min) / 2;
ind = solveHelicalInductance(N, p, Dk, dw, 0, 0, lw, true, accuracy);
}
N_max = N;
while (fabs(1 - (ind / I)) > 0.001) {
N = (N_min + N_max) / 2;
ind = solveHelicalInductance(N, p, Dk, dw, 0, 0, lw, true, accuracy);
if (ind > I) {
N_max = N;
} else {
N_min = N;
}
}
return N;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double getOneLayerN_byWindingLength( double D, double L, double I, _CoilResult *result, unsigned int accuracy){
double dw = 0, lTmp = 0, N = 0, k, lw, dw_max = 0.25 * D, dw_min = 0, Dk;
int i = 0;
while (fabs(1 - lTmp/L) > 0.05){
dw = (dw_min + dw_max) / 2;
k = odCalc(dw);
Dk = D + k;
N = getOneLayerN_withRoundWire(Dk, dw, k, I, &lw, accuracy);
lTmp = N * k + k;
if (lTmp > L){
dw_max = dw;
} else {
dw_min = dw;
}
i++;
if (i > 500)
return 0;
}
result->sec = lw;
result->five = dw;
return N;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double getOneLayerI_withRoundWire(double Dk, double dw, double p, double N, double *lw, unsigned int accuracy){
return solveHelicalInductance(N, p, Dk, dw, 0, 0, lw, true, accuracy);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double getOneLayerN_withRectWire(double Dk, double w, double t, double p, double I, double *lw, unsigned int accuracy){
double ind, N_max, N_min, N, k;
k = 2;
N_min = 0;
N = sqrt(I / (0.0002 * M_PI * Dk * (log(1 + M_PI / (2 * k)) + 1 / (2.3004 + 3.437 * k + 1.763 * k * k - 0.47 / pow((0.755 + 1 / k), 1.44)))));
ind = solveHelicalInductance(N, p, Dk, 0, w, t, lw, false, accuracy);
while (ind < I) {
N_min = N;
N_max = 2 * N;
N = (N_max + N_min) / 2;
ind = solveHelicalInductance(N, p, Dk, 0, w, t, lw, false, accuracy);
}
N_max = N;
while (fabs(1 - (ind / I)) > 0.001) {
N = (N_min + N_max) / 2;
ind = solveHelicalInductance(N, p, Dk, 0, w, t, lw, false, accuracy);
if (ind > I) {
N_max = N;
} else {
N_min = N;
}
}
return N;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double getOneLayerI_withRectWire(double Dk, double w, double t, double p, double N, double *lw, unsigned int accuracy){
return solveHelicalInductance(N, p, Dk, 0, w, t, lw, false, accuracy);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void getMultiLayerN(double I, double D, double dw, double k, double lk, double gap, long Ng, _CoilResult *result, bool isOrthocyclic){
double n_g = 0;
double jg = 0;
D = D / 10;
lk = lk / 10;
dw = dw / 10;
k = k / 10;
gap = gap / 10;
if (Ng == -1) {
gap = 0;
}
double Ltotal = 0; // initialize variable of total self-inductance
int nLayer = 0;
double lw = 0;
double r0 = (D + k) / 2;
unsigned long int N = 0;
int Nl = (int) floor(lk / k); // number of turns in layer
if (isOrthocyclic)
Nl = (int) floor((lk - 0.5 * k) / k);
double g = exp(-0.25) * dw / 2;
while (Ltotal < I) // start calculation loop increasing N-turns to reach requiring inductance (I)
{
N++;
int Nc = (N - 1) % Nl; // position of N-turn in layer
nLayer = (int) floor((N - 1) / Nl); // current layer for N-turn
if (((nLayer % Ng) == 0) && (nLayer > 0)) {
n_g = gap;
} else {
n_g = 0;
}
double nx; // x-offset of turn
if ((isOrthocyclic) && ((nLayer % 2) != 0)){
nx = Nc * k + 0.5 * k;
} else
nx = Nc * k;
double ny; // y-offset of turn
if (isOrthocyclic){
ny = r0 + dens * k * nLayer + n_g;
} else
ny = r0 + k * nLayer + n_g;
double Lns = Mut(ny, ny, g, 0); // self inductance of current turn
lw = lw + find_Helix_turn_length(ny, k); // length of wire with the current turn
double M = 0; // start calculation loop of the mutual inductance - current turn (N) + all another turns (j)
if (N > 1) {
int j;
for (j = N; j >= 2; j--) {
double Jc = (j - 2) % Nl;
double jx; // x-offset of turn
if ((isOrthocyclic) && ((nLayer % 2) != 0)){
jx = Jc * k + 0.5 * k;
} else
jx = Jc * k;
int jLayer = (int) floor((j - 2) / Nl);
if (((jLayer % Ng) == 0) && (jLayer > 0)) {
jg = gap;
} else {
jg = 0;
}
double jy;
if (isOrthocyclic){
jy = r0 + dens * k * jLayer + jg;
} else
jy = r0 + k * jLayer + jg;
M = M + 2 * Mut(ny, jy, nx - jx, g); // mutual inductance
// between current
// N-turn and j-turn
}
}
Ltotal += Lns + M; // total summary inductance (adding self-inductance and mutual inductance of current N-turn)
}
double Resistivity = mtrl[Cu][Rho]*1e2;
double R = (Resistivity * lw * 4) / (M_PI * dw * dw); // resistance of the wire
double lw0 = lw / 100;
double NumberInterLayer = (double) floor(nLayer / Ng);
double c;
if (isOrthocyclic)
c = (nLayer * dens * k + k + NumberInterLayer * gap) *10;
else
c = (nLayer * k + NumberInterLayer * gap) * 10;
result->N = R;
result->sec = lw0;
result->thd = nLayer + 1;
result->fourth = c;
result->five = NumberInterLayer;
result->six = N;
// return: N(turns); R(resistance) Ohm; lw0(length of wire) m;
// NLayer (Number of layer); c (Winding thickness) mm
// NumberInterLayer (Number of inter-layers);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void getMultiLayerI_byN(double D, double lk, double dw, double k, double N, _CoilResult *result, bool isOrthocyclic)
{
D = D / 10;
lk = lk / 10;
dw = dw / 10;
k = k / 10;
int Nl, Nc, Jc, nLayer = 0, jLayer;
double nx, ny, jx, jy, Lns, M;
double Ltotal = 0; // initialize variable of total self-inductance
double lw = 0;
double r0 = (D + k) / 2;
Nl = (int) floor(lk / k);
if (isOrthocyclic)
Nl = (int) floor((lk - 0.5 * k) / k);
double g = exp(-0.25) * dw / 2;
for (int w = 1; w < N + 1; w++){
Nc = (w - 1) % Nl;
nLayer = (int) floor((w - 1) / Nl);
if ((isOrthocyclic) && ((nLayer % 2) != 0)){
nx = Nc * k + 0.5 * k;
} else
nx = Nc * k;
if (isOrthocyclic){
ny = r0 + dens * k * nLayer;
} else
ny = r0 + k * nLayer;
Lns = Mut(ny, ny, g, 0);
// self inductance of current turn
lw = lw + find_Helix_turn_length(ny, k);
M = 0;
if (w > 1) {
for (int j = w; j >= 2; j--) {
Jc = (j - 2) % Nl;
if ((isOrthocyclic) && ((nLayer % 2) != 0)){
jx = Jc * k + 0.5 * k;
} else
jx = Jc * k;
jLayer = (int) floor((j - 2) / Nl);
if (isOrthocyclic){
jy = r0 + dens * k * jLayer;
} else
jy = r0 + k * jLayer;
M = M + 2 * Mut(ny, jy, nx - jx, g);
}
}
Ltotal += Lns + M;
}
double Resistivity = mtrl[Cu][Rho]*1e2;
double Rdc = (Resistivity * lw * 4) / (M_PI * dw * dw);
double thickness = 0.0;
if (isOrthocyclic)
thickness = (nLayer * dens * k + k) * 10;
else
thickness = (nLayer + 1) * k * 10;
result->N = Ltotal; //inductance value
result->sec = nLayer + 1; //number of layers
result->thd = lw * 0.01; //length of wire
result->fourth = Rdc; //resistance to DC
result->five = thickness; //coil thickness
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void getMultiLayerI(double D, double lk, double dw, double k, double c, double gap, long Ng, _CoilResult *result, bool isOrthocyclic){
double bTmp, nTmp, lw, Lns, Ltotal, r0, M, g, nx, ny, jx, jy, n_g = 0, jg = 0, ind1, ind2, N1, N2;
int n, Nl, j, Nc, Jc, nLayer, jLayer;
ind1 = 0;
D = D / 10;
lk = lk / 10;
c = c / 10;
nTmp = 0;
bTmp = 0;
dw = dw / 10;
k = k / 10;
gap = gap / 10;
if (Ng == -1) {
gap = 0;
}
Ltotal = 0; // initialize variable of total self-inductance
lw = 0;
r0 = (D + k) / 2;
n = 0;
Nl = (int) floor(lk / k);
if (isOrthocyclic)
Nl = (int) floor((lk - 0.5 * k) / k);
g = exp(-0.25) * dw / 2;
while (bTmp < c) {
n++;
Nc = (n - 1) % Nl;
nLayer = (int) floor((n - 1) / Nl);
if (((nLayer % Ng) == 0) && (nLayer > 0)) {
n_g = gap;
} else {
n_g = 0;
}
if ((isOrthocyclic) && ((nLayer % 2) != 0)){
nx = Nc * k + 0.5 * k;
} else
nx = Nc * k;
if (isOrthocyclic){
ny = r0 + dens * k * nLayer + n_g;
} else
ny = r0 + k * nLayer + n_g;
Lns = Mut(ny, ny, g, 0);
// self inductance of current turn
lw = lw + find_Helix_turn_length(ny, k);
M = 0;
if (n > 1) {
for (j = n; j >= 2; j--) {
Jc = (j - 2) % Nl;
if ((isOrthocyclic) && ((nLayer % 2) != 0)){
jx = Jc * k + 0.5 * k;
} else
jx = Jc * k;
jLayer = (int) floor((j - 2) / Nl);
if (((jLayer % Ng) == 0) && (jLayer > 0)) {
jg = gap;
} else {
jg = 0;
}
if (isOrthocyclic){
jy = r0 + dens * k * jLayer + jg;
} else
jy = r0 + k * jLayer + jg;
M = M + 2 * Mut(ny, jy, nx - jx, g);
}
}
Ltotal += Lns + M;
if (nTmp < c - k) {
if (isOrthocyclic)
nTmp = (nLayer * dens * k + k);
else
nTmp = (nLayer + 1) * k;
ind1 = Ltotal;
}
if (isOrthocyclic)
bTmp = ((nLayer + 1) * dens * k);
else
bTmp = nLayer * k;
}
N1 = n - Nl;
N2 = n + Nl;
ind2 = Ltotal;
result->N = ind1;
result->sec = ind2;
result->thd = N1;
result->fourth = N2;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void getMultiLayerI_fromResistance (double D, double lk, double c, double k, double Rm, _CoilResult *result, bool isOrthocyclic){
double dw, bTmp, tmpR, lw, Lns, Ltotal, r0, M, g, nx, ny, jx, jy, N1, N2;
int n, Nl, j, Nc, Jc, nLayer = 0, jLayer;
double aWire[67][5] = {{0.06, 0.075, 0.09, 0.085, 0.09},
{0.063, 0.078, 0.09, 0.085, 0.09}, {0.07, 0.084, 0.092, 0.092, 0.1}, {0.071, 0.088, 0.095, 0.095, 0.1},
{0.08, 0.095, 0.105, 0.105, 0.11}, {0.09, 0.105, 0.12, 0.115, 0.12}, {0.1, 0.122, 0.13, 0.125, 0.13},
{0.112, 0.134, 0.14, 0.125, 0.14}, {0.12, 0.144, 0.15, 0.145, 0.15}, {0.125, 0.149, 0.155, 0.15, 0.155},
{0.13, 0.155, 0.16, 0.155, 0.16}, {0.14, 0.165, 0.17, 0.165, 0.17}, {0.15, 0.176, 0.19, 0.18, 0.19},
{0.16, 0.187, 0.2, 0.19, 0.2}, {0.17, 0.197, 0.21, 0.2, 0.21}, {0.18, 0.21, 0.22, 0.21, 0.22},
{0.19, 0.22, 0.23, 0.22, 0.23}, {0.2, 0.23, 0.24, 0.23, 0.24}, {0.21, 0.24, 0.25, 0.25, 0.25},
{0.224, 0.256, 0.27, 0.26, 0.27}, {0.236, 0.26, 0.285, 0.27, 0.28}, {0.25, 0.284, 0.3, 0.275, 0.3},
{0.265, 0.305, 0.315, 0.305, 0.31}, {0.28, 0.315, 0.33, 0.315, 0.33}, {0.3, 0.34, 0.35, 0.34, 0.34},
{0.315, 0.35, 0.365, 0.352, 0.36}, {0.335, 0.375, 0.385, 0.375, 0.38}, {0.355, 0.395, 0.414, 0.395, 0.41},
{0.38, 0.42, 0.44, 0.42, 0.44}, {0.4, 0.44, 0.46, 0.442, 0.46}, {0.425, 0.465, 0.485, 0.47, 0.47},
{0.45, 0.49, 0.51, 0.495, 0.5}, {0.475, 0.525, 0.545, 0.495, 0.53}, {0.5, 0.55, 0.57, 0.55, 0.55},
{0.53, 0.58, 0.6, 0.578, 0.6}, {0.56, 0.61, 0.63, 0.61, 0.62}, {0.6, 0.65, 0.67, 0.65, 0.66},
{0.63, 0.68, 0.7, 0.68, 0.69}, {0.67, 0.72, 0.75, 0.72, 0.75}, {0.71, 0.76, 0.79, 0.77, 0.78},
{0.75, 0.81, 0.84, 0.81, 0.83}, {0.8, 0.86, 0.89, 0.86, 0.89}, {0.85, 0.91, 0.94, 0.91, 0.94},
{0.9, 0.96, 0.99, 0.96, 0.99}, {0.93, 0.99, 1.02, 0.99, 1.02}, {0.95, 1.01, 1.04, 1.02, 1.04},
{1.0, 1.07, 1.1, 1.07, 1.11}, {1.06, 1.13, 1.16, 1.14, 1.16}, {1.08, 1.16, 1.19, 1.16, 1.19},
{1.12, 1.19, 1.22, 1.2, 1.23}, {1.18, 1.26, 1.28, 1.26, 1.26}, {1.25, 1.33, 1.35, 1.33, 1.36},
{1.32, 1.4, 1.42, 1.4, 1.42}, {1.4, 1.48, 1.51, 1.48, 1.51}, {1.45, 1.53, 1.56, 1.53, 1.56},
{1.5, 1.58, 1.61, 1.58, 1.61}, {1.56, 1.63, 1.67, 1.64, 1.67}, {1.6, 1.68, 1.71, 1.68, 1.71},
{1.7, 1.78, 1.81, 1.78, 1.81}, {1.74, 1.82, 1.85, 1.82, 1.85}, {1.8, 1.89, 1.92, 1.89, 1.92},
{1.9, 1.99, 2.02, 1.99, 2.02}, {2.0, 2.1, 2.12, 2.1, 2.12}, {2.12, 2.21, 2.24, 2.22, 2.24},
{2.24, 2.34, 2.46, 2.34, 2.46}, {2.36, 2.46, 2.48, 2.36, 2.48}, {2.5, 2.6, 2.63, 2.6, 2.62}};
D = D / 10;
lk = lk / 10;
k = k / 10;
c = c /10;
bTmp = 0;
for (int z = 0; z < 67; ++z){
dw = aWire[z][0] / 10;
Ltotal = 0;
// initialize variable of total self-inductance
lw = 0;
r0 = (D + k) / 2;
n = 0;
Nl = (int) floor(lk / k);
if (isOrthocyclic)
Nl = (int) floor((lk - 0.5 * k) / k);
g = exp(-0.25) * dw / 2;
tmpR = 0;
while (tmpR <= Rm){
n++;
Nc = (n - 1) % Nl;
nLayer = (int) floor((n - 1) / Nl);
if ((isOrthocyclic) && ((nLayer % 2) != 0)){
nx = Nc * k + 0.5 * k;
} else
nx = Nc * k;
if (isOrthocyclic){
ny = r0 + dens * k * nLayer;
} else
ny = r0 + k * nLayer;
Lns = Mut(ny, ny, g, 0);
// self inductance of current turn
lw +=find_Helix_turn_length(ny, k);
M = 0;
if (n > 1){
for (j = n; j >= 2; j--){
Jc = (j - 2) % Nl;
if ((isOrthocyclic) && ((nLayer % 2) != 0)){
jx = Jc * k + 0.5 * k;
} else
jx = Jc * k;
jLayer = (int) floor((j - 2) / Nl);
if (isOrthocyclic){
jy = r0 + dens * k * jLayer;
} else
jy = r0 + k * jLayer;
M = M + 2 * Mut(ny, jy, nx - jx, g);
}
}
Ltotal += Lns + M;
double Resistivity = mtrl[Cu][Rho] * 1e2;
tmpR = (Resistivity * lw * 4) / (M_PI * dw * dw);
}
if (isOrthocyclic)
bTmp = (nLayer * dens * k + k);
else
bTmp = (nLayer + 1) * k;
if (bTmp > (c - k))
break;
else
result->N = Ltotal;
}
N1 = n - Nl;
N2 = n + Nl;
result->sec = Ltotal;
result->thd = N1;
result->fourth = N2;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void getMultiLayerI_rectFormer(double a, double b, double l, double c, double dw, double k, _CoilResult *result){
double a0, b0, D, Db, Da, nx, ny, jx, jy, lengthNa, lengthNb, lengthJa, lengthJb, Ltotal, Ladd, Lsub, Madd,
Msub, lw, Km, Ks, Lcor, cTmp = 0, nTmp = 0, ind1 = 0, ind2, N1, N2;
int n, Nc, Nl, Jc, nLayer, jLayer;
a = a / 10;
b = b / 10;
l = l / 10;
c = c / 10;
dw = dw / 10;
k = k / 10;
n = 0;
Ltotal = 0;
a0 = a + k;
b0 = b + k;
lw = 0;
nLayer = 0;
Nl = floor(l / k); // Number of turns in layer
while (cTmp < (c + k)) {
n++;
Nc = (n - 1) % Nl; // Position of the turn on x
nLayer = floor((n - 1) / Nl); // Position of the turn on y
nx = Nc * k; // x-offset of current turn
ny = nLayer * k; // y-offset of current turn
lengthNa = a0 + 2 * k * (nLayer); // lenght of straight conductor of current turn (side a)
lengthNb = b0 + 2 * k * (nLayer); // lenght of straight conductor of current turn (side b)
lw = lw + 2 * (a0 + b0 + 2 * k * (nLayer));
Ladd = SelfInductanceStraightWire(lengthNa, dw) + SelfInductanceStraightWire(lengthNb, dw); // half of self-inductance of the current turn
Db = 2 * ny + a0; // distance to opposite cunductor of the same turn (side b)
Da = 2 * ny + b0; // distance to opposite cunductor of the same turn (side a)
Lsub = 2 * MutInductanceStraightWire(lengthNa, lengthNa, Da) + 2 * MutInductanceStraightWire(lengthNb, lengthNb, Db);
// half mutual inductance with opposite conductor of current turn
Madd = 0;
Msub = 0;
if (n > 1){
for (int j = n; j >= 2; j--){
Jc = (j - 2) % Nl; // position of previous turn on x
jx = Jc * k; // x-offset of previous turn
jLayer = floor((j - 2) / Nl); // Position of the turn on y
jy = k * jLayer; // y-offset of previous turn
lengthJa = a0 + 2 * k * (nLayer + 1); // lenght of straight conductor of previous turn (side a)
lengthJb = b0 + 2 * k * (nLayer + 1); // lenght of straight conductor of previous turn (side b)
D = sqrt(pow(nx - jx, 2) + pow(ny - jy, 2)); // distance to in-phase straight conductor of previous turn
Madd = Madd + 2 * MutInductanceStraightWire(lengthNa, lengthJa, D) + 2 * MutInductanceStraightWire(lengthNb, lengthJb, D);
// half mutual inductance with in-phase conductor in previous turn
Db = sqrt(pow(nx - jx, 2) + pow(ny + jy + a0, 2));
// distance to opposite cunductor between the current turn and previous (side b)
Da = sqrt(pow(nx - jx, 2) + pow(ny + jy + b0, 2));
// distance to opposite cunductor between the current turn and previous (side a)
Msub = Msub + 2 * MutInductanceStraightWire(lengthNa, lengthJa, Da) + 2 * MutInductanceStraightWire(lengthNb, lengthJb, Db);
// half mutual inductance with opposite conductor in previous turn
}
}
Ltotal += 2 * (Ladd - Lsub + Madd - Msub);
Ks = rosaKs(k / dw);
Km = rosaKm(n);
Lcor = 0.0002 * M_PI * (a + b) * n * (Ks + Km);
Ltotal -= Lcor;
if (nTmp < c) {
nTmp = (nLayer + 1) * k;
ind1 = Ltotal;
}
cTmp = (nLayer + 1) * k;
}
N1 = n - Nl;
N2 = n + Nl;
ind2 = Ltotal;
result->N = ind1;
result->sec = ind2;
result->thd = N1;
result->fourth = N2;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void getMultiLayerN_rectFormer(double Ind, double a, double b, double l, double dw, double k, _CoilResult *result){
//Calculation formulas of multilayer inductor with rectangular former https://coil32.net/multilayer-rectangular.html
double a0, b0, D, Db, Da, nx, ny, jx, jy, lengthNa, lengthNb, lengthJa, lengthJb, Ltotal, Ladd, Lsub, Madd, Msub, lw, Km, Ks, Lcor, Rdc;
int n, Nc, Nl, Jc, nLayer, jLayer;
a = a / 10;
b = b / 10;
l = l / 10;
dw = dw / 10;
k = k / 10;
n = 0;
Ltotal = 0;
a0 = a + k;
b0 = b + k;
lw = 0;
nLayer = 0;
Nl = floor(l / k); // Number of turns in layer
while (Ltotal < Ind){
n++;
Nc = (n - 1) % Nl; // Position of the turn on x
nLayer = floor((n - 1) / Nl); // Position of the turn on y
nx = Nc * k; // x-offset of current turn
ny = nLayer * k; // y-offset of current turn
lengthNa = a0 + 2 * k * (nLayer); Rdc = (0.0175 * lw * 1E-4 * 4) / (M_PI * dw * dw);// lenght of straight conductor of current turn (side a)
lengthNb = b0 + 2 * k * (nLayer); // lenght of straight conductor of current turn (side b)
lw += 2 * (a0 + b0 + 2 * k * (nLayer));
Ladd = SelfInductanceStraightWire(lengthNa, dw) + SelfInductanceStraightWire(lengthNb, dw); // half of self-inductance of the current turn
Db = 2 * ny + a0; // distance to opposite cunductor of the same turn (side b)
Da = 2 * ny + b0; // distance to opposite cunductor of the same turn (side a)
Lsub = 2 * MutInductanceStraightWire(lengthNa, lengthNa, Da) + 2 * MutInductanceStraightWire(lengthNb, lengthNb, Db);
// half mutual inductance with opposite conductor of current turn
Madd = 0;
Msub = 0;
if (n > 1){
for (int j = n; j >= 2; j--){
Jc = (j - 2) % Nl; // position of previous turn on x
jx = Jc * k; // x-offset of previous turn
jLayer = floor((j - 2) / Nl); // Position of the turn on y
jy = k * jLayer; // y-offset of previous turn
lengthJa = a0 + 2 * k * (nLayer + 1); // lenght of straight conductor of previous turn (side a)
lengthJb = b0 + 2 * k * (nLayer + 1); // lenght of straight conductor of previous turn (side b)
D = sqrt(pow(nx - jx, 2) + pow(ny - jy, 2)); // distance to in-phase straight conductor of previous turn
Madd = Madd + 2 * MutInductanceStraightWire(lengthNa, lengthJa, D) + 2 * MutInductanceStraightWire(lengthNb, lengthJb, D);
// half mutual inductance with in-phase conductor in previous turn
Db = sqrt(pow(nx - jx, 2) + pow(ny + jy + a0, 2));
// distance to opposite cunductor between the current turn and previous (side b)
Da = sqrt(pow(nx - jx, 2) + pow(ny + jy + b0, 2));
// distance to opposite cunductor between the current turn and previous (side a)
Msub = Msub + 2 * MutInductanceStraightWire(lengthNa, lengthJa, Da) + 2 * MutInductanceStraightWire(lengthNb, lengthJb, Db);
// half mutual inductance with opposite conductor in previous turn
}
}
Ltotal += 2 * (Ladd - Lsub + Madd - Msub);
Ks = rosaKs(k / dw);
Km = rosaKm(n);
Lcor = 0.0002 * M_PI * (a + b) * n * (Ks + Km);
Ltotal -= Lcor;
}
double Resistivity = mtrl[Cu][Rho]*1e2;
Rdc = (Resistivity * lw * 4) / (M_PI * dw * dw);
result->N = n; //number of turns
result->sec = nLayer + 1; //number of layers
result->thd = lw * 0.01; //length of wire
result->fourth = Rdc; //resistance to DC
result->five = (nLayer + 1) * k * 10; //coil thickness
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void getMultiLayerI_rectFormer_byN(double N, double a, double b, double l, double dw, double k, _CoilResult *result){
double a0, b0, D, Db, Da, nx, ny, jx, jy, lengthNa, lengthNb, lengthJa, lengthJb, Ltotal, Ladd, Lsub, Madd, Msub, lw, Km, Ks, Lcor;
int Nc, Nl, Jc, nLayer, jLayer;
a = a / 10;
b = b / 10;
l = l / 10;
dw = dw / 10;
k = k / 10;
Ltotal = 0;
a0 = a + k;
b0 = b + k;
lw = 0;
nLayer = 0;
Nl = floor(l / k); // Number of turns in layer
for (int n = 1; n < N + 1; n++){