forked from andrewgiuliani/matplasmaopt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
magneticAxisType.m
1795 lines (1321 loc) · 97.2 KB
/
magneticAxisType.m
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
classdef magneticAxisType < handle
properties
nfp
% axis (R,Z) values
RA
ZA
RAp
ZAp
RApp
ZApp
RAppp
ZAppp
dRA_dcos
dRAp_dcos
dRApp_dcos
dRAppp_dcos
dZA_dsin
dZAp_dsin
dZApp_dsin
dZAppp_dsin
sigma
iota
eta_bar
curvature
torsion
B0
sign_G
sign_psi
I2_over_B0
abs_G_over_B0
d_abs_G_over_B0_dRcos
d_abs_G_over_B0_dZsin
tau_kappa2
s_theta
s_thetatheta
s_thetathetatheta
X1c
Y1s
Y1c
d_X1c
d_Y1s
d_Y1c
d_Y1c_ds
d2_Y1c_ds
B_QS
gradBx_QS
gradBy_QS
gradBz_QS
B_coils
gradBx_coils
gradBy_coils
gradBz_coils
d_curvature_dtheta
r_theta_cyl
r_thetatheta_cyl
r_thetathetatheta_cyl
r_theta_cyl_tc
r_thetatheta_cyl_tc
kappa
d_kappa_dtheta
d_kappa_dtheta1
d_kappa_dtheta2
d_kappa_dtheta3
% sine/cos values on axis
cR
sZ
D
Dtilde
zeta
nzeta
S
C
SIN
COS
dSIN
dCOS
top
% on axis magnetic field values and sensitivities
B
B_mag
BR
Bphi
BZ
t_vec
n_vec
b_vec
dX_dPhi % Tx
dY_dPhi % Ty
dZ_dPhi % TZ
dTx_dr
dTy_dr
dTz_dr
dTx_dz
dTy_dz
dTz_dz
Ta_mag
dB_R_dc
dB_phi_dc
dB_Z_dc
dR_dr
dRp_dr
d_Ta_mag_dRcos
d_Ta_mag_dZsin
d_s_theta_dZsin
d_s_theta_dRcos
d_s_thetatheta_dRcos
d_s_thetatheta_dZsin
d_s_thetathetatheta_dRcos
d_s_thetathetatheta_dZsin
d_r_theta1_cyl_dRcos
d_r_theta2_cyl_dRcos
d_r_theta3_cyl_dRcos
d_r_theta1_cyl_dZsin
d_r_theta2_cyl_dZsin
d_r_theta3_cyl_dZsin
d_r_theta1_cyl_tc_dRcos
d_r_theta2_cyl_tc_dRcos
d_r_theta3_cyl_tc_dRcos
d_r_theta1_cyl_tc_dZsin
d_r_theta2_cyl_tc_dZsin
d_r_theta3_cyl_tc_dZsin
d_r_thetatheta1_cyl_dRcos
d_r_thetatheta2_cyl_dRcos
d_r_thetatheta3_cyl_dRcos
d_r_thetatheta1_cyl_dZsin
d_r_thetatheta2_cyl_dZsin
d_r_thetatheta3_cyl_dZsin
d_r_thetatheta1_cyl_tc_dRcos
d_r_thetatheta2_cyl_tc_dRcos
d_r_thetatheta3_cyl_tc_dRcos
d_r_thetatheta1_cyl_tc_dZsin
d_r_thetatheta2_cyl_tc_dZsin
d_r_thetatheta3_cyl_tc_dZsin
d_r_thetathetatheta1_cyl_dRcos
d_r_thetathetatheta2_cyl_dRcos
d_r_thetathetatheta3_cyl_dRcos
d_r_thetathetatheta1_cyl_dZsin
d_r_thetathetatheta2_cyl_dZsin
d_r_thetathetatheta3_cyl_dZsin
d_curvature_dRcos
d_curvature_dZsin
d_kappaR_dRcos
d_kappaPhi_dRcos
d_kappaZ_dRcos
d_kappaR_dZsin
d_kappaPhi_dZsin
d_kappaZ_dZsin
dt1_dRcos
dt2_dRcos
dt3_dRcos
dt1_dZsin
dt2_dZsin
dt3_dZsin
dn1_dRcos
dn2_dRcos
dn3_dRcos
dn1_dZsin
dn2_dZsin
dn3_dZsin
db1_dRcos
db2_dRcos
db3_dRcos
db1_dZsin
db2_dZsin
db3_dZsin
d_kappa_dtheta1_dRcos
d_kappa_dtheta2_dRcos
d_kappa_dtheta3_dRcos
d_kappa_dtheta1_dZsin
d_kappa_dtheta2_dZsin
d_kappa_dtheta3_dZsin
d_curvature_dtheta_dRcos
d_curvature_dtheta_dZsin
d_torsion_dRcos
d_torsion_dZsin
torsion_numerator
torsion_denominator
d_tau_kappa2_dRcos
d_tau_kappa2_dZsin
d_abs_G0B0taukappa2_dRcos
d_abs_G0B0taukappa2_dZsin
dBx_dRcos
dBy_dRcos
dBz_dRcos
dBx_dZsin
dBy_dZsin
dBz_dZsin
d_X1c_dRcos
d_X1c_dZsin
d_Y1s_dRcos
d_Y1s_dZsin
d_Y1c_dRcos
d_Y1c_dZsin
d2_X1c_dRcos
d2_X1c_dZsin
d2_Y1s_dRcos
d2_Y1s_dZsin
d2_Y1c_dRcos
d2_Y1c_dZsin
d_B1x_dRcos
d_B1y_dRcos
d_B1z_dRcos
d_B2x_dRcos
d_B2y_dRcos
d_B2z_dRcos
d_B3x_dRcos
d_B3y_dRcos
d_B3z_dRcos
d_B1x_dZsin
d_B1y_dZsin
d_B1z_dZsin
d_B2x_dZsin
d_B2y_dZsin
d_B2z_dZsin
d_B3x_dZsin
d_B3y_dZsin
d_B3z_dZsin
dBx_coils_dc
dBy_coils_dc
dBz_coils_dc
dBx_coils_dRcos
dBy_coils_dRcos
dBz_coils_dRcos
dBx_coils_dZsin
dBy_coils_dZsin
dBz_coils_dZsin
dBx_coils_dI
dBy_coils_dI
dBz_coils_dI
dB1x_dI
dB1y_dI
dB1z_dI
dB2x_dI
dB2y_dI
dB2z_dI
dB3x_dI
dB3y_dI
dB3z_dI
dB1x_dRcos
dB1y_dRcos
dB1z_dRcos
dB2x_dRcos
dB2y_dRcos
dB2z_dRcos
dB3x_dRcos
dB3y_dRcos
dB3z_dRcos
dB1x_dZsin
dB1y_dZsin
dB1z_dZsin
dB2x_dZsin
dB2y_dZsin
dB2z_dZsin
dB3x_dZsin
dB3y_dZsin
dB3z_dZsin
B1x_coils_dc
B1y_coils_dc
B1z_coils_dc
B2x_coils_dc
B2y_coils_dc
B2z_coils_dc
B3x_coils_dc
B3y_coils_dc
B3z_coils_dc
d_B1x_ds
d_B1y_ds
d_B1z_ds
d_B2x_ds
d_B2y_ds
d_B2z_ds
d_B3x_ds
d_B3y_ds
d_B3z_ds
d_gradB1_diota
d_gradB2_diota
d_gradB3_diota
d_gradB1_detabar
d_gradB2_detabar
d_gradB3_detabar
d_X1c_detabar
d_Y1s_detabar
d_Y1c_detabar
d2_X1c_detabar
d2_Y1s_detabar
d2_Y1c_detabar
svp
sg
end
methods(Static)
function [R,Z] = get_coords(self,phi)
num_modes = size(self.cR,1);
R = 0.;
Z = 0.;
for j = 1:num_modes
R = R + self.cR(j)*cos(self.nfp * phi * (j-1));
Z = Z + self.sZ(j)*sin(self.nfp * phi * (j-1));
end
end
function [dR_dphi,dZ_dphi] = get_dcoords(self,phi)
num_modes = size(self.cR,1);
dR_dphi = 0.;
dZ_dphi = 0.;
for j = 1:num_modes
dR_dphi = dR_dphi -self.cR(j)*(j-1)*self.nfp * sin(self.nfp * phi * (j-1));
dZ_dphi = dZ_dphi +self.sZ(j)*(j-1)*self.nfp * cos(self.nfp * phi * (j-1));
end
end
end
methods
function obj = magneticAxisType(coilData, in_cR, in_sZ, in_top)
obj.nfp = coilData.nfp;
%% differentiation matrices
obj.nzeta = coilData.M;
if mod(obj.nzeta,2)==0
obj.nzeta = obj.nzeta+1;
end
scheme = 20;
[obj.zeta, ~, obj.D, ~] = sfincs_uniformDiffMatrices(obj.nzeta, 0, 2*pi/obj.nfp, scheme);
obj.cR = dlmread(in_cR);
obj.sZ = dlmread(in_sZ);
obj.cR = obj.cR(1:in_top);
obj.sZ = obj.sZ(1:in_top);
obj.top = in_top;
%% precompute values of sines and cosines on the magnetic axis
tt = linspace(0,2*pi/obj.nfp,obj.nzeta+1)';tt = tt(1:end-1);
obj.COS = zeros(obj.nzeta,obj.top);
obj.SIN = zeros(obj.nzeta,obj.top);
obj.dCOS = zeros(obj.nzeta,obj.top);
obj.dSIN = zeros(obj.nzeta,obj.top);
for i = 1:obj.top
obj.COS(:,i) = cos(obj.nfp*(i-1)*tt);
obj.SIN(:,i) = sin(obj.nfp*(i-1)*tt);
obj.dCOS(:,i) = -obj.nfp*(i-1)*sin(obj.nfp*(i-1)*tt);
obj.dSIN(:,i) = obj.nfp*(i-1)*cos(obj.nfp*(i-1)*tt);
end
obj.B = zeros(obj.nzeta,3);
obj.B_mag = zeros(obj.nzeta,1);
obj.BR = zeros(obj.nzeta,3);
obj.Bphi = zeros(obj.nzeta,3);
obj.BZ = zeros(obj.nzeta,3);
obj.dX_dPhi = zeros(obj.nzeta,1);% Tx
obj.dY_dPhi = zeros(obj.nzeta,1);% Ty
obj.dZ_dPhi = zeros(obj.nzeta,1);% TZ
obj.Ta_mag = zeros(obj.nzeta,1);
obj.dTx_dr = zeros(obj.nzeta,obj.nzeta);
obj.dTy_dr = zeros(obj.nzeta,obj.nzeta);
obj.dTz_dr = zeros(obj.nzeta,obj.nzeta);
obj.dTx_dz = zeros(obj.nzeta,obj.nzeta);
obj.dTy_dz = zeros(obj.nzeta,obj.nzeta);
obj.dTz_dz = zeros(obj.nzeta,obj.nzeta);
obj.dB_R_dc = zeros(obj.nzeta, numel(coilData.coil_coeffs));
obj.dB_phi_dc = zeros(obj.nzeta, numel(coilData.coil_coeffs));
obj.dB_Z_dc = zeros(obj.nzeta, numel(coilData.coil_coeffs));
obj.dR_dr = zeros(obj.nzeta, obj.nzeta);
obj.dRp_dr = zeros(obj.nzeta, obj.nzeta);
obj.sigma = zeros(obj.nzeta,1);
obj.iota = 0.;
obj.eta_bar = 1;
obj.B0 = 1.;
obj.RA = zeros(obj.nzeta,1);
obj.ZA = zeros(obj.nzeta,1);
obj.RAp = zeros(obj.nzeta,1);
obj.ZAp = zeros(obj.nzeta,1);
obj.RApp = zeros(obj.nzeta,1);
obj.ZApp = zeros(obj.nzeta,1);
obj.RAppp = zeros(obj.nzeta,1);
obj.ZAppp = zeros(obj.nzeta,1);
obj.dRA_dcos = zeros(obj.nzeta,obj.top);
obj.dRAp_dcos = zeros(obj.nzeta,obj.top);
obj.dRApp_dcos = zeros(obj.nzeta,obj.top);
obj.dRAppp_dcos = zeros(obj.nzeta,obj.top);
obj.dZA_dsin = zeros(obj.nzeta,obj.top);
obj.dZAp_dsin = zeros(obj.nzeta,obj.top);
obj.dZApp_dsin = zeros(obj.nzeta,obj.top);
obj.dZAppp_dsin = zeros(obj.nzeta,obj.top);
for imn = 1:obj.top
n = obj.nfp*(imn-1);
angle = n * obj.zeta;
sinangle = sin(angle);
cosangle = cos(angle);
obj.dRA_dcos(:,imn) = cosangle;
obj.dZA_dsin(:,imn) = sinangle;
obj.dRAp_dcos(:,imn) = -n*sinangle;
obj.dZAp_dsin(:,imn) = n*cosangle;
obj.dRApp_dcos(:,imn) = - n*n*cosangle;
obj.dZApp_dsin(:,imn) = - n*n*sinangle;
obj.dRAppp_dcos(:,imn) = n*n*n*sinangle;
obj.dZAppp_dsin(:,imn) = - n*n*n*cosangle;
end
obj.dBx_coils_dc = zeros(obj.nzeta, numel(coilData.coil_coeffs));
obj.dBy_coils_dc = zeros(obj.nzeta, numel(coilData.coil_coeffs));
obj.dBz_coils_dc = zeros(obj.nzeta, numel(coilData.coil_coeffs));
obj.B1x_coils_dc = zeros(obj.nzeta, numel(coilData.coil_coeffs));
obj.B1y_coils_dc = zeros(obj.nzeta, numel(coilData.coil_coeffs));
obj.B1z_coils_dc = zeros(obj.nzeta, numel(coilData.coil_coeffs));
obj.B2x_coils_dc = zeros(obj.nzeta, numel(coilData.coil_coeffs));
obj.B2y_coils_dc = zeros(obj.nzeta, numel(coilData.coil_coeffs));
obj.B2z_coils_dc = zeros(obj.nzeta, numel(coilData.coil_coeffs));
obj.B3x_coils_dc = zeros(obj.nzeta, numel(coilData.coil_coeffs));
obj.B3y_coils_dc = zeros(obj.nzeta, numel(coilData.coil_coeffs));
obj.B3z_coils_dc = zeros(obj.nzeta, numel(coilData.coil_coeffs));
obj.dBx_coils_dRcos = zeros(obj.nzeta, obj.top);
obj.dBy_coils_dRcos = zeros(obj.nzeta, obj.top);
obj.dBz_coils_dRcos = zeros(obj.nzeta, obj.top);
obj.dBx_coils_dZsin = zeros(obj.nzeta, obj.top);
obj.dBy_coils_dZsin = zeros(obj.nzeta, obj.top);
obj.dBz_coils_dZsin = zeros(obj.nzeta, obj.top);
obj.dBx_coils_dI = zeros(obj.nzeta,size(coilData.I,1));
obj.dBy_coils_dI = zeros(obj.nzeta,size(coilData.I,1));
obj.dBz_coils_dI = zeros(obj.nzeta,size(coilData.I,1));
obj.dB1x_dI = zeros(obj.nzeta, size(coilData.I,1));
obj.dB1y_dI = zeros(obj.nzeta, size(coilData.I,1));
obj.dB1z_dI = zeros(obj.nzeta, size(coilData.I,1));
obj.dB2x_dI = zeros(obj.nzeta, size(coilData.I,1));
obj.dB2y_dI = zeros(obj.nzeta, size(coilData.I,1));
obj.dB2z_dI = zeros(obj.nzeta, size(coilData.I,1));
obj.dB3x_dI = zeros(obj.nzeta, size(coilData.I,1));
obj.dB3y_dI = zeros(obj.nzeta, size(coilData.I,1));
obj.dB3z_dI = zeros(obj.nzeta, size(coilData.I,1));
obj.dB1x_dRcos = zeros(obj.nzeta, obj.top);
obj.dB1y_dRcos = zeros(obj.nzeta, obj.top);
obj.dB1z_dRcos = zeros(obj.nzeta, obj.top);
obj.dB2x_dRcos = zeros(obj.nzeta, obj.top);
obj.dB2y_dRcos = zeros(obj.nzeta, obj.top);
obj.dB2z_dRcos = zeros(obj.nzeta, obj.top);
obj.dB3x_dRcos = zeros(obj.nzeta, obj.top);
obj.dB3y_dRcos = zeros(obj.nzeta, obj.top);
obj.dB3z_dRcos = zeros(obj.nzeta, obj.top);
obj.dB1x_dZsin = zeros(obj.nzeta, obj.top);
obj.dB1y_dZsin = zeros(obj.nzeta, obj.top);
obj.dB1z_dZsin = zeros(obj.nzeta, obj.top);
obj.dB2x_dZsin = zeros(obj.nzeta, obj.top);
obj.dB2y_dZsin = zeros(obj.nzeta, obj.top);
obj.dB2z_dZsin = zeros(obj.nzeta, obj.top);
obj.dB3x_dZsin = zeros(obj.nzeta, obj.top);
obj.dB3y_dZsin = zeros(obj.nzeta, obj.top);
obj.dB3z_dZsin = zeros(obj.nzeta, obj.top);
obj.d_gradB1_detabar = zeros(obj.nzeta,3);
obj.d_gradB2_detabar = zeros(obj.nzeta,3);
obj.d_gradB3_detabar = zeros(obj.nzeta,3);
obj.svp = 1;
obj.sg = 1;
end
function update(self)
d2X_dPhi_dRcos = self.dRAp_dcos .* cos(self.zeta) - self.dRA_dcos .* sin(self.zeta);
d2Y_dPhi_dRcos = self.dRAp_dcos .* sin(self.zeta) + self.dRA_dcos .* cos(self.zeta);
d2Z_dPhi_dRcos = 0.;
self.d_Ta_mag_dRcos = (self.dX_dPhi .* d2X_dPhi_dRcos + self.dY_dPhi .* d2Y_dPhi_dRcos + self.dZ_dPhi .* d2Z_dPhi_dRcos)./self.Ta_mag;
d2X_dPhi_dZsin = 0.;
d2Y_dPhi_dZsin = 0.;
d2Z_dPhi_dZsin = self.dZAp_dsin;
self.d_Ta_mag_dZsin = (self.dX_dPhi .* d2X_dPhi_dZsin + self.dY_dPhi .* d2Y_dPhi_dZsin + self.dZ_dPhi .* d2Z_dPhi_dZsin)./self.Ta_mag;
% compute all partial derivatives wrt to ca on the magnetic axis
% assumes that compute_f has already been called
self.d_s_theta_dZsin = zeros(self.nzeta,numel(self.sZ));
self.d_s_theta_dRcos = zeros(self.nzeta,numel(self.cR));
self.d_s_thetatheta_dRcos = zeros(self.nzeta,numel(self.cR));
self.d_s_thetatheta_dZsin = zeros(self.nzeta,numel(self.sZ));
for imn = 1:numel(self.cR)
self.d_s_theta_dRcos(:,imn) = (self.RA.*self.dRA_dcos(:,imn) + self.RAp.*self.dRAp_dcos(:,imn) )./ self.s_theta;
self.d_s_theta_dZsin(:,imn) = self.ZAp.*self.dZAp_dsin(:,imn)./ self.s_theta;
end
for imn = 1:numel(self.cR)
self.d_s_thetatheta_dRcos(:,imn) = self.RA.*(self.dRAp_dcos(:,imn)./self.s_theta - self.RAp.*self.d_s_theta_dRcos(:,imn)./self.s_theta.^2)...
+self.RAp.*((self.dRA_dcos(:,imn)+self.dRApp_dcos(:,imn))./self.s_theta - self.RApp.*self.d_s_theta_dRcos(:,imn)./self.s_theta.^2)...
+self.ZAp.*( - self.ZApp.*self.d_s_theta_dRcos(:,imn)./self.s_theta.^2 ) ...
+(self.dRAp_dcos(:,imn).*self.RApp )./self.s_theta;
self.d_s_thetatheta_dZsin(:,imn) = self.RA.*( - self.RAp.*self.d_s_theta_dZsin(:,imn)./self.s_theta.^2)...
+self.RAp.*( - self.RApp.*self.d_s_theta_dZsin(:,imn)./self.s_theta.^2)...
+self.ZAp.*( self.dZApp_dsin(:,imn)./self.s_theta - self.ZApp.*self.d_s_theta_dZsin(:,imn)./self.s_theta.^2 )...
+( self.dZAp_dsin(:,imn).*self.ZApp )./self.s_theta;
end
self.d_s_thetathetatheta_dRcos = compute_d_stt_dRc(self.RA, self.RAp, self.RApp, self.RAppp, self.ZA, self.ZAp, self.ZApp, self.ZAppp,...
self.dRA_dcos,self.dRAp_dcos,self.dRApp_dcos,self.dRAppp_dcos,...
self.s_theta, self.s_thetatheta, self.d_s_theta_dRcos, self.d_s_thetatheta_dRcos,...
self.zeta, self.cR);
self.d_s_thetathetatheta_dZsin = compute_d_stt_dZc(self.RA, self.RAp, self.RApp, self.RAppp, self.ZA, self.ZAp, self.ZApp, self.ZAppp,...
self.dZA_dsin, self.dZAp_dsin, self.dZApp_dsin, self.dZAppp_dsin,...
self.s_theta, self.s_thetatheta, self.d_s_theta_dZsin, self.d_s_thetatheta_dZsin,...
self.zeta, self.sZ);
self.d_abs_G_over_B0_dRcos = mean(self.d_s_theta_dRcos,1)/self.B0;
self.d_abs_G_over_B0_dZsin = mean(self.d_s_theta_dZsin,1)/self.B0;
self.d_r_theta1_cyl_dRcos = self.dRAp_dcos;
self.d_r_theta2_cyl_dRcos = self.dRA_dcos;
self.d_r_theta3_cyl_dRcos = zeros(self.nzeta,numel(self.cR));
self.d_r_theta1_cyl_dZsin = zeros(self.nzeta,numel(self.sZ));
self.d_r_theta2_cyl_dZsin = zeros(self.nzeta,numel(self.sZ));
self.d_r_theta3_cyl_dZsin = self.dZAp_dsin;
self.d_r_theta1_cyl_tc_dRcos = self.dRApp_dcos;
self.d_r_theta2_cyl_tc_dRcos = self.dRAp_dcos;
self.d_r_theta3_cyl_tc_dRcos = zeros(self.nzeta,numel(self.cR));
self.d_r_theta1_cyl_tc_dZsin = zeros(self.nzeta,numel(self.sZ));
self.d_r_theta2_cyl_tc_dZsin = zeros(self.nzeta,numel(self.sZ));
self.d_r_theta3_cyl_tc_dZsin = self.dZApp_dsin;
self.d_r_thetatheta1_cyl_dRcos = self.dRApp_dcos - self.dRA_dcos;
self.d_r_thetatheta2_cyl_dRcos = 2*self.dRAp_dcos;
self.d_r_thetatheta3_cyl_dRcos = zeros(self.nzeta,numel(self.cR));
self.d_r_thetatheta1_cyl_dZsin = zeros(self.nzeta,numel(self.sZ));
self.d_r_thetatheta2_cyl_dZsin = zeros(self.nzeta,numel(self.sZ));
self.d_r_thetatheta3_cyl_dZsin = self.dZApp_dsin;
self.d_r_thetatheta1_cyl_tc_dRcos = self.dRAppp_dcos - self.dRAp_dcos;
self.d_r_thetatheta2_cyl_tc_dRcos = 2*self.dRApp_dcos;
self.d_r_thetatheta3_cyl_tc_dRcos = zeros(self.nzeta,numel(self.cR));
self.d_r_thetatheta1_cyl_tc_dZsin = zeros(self.nzeta,numel(self.sZ));
self.d_r_thetatheta2_cyl_tc_dZsin = zeros(self.nzeta,numel(self.sZ));
self.d_r_thetatheta3_cyl_tc_dZsin = self.dZAppp_dsin;
self.d_r_thetathetatheta1_cyl_dRcos = self.dRAppp_dcos-3*self.dRAp_dcos;
self.d_r_thetathetatheta2_cyl_dRcos = 3.*self.dRApp_dcos - self.dRA_dcos;
self.d_r_thetathetatheta3_cyl_dRcos = zeros(self.nzeta,numel(self.cR));
self.d_r_thetathetatheta1_cyl_dZsin = zeros(self.nzeta,numel(self.sZ));
self.d_r_thetathetatheta2_cyl_dZsin = zeros(self.nzeta,numel(self.sZ));
self.d_r_thetathetatheta3_cyl_dZsin = self.dZAppp_dsin;
self.d_kappaR_dRcos = compute_d_k_dc(self.s_theta, self.s_thetatheta, ...
self.d_s_theta_dRcos, self.d_s_thetatheta_dRcos,...
self.r_theta_cyl(:,1), self.r_thetatheta_cyl(:,1), ...
self.d_r_theta1_cyl_dRcos, self.d_r_thetatheta1_cyl_dRcos,...
self.zeta, self.cR);
self.d_kappaPhi_dRcos = compute_d_k_dc(self.s_theta, self.s_thetatheta, ...
self.d_s_theta_dRcos, self.d_s_thetatheta_dRcos,...
self.r_theta_cyl(:,2), self.r_thetatheta_cyl(:,2), ...
self.d_r_theta2_cyl_dRcos, self.d_r_thetatheta2_cyl_dRcos,...
self.zeta, self.cR);
self.d_kappaZ_dRcos = compute_d_k_dc(self.s_theta, self.s_thetatheta, ...
self.d_s_theta_dRcos, self.d_s_thetatheta_dRcos,...
self.r_theta_cyl(:,3), self.r_thetatheta_cyl(:,3), ...
self.d_r_theta3_cyl_dRcos, self.d_r_thetatheta3_cyl_dRcos,...
self.zeta, self.cR);
self.d_kappaR_dZsin = compute_d_k_dc(self.s_theta, self.s_thetatheta, ...
self.d_s_theta_dZsin, self.d_s_thetatheta_dZsin,...
self.r_theta_cyl(:,1), self.r_thetatheta_cyl(:,1), ...
self.d_r_theta1_cyl_dZsin, self.d_r_thetatheta1_cyl_dZsin,...
self.zeta, self.sZ);
self.d_kappaPhi_dZsin = compute_d_k_dc(self.s_theta, self.s_thetatheta, ...
self.d_s_theta_dZsin, self.d_s_thetatheta_dZsin,...
self.r_theta_cyl(:,2), self.r_thetatheta_cyl(:,2), ...
self.d_r_theta2_cyl_dZsin, self.d_r_thetatheta2_cyl_dZsin,...
self.zeta, self.sZ);
self.d_kappaZ_dZsin = compute_d_k_dc(self.s_theta, self.s_thetatheta, ...
self.d_s_theta_dZsin, self.d_s_thetatheta_dZsin,...
self.r_theta_cyl(:,3), self.r_thetatheta_cyl(:,3), ...
self.d_r_theta3_cyl_dZsin, self.d_r_thetatheta3_cyl_dZsin,...
self.zeta, self.sZ);
self.d_curvature_dRcos = (self.kappa(:,1) .* self.d_kappaR_dRcos + self.kappa(:,2) .* self.d_kappaPhi_dRcos + self.kappa(:,3) .* self.d_kappaZ_dRcos)./self.curvature;
self.d_curvature_dZsin = (self.kappa(:,1) .* self.d_kappaR_dZsin + self.kappa(:,2) .* self.d_kappaPhi_dZsin + self.kappa(:,3) .* self.d_kappaZ_dZsin)./self.curvature;
dt1_cyl_dRcos = zeros(self.nzeta,numel(self.cR));
dt2_cyl_dRcos = zeros(self.nzeta,numel(self.cR));
dt3_cyl_dRcos = zeros(self.nzeta,numel(self.cR));
dt1_cyl_dZsin = zeros(self.nzeta,numel(self.sZ));
dt2_cyl_dZsin = zeros(self.nzeta,numel(self.sZ));
dt3_cyl_dZsin = zeros(self.nzeta,numel(self.sZ));
self.dt1_dRcos = zeros(self.nzeta,numel(self.cR));
self.dt2_dRcos = zeros(self.nzeta,numel(self.cR));
self.dt3_dRcos = zeros(self.nzeta,numel(self.cR));
self.dt1_dZsin = zeros(self.nzeta,numel(self.sZ));
self.dt2_dZsin = zeros(self.nzeta,numel(self.sZ));
self.dt3_dZsin = zeros(self.nzeta,numel(self.sZ));
for imn = 1:numel(self.cR)
dt1_cyl_dRcos(:,imn) = (self.d_r_theta1_cyl_dRcos(:,imn).*self.s_theta - self.d_s_theta_dRcos(:,imn).*self.RAp)./self.s_theta.^2;
dt2_cyl_dRcos(:,imn) = (self.d_r_theta2_cyl_dRcos(:,imn).*self.s_theta - self.d_s_theta_dRcos(:,imn).*self.RA) ./self.s_theta.^2;
dt3_cyl_dRcos(:,imn) = (self.d_r_theta3_cyl_dRcos(:,imn).*self.s_theta - self.d_s_theta_dRcos(:,imn).*self.ZAp)./self.s_theta.^2;
dt1_cyl_dZsin(:,imn) = (self.d_r_theta1_cyl_dZsin(:,imn).*self.s_theta - self.d_s_theta_dZsin(:,imn).*self.RAp)./self.s_theta.^2;
dt2_cyl_dZsin(:,imn) = (self.d_r_theta2_cyl_dZsin(:,imn).*self.s_theta - self.d_s_theta_dZsin(:,imn).*self.RA) ./self.s_theta.^2;
dt3_cyl_dZsin(:,imn) = (self.d_r_theta3_cyl_dZsin(:,imn).*self.s_theta - self.d_s_theta_dZsin(:,imn).*self.ZAp)./self.s_theta.^2;
end
for imn = 1:numel(self.cR)
self.dt1_dRcos(:,imn) = cos(self.zeta).*dt1_cyl_dRcos(:,imn)-sin(self.zeta).*dt2_cyl_dRcos(:,imn);
self.dt2_dRcos(:,imn) = sin(self.zeta).*dt1_cyl_dRcos(:,imn)+cos(self.zeta).*dt2_cyl_dRcos(:,imn);
self.dt3_dRcos(:,imn) = dt3_cyl_dRcos(:,imn);
self.dt1_dZsin(:,imn) = cos(self.zeta).*dt1_cyl_dZsin(:,imn)-sin(self.zeta).*dt2_cyl_dZsin(:,imn);
self.dt2_dZsin(:,imn) = sin(self.zeta).*dt1_cyl_dZsin(:,imn)+cos(self.zeta).*dt2_cyl_dZsin(:,imn);
self.dt3_dZsin(:,imn) = dt3_cyl_dZsin(:,imn);
end
dn1_cyl_dRcos = zeros(self.nzeta,numel(self.cR));
dn2_cyl_dRcos = zeros(self.nzeta,numel(self.cR));
dn3_cyl_dRcos = zeros(self.nzeta,numel(self.cR));
dn1_cyl_dZsin = zeros(self.nzeta,numel(self.sZ));
dn2_cyl_dZsin = zeros(self.nzeta,numel(self.sZ));
dn3_cyl_dZsin = zeros(self.nzeta,numel(self.sZ));
self.dn1_dRcos = zeros(self.nzeta,numel(self.cR));
self.dn2_dRcos = zeros(self.nzeta,numel(self.cR));
self.dn3_dRcos = zeros(self.nzeta,numel(self.cR));
self.dn1_dZsin = zeros(self.nzeta,numel(self.sZ));
self.dn2_dZsin = zeros(self.nzeta,numel(self.sZ));
self.dn3_dZsin = zeros(self.nzeta,numel(self.sZ));
for imn = 1:numel(self.cR)
dn1_cyl_dRcos(:,imn) = (self.d_kappaR_dRcos(:,imn).*self.curvature - self.d_curvature_dRcos(:,imn).*self.kappa(:,1))./self.curvature.^2;
dn2_cyl_dRcos(:,imn)=(self.d_kappaPhi_dRcos(:,imn).*self.curvature - self.d_curvature_dRcos(:,imn).*self.kappa(:,2))./self.curvature.^2;
dn3_cyl_dRcos(:,imn) = (self.d_kappaZ_dRcos(:,imn).*self.curvature - self.d_curvature_dRcos(:,imn).*self.kappa(:,3))./self.curvature.^2;
dn1_cyl_dZsin(:,imn) = (self.d_kappaR_dZsin(:,imn).*self.curvature - self.d_curvature_dZsin(:,imn).*self.kappa(:,1))./self.curvature.^2;
dn2_cyl_dZsin(:,imn)=(self.d_kappaPhi_dZsin(:,imn).*self.curvature - self.d_curvature_dZsin(:,imn).*self.kappa(:,2)) ./self.curvature.^2;
dn3_cyl_dZsin(:,imn) = (self.d_kappaZ_dZsin(:,imn).*self.curvature - self.d_curvature_dZsin(:,imn).*self.kappa(:,3))./self.curvature.^2;
end
for imn = 1:numel(self.cR)
self.dn1_dRcos(:,imn) = cos(self.zeta).*dn1_cyl_dRcos(:,imn)-sin(self.zeta).*dn2_cyl_dRcos(:,imn);
self.dn2_dRcos(:,imn) = sin(self.zeta).*dn1_cyl_dRcos(:,imn)+cos(self.zeta).*dn2_cyl_dRcos(:,imn);
self.dn3_dRcos(:,imn) = dn3_cyl_dRcos(:,imn);
self.dn1_dZsin(:,imn) = cos(self.zeta).*dn1_cyl_dZsin(:,imn)-sin(self.zeta).*dn2_cyl_dZsin(:,imn);
self.dn2_dZsin(:,imn) = sin(self.zeta).*dn1_cyl_dZsin(:,imn)+cos(self.zeta).*dn2_cyl_dZsin(:,imn);
self.dn3_dZsin(:,imn) = dn3_cyl_dZsin(:,imn);
end
self.db1_dRcos = zeros(self.nzeta,numel(self.cR));
self.db2_dRcos = zeros(self.nzeta,numel(self.cR));
self.db3_dRcos = zeros(self.nzeta,numel(self.cR));
self.db1_dZsin = zeros(self.nzeta,numel(self.sZ));
self.db2_dZsin = zeros(self.nzeta,numel(self.sZ));
self.db3_dZsin = zeros(self.nzeta,numel(self.sZ));
for imn = 1:numel(self.cR)
out = cross([self.dt1_dRcos(:,imn), self.dt2_dRcos(:,imn), self.dt3_dRcos(:,imn)],self.n_vec)+cross(self.t_vec,[self.dn1_dRcos(:,imn), self.dn2_dRcos(:,imn), self.dn3_dRcos(:,imn)]);
self.db1_dRcos(:,imn) = out(:,1);
self.db2_dRcos(:,imn) = out(:,2);
self.db3_dRcos(:,imn) = out(:,3);
out = cross([self.dt1_dZsin(:,imn), self.dt2_dZsin(:,imn), self.dt3_dZsin(:,imn)],self.n_vec)+cross(self.t_vec,[self.dn1_dZsin(:,imn), self.dn2_dZsin(:,imn), self.dn3_dZsin(:,imn)]);
self.db1_dZsin(:,imn) = out(:,1);
self.db2_dZsin(:,imn) = out(:,2);
self.db3_dZsin(:,imn) = out(:,3);
end
self.d_kappa_dtheta1_dRcos = d_kappa_dtheta_dc(self.s_theta, self.s_thetatheta, self.s_thetathetatheta, ...
self.d_s_theta_dRcos, self.d_s_thetatheta_dRcos,self.d_s_thetathetatheta_dRcos,...
self.r_theta_cyl(:,1), self.r_thetatheta_cyl(:,1), self.r_theta_cyl_tc(:,1), self.r_thetatheta_cyl_tc(:,1),...
self.d_r_theta1_cyl_dRcos, self.d_r_thetatheta1_cyl_dRcos, self.d_r_theta1_cyl_tc_dRcos,self.d_r_thetatheta1_cyl_tc_dRcos,...
self.zeta, self.cR);
self.d_kappa_dtheta2_dRcos = d_kappa_dtheta_dc(self.s_theta, self.s_thetatheta, self.s_thetathetatheta, ...
self.d_s_theta_dRcos, self.d_s_thetatheta_dRcos,self.d_s_thetathetatheta_dRcos,...
self.r_theta_cyl(:,2), self.r_thetatheta_cyl(:,2), self.r_theta_cyl_tc(:,2), self.r_thetatheta_cyl_tc(:,2),...
self.d_r_theta2_cyl_dRcos, self.d_r_thetatheta2_cyl_dRcos, self.d_r_theta2_cyl_tc_dRcos,self.d_r_thetatheta2_cyl_tc_dRcos,...
self.zeta, self.cR);
self.d_kappa_dtheta3_dRcos = d_kappa_dtheta_dc(self.s_theta, self.s_thetatheta, self.s_thetathetatheta, ...
self.d_s_theta_dRcos, self.d_s_thetatheta_dRcos,self.d_s_thetathetatheta_dRcos,...
self.r_theta_cyl(:,3), self.r_thetatheta_cyl(:,3), self.r_theta_cyl_tc(:,3), self.r_thetatheta_cyl_tc(:,3),...
self.d_r_theta3_cyl_dRcos, self.d_r_thetatheta3_cyl_dRcos, self.d_r_theta3_cyl_tc_dRcos,self.d_r_thetatheta3_cyl_tc_dRcos,...
self.zeta, self.cR);
self.d_kappa_dtheta1_dZsin = d_kappa_dtheta_dc(self.s_theta, self.s_thetatheta, self.s_thetathetatheta, ...
self.d_s_theta_dZsin, self.d_s_thetatheta_dZsin,self.d_s_thetathetatheta_dZsin,...
self.r_theta_cyl(:,1), self.r_thetatheta_cyl(:,1), self.r_theta_cyl_tc(:,1), self.r_thetatheta_cyl_tc(:,1),...
self.d_r_theta1_cyl_dZsin, self.d_r_thetatheta1_cyl_dZsin, self.d_r_theta1_cyl_tc_dZsin,self.d_r_thetatheta1_cyl_tc_dZsin,...
self.zeta, self.sZ);
self.d_kappa_dtheta2_dZsin = d_kappa_dtheta_dc(self.s_theta, self.s_thetatheta, self.s_thetathetatheta, ...
self.d_s_theta_dZsin, self.d_s_thetatheta_dZsin,self.d_s_thetathetatheta_dZsin,...
self.r_theta_cyl(:,2), self.r_thetatheta_cyl(:,2), self.r_theta_cyl_tc(:,2), self.r_thetatheta_cyl_tc(:,2),...
self.d_r_theta2_cyl_dZsin, self.d_r_thetatheta2_cyl_dZsin, self.d_r_theta2_cyl_tc_dZsin,self.d_r_thetatheta2_cyl_tc_dZsin,...
self.zeta, self.sZ);
self.d_kappa_dtheta3_dZsin = d_kappa_dtheta_dc(self.s_theta, self.s_thetatheta, self.s_thetathetatheta, ...
self.d_s_theta_dZsin, self.d_s_thetatheta_dZsin,self.d_s_thetathetatheta_dZsin,...
self.r_theta_cyl(:,3), self.r_thetatheta_cyl(:,3), self.r_theta_cyl_tc(:,3), self.r_thetatheta_cyl_tc(:,3),...
self.d_r_theta3_cyl_dZsin, self.d_r_thetatheta3_cyl_dZsin, self.d_r_theta3_cyl_tc_dZsin,self.d_r_thetatheta3_cyl_tc_dZsin,...
self.zeta, self.sZ);
self.d_curvature_dtheta_dRcos = compute_dk_dt_dc(self.kappa(:,1), self.kappa(:,2), self.kappa(:,3),...
self.d_kappa_dtheta(:,1), self.d_kappa_dtheta(:,2), self.d_kappa_dtheta(:,3),...
self.d_kappaR_dRcos, self.d_kappaPhi_dRcos, self.d_kappaZ_dRcos,...
self.d_kappa_dtheta1_dRcos, self.d_kappa_dtheta2_dRcos, self.d_kappa_dtheta3_dRcos,...
self.curvature,self.d_curvature_dRcos,...
self.zeta, self.cR);
self.d_curvature_dtheta_dZsin = compute_dk_dt_dc(self.kappa(:,1), self.kappa(:,2), self.kappa(:,3),...
self.d_kappa_dtheta(:,1), self.d_kappa_dtheta(:,2), self.d_kappa_dtheta(:,3),...
self.d_kappaR_dZsin, self.d_kappaPhi_dZsin, self.d_kappaZ_dZsin,...
self.d_kappa_dtheta1_dZsin, self.d_kappa_dtheta2_dZsin, self.d_kappa_dtheta3_dZsin,...
self.curvature,self.d_curvature_dZsin,...
self.zeta, self.sZ);
self.d_torsion_dRcos = compute_torsion_dc(self.torsion_numerator,self.torsion_denominator, ...
self.r_theta_cyl(:,1), self.r_thetatheta_cyl(:,1),self.r_thetathetatheta_cyl(:,1),self.d_r_theta1_cyl_dRcos, self.d_r_thetatheta1_cyl_dRcos, self.d_r_thetathetatheta1_cyl_dRcos,...
self.r_theta_cyl(:,2), self.r_thetatheta_cyl(:,2),self.r_thetathetatheta_cyl(:,2),self.d_r_theta2_cyl_dRcos, self.d_r_thetatheta2_cyl_dRcos, self.d_r_thetathetatheta2_cyl_dRcos,...
self.r_theta_cyl(:,3), self.r_thetatheta_cyl(:,3),self.r_thetathetatheta_cyl(:,3),self.d_r_theta3_cyl_dRcos, self.d_r_thetatheta3_cyl_dRcos, self.d_r_thetathetatheta3_cyl_dRcos,...
self.zeta, self.cR);
self.d_torsion_dZsin = compute_torsion_dc(self.torsion_numerator,self.torsion_denominator, ...
self.r_theta_cyl(:,1), self.r_thetatheta_cyl(:,1),self.r_thetathetatheta_cyl(:,1),self.d_r_theta1_cyl_dZsin, self.d_r_thetatheta1_cyl_dZsin, self.d_r_thetathetatheta1_cyl_dZsin,...
self.r_theta_cyl(:,2), self.r_thetatheta_cyl(:,2),self.r_thetathetatheta_cyl(:,2),self.d_r_theta2_cyl_dZsin, self.d_r_thetatheta2_cyl_dZsin, self.d_r_thetathetatheta2_cyl_dZsin,...
self.r_theta_cyl(:,3), self.r_thetatheta_cyl(:,3),self.r_thetathetatheta_cyl(:,3),self.d_r_theta3_cyl_dZsin, self.d_r_thetatheta3_cyl_dZsin, self.d_r_thetathetatheta3_cyl_dZsin,...
self.zeta, self.sZ);
self.tau_kappa2 = self.torsion./self.curvature.^2;
self.d_tau_kappa2_dRcos = (self.curvature.^2 .* self.d_torsion_dRcos - 2 .* self.torsion .* self.curvature .* self.d_curvature_dRcos)./self.curvature.^4;
self.d_tau_kappa2_dZsin = (self.curvature.^2 .* self.d_torsion_dZsin - 2 .* self.torsion .* self.curvature .* self.d_curvature_dZsin)./self.curvature.^4;
self.d_abs_G0B0taukappa2_dRcos = self.tau_kappa2.*self.d_abs_G_over_B0_dRcos+ self.abs_G_over_B0.*self.d_tau_kappa2_dRcos;
self.d_abs_G0B0taukappa2_dZsin = self.tau_kappa2.*self.d_abs_G_over_B0_dZsin+ self.abs_G_over_B0.*self.d_tau_kappa2_dZsin;
% ------------------------------------------------------------------------------------
% On axis field and gradient of field
% ------------------------------------------------------------------------------------
self.dBx_dRcos = self.B0 * self.dt1_dRcos;
self.dBy_dRcos = self.B0 * self.dt2_dRcos;
self.dBz_dRcos = self.B0 * self.dt3_dRcos;
self.dBx_dZsin = self.B0 * self.dt1_dZsin;
self.dBy_dZsin = self.B0 * self.dt2_dZsin;
self.dBz_dZsin = self.B0 * self.dt3_dZsin;
self.d_X1c_dRcos = -self.eta_bar *self.d_curvature_dRcos./ self.curvature.^2;
self.d_X1c_dZsin = -self.eta_bar *self.d_curvature_dZsin./ self.curvature.^2;
self.d_Y1s_dRcos = self.d_curvature_dRcos./ self.eta_bar;
self.d_Y1s_dZsin = self.d_curvature_dZsin./ self.eta_bar;
self.d_Y1c_dRcos = self.d_curvature_dRcos.* self.sigma ./ self.eta_bar;
self.d_Y1c_dZsin = self.d_curvature_dZsin.* self.sigma ./ self.eta_bar;
self.d2_X1c_dRcos = compute_d2_X1c_dc(self.abs_G_over_B0, self.d_abs_G_over_B0_dRcos,...
self.s_theta, self.d_s_theta_dRcos,...
self.curvature, self.d_curvature_dRcos, self.d_curvature_dtheta, self.d_curvature_dtheta_dRcos,...
self.zeta, self.cR, self.eta_bar);
self.d2_X1c_dZsin = compute_d2_X1c_dc(self.abs_G_over_B0, self.d_abs_G_over_B0_dZsin,...
self.s_theta, self.d_s_theta_dZsin,...
self.curvature, self.d_curvature_dZsin, self.d_curvature_dtheta, self.d_curvature_dtheta_dZsin,...
self.zeta, self.sZ, self.eta_bar);
self.d2_Y1s_dRcos = compute_d2_Y1s_dc(self.abs_G_over_B0, self.d_abs_G_over_B0_dRcos,...
self.s_theta, self.d_s_theta_dRcos,...
self.curvature, self.d_curvature_dtheta, self.d_curvature_dtheta_dRcos,...
self.zeta, self.cR, self.eta_bar);
self.d2_Y1s_dZsin = compute_d2_Y1s_dc(self.abs_G_over_B0, self.d_abs_G_over_B0_dZsin,...
self.s_theta, self.d_s_theta_dZsin,...
self.curvature, self.d_curvature_dtheta, self.d_curvature_dtheta_dZsin,...
self.zeta, self.sZ, self.eta_bar);
self.d2_Y1c_dRcos = compute_d2_Y1c_dc(self.abs_G_over_B0, self.d_abs_G_over_B0_dRcos,...
self.s_theta, self.d_s_theta_dRcos,...
self.curvature, self.d_curvature_dRcos, self.d_curvature_dtheta, self.d_curvature_dtheta_dRcos,...
self.zeta, self.cR, self.eta_bar, self.D, self.sigma);
self.d2_Y1c_dZsin = compute_d2_Y1c_dc(self.abs_G_over_B0, self.d_abs_G_over_B0_dZsin,...
self.s_theta, self.d_s_theta_dZsin,...
self.curvature, self.d_curvature_dZsin, self.d_curvature_dtheta, self.d_curvature_dtheta_dZsin,...
self.zeta, self.sZ, self.eta_bar, self.D, self.sigma);
self.d_X1c_detabar = 1./self.curvature;
self.d_Y1s_detabar = self.svp * self.sg .* self.curvature .* (-1./self.eta_bar.^2);
self.d_Y1c_detabar = self.svp * self.sg .* self.curvature .* (-1./self.eta_bar.^2) .* self.sigma;
self.d2_X1c_detabar = self.d_X1c / self.eta_bar;
self.d2_Y1s_detabar = self.eta_bar*self.d_Y1s * (-1./self.eta_bar.^2);
self.d2_Y1c_detabar = self.eta_bar*self.d_Y1c * (-1./self.eta_bar.^2);
[self.d_gradB1_detabar, self.d_gradB2_detabar, self.d_gradB3_detabar] = compute_gradB_detabar(self.B0, self.abs_G_over_B0,...
self.iota, ...
self.t_vec,self.n_vec,self.b_vec,...
self.X1c, self.Y1s, self.Y1c, self.d_X1c, self.d_Y1s, self.d_Y1c,...
self.d_X1c_detabar, self.d_Y1s_detabar, self.d_Y1c_detabar, ...
self.d2_X1c_detabar, self.d2_Y1s_detabar, self.d2_Y1c_detabar);
[self.d_B1x_dRcos, self.d_B1y_dRcos, self.d_B1z_dRcos,...
self.d_B2x_dRcos, self.d_B2y_dRcos, self.d_B2z_dRcos,...
self.d_B3x_dRcos, self.d_B3y_dRcos, self.d_B3z_dRcos] = compute_gradB_dc(self.abs_G_over_B0,self.d_abs_G_over_B0_dRcos,...
self.torsion, self.curvature, ...
self.d_torsion_dRcos, self.d_curvature_dRcos,...
self.t_vec,self.n_vec,self.b_vec,...
self.dt1_dRcos, self.dn1_dRcos,self.db1_dRcos,...
self.dt2_dRcos, self.dn2_dRcos,self.db2_dRcos,...
self.dt3_dRcos, self.dn3_dRcos,self.db3_dRcos,...
self.X1c, self.Y1s, self.Y1c,self.d_X1c_dRcos, self.d_Y1s_dRcos, self.d_Y1c_dRcos,...
self.d_X1c, self.d_Y1s, self.d_Y1c, self.d2_X1c_dRcos,self.d2_Y1s_dRcos,self.d2_Y1c_dRcos,...
self.s_theta, self.d_s_theta_dRcos,...
self.B0, self.iota, self.zeta, self.cR);
[self.d_B1x_dZsin, self.d_B1y_dZsin, self.d_B1z_dZsin,...
self.d_B2x_dZsin, self.d_B2y_dZsin, self.d_B2z_dZsin,...
self.d_B3x_dZsin, self.d_B3y_dZsin, self.d_B3z_dZsin] = compute_gradB_dc(self.abs_G_over_B0,self.d_abs_G_over_B0_dZsin,...
self.torsion, self.curvature, ...
self.d_torsion_dZsin, self.d_curvature_dZsin,...
self.t_vec,self.n_vec,self.b_vec,...