-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBCEndRings.js
355 lines (256 loc) · 10 KB
/
BCEndRings.js
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
/* Birdcage Builder
*
* Birdcage End Rings (Circular)
*
* Doug Brantner
* 28 April 2023
* NYU Langone Health
* cai2r.net
*
* Based on Android implementation of BirdcageBuilder by Giuseppe Carluccio & Christopher Collins.
*/
class BCEndRings {
//constructor(n, legs) {
constructor(n) {
// TODO is n input redundant? since we require BCLegs to be setup already?
this.n_legs = Number(n);
// NOTE for now keeping the Leg & EndRing objects separate;
// functions that require leg info must be given the leg object as an input arg
this.er_shape = 'null'; // 'rect' or 'tube'
// TODO units for all!
// for rectangular end ring copper:
this.er_arclen = -1; // arc length of each endring segment (circumference/N) (meters)
this.er_width = -1; // meters
// for tubular endrings:
this.er_r_inner = -1; // tube endring inner radius (meters)
this.er_r_outer = -1; // tube endring outer radius (meters)
this.er_self_inductance = -1;
this.er_mutual_inductance = new Array(n);
this.er_currents = new Array(n); // end ring currents
// USER MUST CALL:
// init_endrings() (called automatically in BircageBuilder constructor
// NOTE: if user wants to specify custom endring arclength values, do it AFTER
// BirdcageBuilder constructor and before anything else!)
// set_legs_<geom>
}
init_endrings(legs) {
/* Initialize the currents of the endrings
*
* legs = BCLegs object (must be fully set up!)
*
* BCJ.172
*/
console.assert(this.n_legs == legs.n_legs, 'BCEndRings: init_endrings: # of legs must match!');
this.er_arclen = 2 * Math.PI * legs.r_coil / this.n_legs;
this.er_currents[0] = legs.leg_currents[0];
var k;
for (k = 1; k < this.n_legs; k++) {
this.er_currents[k] = legs.leg_currents[k] + this.er_currents[k-1];
}
}
set_endrings_rect(w) {
/* Set up rectangular endring segments
*
* w = end ring width (meters)
*
*/
this.er_shape = 'rect';
this.er_width = Number(w);
//this.er_self_inductance = 2 * this.er_arclen * (Math.log(2*this.er_arclen/this.er_width) + 0.5);
this.er_self_inductance = this.calc_er_self_inductance_rect(this.er_arclen, this.er_width);
}
set_endrings_tube(ir, or) {
/* Set up tubular endring segments
*
* ir = inner radius of tube (meters)
* or = outer radius of tube (meters)
*/
this.er_shape = 'tube';
this.er_r_inner = Number(ir);
this.er_r_outer = Number(or);
this.er_self_inductance = this.calc_er_self_inductance_tube(this.er_arclen, this.er_r_inner, this.er_r_outer);
}
calc_er_self_inductance_rect(arclen, width) {
/* Calculate self inductance for Rectangular endrings
*
* arclen = arc length of each segment (meters)
* width = width of each segment (meters)
*
* Returns self inductance value.
*
* BCJ.183
*/
arclen = Number(arclen);
width = Number(width);
return 2 * arclen * (Math.log(2*arclen/width) + 0.5);
}
calc_er_self_inductance_tube(arclen, r_in, r_out) {
/* Calculate the self inductance for Tube legs
*
* arclen = arc length of each segment (meters)
* r_in = inner radius of tube (meters)
* r_out = outer radius of tube (meters)
*
* Returns the self inductance value
*
* BCJ.185
*/
arclen = Number(arclen);
r_in = Number(r_in);
r_out = Number(r_out);
if (r_in > 0) {
var ratio = r_in/r_out;
var c = 0.1493*Math.pow(ratio, 3) - 0.3606*Math.pow(ratio, 2) - 0.0405*ratio + 0.2526;
return 2 * arclen * (Math.log(4*arclen/r_out) + c - 1);
}
else {
return 2 * arclen * (Math.log(4*arclen/r_out) - 0.75);
}
}
calc_er_mutual_inductance(legs) {
/* Calculate End Ring Mutual Inductance
*
* - This is a bit of a black box, mostly translated directly from the Java code
* - TODO could use more clarification / descriptive variable names
*
* legs = BCLegs object (must be fully setup!)
*
* Starting on BCJ.195 - BCJ.294
*
* Directly modifies this.er_mutual_inductance
*/
console.assert(this.n_legs == legs.n_legs, 'BCEndRings: calc_er_mutual_inductance: # of legs must match!');
// TODO descriptions???
var n = this.n_legs;
var d, m1, l1, R1, ang1, Mnext, Mprev, Lop, Ladj, Lnadj, M, L, R3, R4, R2, a2, ang, p, mu, v, t1, t2, t3, t4, s1, s2, s3, s4;
var lmu = new Array(n);
var z, z1;
var idx1, idxN, idx2, idxK, iKN2N, iKN1N;
var iKpK1N, iKpK1m1N;
//debug('n = ' + n);
//debug('n_legs = ' + this.n_legs);
// TODO - source starts at 0 but should this start at 1?
var k, k1;
for (k=0; k < n; k++){
//debug('k: ' + k);
//debug('--------');
// pre-compute modulo indexes (NOTE javascript % operator does NOT behave as expected)
// see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Remainder
idx1 = mod(k+1, n);
idxN = mod(k+n, n);
//debug('k = ' + k);
//debug('n = ' + n);
//debug('k+1 = ' + (k+1));
//debug('idx1: (k+1) mod n: ' + idx1);
//debug('test idx1 : ' + mod(k+1, n));
////debug('test idx1-2 : ' + mod(1, 8));
//debug('');
//debug('idxN: mod(k+n, n): ' + idxN);
//debug('test idxN: : ' + mod(k+n, n));
////debug('test idxN-2 : ' + mod(8, 8));
//debug('');
idx2 = mod(k+2, n);
idxK = mod(k, n);
iKN2N = mod(k+n/2, n);
iKN1N = mod(k+n-1, n);
//Mutual Inductance of Opposite Rings
d = Math.sqrt(Math.pow(legs.leg_x[idx1]-legs.leg_x[iKN2N],2)+Math.pow(legs.leg_y[idx1]-legs.leg_y[iKN2N],2));
Lop = 0;
if (Math.abs(this.er_currents[idxK])>(1/10000)) {
Lop = 2*this.er_arclen*(Math.log(this.er_arclen/d+Math.sqrt(1+Math.pow(this.er_arclen/d, 2)))-Math.sqrt(1+Math.pow(d/this.er_arclen,2))+d/this.er_arclen);
}
//debug('d: ' + d);
//debug('Lop: ' + Lop);
//Mutual Inductance of Adjacent Rings
// TODO m1 is zero when k=1 in app default value test
m1 = Math.sqrt(Math.pow(legs.leg_x[idx1]-legs.leg_x[idxN],2)+Math.pow(legs.leg_y[idx1]-legs.leg_y[idxN],2));
l1 = Math.sqrt(Math.pow(legs.leg_x[idx1]-legs.leg_x[idx2],2)+Math.pow(legs.leg_y[idx1]-legs.leg_y[idx2],2));
R1 = Math.sqrt(Math.pow(legs.leg_x[idx2]-legs.leg_x[idxK],2)+Math.pow(legs.leg_y[idx2]-legs.leg_y[idxK],2));
//debug('m1 first calc:');
//debug('Math.pow(legs.leg_x[idx1]-legs.leg_x[idxN],2): ' + Math.pow(legs.leg_x[idx1]-legs.leg_x[idxN],2));
//debug('Math.pow(legs.leg_y[idx1]-legs.leg_y[idxN],2): ' + Math.pow(legs.leg_y[idx1]-legs.leg_y[idxN],2));
//debug('m1: ' + m1);
//debug('l1: ' + l1);
//debug('R1: ' + R1);
ang1 = (Math.pow(l1,2)+Math.pow(m1,2)-Math.pow(R1,2))/(2*l1*m1);
//debug('Math.pow(l1,2): ' + Math.pow(l1,2));
//debug('Math.pow(m1,2): ' + Math.pow(m1,2));
//debug('Math.pow(R1,2): ' + Math.pow(R1,2));
//debug('(2*l1*m1): ' + (2*l1*m1));
//debug('ang1: ' + ang1);
Mnext = Math.abs(2*ang1*(l1*this.harct(m1/(l1+R1))+m1*this.harct(m1/(m1+R1)) ));
// TODO m1 is zero when k=1 in app default value test (zero appears in first one above too)
m1 = Math.sqrt(Math.pow(legs.leg_x[idxK]-legs.leg_x[iKN1N],2)+Math.pow(legs.leg_y[idxK]-legs.leg_y[iKN1N],2));
l1 = Math.sqrt(Math.pow(legs.leg_x[idxK]-legs.leg_x[idx1],2)+Math.pow(legs.leg_y[idxK]-legs.leg_y[idx1],2));
R1 = Math.sqrt(Math.pow(legs.leg_x[idx1]-legs.leg_x[iKN1N],2)+Math.pow(legs.leg_y[idx1]-legs.leg_y[iKN1N],2));
//debug('Mnext: ' + Mnext);
//debug('m1: ' + m1);
//debug('l1: ' + l1);
//debug('R1: ' + R1);
ang1 = (Math.pow(l1,2) + Math.pow(m1,2) - Math.pow(R1,2))/(2*l1*m1);
Mprev = Math.abs(2*ang1*(l1*this.harct(m1/(l1+R1))+m1*this.harct(m1/(m1+R1)) ));
//debug('ang1: ' + ang1);
//debug('Mprev: ' + Mprev);
Ladj=0;
if (Math.abs(this.er_currents[idxK])>(1/100000)) {
Ladj = (Mnext*this.er_currents[idx1]+Mprev*this.er_currents[iKN1N])/this.er_currents[idxK];
}
//Mutual Inductance of Non Adjacent Rings
Lnadj = 0;
for (k1 = 3; k1<n; k1++) {
// pre-compute modulo indexes (see above, do NOT use % operator)
iKpK1N = mod(k+k1, n);
iKpK1m1N = mod(k+k1-1, n);
M = Math.sqrt(Math.pow(legs.leg_x[idx1]-legs.leg_x[idxK],2)+Math.pow(legs.leg_y[idx1]-legs.leg_y[idxK],2));
L = Math.sqrt(Math.pow(legs.leg_x[iKpK1N]-legs.leg_x[iKpK1m1N],2)+Math.pow(legs.leg_y[iKpK1N]-legs.leg_y[iKpK1m1N],2));
R3 = (Math.pow(legs.leg_x[idxK]-legs.leg_x[iKpK1m1N],2)+Math.pow(legs.leg_y[idxK]-legs.leg_y[iKpK1m1N],2));
R4 = (Math.pow(legs.leg_x[idx1]-legs.leg_x[iKpK1m1N],2)+Math.pow(legs.leg_y[idx1]-legs.leg_y[iKpK1m1N],2));
R2 = (Math.pow(legs.leg_x[idxK]-legs.leg_x[iKpK1N],2)+Math.pow(legs.leg_y[idxK]-legs.leg_y[iKpK1N],2));
R1 = (Math.pow(legs.leg_x[idx1]-legs.leg_x[iKpK1N],2)+Math.pow(legs.leg_y[idx1]-legs.leg_y[iKpK1N],2));
a2 = R4 - R3 + R2 - R1;
ang = a2/(L*M);
p = 4*Math.pow(L,2)*Math.pow(M,2)-Math.pow(a2,2);
if (p==0) {
mu = 0;
v = 0;
} else {
mu = L*(2*Math.pow(M,2)*(R2-R3-Math.pow(L,2))+a2*(R4-R3-Math.pow(M,2)))/(4*Math.pow(L,2)*Math.pow(M,2)-Math.pow(a2,2));
v = M*(2*Math.pow(L,2)*(R4-R3-Math.pow(M,2))+a2*(R2-R3-Math.pow(L,2)))/(4*Math.pow(L,2)*Math.pow(M,2)-Math.pow(a2,2));
}
t4 = Math.sqrt(R4);
t3 = Math.sqrt(R3);
t2 = Math.sqrt(R2);
t1 = Math.sqrt(R1);
s1 = (mu+L)*this.harct(M/(t1+t2));
s2 = (v+M)*this.harct(L/(t1+t4));
s3 = (mu)*this.harct(M/(t3+t4));
s4 = (v)*this.harct(L/(t3+t2));
lmu[k1] = ang*(s1+s2-s3-s4);
if (k1==(n/2+1)) {
lmu[k1]=0;
}
if (Math.abs(this.er_currents[idxK])>(1/100000)) {
Lnadj = Lnadj + lmu[k1]*Math.abs(this.er_currents[iKpK1m1N]/this.er_currents[idxK]);
}
}
this.er_mutual_inductance[k] = Lnadj + this.er_self_inductance + Lop + Ladj;
//debug('');
} // end of loop
this.er_self_inductance = this.er_self_inductance*1e-7;
for (k=0;k<n;k++) {
this.er_mutual_inductance[k] = this.er_mutual_inductance[k]*1e-7;
}
}
/*** Helper Functions ***/
harct(x) {
/* Inverse Hyperbolic Tangent (arctan)
* https://en.wikipedia.org/wiki/Inverse_hyperbolic_functions
*
* Supported on -1 < x < 1
*
* BCJ.357
*/
x = Number(x);
return Math.log((1+x)/(1-x)) / 2;
}
}