-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
1498 lines (907 loc) · 44.7 KB
/
main.c
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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "fitsio.h"
long i, j, k, gs;
int disk, halo, disk_odd, halo_odd, halo_n, equipartition, gaussian_bfield, clockwise_north, dynamo, idyn, cone, cylinder, expanding_flow, suppress_halo_field, diffusion_dynamo;
double x[207], y[207], z[207], y_ss[207][207][207], z_ss[207][207][207],
x_ss[207][207], TP[207][207], PF[207][207], Q_0[207][207], Q_1[207][207], U_0[207][207], U_1[207][207], Q_2[207][207],
U_2[207][207], Q_3[207][207],
U_3[207][207], RM[207][207], RM_2[207][207],
psi_d[207][207][207], psi_h[207][207][207], delta_phi_1[207][207][207],
delta_phi_2[207][207][207], delta_phi_3[207][207][207], map[207][207], PI_1[207][207], PI_2[207][207],
E_x_d[207][207][207], E_x_d_turb[207][207][207], E_y_d[207][207][207], E_y_d_turb[207][207][207],
E_z_d[207][207][207], E_z_d_turb[207][207][207],
E_x_h[207][207][207], E_x_h_turb[207][207][207], E_y_h[207][207][207], E_y_h_turb[207][207][207], E_z_h[207][207][207], E_z_h_turb[207][207][207],
Et[207][207], delta_phi_o1[207][207], PI_0[207][207];
double delta_x, delta_y, delta_z, E, E_phi, E_R, E_phi_h, E_phi_d, E_R_h, E_R_d,
E_xs_d, E_ys_d, E_zs_d, E_xs_h, E_ys_h, E_zs_h,
theta, phi, x_ref, y_ref, z_ref, ne, ne_0, h_e,
lambda_1, lambda_2, lambda_3, psi_1_d, psi_2_d, psi_3_d, psi_1_h, psi_2_h, psi_3_h, psi_obs_1, psi_obs_2, psi_obs_3, psi_obs_0, aniso_d, aniso_h, dyn_D, dyn_Q, b_odd_max, FWHM_d, sigma_d, d_fil, sigma_fil, h_cr, l_fil, r1, r2, ne_cone, ne_cone_0, h_cr_fil;
double E_d_turb_0, E_h_turb_0, E_d_turb, E_h_turb, E_d_total_0, E_h_total_0, E_phi_h_prime, zeta, dynamo_scale;
double PI, cell_x, cell_y, cell_z, D, h_B_d, h_B_h, FWHM_1, FWHM_2, alpha, beta,
ia, iat, PA, PAt, pitch, sigma_1, sigma_2, sod, FWHM_e,
sigma_e,
FWHM_b,sigma_b, pi_max, E_d, E_h, E_d0, E_h0, n_CR, FWHM_h, sigma_h, scale_factor, c_constant, v_constant, E_phi_h_0;
int main( void );
void setup_array ( void );
void setup_electric_field ( void );
void writeimage( char filename[], double map[207][207], double crval3, double cdelt3, double crval4 );
void writecube( char filename[], double map[207][207][207], double crval3, double cdelt3, double crval4 );
void printerror ( int status );
int main()
{
// 205
/* grid size */
gs = 205;
PI = 3.141592654;
//10 is the number for gs=200
/* cell size in arcsec */
cell_x = 2.0;
cell_y = 2.0;
cell_z = 2.0;
D = 26.9e6; //distance in pc
h_B_d = 1600.0; //scale height disk field in pc
h_B_h = 7000.0;//scale height halo field 4.0 * 1700.0;
/* maximum of magnetic field in case of odd parity */
b_odd_max = 500.0;
/* scaleheight of the thermal electrons */
h_e = 4000.0;// 1400.0 is from paper2, measured with halpha in pc
/* electron density in cm^-3 */
ne_0 = 0.01;
lambda_1 = 0.062; // wavelength in meters
lambda_2 = 0.036; // wavelength in meters
lambda_3 = 0.02; // wavelength in meters
FWHM_1 = 12000.0; // in pc (gaussian, disk along the major axis, PaperII Fig 9 left)
FWHM_2 = 12000.0; // in pc (gaussian, disk along the major axis)
FWHM_h = 12000.0;// in pc (gaussian, halo along the major axis PaperII Fig 9 right)
/* FWHM of disk field in case of odd parity */
FWHM_d = 400;
FWHM_e = 12000.0; // electron density
/* if a vertical Gaussian magnetic field is used */
FWHM_b = 2000.0;
sod = 0.0; // free parameter: FWHM_1/FWHM_2 disk
/* disk = 1: switch disk magnetic field on */
disk = -1;
/* halo=1: switch halo magnetic field on */
halo = -1;
/* disk_odd = 1 on */
disk_odd = -1;
/* halo_odd = 1: halo field is of odd parity */
halo_odd = -1;
/* clockwise_north = 1: if disk field is odd: disk magnetic field points in clockwise direction in the northern hemisphere */
clockwise_north = -1;
/*halo_n =1: halo mf points inward in northern hemisphere */
halo_n = -1;
/* equipartition=1: switch equipartition on */
equipartition= -1;
scale_factor = 1.e-5;
/* gaussian_bfield=1: switch Gaussian vertical bfield distribution on */
gaussian_bfield = -1;
dynamo = -1; //?
idyn = 1;//?
dyn_D = 1.0;//?
dyn_Q = 0.0;//?
alpha = 25.0 * PI / 180.0;// helical field, phi-direction, 25 for n5775
beta = 40.0 * PI / 180.0;// helical field, beta_n = 45.0 * PI / 180.0, r-direction;
/* pitch = pitch angle of the magnetic field spiral */
pitch = -20.0 * PI / 180.0;
/* inclination angle; ia = 90d means edge on */
ia = 84.0;
iat = ( 90.0 - ia ) * PI / 180.0;
PA = 145.0;
PAt = ( 90.0 - PA ) * PI / 180.0;
E_d_total_0 = 12.0;//Total disk field strength
E_h_total_0 = 9.0;//Total halo field strength
E_d0 = 4.0;//4.4 is from paper2, ordered magnetic field strength disk
E_h0 = 4.0;//20.0 for the filaments 4.4 is form paper2, ordered magnetic field strength halo
E_d_turb_0 = sqrt( pow( E_d_total_0, 2.0 ) - pow( E_d0, 2.0 ) );//Turbulent magnetic field strength of the disk
E_h_turb_0 = sqrt( pow( E_h_total_0, 2.0 ) - pow( E_h0, 2.0 ) );//Turbulent magnetic field strength of the halo
aniso_d = 1.0;//0.68 is from paper2, anisotropical component
aniso_h = 1.0;//0.68 is from paper2
/* conical magnetic field with filaments */
cone = -1;
d_fil = 40.0;//40.0
l_fil = 300.0; //300.0
h_cr = 3500.0;
h_cr_fil = 200.0;
ne_cone_0 = 2.0;//1.0
/* halo field confined within a cylinder with a diameter of FWHM_h and has no radius dependence */
cylinder = -1;
/* expanding flow, so that FWHM_h is a function of height */
expanding_flow = -1;
/* Suppress the ordered halo field within the thin disc */
suppress_halo_field = -1;
if ( halo == -1 )
{
E_h0 = 0.0;
E_h_turb_0 = 0.0;
}
if ( disk == -1 )
{
E_h0 = 0.0;
E_h_turb_0 = 0.0;
E_d0 = 0.0;
E_d_turb_0 = 0.0;
}
/* Dynamo model from Henriksen et al. (2018), Section 2.2 */
diffusion_dynamo = 1;
c_constant = 1.0;
if ( diffusion_dynamo == 1 )
E_h0 = c_constant;
/* Rotation speed of the galaxy */
v_constant = 0.25;
/* This scales the intensities of the dynamo solution */
dynamo_scale = 1.0;
c_constant = c_constant * dynamo_scale;
// v_constant = v_constant * dynamo_scale;
/* This is another free parameter but should be set to zero usually */
E_phi_h_0 = 0.0;
/*************************************************************************************** Here ends the parameter input ***************/
setup_array ();
setup_electric_field ();
writeimage ( "TP.fits", TP, 0.0, 0.0, 1.0 );
writeimage ( "PF.fits", PF, 0.0, 0.0, 1.0 );
writeimage ( "Q0.fits", Q_0, 0.0, 0.0, 2.0 );
writeimage ( "Q1.fits", Q_1, 4.8e9, 1.0e7, 2.0 ); // Frequenz1,Bandbreite1,?
writeimage ( "Q2.fits", Q_2, 8.5e9, 1.0e7, 2.0 ); // Frequenz1,Bandbreite1,?
writeimage ( "Q3.fits", Q_3, 6.2e9, 5.0e8, 2.0 );
writeimage ( "U0.fits", U_0, 0.0, 0.0, 3.0 );
writeimage ( "U1.fits", U_1, 4.8e9, 1.0e7, 3.0 );
writeimage ( "U2.fits", U_2, 8.5e9, 1.0e7, 3.0 );
writeimage ( "U3.fits", U_3, 6.2e9, 5.0e8, 3.0 );
writeimage ( "RM.fits", RM, 4.8e9, 1.0e7, 0.0 );
writeimage ( "RMs.fits", RM_2, 4.8e9, 1.0e7, 0.0 );
writeimage ( "PI0.fits", PI_0, 0.0, 0.0, 1.0 );
writeimage ( "PI1.fits", PI_1, 4.8e9, 1.0e7, 1.0 );
writeimage ( "PI2.fits", PI_2, 8.5e9, 1.0e9, 1.0 );
return(0);
}
void setup_array ( void )
{
x[0]=0;
y[0]=0;
z[0]=0;
delta_x = cell_x * D * tan(PI / (3600.0 * 180.0));
delta_y = cell_y * D * tan(PI / (3600.0 * 180.0));
delta_z = cell_z * D * tan(PI / (3600.0 * 180.0));
for (i=1; i <= gs; i++)
{
x[i] = x[i-1] + delta_x;
}
for (j=1; j <= gs; j++)
{
y[j]= y[j-1] + delta_y;
}
for (k=1; k <= gs; k++)
{
z[k]= z[k-1] + delta_z;
}
x_ref = 0.5 * x[gs];
y_ref = 0.5 * y[gs];
z_ref = 0.5 * z[gs];
for (i=1; i <= gs; i++)
{
for (j=1; j <= gs; j++)
{
for (k=1; k <= gs; k++)
{
/* x_ss[i][k] = ( x[i] - x_ref ); A1
y_ss[i][j][k] = cos( iat ) * ( y[j] - y_ref ) - A2
sin( iat ) * ( z[k] - z_ref );
z_ss[i][j][k] = cos ( iat ) * ( z[k] - z_ref ) + A3
sin ( iat ) * ( y[j] - y_ref ); */
x_ss[i][k] = cos ( PAt ) * ( x[i] - x_ref ) - sin( PAt ) *
( z[k] - z_ref );
y_ss[i][j][k] = -sin( PAt ) * sin( iat ) * ( x[i] - x_ref ) +
cos( iat ) * ( y[j] - y_ref ) - sin( iat ) *
cos ( PAt ) * ( z[k] - z_ref );
z_ss[i][j][k] = sin( PAt ) * cos( iat ) * ( x[i] - x_ref ) +
sin( iat ) * ( y[j] - y_ref ) +
cos( iat ) * cos( PAt ) * ( z[k] - z_ref );
}
}
}
return;
}
void setup_electric_field ( void )
{
if (equipartition == 1)
{
FWHM_1 = 2.0 * FWHM_1;
FWHM_2 = 2.0 * FWHM_2;
FWHM_b = 2.0 * FWHM_b;
FWHM_h = 2.0 * FWHM_h;
FWHM_d = 2.0 * FWHM_d;
}
sigma_1 = FWHM_1 / ( 2.0 * sqrt( 2.0 * log (2.0) ) );
sigma_2 = FWHM_2 / ( 2.0 * sqrt( 2.0 * log (2.0) ) );
sigma_e = FWHM_e / ( 2.0 * sqrt( 2.0 * log (2.0) ) );
sigma_b = FWHM_b / ( 2.0 * sqrt( 2.0 * log (2.0) ) );
sigma_h = FWHM_h / ( 2.0 * sqrt( 2.0 * log (2.0) ) );
sigma_d = FWHM_d / ( 2.0 * sqrt( 2.0 * log (2.0) ) );
sigma_fil = d_fil / ( 2.0 * sqrt( 2.0 * log (2.0) ) );
for (i=1; i <= gs; i++)
{
for (k=1; k <= gs; k++)
{
delta_phi_1[i][1][k] = 0.0;
delta_phi_2[i][1][k] = 0.0;
// RM[i][k] = 0.0;
RM_2[i][k] = 0.0;
// Q_0[i][k] = 0.0;
// U_0[i][k] = 0.0;
delta_phi_o1[i][k] = 0.0;
for (j=1; j <= gs; j++)
{
if ( disk == 1 )
{
if (gaussian_bfield == 1) // scheibenfeldstaerke A4
E_d = E_d0 * exp (-pow( z_ss[i][j][k], 2.0 ) /
(2.0 * pow(sigma_b, 2.0) ) ) *
( exp( -(pow( x_ss[i][k], 2.0 ) +
pow( y_ss[i][j][k], 2.0 ) ) /
( 2.0 * pow( sigma_1, 2.0) ) ) + sod *
exp( -(pow( x_ss[i][k], 2.0 ) +
pow( y_ss[i][j][k], 2.0 ) ) /
( 2.0 * pow( sigma_2, 2.0) ) ) ) /
(1.0 + sod);
else if (disk_odd == 1)
E_d = E_d0 * fabs( z_ss[i][j][k] ) / b_odd_max *
exp ( 1.0 - fabs ( z_ss[i][j][k] ) / b_odd_max );
/* if (fabs( z_ss[i][j][k] ) <= b_odd_max )
E_d = E_d0 * ( pow ( sin( ( z_ss[i][j][k] /
b_odd_max ) * PI /
2.0 ), 2.0 ) );
else
E_d = E_d0 * exp ( -pow( fabs (z_ss[i][j][k] ) -
b_odd_max, 2.0 ) /
(2.0 * pow(sigma_b, 2.0) ) );*/
else
{
E_d = E_d0 * exp (-sqrt( pow( z_ss[i][j][k], 2.0 ) ) /
h_B_d) *
( exp(-pow( sqrt( pow( x_ss[i][k], 2.0 ) +
pow( y_ss[i][j][k], 2.0 ) ), 2.0 ) /
( 2.0 * pow( sigma_1, 2.0) ) ) + sod *
exp(-pow( sqrt( pow( x_ss[i][k], 2.0 ) +
pow( y_ss[i][j][k], 2.0 ) ), 2.0 ) /
( 2.0 * pow( sigma_2, 2.0) ) ) ) /
(1.0 + sod);
E_d_turb = E_d_turb_0 * exp (-sqrt( pow( z_ss[i][j][k], 2.0 ) ) /
h_B_d) *
( exp(-pow( sqrt( pow( x_ss[i][k], 2.0 ) +
pow( y_ss[i][j][k], 2.0 ) ), 2.0 ) /
( 2.0 * pow( sigma_1, 2.0) ) ) + sod *
exp(-pow( sqrt( pow( x_ss[i][k], 2.0 ) +
pow( y_ss[i][j][k], 2.0 ) ), 2.0 ) /
( 2.0 * pow( sigma_2, 2.0) ) ) ) /
(1.0 + sod);
}
}
else
{
E_d = 0.0;
E_d_turb = 0.0;
}
if ( halo == 1 )
{
if ( cylinder == 1 )
{
if ( sqrt( pow( x_ss[i][k], 2.0 ) + pow( y_ss[i][j][k], 2.0 ) ) <= FWHM_h / 2.0 )
E_h = E_h0 * exp (-sqrt( pow( z_ss[i][j][k], 2.0 ) ) /
h_B_h);
else
E_h = 0.0;
}
else
{
if ( expanding_flow == 1 )
sigma_h = FWHM_h / ( 2.0 * sqrt( 2.0 * log (2.0) ) ) * ( sqrt( pow( z_ss[i][j][k], 2.0 ) ) * tan( beta ) + FWHM_h / 2.0) / FWHM_h * 2.0;
E_h = E_h0 * exp (-sqrt( pow( z_ss[i][j][k], 2.0 ) ) /
h_B_h ) *
exp(-pow( sqrt( pow( x_ss[i][k], 2.0 ) +
pow( y_ss[i][j][k], 2.0 ) ), 2.0 ) /
( 2.0 * pow( sigma_h, 2.0) ) );
if ( suppress_halo_field == 1 )
if ( sqrt( pow( z_ss[i][j][k], 2.0 ) ) <= h_B_d )
E_h = E_h0 * sqrt( pow( z_ss[i][j][k], 2.0 ) ) /
h_B_d *
exp(-pow( sqrt( pow( x_ss[i][k], 2.0 ) +
pow( y_ss[i][j][k], 2.0 ) ), 2.0 ) /
( 2.0 * pow( sigma_h, 2.0) ) );
E_h_turb = E_h_turb_0 * exp (-sqrt( pow( z_ss[i][j][k], 2.0 ) ) /
h_B_h) *
exp(-pow( sqrt( pow( x_ss[i][k], 2.0 ) +
pow( y_ss[i][j][k], 2.0 ) ), 2.0 ) /
( 2.0 * pow( sigma_h, 2.0) ) );
}
}
else if ( dynamo == 1 )
E_h = E_h0 * exp ( - sqrt ( x_ss[i][k] * x_ss[i][k] +
y_ss[i][j][k] * y_ss[i][j][k] +
z_ss[i][j][k] * z_ss[i][j][k] )
/ h_B_h);
else if ( cone == 1 )
{
r1 = fabs ( z_ss[i][j][k] ) *
sqrt ( 1.0 / pow ( cos ( beta ), 2.0 )
- 1.0 )
+ l_fil - d_fil / (2.0 * cos (beta) );
r2 = r1 + d_fil / cos (beta);
ne_cone = ne_cone_0 *
exp (-sqrt( pow( z_ss[i][j][k], 2.0 ) ) / h_e) *
exp(-pow( sqrt( pow( x_ss[i][k], 2.0 ) +
pow( y_ss[i][j][k], 2.0 ) ), 2.0 ) /
( 2.0 * pow( sigma_e, 2.0) ) );
E_h = E_h * exp(-pow( sqrt( pow( x_ss[i][k], 2.0 ) +
pow( y_ss[i][j][k], 2.0 ) )
- (r1 + r2) / 2.0, 2.0 ) /
( 2.0 * pow( sigma_fil, 2.0) ) );
if ( fabs ( z_ss[i][j][k] ) < 1200.0 )
alpha = 0.5 * PI / 2.0 * fabs ( z_ss[i][j][k] )
/ 1200.0;
else
alpha = 0.5 * PI / 2.0;
if ( sqrt( pow( x_ss[i][k], 2.0 ) +
pow( y_ss[i][j][k], 2.0 ) ) < r1 )
ne_cone = 0.0;
if ( sqrt( pow( x_ss[i][k], 2.0 ) +
pow( y_ss[i][j][k], 2.0 ) ) > r2 )
ne_cone = 0.0;
/* if ( (sqrt( pow( x_ss[i][k], 2.0 ) +
pow( y_ss[i][j][k], 2.0 ) ) > (r1 + r2) / 2.0 ) && fabs( z_ss[i][j][k] ) >= 400.0)
E_h = - E_h; */
}
E_zs_h = 0.0;
E_phi_h = 0.0;
E_R_h = 0.0;
E_phi_d = 0.0;
E_R_d = 0.0;
E_zs_d = 0.0;
if ( halo == 1 )
{
if ( halo_odd == 1 )
E_zs_h = E_h / sqrt( 1.0 + pow( tan( alpha ), 2 ) +
pow ( tan ( beta ), 2 ) );
else
{
if ( ( z_ss[i][j][k] ) >=0 )
E_zs_h = E_h / sqrt( 1.0 + pow( tan( alpha ), 2 ) +
pow ( tan ( beta ), 2 ) );
else
E_zs_h = -E_h /
sqrt( 1.0 + pow( tan( alpha ), 2 ) +
pow ( tan ( beta ), 2 ) );
}
if ( halo_n == 1 )
E_zs_h = -E_zs_h;
if ( ( z_ss[i][j][k] ) >=0 )
E_phi_h = E_zs_h * tan( alpha );
else
E_phi_h = -E_zs_h * tan( alpha );
if ( ( z_ss[i][j][k] ) >=0 )
E_R_h = E_zs_h * tan ( beta );
else
E_R_h = -E_zs_h * tan ( beta );
}
else if ( dynamo == 1 )
{
theta = atan2 ( sqrt ( x_ss[i][k] * x_ss[i][k] +
y_ss[i][j][k] * y_ss[i][j][k]),
z_ss[i][j][k]);
E_R_h = 3.0 * dyn_D * sin ( theta ) * cos ( theta )
+ 3.0 * dyn_Q * cos ( theta ) * cos ( theta ) *
sin ( theta ) + 3.0 * dyn_Q * sin ( theta ) *
( 3.0 * cos ( theta ) * cos ( theta ) - 1.0 );
E_zs_h = - dyn_D * sin ( theta ) * sin ( theta ) +
2.0 * dyn_D * cos ( theta ) * cos ( theta )
- 3.0 * dyn_Q * sin ( theta ) * sin ( theta ) *
cos ( theta ) + 3.0 * dyn_Q * cos ( theta ) *
( 3.0 * cos ( theta ) * cos ( theta ) - 1.0 );
E_R_h = E_h / sqrt ( E_R_h * E_R_h + E_zs_h * E_zs_h ) *
E_R_h;
E_zs_h = E_h / sqrt ( E_R_h * E_R_h + E_zs_h * E_zs_h ) *
E_zs_h;
if ( idyn == 1 )
{
E_R_h = - E_R_h;
E_zs_h = - E_zs_h;
}
}
else if ( diffusion_dynamo == 1)
{
// zeta = z_ss[i][j][k] / sqrt( pow( x_ss[i][k], 2.0 ) + pow( y_ss[i][j][k], 2.0 ) +
// pow( z_ss[i][j][k], 2.0 ) );
zeta = z_ss[i][j][k] / sqrt( pow( x_ss[i][k], 2.0 ) + pow( y_ss[i][j][k], 2.0 ) );
/* if ( fabs( zeta ) > 1.0 ) */
/* { */
/* zeta = 1.0 * zeta / fabs( zeta ); */
/* // printf("zeta = %g\n", zeta); */
/* } */
E_phi_h = E_phi_h_0 + c_constant * asinh ( zeta );
E_phi_h_prime = c_constant / sqrt( 1.0 + pow( zeta, 2.0 ) );
E_R_h = zeta * E_phi_h_prime / v_constant;
E_zs_h = E_phi_h_prime / v_constant;
/* if ( sqrt( pow( x_ss[i][k], 2.0 ) + pow( y_ss[i][j][k], 2.0 ) ) < 2000.0 ) */
/* { */
/* E_phi_h = 0.0; */
/* E_R_h = 0.0; */
/* E_zs_h = 0.0; */
/* } */
}
else
{
E_zs_h = 0.0;
E_phi_h = 0.0;
E_R_h = 0.0;
}
if ( disk == 1)
{
if ( disk_odd == 1 )
{
if ( ( z_ss[i][j][k] ) >=0 )
{
E_phi_d = E_d / sqrt( 1.0 + pow( tan( pitch ), 2 ) );
}
else
{
E_phi_d = -E_d / sqrt( 1.0 + pow( tan( pitch ), 2 ) );
}
}
else
{
E_phi_d = E_d / sqrt( 1.0 + pow( tan( pitch ), 2 ) );
}
E_R_d = - tan( pitch ) * E_phi_d;
if ( clockwise_north == 1 )
{
E_phi_d = -E_phi_d;
E_R_d = -E_R_d;
}
}
else
{
E_phi_d = 0.0;
E_R_d = 0.0;
}
phi = atan2( y_ss[i][j][k], x_ss[i][k] );
E_xs_d = E_R_d * cos( phi ) - E_phi_d * sin( phi );
E_ys_d = E_R_d * sin( phi ) + E_phi_d * cos( phi );
E_x_d[i][j][k] = cos( PAt ) * E_xs_d - sin( PAt ) *
sin( iat ) * E_ys_d + sin( PAt ) * cos ( iat ) * E_zs_d;
E_y_d[i][j][k] = cos( iat ) * E_ys_d + sin( iat ) * E_zs_d;
E_z_d[i][j][k] = -sin( PAt ) * E_xs_d - sin( iat ) *
cos( PAt ) * E_ys_d + cos( iat ) * cos( PAt ) * E_zs_d;
E_x_d_turb[i][j][k] = sqrt(1./3.) * E_d_turb;
E_y_d_turb[i][j][k] = sqrt(1./3.) * E_d_turb;
E_z_d_turb[i][j][k] = sqrt(1./3.) * E_d_turb;
E_xs_h = E_R_h * cos( phi ) - E_phi_h * sin( phi );
E_ys_h = E_R_h * sin( phi ) + E_phi_h * cos( phi );
E_x_h[i][j][k] = cos( PAt ) * E_xs_h - sin( PAt ) *
sin( iat ) * E_ys_h + sin( PAt ) * cos ( iat ) * E_zs_h;
E_y_h[i][j][k] = cos( iat ) * E_ys_h + sin( iat ) * E_zs_h;
E_z_h[i][j][k] = -sin( PAt ) * E_xs_h - sin( iat ) *
cos( PAt ) * E_ys_h + cos( iat ) * cos( PAt ) * E_zs_h;
E_x_h_turb[i][j][k] = sqrt(1./3.) * E_h_turb;
E_y_h_turb[i][j][k] = sqrt(1./3.) * E_h_turb;
E_z_h_turb[i][j][k] = sqrt(1./3.) * E_h_turb;
psi_d[i][j][k] = atan2(-E_x_d[i][j][k], E_z_d[i][j][k]) -
PI / 2.0;
psi_h[i][j][k] = atan2(-E_x_h[i][j][k], E_z_h[i][j][k]) -
PI / 2.0;
ne = ne_0 * exp (-sqrt( pow( z_ss[i][j][k], 2.0 ) ) / h_e) *
exp(-pow( sqrt( pow( x_ss[i][k], 2.0 ) +
pow( y_ss[i][j][k], 2.0 ) ), 2.0 ) /
( 2.0 * pow( sigma_e, 2.0) ) );
delta_phi_1[i][j+1][k] = delta_phi_1[i][j][k] -
0.81 * pow( lambda_1, 2.0) *
( ne + ne_cone ) * (aniso_d * E_y_d[i][j][k] + aniso_h *
E_y_h[i][j][k]) * delta_y;
delta_phi_2[i][j+1][k] = delta_phi_2[i][j][k] -
0.81 * pow( lambda_2, 2.0) *
( ne + ne_cone ) * (aniso_d * E_y_d[i][j][k] + aniso_h *
E_y_h[i][j][k]) * delta_y;
delta_phi_3[i][j+1][k] = delta_phi_3[i][j][k] -
0.81 * pow( lambda_3, 2.0) *
( ne + ne_cone ) * (aniso_d * E_y_d[i][j][k] + aniso_h *
E_y_h[i][j][k]) * delta_y;
delta_phi_o1[i][k] = delta_phi_1[i][10][k] -
delta_phi_2[i][10][k];
/* RM for a Faraday Screen. The "-" corrects that the observer is at the front side of the cube. */
RM_2[i][k] = RM_2[i][k] - 0.81 *
( ne + ne_cone ) * (aniso_d * E_y_d[i][j][k] + aniso_h *
E_y_h[i][j][k])* delta_y;
}
}
}
for (i=1; i <= gs; i++)
{
for (k=1; k <= gs; k++)
{
TP[i][k] = 0.0;
Q_0[i][k] = 0.0;
U_0[i][k] = 0.0;
Q_1[i][k] = 0.0;
U_1[i][k] = 0.0;
Q_2[i][k] = 0.0;
U_2[i][k] = 0.0;
Q_3[i][k] = 0.0;
U_3[i][k] = 0.0;
Et[i][k] = 0.0;
RM[i][k] = 0.0;
for (j=1; j <= gs; j++)
{
psi_1_d = psi_d[i][j][k] + delta_phi_1[i][j][k];
psi_2_d = psi_d[i][j][k] + delta_phi_2[i][j][k];
psi_3_d = psi_d[i][j][k] + delta_phi_3[i][j][k];
psi_1_h = psi_h[i][j][k] + delta_phi_1[i][j][k];
psi_2_h = psi_h[i][j][k] + delta_phi_2[i][j][k];
psi_3_h = psi_h[i][j][k] + delta_phi_3[i][j][k];
if (equipartition == 1)
n_CR = (pow( E_x_d[i][j][k], 2.0 ) +
pow( E_y_d[i][j][k], 2.0 ) +
pow( E_z_d[i][j][k], 2.0 ) +
pow( E_x_h[i][j][k], 2.0 ) +
pow( E_y_h[i][j][k], 2.0 ) +
pow( E_z_h[i][j][k], 2.0 ) +
pow( E_x_d_turb[i][j][k], 2.0 ) +
pow( E_y_d_turb[i][j][k], 2.0 ) +
pow( E_z_d_turb[i][j][k], 2.0 ) +
pow( E_x_h_turb[i][j][k], 2.0 ) +
pow( E_y_h_turb[i][j][k], 2.0 ) +
pow( E_z_h_turb[i][j][k], 2.0 ) ) /
pow(E_d0 + E_h0 + E_d_turb_0 + E_h_turb_0, 2.0);
else if ( cone == 1 )
{
r1 = fabs ( z_ss[i][j][k] ) *
sqrt ( 1.0 / pow ( cos ( beta ), 2.0 )
- 1.0 )
+ l_fil - d_fil / (2.0 * cos (beta) );
r2 = r1 + d_fil / cos (beta);