-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneo_magfie.f90.orig
1393 lines (1302 loc) · 65.9 KB
/
neo_magfie.f90.orig
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
MODULE neo_magfie_mod
USE neo_precision
USE neo_input, &
ONLY: es, ixm, ixn, mnmax, psi_pr, pixm, pixn, nfp
USE neo_control, &
ONLY: fluxs_interp, write_progress, phi_n, theta_n, lab_swi
USE neo_sub_mod, &
ONLY: neo_read_control, neo_init, neo_init_spline, &
neo_eval, neo_zeros2d
USE neo_spline_data, &
ONLY: r_mhalf, &
a_bmnc, b_bmnc, c_bmnc, d_bmnc, &
a_bmns, b_bmns, c_bmns, d_bmns, &
a_rmnc, b_rmnc, c_rmnc, d_rmnc, &
a_rmns, b_rmns, c_rmns, d_rmns, &
a_zmnc, b_zmnc, c_zmnc, d_zmnc, &
a_zmns, b_zmns, c_zmns, d_zmns, &
a_lmnc, b_lmnc, c_lmnc, d_lmnc, &
a_lmns, b_lmns, c_lmns, d_lmns, &
a_iota, b_iota, c_iota, d_iota, &
a_curr_tor, b_curr_tor, c_curr_tor, d_curr_tor, &
a_curr_pol, b_curr_pol, c_curr_pol, d_curr_pol, &
a_pprime, b_pprime, c_pprime, d_pprime, &
a_sqrtg00, b_sqrtg00, c_sqrtg00, d_sqrtg00
USE inter_interfaces, &
ONLY: splint_horner3, &
tf, tfp, tfpp, tfppp, &
tfone, tfzero
USE neo_work, &
ONLY: cosmth, cosnph, sinmth, sinnph, theta_int, phi_int, &
theta_start, theta_end, phi_start, phi_end, &
phi_arr,theta_arr
USE neo_actual_fluxs, ONLY : s_sqrtg00
USE spline_mod, ONLY: spl2d, poi2d, eva2d
USE neo_exchange, ONLY: nper,b_min,b_max, &
theta_bmin,theta_bmax,phi_bmin,phi_bmax
!USE neo_eval_switch, ONLY: eval_switch
!! Modifications by Andreas F. Martitsch (12.03.2014)
! Use this quantity for normalization. Note:
! Variable is computed in mag_interface.f90 ("boozer_bmod0").
! It is available for the first time after 1st call
! of "make_magnetics". Therefore, within the first two calls
! of "neo_magfie" this variable is zero, but these calls are
! not used for the computation of physical quantities.
USE partpa_mod, ONLY : bmod0
!! End Modifications by Andreas F. Martitsch (12.03.2014)
!---------------------------------------------------------------------------
!USE var_sub_misc, ONLY: fac_c,iota_m ! fac_m
!---------------------------------------------------------------------------
IMPLICIT NONE
REAL(dp), DIMENSION(:), ALLOCATABLE :: magfie_sarray
INTEGER :: magfie_spline = 0
INTEGER :: magfie_newspline = 1
! switch for different output:
! 0: output for SMT and BMC
! 1: output for NEO
INTEGER :: magfie_result = 0
INTEGER :: magfie_sarray_len
REAL(dp), DIMENSION(:), ALLOCATABLE :: curr_tor_array
REAL(dp), DIMENSION(:), ALLOCATABLE :: curr_tor_s_array
REAL(dp), DIMENSION(:), ALLOCATABLE :: curr_pol_array
REAL(dp), DIMENSION(:), ALLOCATABLE :: curr_pol_s_array
REAL(dp), DIMENSION(:), ALLOCATABLE :: iota_array
REAL(dp), DIMENSION(:), ALLOCATABLE :: iota_s_array
REAL(dp), DIMENSION(:), ALLOCATABLE :: pprime_array
REAL(dp), DIMENSION(:), ALLOCATABLE :: sqrtg00_array
REAL(dp) :: s_pprime
REAL(dp), DIMENSION(:,:,:,:,:), ALLOCATABLE, TARGET :: bmod_spl
REAL(dp), DIMENSION(:,:,:,:,:), ALLOCATABLE, TARGET :: bb_s_spl
REAL(dp), DIMENSION(:,:,:,:,:), ALLOCATABLE, TARGET :: bb_tb_spl
REAL(dp), DIMENSION(:,:,:,:,:), ALLOCATABLE, TARGET :: bb_pb_spl
REAL(dp), DIMENSION(:,:,:,:,:), ALLOCATABLE, TARGET :: gval_spl
!! Modifications by Andreas F. Martitsch (11.03.2014)
! Storage arrays for the 2d splines (over the flux-surface) of the additionally
! needed metric tensor elements (used to compute the B-field components,
! which are necessary for modeling the magnetic rotation).
! Once computed these arrays can be used to reconstruct the desired
! quantities at intermediate (theta,phi)-values.
REAL(dp), DIMENSION(:,:,:,:,:), ALLOCATABLE, TARGET :: gstb_spl
REAL(dp), DIMENSION(:,:,:,:,:), ALLOCATABLE, TARGET :: gspb_spl
REAL(dp), DIMENSION(:,:,:,:,:), ALLOCATABLE, TARGET :: gstb_tb_spl
REAL(dp), DIMENSION(:,:,:,:,:), ALLOCATABLE, TARGET :: gspb_tb_spl
REAL(dp), DIMENSION(:,:,:,:,:), ALLOCATABLE, TARGET :: gstb_pb_spl
REAL(dp), DIMENSION(:,:,:,:,:), ALLOCATABLE, TARGET :: gspb_pb_spl
!! End Modifications by Andreas F. Martitsch (11.03.2014)
!! Modifications by Andreas F. Martitsch (13.11.2014)
! Storage arrays for the 2d splines (over the flux-surface) of the additionally
! needed quantities for NTV output
REAL(dp), DIMENSION(:,:,:,:,:), ALLOCATABLE, TARGET :: R_spl
REAL(dp), DIMENSION(:,:,:,:,:), ALLOCATABLE, TARGET :: Z_spl
!! End Modifications by Andreas F. Martitsch (13.11.2014)
REAL(dp) :: boozer_iota
REAL(dp) :: boozer_iota_s
REAL(dp) :: boozer_sqrtg00
!! Modifications by Andreas F. Martitsch (12.03.2014)
! boozer_curr_tor, boozer_curr_pol, boozer_psi_pr,
! boozer_sqrtg11 and boozer_isqrg are now converted
! to cgs-units.
! This step requires changes within rhs_kin.f90 and
! ripple_solver.f90!
REAL(dp) :: boozer_curr_pol_hat
REAL(dp) :: boozer_curr_tor_hat
! Radial derivatives of toroidal / poloidal currents
! (In fact these currents are already the respective
! covariant B-field components; conversion done within
! neo_read)
REAL(dp) :: boozer_curr_pol_hat_s
REAL(dp) :: boozer_curr_tor_hat_s
REAL(dp) :: boozer_psi_pr_hat
REAL(dp) :: boozer_sqrtg11 ! Test
REAL(dp) :: boozer_isqrg
!! End Modifications by Andreas F. Martitsch (12.03.2014)
REAL(dp) :: s_used_for_spline = -1.0d0
REAL(dp), PRIVATE :: av_b2_m ! Klaus
!! Modifications by Andreas F. Martitsch (11.03.2014)
! Transfer the computed values of the additionally needed
! B-field components between neo_magfie_a and neo_magfie_b
! (best solution at the moment, since keyword optional
! does not seem to work for a module procedure)
REAL(dp), PRIVATE :: dbcovar_s_dtheta
REAL(dp), PRIVATE :: dbcovar_s_dphi
!! End Modifications by Andreas F. Martitsch (11.03.2014)
!! Modifications by Andreas F. Martitsch (13.11.2014)
! Local variables for the additionally needed quantities for NTV output
REAL(dp), PRIVATE :: r_val, z_val
!! End Modifications by Andreas F. Martitsch (13.11.2014)
INTERFACE neo_magfie
MODULE PROCEDURE neo_magfie_a, neo_magfie_b, neo_magfie_c
END INTERFACE
CONTAINS
SUBROUTINE neo_magfie_a( x, bmod, sqrtg, bder, hcovar, hctrvr, hcurl )
! input / output
REAL(dp), DIMENSION(:), INTENT(in) :: x
REAL(dp), INTENT(out) :: bmod
REAL(dp), INTENT(out) :: sqrtg
REAL(dp), DIMENSION(SIZE(x)), INTENT(out) :: bder
REAL(dp), DIMENSION(SIZE(x)), INTENT(out) :: hcovar
REAL(dp), DIMENSION(SIZE(x)), INTENT(out) :: hctrvr
REAL(dp), DIMENSION(SIZE(x)), INTENT(out) :: hcurl
! local definitions
!! Modifications by Andreas F. Martitsch (11.03.2014)
! Locally computed values of the additionally needed
! metric tensor elements
REAL(dp) :: gstb, gspb
REAL(dp) :: gstb_tb, gspb_tb
REAL(dp) :: gstb_pb, gspb_pb
! Locally computed value of the additionally needed
! B-field component
REAL(dp) :: bcovar_s
!! End Modifications by Andreas F. Martitsch (11.03.2014)
INTEGER(i4b) :: swd = 1
INTEGER :: i, m, n
INTEGER :: npsi
REAL(dp) :: m0 = 0.0_dp
REAL(dp) :: yp, ypp, yppp
REAL(dp) :: bmnc, bmnc_s
REAL(dp) :: sinv, cosv
REAL(dp) :: iota, iota_s
REAL(dp) :: curr_tor, curr_tor_s
REAL(dp) :: curr_pol, curr_pol_s
REAL(dp) :: bb_s, bb_tb, bb_pb
REAL(dp) :: fac, fac1
INTEGER :: k_es
INTEGER :: s_detected
INTEGER :: imn
INTEGER :: it, ip, im, in
INTEGER :: mt = 1
INTEGER :: mp = 1
INTEGER :: theta_ind, phi_ind
INTEGER :: ierr
REAL(dp) :: s
REAL(dp) :: magfie_epsi = 1.e-9
REAL(dp) :: bi, bi_s, ri, zi, li
!! Modifications by Andreas F. Martitsch (07.03.2014)
! Auxiliary variables for the Fourier summation
REAL(dp) :: ri_s, zi_s, li_s
REAL(dp) :: bis, bis_s, ris, zis, lis
REAL(dp) :: ris_s, zis_s, lis_s
!! End Modifications by Andreas F. Martitsch (07.03.2014)
REAL(dp) :: theta_d, phi_d
REAL(dp), DIMENSION(:), ALLOCATABLE :: s_bmnc, s_bmnc_s
REAL(dp), DIMENSION(:), ALLOCATABLE :: s_rmnc, s_zmnc, s_lmnc
!! Modifications by Andreas F. Martitsch (06.03.2014)
! Radial derivatives of (R,Z,phi)-components obtained from the 1d spline
REAL(dp), DIMENSION(:), ALLOCATABLE :: s_rmnc_s, s_zmnc_s, s_lmnc_s
!! End Modifications by Andreas F. Martitsch (06.03.2014)
!! Modifications by Andreas F. Martitsch (06.08.2014)
! Additional data from Boozer files without Stellarator symmetry
REAL(kind=dp), DIMENSION(:), ALLOCATABLE :: s_bmns, s_bmns_s
REAL(kind=dp), DIMENSION(:), ALLOCATABLE :: s_rmns, s_zmns, s_lmns
REAL(kind=dp), DIMENSION(:), ALLOCATABLE :: s_rmns_s, s_zmns_s, s_lmns_s
!! End Modifications by Andreas F. Martitsch (06.08.2014)
REAL(dp), DIMENSION(:,:), ALLOCATABLE :: bmod_a
REAL(dp), DIMENSION(:,:), ALLOCATABLE :: bb_s_a
REAL(dp), DIMENSION(:,:), ALLOCATABLE :: bb_tb_a
REAL(dp), DIMENSION(:,:), ALLOCATABLE :: bb_pb_a
REAL(dp), DIMENSION(:,:), ALLOCATABLE :: r,z,l
REAL(dp), DIMENSION(:,:), ALLOCATABLE :: r_tb,z_tb,p_tb
REAL(dp), DIMENSION(:,:), ALLOCATABLE :: r_pb,z_pb,p_pb
REAL(dp), DIMENSION(:,:), ALLOCATABLE :: gtbtb,gpbpb,gtbpb
!! Modifications by Andreas F. Martitsch (11.03.2014)
! Temporary storage arrays for the Fourier summations related to
! the radial derivatives of (R,Z,phi)-components and the
! additionally needed metric tensor elements
REAL(dp), DIMENSION(:,:), ALLOCATABLE :: r_s,z_s,p_s
REAL(dp), DIMENSION(:,:), ALLOCATABLE :: r_stb,z_stb,p_stb
REAL(dp), DIMENSION(:,:), ALLOCATABLE :: r_tbtb,z_tbtb,p_tbtb
REAL(dp), DIMENSION(:,:), ALLOCATABLE :: r_pbtb,z_pbtb,p_pbtb
REAL(dp), DIMENSION(:,:), ALLOCATABLE :: r_spb,z_spb,p_spb
REAL(dp), DIMENSION(:,:), ALLOCATABLE :: r_pbpb,z_pbpb,p_pbpb
REAL(dp), DIMENSION(:,:), ALLOCATABLE :: gstb_a,gspb_a
REAL(dp), DIMENSION(:,:), ALLOCATABLE :: gstb_tb_a,gspb_tb_a
REAL(dp), DIMENSION(:,:), ALLOCATABLE :: gstb_pb_a,gspb_pb_a
!! End Modifications by Andreas F. Martitsch (11.03.2014)
REAL(dp), DIMENSION(:,:), ALLOCATABLE :: sqrg11_met
REAL(dp), DIMENSION(:,:,:,:), POINTER :: p_spl
REAL(dp) :: isqrg, sqrg11
INTEGER, DIMENSION(2) :: b_minpos, b_maxpos
! This does not work
!REAL(kind=dp), PARAMETER :: eps_newt = 1.0d-10
!INTEGER :: iter, error
!INTEGER, PARAMETER :: iterma_newt = 100
!REAL(kind=dp) :: gval_bmin
!REAL(kind=dp) :: kval_bmin,pval_bmin
!REAL(kind=dp) :: gval_bmax
!REAL(kind=dp) :: kval_bmax,pval_bmax
!REAL(kind=dp) :: qval_bmin,qval_bmax
!REAL(kind=dp) :: rval_bmin,rval_bmax
!REAL(dp) :: s_sqrtg00_m Klaus
!*******************************************************************
! Initialisation if necessary
!*******************************************************************
IF ( .NOT. ALLOCATED(es) ) THEN
CALL neo_read_control()
fluxs_interp = 1
CALL neo_init(npsi)
!PRINT *, 'theta_start,theta_end,phi_start,phi_end'
!PRINT *, theta_start,theta_end,phi_start,phi_end
END IF
!*******************************************************************
! Detect a new s, so that splines on the surface a updated
!*******************************************************************
if (magfie_spline .EQ. 1 .AND. magfie_newspline .EQ. 0 .and. &
SIZE(magfie_sarray) .eq. 1) THEN
! Here in principle no new spline on the surface has to be done
! There is now a new feature, that a new value of s is detected
! and therefore a spline on the surface is done
!if (x(1) .ne. s_used_for_spline) then
if ( ABS(x(1)-s_used_for_spline) .GT. magfie_epsi ) then
magfie_newspline = 1
magfie_sarray(1) = x(1)
s_used_for_spline = x(1)
end if
else
s_used_for_spline = magfie_sarray(1)
end if
!*******************************************************************
! Spline of surfaces in magfie_sarray
!*******************************************************************
IF (magfie_spline .EQ. 1 .AND. magfie_newspline .EQ. 1) THEN
magfie_sarray_len = SIZE(magfie_sarray)
!****************************************************************
! Allocation
!****************************************************************
if (allocated(bmod_spl)) deallocate(bmod_spl)
ALLOCATE( bmod_spl(4,4,theta_n,phi_n,magfie_sarray_len) )
if (allocated(bb_s_spl)) deallocate(bb_s_spl)
ALLOCATE( bb_s_spl(4,4,theta_n,phi_n,magfie_sarray_len) )
if (allocated(bb_tb_spl)) deallocate(bb_tb_spl)
ALLOCATE( bb_tb_spl(4,4,theta_n,phi_n,magfie_sarray_len) )
if (allocated(bb_pb_spl)) deallocate(bb_pb_spl)
ALLOCATE( bb_pb_spl(4,4,theta_n,phi_n,magfie_sarray_len) )
if (allocated(gval_spl)) deallocate(gval_spl)
ALLOCATE( gval_spl(4,4,theta_n,phi_n,magfie_sarray_len) )
!! Modifications by Andreas F. Martitsch (11.03.2014)
! Allocate the storage arrays for the 2d spline interpolation
! (over the flux-surface) of the additionally needed metric
! tensor elements
ALLOCATE( gstb_spl(4,4,theta_n,phi_n,magfie_sarray_len) )
ALLOCATE( gspb_spl(4,4,theta_n,phi_n,magfie_sarray_len) )
ALLOCATE( gstb_tb_spl(4,4,theta_n,phi_n,magfie_sarray_len) )
ALLOCATE( gspb_tb_spl(4,4,theta_n,phi_n,magfie_sarray_len) )
ALLOCATE( gstb_pb_spl(4,4,theta_n,phi_n,magfie_sarray_len) )
ALLOCATE( gspb_pb_spl(4,4,theta_n,phi_n,magfie_sarray_len) )
!! End Modifications by Andreas F. Martitsch (11.03.2014)
!! Modifications by Andreas F. Martitsch (13.11.2014)
! Allocate storage arrays for the 2d periodic splines
! of the additionally needed quantities for NTV output
ALLOCATE( R_spl(4,4,theta_n,phi_n,magfie_sarray_len) )
ALLOCATE( Z_spl(4,4,theta_n,phi_n,magfie_sarray_len) )
!! End Modifications by Andreas F. Martitsch (13.11.2014)
if (allocated(curr_tor_array)) deallocate(curr_tor_array)
ALLOCATE( curr_tor_array(magfie_sarray_len) )
if (allocated(curr_tor_s_array)) deallocate(curr_tor_s_array)
ALLOCATE( curr_tor_s_array(magfie_sarray_len) )
if (allocated(curr_pol_array)) deallocate(curr_pol_array)
ALLOCATE( curr_pol_array(magfie_sarray_len) )
if (allocated(curr_pol_s_array)) deallocate(curr_pol_s_array)
ALLOCATE( curr_pol_s_array(magfie_sarray_len) )
if (allocated(iota_array)) deallocate(iota_array)
ALLOCATE( iota_array(magfie_sarray_len) )
if (allocated(pprime_array)) deallocate(pprime_array)
ALLOCATE( pprime_array(magfie_sarray_len) )
if (allocated(sqrtg00_array)) deallocate(sqrtg00_array)
ALLOCATE( sqrtg00_array(magfie_sarray_len) )
!****************************************************************
! Loop over predefined s-values
!****************************************************************
DO k_es = 1, magfie_sarray_len
s = magfie_sarray(k_es)
!*************************************************************
! Surface
!*************************************************************
IF (write_progress .EQ. 1) THEN
PRINT *, 'Initialize Surface, k_es = ',k_es,' with s = ',s
END IF
if (allocated(s_bmnc)) deallocate(s_bmnc)
ALLOCATE ( s_bmnc(mnmax) )
if (allocated(s_bmnc_s)) deallocate(s_bmnc_s)
ALLOCATE ( s_bmnc_s(mnmax) )
if (allocated(s_rmnc)) deallocate(s_bmnc)
ALLOCATE ( s_rmnc(mnmax) )
if (allocated(s_zmnc)) deallocate(s_bmnc)
ALLOCATE ( s_zmnc(mnmax) )
if (allocated(s_lmnc)) deallocate(s_bmnc)
ALLOCATE ( s_lmnc(mnmax) )
!! Modifications by Andreas F. Martitsch (06.03.2014)
! Compute the necessary radial derivatives for the
! (R,Z,phi)-components obtained from the 1d spline
ALLOCATE ( s_rmnc_s(mnmax) ) ! Allocate arrays for additional
ALLOCATE ( s_zmnc_s(mnmax) ) ! radial derivatives
ALLOCATE ( s_lmnc_s(mnmax) )
!! End Modifications by Andreas F. Martitsch (06.03.2014)
!
!! Modifications by Andreas F. Martitsch (06.08.2014)
! Additional data from Boozer files without Stellarator symmetry
IF (inp_swi .EQ. 9) THEN ! ASDEX-U (E. Strumberger)
ALLOCATE ( s_bmns(mnmax) )
ALLOCATE ( s_bmns_s(mnmax) )
ALLOCATE ( s_rmns(mnmax) )
ALLOCATE ( s_zmns(mnmax) )
ALLOCATE ( s_lmns(mnmax) )
ALLOCATE ( s_rmns_s(mnmax) )
ALLOCATE ( s_zmns_s(mnmax) )
ALLOCATE ( s_lmns_s(mnmax) )
END IF
!! End Modifications by Andreas F. Martitsch (06.08.2014)
!
DO imn = 1, mnmax
! Switch swd turns on (1) / off (0) the computation of the
! radial derivatives within splint_horner3
swd = 1
CALL splint_horner3(es, &
a_bmnc(:,imn), b_bmnc(:,imn), &
c_bmnc(:,imn), d_bmnc(:,imn), &
swd, r_mhalf(imn), &
s, tf, tfp, tfpp, tfppp, &
s_bmnc(imn), s_bmnc_s(imn), ypp, yppp)
!swd = 0 ! Now we want to compute the radial derivatives
swd = 1
CALL splint_horner3(es, &
a_rmnc(:,imn), b_rmnc(:,imn), &
c_rmnc(:,imn), d_rmnc(:,imn), &
swd, r_mhalf(imn), &
s, tf, tfp, tfpp, tfppp, &
s_rmnc(imn), s_rmnc_s(imn), ypp, yppp)
swd = 1
CALL splint_horner3(es, &
a_zmnc(:,imn), b_zmnc(:,imn), &
c_zmnc(:,imn), d_zmnc(:,imn), &
swd, r_mhalf(imn), &
s, tf, tfp, tfpp, tfppp, &
s_zmnc(imn), s_zmnc_s(imn), ypp, yppp)
swd = 1
CALL splint_horner3(es, &
a_lmnc(:,imn), b_lmnc(:,imn), &
c_lmnc(:,imn), d_lmnc(:,imn), &
swd, r_mhalf(imn), &
s, tf, tfp, tfpp, tfppp, &
s_lmnc(imn), s_lmnc_s(imn), ypp, yppp)
!
!! Modifications by Andreas F. Martitsch (06.08.2014)
! Additional data from Boozer files without Stellarator symmetry
IF (inp_swi .EQ. 9) THEN ! ASDEX-U (E. Strumberger)
swd = 1
CALL splint_horner3(es, &
a_bmns(:,imn), b_bmns(:,imn), &
c_bmns(:,imn), d_bmns(:,imn), &
swd, r_mhalf(imn), &
s, tf, tfp, tfpp, tfppp, &
s_bmns(imn), s_bmns_s(imn), ypp, yppp)
swd = 1
CALL splint_horner3(es, &
a_rmns(:,imn), b_rmns(:,imn), &
c_rmns(:,imn), d_rmns(:,imn), &
swd, r_mhalf(imn), &
s, tf, tfp, tfpp, tfppp, &
s_rmns(imn), s_rmns_s(imn), ypp, yppp)
swd = 1
CALL splint_horner3(es, &
a_zmns(:,imn), b_zmns(:,imn), &
c_zmns(:,imn), d_zmns(:,imn), &
swd, r_mhalf(imn), &
s, tf, tfp, tfpp, tfppp, &
s_zmns(imn), s_zmns_s(imn), ypp, yppp)
swd = 1
CALL splint_horner3(es, &
a_lmns(:,imn), b_lmns(:,imn), &
c_lmns(:,imn), d_lmns(:,imn), &
swd, r_mhalf(imn), &
s, tf, tfp, tfpp, tfppp, &
s_lmns(imn), s_lmns_s(imn), ypp, yppp)
END IF
!! End Modifications by Andreas F. Martitsch (06.08.2014)
!
END DO
!*************************************************************
! Fourier summation for the full theta-phi array
!*************************************************************
IF (write_progress .EQ. 1) THEN
PRINT *, 'Do Fourier'
END IF
if (allocated(bmod_a)) deallocate(bmod_a)
ALLOCATE( bmod_a(theta_n,phi_n) )
if (allocated(bb_s_a)) deallocate(bb_s_a)
ALLOCATE( bb_s_a(theta_n,phi_n) )
if (allocated(bb_tb_a)) deallocate(bb_tb_a)
ALLOCATE( bb_tb_a(theta_n,phi_n) )
if (allocated(bb_pb_a)) deallocate(bb_pb_a)
ALLOCATE( bb_pb_a(theta_n,phi_n) )
bmod_a = 0.0_dp
bb_s_a = 0.0_dp
bb_tb_a = 0.0_dp
bb_pb_a = 0.0_dp
if (allocated(r)) deallocate(r)
ALLOCATE( r(theta_n,phi_n) ) ! NEW
if (allocated(z)) deallocate(z)
ALLOCATE( z(theta_n,phi_n) )
if (allocated(l)) deallocate(l)
ALLOCATE( l(theta_n,phi_n) )
if (allocated(r_tb)) deallocate(r_tb)
ALLOCATE( r_tb(theta_n,phi_n) )
if (allocated(z_tb)) deallocate(z_tb)
ALLOCATE( z_tb(theta_n,phi_n) )
if (allocated(p_tb)) deallocate(p_tb)
ALLOCATE( p_tb(theta_n,phi_n) )
if (allocated(r_pb)) deallocate(r_pb)
ALLOCATE( r_pb(theta_n,phi_n) )
if (allocated(z_pb)) deallocate(z_pb)
ALLOCATE( z_pb(theta_n,phi_n) )
if (allocated(p_pb)) deallocate(p_pb)
ALLOCATE( p_pb(theta_n,phi_n) )
r = 0.0d0
z = 0.0d0
l = 0.0d0
r_tb = 0.0d0
z_tb = 0.0d0
p_tb = 0.0d0
r_pb = 0.0d0
z_pb = 0.0d0
p_pb = 0.0d0
!! Modifications by Andreas F. Martitsch (11.03.2014)
! Allocate temporary storage arrays for the Fourier summations
! related to the radial derivatives of (R,Z,phi)-components
ALLOCATE( r_s(theta_n,phi_n) )
ALLOCATE( z_s(theta_n,phi_n) )
ALLOCATE( p_s(theta_n,phi_n) )
ALLOCATE( r_stb(theta_n,phi_n) )
ALLOCATE( z_stb(theta_n,phi_n) )
ALLOCATE( p_stb(theta_n,phi_n) )
ALLOCATE( r_tbtb(theta_n,phi_n) )
ALLOCATE( z_tbtb(theta_n,phi_n) )
ALLOCATE( p_tbtb(theta_n,phi_n) )
ALLOCATE( r_pbtb(theta_n,phi_n) )
ALLOCATE( z_pbtb(theta_n,phi_n) )
ALLOCATE( p_pbtb(theta_n,phi_n) )
ALLOCATE( r_spb(theta_n,phi_n) )
ALLOCATE( z_spb(theta_n,phi_n) )
ALLOCATE( p_spb(theta_n,phi_n) )
ALLOCATE( r_pbpb(theta_n,phi_n) )
ALLOCATE( z_pbpb(theta_n,phi_n) )
ALLOCATE( p_pbpb(theta_n,phi_n) )
r_s = 0.0d0
z_s = 0.0d0
p_s = 0.0d0
r_stb = 0.0d0
z_stb = 0.0d0
p_stb = 0.0d0
r_tbtb = 0.0d0
z_tbtb = 0.0d0
p_tbtb = 0.0d0
r_pbtb = 0.0d0
z_pbtb = 0.0d0
p_pbtb = 0.0d0
r_spb = 0.0d0
z_spb = 0.0d0
p_spb = 0.0d0
r_pbpb = 0.0d0
z_pbpb = 0.0d0
p_pbpb = 0.0d0
!! End Modifications by Andreas F. Martitsch (11.03.2014)
DO imn=1,mnmax
ri = s_rmnc(imn) ! NEW
zi = s_zmnc(imn)
li = s_lmnc(imn)
!! Modifications by Andreas F. Martitsch (07.03.2014)
! Auxiliary variables for the Fourier summation
ri_s = s_rmnc_s(imn)
zi_s = s_zmnc_s(imn)
li_s = s_lmnc_s(imn)
!! End Modifications by Andreas F. Martitsch (07.03.2014)
bi = s_bmnc(imn)
bi_s = s_bmnc_s(imn)
!! Modifications by Andreas F. Martitsch (06.08.2014)
! Additional data from Boozer files without Stellarator symmetry
IF (inp_swi .EQ. 9) THEN ! ASDEX-U (E. Strumberger)
!
ris = s_rmns(imn)
zis = s_zmns(imn)
lis = s_lmns(imn)
bis = s_bmns(imn)
!
ris_s = s_rmns_s(imn)
zis_s = s_zmns_s(imn)
lis_s = s_lmns_s(imn)
bis_s = s_bmns_s(imn)
!
END IF
!! End Modifications by Andreas F. Martitsch (06.08.2014)
m = ixm(imn)
n = ixn(imn)
im = pixm(imn)
in = pixn(imn)
DO ip=1,phi_n
DO it=1,theta_n
!! Modifications by Andreas F. Martitsch (06.08.2014)
! Additional data from Boozer files without Stellarator symmetry
IF (inp_swi .EQ. 9) THEN ! ASDEX-U (E. Strumberger)
cosv = cosmth(it,im) * cosnph(ip,in) - sinmth(it,im) * sinnph(ip,in)
sinv = sinmth(it,im) * cosnph(ip,in) + cosmth(it,im) * sinnph(ip,in)
bmod_a(it,ip) = bmod_a(it,ip) + bi*cosv + bis*sinv
bb_s_a(it,ip) = bb_s_a(it,ip) + bi_s*cosv + bis_s*sinv
bb_tb_a(it,ip) = bb_tb_a(it,ip) - m*bi*sinv + m*bis*cosv
bb_pb_a(it,ip) = bb_pb_a(it,ip) - n*bi*sinv + n*bis*cosv
r(it,ip) = r(it,ip) + ri*cosv + ris*sinv
z(it,ip) = z(it,ip) + zi*cosv + zis*sinv
l(it,ip) = l(it,ip) + li*cosv + lis*sinv
r_tb(it,ip) = r_tb(it,ip) - m*ri*sinv + m*ris*cosv
r_pb(it,ip) = r_pb(it,ip) - n*ri*sinv + n*ris*cosv
z_tb(it,ip) = z_tb(it,ip) - m*zi*sinv + m*zis*cosv
z_pb(it,ip) = z_pb(it,ip) - n*zi*sinv + n*zis*cosv
p_tb(it,ip) = p_tb(it,ip) + m*li*sinv - m*lis*cosv ! -l_tb
p_pb(it,ip) = p_pb(it,ip) + n*li*sinv - n*lis*cosv ! -l_pb
r_s(it,ip) = r_s(it,ip) + ri_s*cosv + ris_s*sinv
z_s(it,ip) = z_s(it,ip) + zi_s*cosv + zis_s*sinv
p_s(it,ip) = p_s(it,ip) + li_s*cosv + lis_s*sinv ! -l_s
r_stb(it,ip) = r_stb(it,ip) - m*ri_s*sinv + m*ris_s*cosv
z_stb(it,ip) = z_stb(it,ip) - m*zi_s*sinv + m*zis_s*cosv
p_stb(it,ip) = p_stb(it,ip) + m*li_s*sinv - m*lis_s*cosv ! -l_stb
r_spb(it,ip) = r_spb(it,ip) - n*ri_s*sinv + n*ris_s*cosv
z_spb(it,ip) = z_spb(it,ip) - n*zi_s*sinv + n*zis_s*cosv
p_spb(it,ip) = p_spb(it,ip) + n*li_s*sinv - n*lis_s*cosv ! -l_spb
r_tbtb(it,ip) = r_tbtb(it,ip) - m*m*ri*cosv - m*m*ris*sinv
z_tbtb(it,ip) = z_tbtb(it,ip) - m*m*zi*cosv - m*m*zis*sinv
p_tbtb(it,ip) = p_tbtb(it,ip) + m*m*li*cosv + m*m*lis*sinv ! -l_tbtb
r_pbtb(it,ip) = r_pbtb(it,ip) - m*n*ri*cosv - m*n*ris*sinv
z_pbtb(it,ip) = z_pbtb(it,ip) - m*n*zi*cosv - m*n*zis*sinv
p_pbtb(it,ip) = p_pbtb(it,ip) + m*n*li*cosv + m*n*lis*sinv ! -l_pbtb
r_pbpb(it,ip) = r_pbpb(it,ip) - n*n*ri*cosv - n*n*ris*sinv
z_pbpb(it,ip) = z_pbpb(it,ip) - n*n*zi*cosv - n*n*zis*sinv
p_pbpb(it,ip) = p_pbpb(it,ip) + n*n*li*cosv + n*n*lis*sinv ! -l_pbpb
ELSE
cosv = cosmth(it,im) * cosnph(ip,in) + sinmth(it,im) * sinnph(ip,in)
sinv = sinmth(it,im) * cosnph(ip,in) - cosmth(it,im) * sinnph(ip,in)
bmod_a(it,ip) = bmod_a(it,ip) + bi * cosv
bb_s_a(it,ip) = bb_s_a(it,ip) + bi_s * cosv
bb_tb_a(it,ip) = bb_tb_a(it,ip) - m * bi * sinv
bb_pb_a(it,ip) = bb_pb_a(it,ip) + n * bi * sinv
r(it,ip) = r(it,ip) + ri*cosv
z(it,ip) = z(it,ip) + zi*sinv
l(it,ip) = l(it,ip) + li*sinv
r_tb(it,ip) = r_tb(it,ip) - m*ri*sinv
r_pb(it,ip) = r_pb(it,ip) + n*ri*sinv
z_tb(it,ip) = z_tb(it,ip) + m*zi*cosv
z_pb(it,ip) = z_pb(it,ip) - n*zi*cosv
p_tb(it,ip) = p_tb(it,ip) - m*li*cosv ! -l_tb
p_pb(it,ip) = p_pb(it,ip) + n*li*cosv ! -l_pb
!! Modifications by Andreas F. Martitsch (07.03.2014)
! Temporary storage arrays for the Fourier summations
! related to the radial derivatives of (R,Z,phi)-components
r_s(it,ip) = r_s(it,ip) + ri_s*cosv
z_s(it,ip) = z_s(it,ip) + zi_s*sinv
p_s(it,ip) = p_s(it,ip) - li_s*sinv ! -l_s
r_stb(it,ip) = r_stb(it,ip) - m*ri_s*sinv
z_stb(it,ip) = z_stb(it,ip) + m*zi_s*cosv
p_stb(it,ip) = p_stb(it,ip) - m*li_s*cosv ! -l_stb
r_tbtb(it,ip) = r_tbtb(it,ip) - m*m*ri*cosv
z_tbtb(it,ip) = z_tbtb(it,ip) - m*m*zi*sinv
p_tbtb(it,ip) = p_tbtb(it,ip) + m*m*li*sinv ! -l_tbtb
r_pbtb(it,ip) = r_pbtb(it,ip) + m*n*ri*cosv
z_pbtb(it,ip) = z_pbtb(it,ip) + m*n*zi*sinv
p_pbtb(it,ip) = p_pbtb(it,ip) - m*n*li*sinv ! -l_pbtb
r_spb(it,ip) = r_spb(it,ip) + n*ri_s*sinv
z_spb(it,ip) = z_spb(it,ip) - n*zi_s*cosv
p_spb(it,ip) = p_spb(it,ip) + n*li_s*cosv ! -l_spb
r_pbpb(it,ip) = r_pbpb(it,ip) - n*n*ri*cosv
z_pbpb(it,ip) = z_pbpb(it,ip) - n*n*zi*sinv
p_pbpb(it,ip) = p_pbpb(it,ip) + n*n*li*sinv ! -l_pbpb
!! End Modifications by Andreas F. Martitsch (07.03.2014)
END IF
!! End Modifications by Andreas F. Martitsch (06.08.2014)
END DO
END DO
END DO
DEALLOCATE( s_bmnc )
DEALLOCATE( s_bmnc_s )
DEALLOCATE( s_rmnc )
DEALLOCATE( s_zmnc )
DEALLOCATE( s_lmnc )
!! Modifications by Andreas F. Martitsch (07.03.2014)
! Deallocate arrays for the additional radial derivatives
DEALLOCATE( s_rmnc_s )
DEALLOCATE( s_zmnc_s )
DEALLOCATE( s_lmnc_s )
!! End Modifications by Andreas F. Martitsch (07.03.2014)
!
!! Modifications by Andreas F. Martitsch (06.08.2014)
! Additional data from Boozer files without Stellarator symmetry
IF (inp_swi .EQ. 9) THEN ! ASDEX-U (E. Strumberger)
DEALLOCATE ( s_bmns )
DEALLOCATE ( s_bmns_s )
DEALLOCATE ( s_rmns )
DEALLOCATE ( s_zmns )
DEALLOCATE ( s_lmns )
DEALLOCATE ( s_rmns_s )
DEALLOCATE ( s_zmns_s )
DEALLOCATE ( s_lmns_s )
END IF
!! End Modifications by Andreas F. Martitsch (06.08.2014)
!
IF (lab_swi .EQ. 5 .OR. lab_swi .EQ. 3) THEN ! CHS, LHD
p_tb = - p_tb
p_pb = 1 - p_pb
!! Modifications by Andreas F. Martitsch (07.03.2014)
! ToDo: Implement conversion for p_s
PRINT *,'WARNING FROM NEO_MAGFIE: CONVERSION FOR RADIAL DERIVATIVE OF BOOZER-PHI NOT IMPLEMENTED!'
!! End Modifications by Andreas F. Martitsch (07.03.2014)
ELSE
p_tb = p_tb * twopi / nfp
p_pb = 1.0_dp + p_pb * twopi / nfp
!! Modifications by Andreas F. Martitsch (11.03.2014)
! Conversion factor between Boozer-phi and L (see Boozer-file)
p_s = p_s * twopi / nfp
p_stb = p_stb * twopi / nfp
p_tbtb = p_tbtb * twopi / nfp
p_pbtb = p_pbtb * twopi / nfp
p_spb = p_spb * twopi / nfp
p_pbpb = p_pbpb * twopi / nfp
!! End Modifications by Andreas F. Martitsch (11.03.2014)
END IF
! **********************************************************************
! Ensure periodicity boundaries to be the same
! **********************************************************************
r(theta_n,:) = r(1,:)
r(:,phi_n) = r(:,1)
z(theta_n,:) = z(1,:)
z(:,phi_n) = z(:,1)
l(theta_n,:) = l(1,:)
l(:,phi_n) = l(:,1)
bmod_a(theta_n,:) = bmod_a(1,:)
bmod_a(:,phi_n) = bmod_a(:,1)
r_tb(theta_n,:) = r_tb(1,:)
r_tb(:,phi_n) = r_tb(:,1)
r_pb(theta_n,:) = r_pb(1,:)
r_pb(:,phi_n) = r_pb(:,1)
z_tb(theta_n,:) = z_tb(1,:)
z_tb(:,phi_n) = z_tb(:,1)
z_pb(theta_n,:) = z_pb(1,:)
z_pb(:,phi_n) = z_pb(:,1)
p_tb(theta_n,:) = p_tb(1,:)
p_tb(:,phi_n) = p_tb(:,1)
p_pb(theta_n,:) = p_pb(1,:)
p_pb(:,phi_n) = p_pb(:,1)
!! Modifications by Andreas F. Martitsch (07.03.2014)
! Temporary storage arrays for the Fourier summations
! related to the radial derivatives of (R,Z,phi)-components
r_s(theta_n,:) = r_s(1,:)
r_s(:,phi_n) = r_s(:,1)
z_s(theta_n,:) = z_s(1,:)
z_s(:,phi_n) = z_s(:,1)
p_s(theta_n,:) = p_s(1,:)
p_s(:,phi_n) = p_s(:,1)
r_stb(theta_n,:) = r_stb(1,:)
r_stb(:,phi_n) = r_stb(:,1)
z_stb(theta_n,:) = z_stb(1,:)
z_stb(:,phi_n) = z_stb(:,1)
p_stb(theta_n,:) = p_stb(1,:)
p_stb(:,phi_n) = p_stb(:,1)
r_tbtb(theta_n,:) = r_tbtb(1,:)
r_tbtb(:,phi_n) = r_tbtb(:,1)
z_tbtb(theta_n,:) = z_tbtb(1,:)
z_tbtb(:,phi_n) = z_tbtb(:,1)
p_tbtb(theta_n,:) = p_tbtb(1,:)
p_tbtb(:,phi_n) = p_tbtb(:,1)
r_pbtb(theta_n,:) = r_pbtb(1,:)
r_pbtb(:,phi_n) = r_pbtb(:,1)
z_pbtb(theta_n,:) = z_pbtb(1,:)
z_pbtb(:,phi_n) = z_pbtb(:,1)
p_pbtb(theta_n,:) = p_pbtb(1,:)
p_pbtb(:,phi_n) = p_pbtb(:,1)
r_spb(theta_n,:) = r_spb(1,:)
r_spb(:,phi_n) = r_spb(:,1)
z_spb(theta_n,:) = z_spb(1,:)
z_spb(:,phi_n) = z_spb(:,1)
p_spb(theta_n,:) = p_spb(1,:)
p_spb(:,phi_n) = p_spb(:,1)
r_pbpb(theta_n,:) = r_pbpb(1,:)
r_pbpb(:,phi_n) = r_pbpb(:,1)
z_pbpb(theta_n,:) = z_pbpb(1,:)
z_pbpb(:,phi_n) = z_pbpb(:,1)
p_pbpb(theta_n,:) = p_pbpb(1,:)
p_pbpb(:,phi_n) = p_pbpb(:,1)
!! End Modifications by Andreas F. Martitsch (07.03.2014)
bb_tb_a(theta_n,:) = bb_tb_a(1,:)
bb_tb_a(:,phi_n) = bb_tb_a(:,1)
!! Modifications by Andreas F. Martitsch (25.08.2014)
! This seems to be a copy-paste, which moved one version
! to another:
!bb_s_a(theta_n,:) = bb_tb_a(1,:)
!bb_s_a(:,phi_n) = bb_tb_a(:,1)
! this should be correct now:
bb_s_a(theta_n,:) = bb_s_a(1,:)
bb_s_a(:,phi_n) = bb_s_a(:,1)
!! End Modifications by Andreas F. Martitsch (25.08.2014)
bb_pb_a(theta_n,:) = bb_pb_a(1,:)
bb_pb_a(:,phi_n) = bb_pb_a(:,1)
! **********************************************************************
! Derived quantities
! **********************************************************************
if (allocated(gtbtb)) deallocate(gtbtb)
ALLOCATE( gtbtb(theta_n,phi_n) )
if (allocated(gpbpb)) deallocate(gpbpb)
ALLOCATE( gpbpb(theta_n,phi_n) )
if (allocated(gtbpb)) deallocate(gtbpb)
ALLOCATE( gtbpb(theta_n,phi_n) )
if (allocated(sqrg11_met)) deallocate(sqrg11_met)
ALLOCATE( sqrg11_met(theta_n,phi_n) )
!! Modifications by Andreas F. Martitsch (11.03.2014)
! Allocate temporary storage arrays for the Fourier summations
! related to the additionally needed metric tensor elements
ALLOCATE( gstb_a(theta_n,phi_n) )
ALLOCATE( gspb_a(theta_n,phi_n) )
ALLOCATE( gstb_tb_a(theta_n,phi_n) )
ALLOCATE( gspb_tb_a(theta_n,phi_n) )
ALLOCATE( gstb_pb_a(theta_n,phi_n) )
ALLOCATE( gspb_pb_a(theta_n,phi_n) )
!! End Modifications by Andreas F. Martitsch (11.03.2014)
! metric tensor
gtbtb = r_tb*r_tb + z_tb*z_tb + r*r*p_tb*p_tb
gpbpb = r_pb*r_pb + z_pb*z_pb + r*r*p_pb*p_pb
gtbpb = r_tb*r_pb + z_tb*z_pb + r*r*p_tb*p_pb
!! Modifications by Andreas F. Martitsch (11.03.2014)
! Compute the additionally needed metric tensor elements
gstb_a = r_s*r_tb + z_s*z_tb + r*r*p_s*p_tb
gspb_a = r_s*r_pb + z_s*z_pb + r*r*p_s*p_pb
gstb_tb_a = r_stb*r_tb + r_s*r_tbtb + z_stb*z_tb + z_s*z_tbtb + &
2.0d0*r*r_tb*p_s*p_tb + r*r*(p_stb*p_tb + p_s*p_tbtb)
gspb_tb_a = r_stb*r_pb + r_s*r_pbtb + z_stb*z_pb + z_s*z_pbtb + &
2.0d0*r*r_tb*p_s*p_pb + r*r*(p_stb*p_pb + p_s*p_pbtb)
gstb_pb_a = r_spb*r_tb + r_s*r_pbtb + z_spb*z_tb + z_s*z_pbtb + &
2.0d0*r*r_pb*p_s*p_tb + r*r*(p_spb*p_tb + p_s*p_pbtb)
gspb_pb_a = r_spb*r_pb + r_s*r_pbpb + z_spb*z_pb + z_s*z_pbpb + &
2.0d0*r*r_pb*p_s*p_pb + r*r*(p_spb*p_pb + p_s*p_pbpb)
!! End Modifications by Andreas F. Martitsch (11.03.2014)
! Winny for Klaus
av_b2_m = theta_n * phi_n / SUM(1 / (bmod_a*bmod_a))
!PRINT *, 'theta_n,phi_n ',theta_n,phi_n
!PRINT *, 'av_b2_m ',av_b2_m
! Winny for Klaus - Ende
! $1/sqrt(g)$
!! fac = s_curr_pol + s_iota * s_curr_tor ! (J + iota I)
!! isqrg = b*b / fac
! $sqrt(g^{11})$
!IF (g11_swi .EQ. 0) THEN
! sqrg11 = 1.0_dp
!ELSE
!sqrg11 = SQRT( (gtbtb*gpbpb - gtbpb*gtbpb ) * isqrg**2)
sqrg11_met = SQRT( (gtbtb*gpbpb - gtbpb*gtbpb ) )
!END IF
!PRINT *, 'max_gtbtb = ',maxval(gtbtb)
!PRINT *, 'min_gtbtb = ',MINVAL(gtbtb)
!PRINT *, 'max_gpbpb = ',maxval(gpbpb)
!PRINT *, 'min_gpbpb = ',MINVAL(gpbpb)
!PRINT *, 'max_gtbpb = ',MAXVAL(gtbpb)
!PRINT *, 'min_gtbpb = ',MINVAL(gtbpb)
!*************************************************************
! Do the 2-D periodic spline
!*************************************************************
IF (write_progress .EQ. 1) THEN
PRINT *, 'Do 2-D spline of bmod'
END IF
p_spl => bmod_spl(:,:,:,:,k_es)
CALL spl2d(theta_n,phi_n,theta_int,phi_int,mt,mp, &
bmod_a,p_spl)
IF (write_progress .EQ. 1) THEN
PRINT *, 'Do 2-D spline of bb_s'
END IF
p_spl => bb_s_spl(:,:,:,:,k_es)
CALL spl2d(theta_n,phi_n,theta_int,phi_int,mt,mp, &
bb_s_a,p_spl)
IF (write_progress .EQ. 1) THEN
PRINT *, 'Do 2-D spline of bb_tb'
END IF
p_spl => bb_tb_spl(:,:,:,:,k_es)
CALL spl2d(theta_n,phi_n,theta_int,phi_int,mt,mp, &
bb_tb_a,p_spl)
IF (write_progress .EQ. 1) THEN
PRINT *, 'Do 2-D spline of bb_pb'
END IF
p_spl => bb_pb_spl(:,:,:,:,k_es)
CALL spl2d(theta_n,phi_n,theta_int,phi_int,mt,mp, &
bb_pb_a,p_spl)
IF (write_progress .EQ. 1) THEN
PRINT *, 'Do 2-D spline of sqrg11'
END IF
p_spl => gval_spl(:,:,:,:,k_es)
CALL spl2d(theta_n,phi_n,theta_int,phi_int,mt,mp, &
sqrg11_met,p_spl)
!! Modifications by Andreas F. Martitsch (11.03.2014)
! Compute the 2d periodic splines (over the flux-surface)
! of the additionally needed metric tensor elements
p_spl => gstb_spl(:,:,:,:,k_es)
CALL spl2d(theta_n,phi_n,theta_int,phi_int,mt,mp, &
gstb_a,p_spl)
p_spl => gspb_spl(:,:,:,:,k_es)
CALL spl2d(theta_n,phi_n,theta_int,phi_int,mt,mp, &
gspb_a,p_spl)
p_spl => gstb_tb_spl(:,:,:,:,k_es)
CALL spl2d(theta_n,phi_n,theta_int,phi_int,mt,mp, &
gstb_tb_a,p_spl)
p_spl => gspb_tb_spl(:,:,:,:,k_es)
CALL spl2d(theta_n,phi_n,theta_int,phi_int,mt,mp, &
gspb_tb_a,p_spl)
p_spl => gstb_pb_spl(:,:,:,:,k_es)
CALL spl2d(theta_n,phi_n,theta_int,phi_int,mt,mp, &
gstb_pb_a,p_spl)
p_spl => gspb_pb_spl(:,:,:,:,k_es)
CALL spl2d(theta_n,phi_n,theta_int,phi_int,mt,mp, &
gspb_pb_a,p_spl)
!! End Modifications by Andreas F. Martitsch (11.03.2014)
!! Modifications by Andreas F. Martitsch (13.11.2014)
! Compute the 2d periodic splines (over the flux-surface)
! of the additionally needed quantities for NTV output
p_spl => R_spl(:,:,:,:,k_es)
CALL spl2d(theta_n,phi_n,theta_int,phi_int,mt,mp, &
r,p_spl)
p_spl => Z_spl(:,:,:,:,k_es)
CALL spl2d(theta_n,phi_n,theta_int,phi_int,mt,mp, &
z,p_spl)
!! End Modifications by Andreas F. Martitsch (13.11.2014)
!PRINT *, 'max_g11 = ', maxval(sqrg11_met)
!PRINT *, 'min_g11 = ', minval(sqrg11_met)
!stop "Compute magnetic field components via a spline (and not via direct Fourier summation)"
DEALLOCATE( bmod_a )
DEALLOCATE( bb_s_a )
DEALLOCATE( bb_tb_a )
DEALLOCATE( bb_pb_a )
DEALLOCATE( r ) ! NEW
DEALLOCATE( z )
DEALLOCATE( l )
DEALLOCATE( r_tb )
DEALLOCATE( z_tb )
DEALLOCATE( p_tb )
DEALLOCATE( r_pb )
DEALLOCATE( z_pb )
DEALLOCATE( p_pb )
DEALLOCATE( gtbtb )
DEALLOCATE( gpbpb )
DEALLOCATE( gtbpb )
DEALLOCATE( sqrg11_met )
!! Modifications by Andreas F. Martitsch (11.03.2014)
! Deallocate temporary storage arrays for the Fourier summations
! related to the radial derivatives of (R,Z,phi)-components
! and the additionally needed metric tensor elements
DEALLOCATE( r_s )
DEALLOCATE( z_s )
DEALLOCATE( p_s )
DEALLOCATE( r_stb )
DEALLOCATE( z_stb )
DEALLOCATE( p_stb )
DEALLOCATE( r_tbtb )
DEALLOCATE( z_tbtb )
DEALLOCATE( p_tbtb )
DEALLOCATE( r_pbtb )
DEALLOCATE( z_pbtb )
DEALLOCATE( p_pbtb )
DEALLOCATE( gstb_a )
DEALLOCATE( gspb_a )
DEALLOCATE( gstb_tb_a )
DEALLOCATE( gspb_tb_a )
DEALLOCATE( r_spb )
DEALLOCATE( z_spb )
DEALLOCATE( p_spb )
DEALLOCATE( r_pbpb )
DEALLOCATE( z_pbpb )
DEALLOCATE( p_pbpb )
DEALLOCATE( gstb_pb_a )
DEALLOCATE( gspb_pb_a )
!! End Modifications by Andreas F. Martitsch (11.03.2014)
!*************************************************************
! Provide curr_tor, curr_tor_s, curr_pol, curr_pol_s, iota
!*************************************************************
IF (write_progress .EQ. 1) THEN
PRINT *, 'Prep of currents: ',s
END IF
swd = 1 ! derivative
CALL splint_horner3(es, &
a_curr_tor, b_curr_tor, c_curr_tor, d_curr_tor, &
swd, m0, &
s, tfone, tfzero, tfzero, tfzero, &
curr_tor_array(k_es), curr_tor_s_array(k_es), ypp, yppp)
swd = 1 ! derivative
CALL splint_horner3(es, &
a_curr_pol, b_curr_pol, c_curr_pol, d_curr_pol, &
swd, m0, &
s, tfone, tfzero, tfzero, tfzero, &
curr_pol_array(k_es), curr_pol_s_array(k_es) ,ypp, yppp)
CALL splint_horner3(es, &
a_iota, b_iota, c_iota, d_iota, swd, m0, &
s, tfone, tfzero, tfzero, tfzero, &
iota_array(k_es), iota_s_array(k_es), ypp, yppp)
swd = 0 ! no derivative
CALL splint_horner3(es, &
a_pprime, b_pprime, c_pprime, d_pprime, swd, m0, &
s, tfone, tfzero, tfzero, tfzero, &
pprime_array(k_es), yp, ypp, yppp)
CALL splint_horner3(es, &
a_sqrtg00, b_sqrtg00, c_sqrtg00, d_sqrtg00, swd, m0, &
s, tfone, tfzero, tfzero, tfzero, &
sqrtg00_array(k_es), yp, ypp, yppp)
END DO
! Minimum and Maximum in the new mode
if (magfie_sarray_len .eq. 1) then