-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathpostproc.c
More file actions
3333 lines (2735 loc) · 89.4 KB
/
postproc.c
File metadata and controls
3333 lines (2735 loc) · 89.4 KB
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
/*! \file postproc.c
\brief Routines for postprocessing, used both on the go and separately
*/
#include "ko.h"
/*********************************************/
//int calc_radialprofiles(ldouble profiles[][NX])
/* calculates radial profiles - L(r) etc. */
/* uses mostly primitives, but may use avg quantities as well */
/* however, this part would work only when postprocessing with */
/* ./avg, otherwise pavg hold non-normalized numbers */
//surface density (2) (column)
//rest mass flux (3)
//rho-weighted minus radial velocity (4)
//<u_phi>* (5)
//Keplerian u_phi (6)
//abs optical depth (7)
//tot optical depth (8)
//net accretion rate at given radius (9)
//inflow accretion rate at given radius (10)
//outflow accretion rate at given radius (11)
//luminosity at given radius opt. thin (12)
//location of the photosphere (13)
//total mhd energy flux (14)
//outflowin mhd energy flux (15)
//jet mhd energy flux (16)
//total rad energy flux (17)
//outflowin rad energy flux (18)
//jet rad energy flux (19)
//outflowing mass flux (20)
//jet mass flux (21)
//luminosity at given radius everywhere (22)
//surface density in the inflow (23)
//rho-weighted minus radial velocity in the inflow (24)
//opt thin mhd energy flux (25)
//opt. thin rad energy flux (26)
//opt. thin mass flux (27)
//rho-weighted qtheta (28)
//rho-weighted temperature (29)
//rho-weighted magn.field angle <sqrt(grr gphph)b^r b^ph> / <bsq> (30)
//scale-height (31)
//rho-weighted beta (32)
//rho-wighted prad/pgas (33)
//alpha (34)
//rad. viscosity energy flux (35)
//rho-weighted minus radial velocity in the outflow (36) -> rho-weighted eccentricity for problem 87
//conserved flux rho ur transformed to OUTCOORDS (37)
//conserved flux rho ur in MYCOORDS (38)
//conserved flux rho ur+Trt in MYCOORDS (39)
//conserved flux for Rrt int MYCOORDS (40)
//surface density of energy for Be<0. = int (Ehat + uint) (41)
//rho-weighted radial velocity in the jet (42)
//magnetic flux in the jet (43)
//kinetic + binding flux in the jet (44)
//radial velocity close to the axis (45)
//rho-weighted Bernoulli (46)
//rho-weighted qphi (47)
//magnetic flux everywhere (48)
//kinetic flux everywhere (49)
//radial profiles of rho-weighted radiation temperature (50)
//<u_phi> in the outflow (51)
//integrated heating/cooling rate fluid frame G^t (52)
//energy-averaged radial transport velocity (53)
//energy-averaged vertical transport velocity (54)
//inclination angle of the integrated angular momentum vector (55)
//thermal energy flux everywhere (56)
//convective hydro luminosity (57)
//integrated T^r_phi (58)
//rho-weighted Bernoulli without thermal component (59)
//average dissipation (60)
//jet CM X (61) (see code comparison document)
//jet CM Y (62)
//jet Ixx (63)
//jet Iyy (64)
//jet Ixy (65)
//jet Area (66)
/*********************************************/
int calc_radialprofiles(ldouble profiles[][NX])
{
//adjust NRADPROFILES in problem.h
#ifdef CONSISTENTGAMMA
if(PROCID==0) printf("1 gammas not consistent in postprocessing when CONSISTENTGAMMA\n");
#endif
//calculates scale-height etc.
calc_avgs_throughout();
int ix;
//define extra quantities for problem 134
ldouble normalize[NX], rho134[NX], pgas134[NX], bfield134[NX], uconphi134[NX], ptot134[NX], betainv134[NX],scaleheight134[NX],rholambda134[NX];
ldouble thetamin_134=M_PI/3.;
ldouble thetamax_134=2*M_PI/3.;
ldouble sigmagdet[NX];
//search for appropriate radial index
#pragma omp parallel for private(ix)
for(ix=0;ix<NX;ix++)
{
int iy,iz,iv,i,j;
ldouble x0[3],x0l[3],x0r[3],xm1[3],xp1[3];
ldouble dx0, dxm2, dxm1, dxp1, dxp2;
ldouble xx[4],xxBL[4],dx[3],dxph[3],dxcgs[3],mdot,rho,rhouconrcons,uint,temp,temprad,ucon[4],utcon[4],ucon3[4],TttBe,TttBenoth;
ldouble rhoucont,enden,rhouconr,rhouconrucovphi,Tij[4][4],Tij22[4][4],Rij[4][4],Rviscij[4][4],Trt,Trphi,Fluxx[NV],Rrt,Rtt,Ttt,Rviscrt,bsq,bcon[4],bcov[4];
ldouble Trtmagn,Trtkin,Trtuint,endensimple,endenuconr,endenuconth,Omega;
ldouble ucov[4],pp[NV],gg[4][5],GG[4][5],ggBL[4][5],GGBL[4][5],Ehat;
ldouble tautot,tautotloc,tauabs,tauabsloc;
ldouble avgsums[NV+NAVGVARS][NX];
ldouble Bangle1,Bangle2,brbphi;
ldouble diffflux[NV];
ldouble fd_u0[NV],fd_up1[NV],fd_up2[NV],fd_um1[NV],fd_um2[NV];
ldouble fd_p0[NV],fd_pp1[NV],fd_pp2[NV],fd_pm1[NV],fd_pm2[NV],fd_pm3[NV],fd_pp3[NV];
ldouble fd_pl[NV],fd_pr[NV],fd_plm1[NV],fd_prm1[NV],fd_plp1[NV],fd_prp1[NV];
ldouble fd_ul[NV],fd_ur[NV],fd_ulm1[NV],fd_urm1[NV],fd_ulp1[NV],fd_urp1[NV];
ldouble du[NV],dul[NV],dur[NV],aaa[24],ahd,arad,Jvec[3];
ldouble Gi[4],Giff[4];
//vertically integrated/averaged profiles
for(iv=0;iv<NRADPROFILES;iv++)
profiles[iv][ix]=0.;
Jvec[0]=Jvec[1]=Jvec[2]=0.;
//keep track of extra quantities for problem 134/139
if (PROBLEM == 134 || PROBLEM == 139)
{
normalize[ix] = 0.;
rho134[ix] = 0.;
pgas134[ix] = 0.;
bfield134[ix] = 0.;
uconphi134[ix] = 0.;
ptot134[ix] = 0.;
betainv134[ix] = 0.;
scaleheight134[ix]=0.;
rholambda134[ix]=0.;
}
//outside horizon?
struct geometry geomBLtemp;
fill_geometry_arb(ix,0,0,&geomBLtemp,OUTCOORDS);
if(geomBLtemp.xx<=1.1*rhorizonBL) continue; //to avoid working inside horizon
Bangle1=Bangle2=0.;
sigmagdet[ix]=0.;
ldouble jetsigma=0.;
for(iv=0;iv<NAVGVARS;iv++)
avgsums[iv][ix]=0.;
tautot=tauabs=0.;
for(iz=0;iz<NZ;iz++)
{
for(iy=0;iy<NY;iy++)
{
//metric
pick_g(ix,iy,iz,gg);
pick_G(ix,iy,iz,GG);
// cell center geometries
struct geometry geom;
fill_geometry_arb(ix,iy,iz,&geom,MYCOORDS);
struct geometry geomm1;
fill_geometry_arb(ix-1,iy,iz,&geomm1,MYCOORDS);
struct geometry geomp1;
fill_geometry_arb(ix+1,iy,iz,&geomp1,MYCOORDS);
struct geometry geomBL;
fill_geometry_arb(ix,iy,iz,&geomBL,OUTCOORDS);
struct geometry geomBLm1;
fill_geometry_arb(ix-1,iy,iz,&geomBLm1,OUTCOORDS);
struct geometry geomBLp1;
fill_geometry_arb(ix+1,iy,iz,&geomBLp1,OUTCOORDS);
// face geometries
struct geometry geoml;
fill_geometry_face(ix,iy,iz,0,&geoml);
struct geometry geomr;
fill_geometry_face(ix+1,iy,iz,0,&geomr);
struct geometry geomBLl;
fill_geometry_face_arb(ix,iy,iz,0,&geomBLl,OUTCOORDS);
struct geometry geomBLr;
fill_geometry_face_arb(ix+1,iy,iz,0,&geomBLr,OUTCOORDS);
ldouble gdetuBL=geomBL.gdet;
#ifdef RADOUTPUTWITHINDISK
if(fabs(geomBL.yy-M_PI/2)>scaleth_otg[ix])
continue;
#endif
#ifdef RADOUTPUTWITHINDTHETA // this limits the theta integral
if(fabs(geomBL.yy-M_PI/2)>RADOUTPUTWITHINDTHETA)
continue;
#endif
#if (GDETIN==0) //gdet out of derivatives
gdetuBL=1.;
#endif
//coordinates
get_xx(ix,iy,iz,xx);
#ifdef PRECOMPUTE_MY2OUT
get_xxout(ix, iy, iz, xxBL);
#else
coco_N(xx,xxBL,MYCOORDS,OUTCOORDS);
#endif
//cell dimensions
get_cellsize_out(ix, iy, iz, dx);
if(NZ==1)
{
dx[2]=2.*M_PI;
}
else
{
#ifdef PHIWEDGE
dx[2]*=(2.*M_PI/PHIWEDGE);
#endif
}
ldouble dxph[3];
dxph[0]=dx[0]*sqrt(geomBL.gg[1][1]);
dxph[1]=dx[1]*sqrt(geomBL.gg[2][2]);
dxph[2]=dx[2]*sqrt(geomBL.gg[3][3]);
//primitives at the cell - either averaged or original, in BL or MYCOORDS
for(iv=0;iv<NV;iv++)
{
pp[iv]=get_u(p,iv,ix,iy,iz);
}
#ifdef CONSERVED_FLUX_OUTPUT
// These are all defined on the face, so we can't use precomputed
// can take a long time and don't seem necessary in radial profiles
//primitives at radial neighbours
for(i=0;i<NV;i++)
{
fd_p0[i]=pp[i];
fd_pp1[i]=get_u(p,i,ix+1,iy,iz);
fd_pm1[i]=get_u(p,i,ix-1,iy,iz);
fd_pm2[i]=get_u(p,i,ix-2,iy,iz);
fd_pp2[i]=get_u(p,i,ix+2,iy,iz);
}
//internal coordinates
x0[0]=get_x(ix,0);
x0l[0]=get_xb(ix,0);
xm1[0]=get_x(ix-1,0);
x0l[1]=xm1[1]=get_x(iy,1);
x0l[2]=xm1[2]=get_x(iz,2);
x0r[0]=get_xb(ix+1,0);
xp1[0]=get_x(ix+1,0);
x0r[1]=xp1[1]=get_x(iy,1);
x0r[2]=xp1[2]=get_x(iz,2);
dx0=get_size_x(ix,0);
dxm1=get_size_x(ix-1,0);
dxp1=get_size_x(ix+1,0);
//interpolation to get left/right biased interpolated primtives
avg2point(fd_pm2,fd_pm1,fd_p0,fd_pp1,fd_pp2,fd_pl,fd_pr,dxm2,dxm1,dx0,dxp1,dxp2,0,MINMOD_THETA);
avg2point(fd_pm1,fd_p0,fd_pp1,fd_pp2,fd_pp2,fd_plp1,fd_prp1,dxm1,dx0,dxp1,dxp2,dxp2,0,MINMOD_THETA);
avg2point(fd_pm2,fd_pm2,fd_pm1,fd_p0,fd_pp1,fd_plm1,fd_prm1,dxm2,dxm2,dxm1,dx0,dxp1,0,MINMOD_THETA);
trans_pall_coco(fd_pl,fd_pl,MYCOORDS,OUTCOORDS,xx,&geoml,&geomBLl);
trans_pall_coco(fd_pr,fd_pr,MYCOORDS,OUTCOORDS,xx,&geomr,&geomBLr);
trans_pall_coco(fd_plp1,fd_plp1,MYCOORDS,OUTCOORDS,xx,&geoml,&geomBLl);
trans_pall_coco(fd_prm1,fd_prm1,MYCOORDS,OUTCOORDS,xx,&geomr,&geomBLr);
#else
for(i=0;i<NV;i++) Fluxx[i]=0.; // no conserved fluxes if this flag is off
#endif
//transforming interpolated primitives to BL
#ifdef PRECOMPUTE_MY2OUT
trans_pall_coco_my2out(pp,pp,&geom,&geomBL);
#else
trans_pall_coco(pp,pp,MYCOORDS,OUTCOORDS,xx,&geom,&geomBL);
#endif
ldouble vischeating=0.;
if(doingavg)
{
rho=get_uavg(pavg,RHO,ix,iy,iz);
uint=get_uavg(pavg,UU,ix,iy,iz);
temp=calc_PEQ_Tfromurho(uint,rho,ix,iy,iz);
bsq=get_uavg(pavg,AVGBSQ,ix,iy,iz);
bcon[0]=get_uavg(pavg,AVGBCON(0),ix,iy,iz);
bcon[1]=get_uavg(pavg,AVGBCON(1),ix,iy,iz);
bcon[2]=get_uavg(pavg,AVGBCON(2),ix,iy,iz);
bcon[3]=get_uavg(pavg,AVGBCON(3),ix,iy,iz);
utcon[0]=get_uavg(pavg,AVGRHOUCON(0),ix,iy,iz)/get_uavg(pavg,RHO,ix,iy,iz);
utcon[1]=get_uavg(pavg,AVGRHOUCON(1),ix,iy,iz)/get_uavg(pavg,RHO,ix,iy,iz);
utcon[2]=get_uavg(pavg,AVGRHOUCON(2),ix,iy,iz)/get_uavg(pavg,RHO,ix,iy,iz);
utcon[3]=get_uavg(pavg,AVGRHOUCON(3),ix,iy,iz)/get_uavg(pavg,RHO,ix,iy,iz);
vischeating=get_uavg(pavg,AVGVISCHEATING,ix,iy,iz);
ldouble uconpp[4]={utcon[0],utcon[1],utcon[2],utcon[3]};
conv_vels(uconpp,uconpp,VEL4,VEL4,geomBL.gg,geomBL.GG);
conv_vels(uconpp,uconpp,VEL4,VELPRIM,geomBL.gg,geomBL.GG);
pp[VX]=uconpp[1];
pp[VY]=uconpp[2];
pp[VZ]=uconpp[3];
Omega=utcon[3]/utcon[0];
rhouconr=get_uavg(pavg,AVGRHOUCON(1),ix,iy,iz);
rhoucont=get_uavg(pavg,AVGRHOUCON(0),ix,iy,iz);
endenuconr = get_uavg(pavg,AVGUUUCON(1),ix,iy,iz) * sqrt(geomBL.gg[1][1]);
endenuconth = get_uavg(pavg,AVGUUUCON(2),ix,iy,iz) * sqrt(geomBL.gg[2][2]);
rhouconrcons=get_uavg(pavg,AVGRHOURDIFF,ix,iy,iz);
rhouconrucovphi=get_uavg(pavg,AVGRHOUCONUCOV(1,3),ix,iy,iz);
TttBe=get_uavg(pavg,AVGRHOUCONUCOV(0,0),ix,iy,iz)
+ GAMMA*get_uavg(pavg,AVGUUUCONUCOV(0,0),ix,iy,iz)
+ get_uavg(pavg,AVGBSQUCONUCOV(0,0),ix,iy,iz)
- get_uavg(pavg,AVGBCONBCOV(0,0),ix,iy,iz);
TttBenoth=get_uavg(pavg,AVGRHOUCONUCOV(0,0),ix,iy,iz);
for(i=0;i<4;i++)
for(j=0;j<4;j++)
Tij[i][j]=get_uavg(pavg,AVGTIJ(i,j),ix,iy,iz);
for(i=0;i<NV;i++)
Fluxx[i]=get_uavg(pavg,AVGFLUXXL(i),ix,iy,iz);
Trphi=Tij[1][3];
Trt=Tij[1][0];
Ttt=Tij[0][0];
enden = Tij[0][0]+rhoucont;
endensimple = uint;
Trtmagn = get_uavg(pavg,AVGBSQUCONUCOV(1,0),ix,iy,iz)
- get_uavg(pavg,AVGBCONBCOV(1,0),ix,iy,iz);
Trtkin = get_uavg(pavg,AVGRHOUCONUCOV(1,0),ix,iy,iz);
Trtuint = get_uavg(pavg,AVGUUUCONUCOV(1,0),ix,iy,iz);
indices_2122(Tij,Tij22,geomBL.GG);
#ifdef RADIATION
for(i=0;i<4;i++)
for(j=0;j<4;j++)
Rij[i][j]=get_uavg(pavg,AVGRIJ(i,j),ix,iy,iz);
enden += Rij[0][0];
Rrt = Rij[1][0];
Rtt = Rij[0][0];
Ehat = get_uavg(pavg,AVGEHAT,ix,iy,iz);
temprad=calc_ncompt_Thatrad_fromEN(Ehat,get_uavg(pavg,AVGNFHAT,ix,iy,iz));
endensimple+=Ehat;
endenuconr += get_uavg(pavg,AVGEHATUCON(1),ix,iy,iz) * sqrt(geomBL.gg[1][1]);
endenuconth += get_uavg(pavg,AVGEHATUCON(2),ix,iy,iz) * sqrt(geomBL.gg[2][2]);
int derdir[3]={0,0,0};
calc_Rij_visc(pp,&geomBL,Rviscij,derdir);
Rviscrt = Rviscij[1][0];
for(iv=0;iv<4;iv++)
Giff[iv]=get_uavg(pavg,AVGGHAT(iv),ix,iy,iz);
#endif
//no need of transforming interpolated primitives to BL, already there
} // end if(doingavg)
else //on the go from the primitives
{
rho=pp[RHO];
uint=pp[UU];
utcon[1]=pp[VX];
utcon[2]=pp[VY];
utcon[3]=pp[VZ];
temp=calc_PEQ_Tfromurho(uint,rho,ix,iy,iz);
#ifdef MAGNFIELD
calc_bcon_prim(pp,bcon,&geomBL);
indices_21(bcon,bcov,geomBL.gg);
bsq = dotB(bcon,bcov);
#endif
conv_vels_both(utcon,utcon,ucov,VELPRIM,VEL4,geomBL.gg,geomBL.GG);
Omega=utcon[3]/utcon[0];
rhouconr=rhouconrcons=rho*utcon[1];
endenuconr = uint*utcon[1]* sqrt(geomBL.gg[1][1]);
endenuconth = uint*utcon[2]* sqrt(geomBL.gg[2][2]);
calc_Tij(pp,&geomBL,Tij22);
indices_2221(Tij22,Tij,geomBL.gg);
Trphi=Tij[1][3];
Trt = Tij[1][0];
Ttt = Tij[0][0];
TttBe=Ttt-(GAMMAM1*uint+bsq/2.);
TttBenoth= rho*utcon[0]*ucov[0];
Trtmagn = bsq*utcon[1]*ucov[0] - bcon[1]*bcov[0];
Trtkin = rho*utcon[1]*ucov[0];
Trtuint = uint*utcon[1]*ucov[0];
enden = Tij[0][0] + rho*utcon[0];
endensimple = uint;
#ifdef RADIATION
calc_Rij(pp,&geomBL,Rij);
indices_2221(Rij,Rij,geomBL.gg);
Rrt = Rij[1][0];
Rtt = Rij[0][0];
ldouble Rtthat,uconr[4];
calc_ff_Rtt(&get_u(p,0,ix,iy,iz),&Rtthat,uconr,&geomBL);
Ehat=-Rtthat;
enden+=Rij[0][0];
endensimple+=Ehat;
endenuconr+=Ehat*ucon[1]*sqrt(geomBL.gg[1][1]);
endenuconth+=Ehat*ucon[2]*sqrt(geomBL.gg[2][2]);
int derdir[3]={0,0,0};
calc_Rij_visc(pp,&geomBL,Rviscij,derdir);
Rviscrt = Rviscij[1][0];
//lab-frame four fource
calc_Gi(pp,&geomBL,Gi,0.0, 1, 0);//ANDREW Lab frame=1
boost2_lab2ff(Gi,Giff,pp,geomBL.gg,geomBL.GG);
#endif
#ifdef CONSERVED_FLUX_OUTPUT
//estimating the diffusive flux
//to conserved
p2u(fd_pl,fd_ul,&geomBLl);
p2u(fd_pr,fd_ur,&geomBLr);
p2u(fd_plp1,fd_ulp1,&geomBLr);
p2u(fd_prm1,fd_urm1,&geomBLl);
//gradient of conserved
PLOOP(iv)
{
//getting rid of gdetu in conserved - integrated with gdet lateron
dul[iv]=fd_ul[iv]-fd_urm1[iv];
dur[iv]=fd_ulp1[iv]-fd_ur[iv];
du[iv]=.5*(dul[iv]+dur[iv]);
du[iv]/=gdetuBL;
}
//wavespeeds
calc_wavespeeds_lr_pure(pp,&geomBL,aaa);
ahd=my_max(fabs(aaa[0]),fabs(aaa[1]));
arad=my_max(fabs(aaa[6]),fabs(aaa[7]));
//diffusive flux
PLOOP(iv)
{
if(iv<NVMHD) diffflux[iv]=-0.5*ahd*du[iv];
else diffflux[iv]=-0.5*arad*du[iv];
}
//adding up to the conserved fluxes
Fluxx[RHO]=geomBL.gdet*(rhouconr+diffflux[RHO]);
Fluxx[UU]=geomBL.gdet*(rhouconr+Trt+diffflux[UU]);
#ifdef RADIATION
Fluxx[EE0]=geomBL.gdet*(Rrt+diffflux[EE0]);
#endif
#endif //CONSERVED_FLUX_OUTPUT
} // end on the go from primitives
ldouble muBe,Be,Benoth,betagamma2;
betagamma2=(-Trt/rhouconr)*(-Trt/rhouconr) - 1.;
muBe=-(Trt+rhouconr)/rhouconr;
Be=-(TttBe+rhoucont)/rhoucont;
Benoth=-(TttBenoth+rhoucont)/rhoucont;
#ifdef RADIATION
muBe+=-Rrt/rhouconr;
Be+=-Rtt/rhoucont;
#endif
int isjet;
//old criterion based on Bernoulli
//if(muBe>0.05 && (xxBL[2]<M_PI/4. || xxBL[2]>3.*M_PI/4.))
// isjet=1;
//new criterion based on beta*gamma
if(betagamma2>1. && xxBL[2]<M_PI/3.) // top jet only
isjet=1;
else
isjet=0;
ldouble pregas = GAMMAM1*uint;
ldouble ptot = pregas;
#ifdef MAGNFIELD
ptot+=bsq/2.;
#endif
#ifdef RADIATION
ldouble prerad = Ehat/3.;
ptot+=prerad;
#endif
//alpha
boost22_lab2ff(Tij22,Tij22,pp,geomBL.gg,geomBL.GG);
ldouble alpha=sqrt(geomBL.gg[1][1]*geomBL.gg[3][3])*Tij22[1][3]/ptot;
//angular velocity
ldouble Omega=utcon[3]/utcon[0];
//MRI resolution parameters
ldouble qtheta,qphi;
calc_Qthetaphi(ix,iy,iz,&qtheta,&qphi);
//to calculate magn. field angle
//bsq and brbphi taken from avg if neeeded
ldouble bconfake[4],bcovfake[4],bsqfake;
calc_angle_brbphibsq(ix,iy,iz,&brbphi,&bsqfake,bconfake,bcovfake);
Bangle1+=rho*brbphi*dxph[1];
Bangle2+=rho*bsq*dxph[1];
//optical depths
struct opacities opac;
ldouble tauabsloc = utcon[0]*calc_kappa(pp,&geomBL,&opac);
ldouble tautotloc = utcon[0]*calc_kappaes(pp,&geomBL);
tautot+=tautotloc*dxph[1];
tauabs+=tauabsloc*dxph[1];
//alpha (34) (column)
profiles[32][ix]+=alpha*rho*dxph[1];
//rho-weighted beta (32)
ldouble prermhd = GAMMAM1*uint;
#ifdef RADIATION
prermhd+=Ehat/3.;
#endif
ldouble ibeta=bsq/2./(prermhd+bsq/2.);
profiles[30][ix]+=rho*ibeta*dxph[1];
if (PROBLEM==93){
profiles[57][ix]+=bsq/2.*dxph[1];
profiles[58][ix]+=prermhd*dxph[1];
}
//rho-weighted prad/pgas (33)
#ifdef RADIATION
profiles[31][ix]+=rho*prerad/(pregas+prerad+0.5*bsq)*dxph[1];
#else
profiles[31][ix]+=0.;
#endif
//surface density (2) (column)
profiles[0][ix]+=rho*dxph[1];
//surface energy density (41)
if(muBe<0.)
profiles[39][ix]+=endensimple*dxph[1];
//numerator of scale height (31) (column)
#ifndef CALCHRONTHEGO
profiles[29][ix]+=rho*dxph[1]*pow(tan(fabs(M_PI/2.-xxBL[2])),2.);
#endif
//rho-weighted q-theta (28)
profiles[26][ix]+=rho*qtheta*dxph[1];
//rho-weighted q-phi (47)
profiles[45][ix]+=rho*qphi*dxph[1];
//rho-weighted temperature (29)
profiles[27][ix]+=rho*temp*dxph[1];
//rho-weighted rad temperature (50)
profiles[48][ix]+=rho*temprad*dxph[1];
//rest mass flux (3)
profiles[1][ix]+=-rhouconr*dx[1]*dx[2]*geomBL.gdet;
//conserved flux (rhour) transformed to OUTCOORDS (may be imprecise) (37)
profiles[35][ix]+=-rhouconrcons*dx[1]*dx[2];
//conserved flux (gdet rhour) in MYCOORDS (38)
profiles[36][ix]+=-Fluxx[RHO]*get_size_x(iy,1)*dx[2];
//conserved flux for Trt (39) in MYCOORDS
profiles[37][ix]+=-Fluxx[UU]*get_size_x(iy,1)*dx[2];
//temporary surface density to normalize scale height
sigmagdet[ix] +=rho*dx[1]*dx[2]*geomBL.gdet;
//scale height using code comparison paper defn;
scaleheight134[ix] += rho*fabs(0.5*M_PI - xxBL[2]) * dx[1]*dx[2]*geomBL.gdet;
//density-weighted MRI wavelength using code comparison paper defn
ldouble lambdaMRI = 2*M_PI * fabs(bcon[2]) / sqrt(bsq + rho + uint + pregas) / fabs(Omega);
rholambda134[ix] += rho*lambdaMRI* dx[1]*dx[2]*geomBL.gdet;
//total mhd energy flux (14)
profiles[12][ix]+=(-Trt)*dx[1]*dx[2]*geomBL.gdet;
//convective mhd energy flux (57)
profiles[55][ix]+=rhouconr/rho*(Ttt)*dx[1]*dx[2]*geomBL.gdet;
//integrated Trphi (58)
profiles[56][ix]+=(Trphi-rhouconrucovphi)*Omega*dx[1]*dx[2]*geomBL.gdet;
//magnetic mhd energy flux in jet (43)
if(isjet==1)
profiles[41][ix]+=(-Trtmagn)*dx[1]*dx[2]*geomBL.gdet;
//kinetic + binding mhd energy flux in jet (44)
if(isjet==1)
profiles[42][ix]+=(-Trtkin)*dx[1]*dx[2]*geomBL.gdet;
//magnetic mhd energy flux (48)
profiles[46][ix]+=(-Trtmagn)*dx[1]*dx[2]*geomBL.gdet;
//kinetic mhd energy flux (49)
profiles[47][ix]+=(-Trtkin)*dx[1]*dx[2]*geomBL.gdet;
//thermal energy flux (56)
profiles[54][ix]+=(-Trtuint)*dx[1]*dx[2]*geomBL.gdet;
//integrated cooling rate (52)
profiles[50][ix]+=Giff[0]*dx[1]*dx[2]*geomBL.gdet;
//opt thin mhd energy flux (25)
if(tautot<1.)
profiles[23][ix]+=(-Trt)*dx[1]*dx[2]*geomBL.gdet;
//outflowin mhd energy flux (15)
if(utcon[1]>0.)
profiles[13][ix]+=(-Trt)*dx[1]*dx[2]*geomBL.gdet;
//jet mhd energy flux (16)
if(isjet==1)
profiles[14][ix]+=(-Trt)*dx[1]*dx[2]*geomBL.gdet;
//jet gas velocity (42)
if(isjet==1)
{
profiles[40][ix]+=rhouconr*dx[1]*dx[2]*geomBL.gdet;
jetsigma+=rho*dx[1]*dx[2]*geomBL.gdet;
}
//gas velocity near the axis (45)
if((doingavg && (iy==NCCORRECTPOLAR+1 || iy==(NY-NCCORRECTPOLAR-2))))
profiles[43][ix]+=0.5*utcon[1];
if((!doingavg && (iy==NCCORRECTPOLAR+1)))
profiles[43][ix]+=utcon[1];
//rho-weighted Bernoulli (46)
profiles[44][ix]+=rho*Be*dxph[1];
//rho-weighted Bernoulli without thermal component (59)
profiles[57][ix]+=rho*Benoth*dxph[1];
//integrated dissipation
profiles[58][ix]+=vischeating*dxph[1];
//projected TOP jet CM and MOI tensor (according to code comparison paper)
//assumes flat space
if(xxBL[2]>0. && xxBL[2]<=thetamin_134)
{
ldouble sigloc = bsq/rho;
ldouble psiloc=0.;
if(sigloc>1) psiloc=1.;
else if(sigloc>0.1) psiloc=sigloc;
ldouble xloc=xxBL[1]*sin(xxBL[2])*cos(xxBL[3]);
ldouble yloc=xxBL[1]*sin(xxBL[2])*sin(xxBL[3]);
ldouble dA=psiloc*xxBL[1]*xxBL[1]*sin(xxBL[2])*cos(xxBL[2])*dx[1]*dx[2];
profiles[59][ix] += xloc*dA;
profiles[60][ix] += yloc*dA;
profiles[61][ix] += xloc*xloc*dA;
profiles[62][ix] += yloc*yloc*dA;
profiles[63][ix] += xloc*yloc*dA;
profiles[64][ix] += dA;
}
#ifdef RADIATION
//total rad energy flux (17)
profiles[15][ix]+=(-Rrt)*dx[1]*dx[2]*geomBL.gdet;
//conserved flux for Rrt in MYCOORDS (40)
profiles[38][ix]+=-Fluxx[EE0]*get_size_x(iy,1)*dx[2];
//rad viscosity energy flux (35)
profiles[33][ix]+=(-Rviscrt)*dx[1]*dx[2]*geomBL.gdet;
//opt. thin rad energy flux (26)
if(tautot<1.)
profiles[24][ix]+=(-Rrt)*dx[1]*dx[2]*geomBL.gdet;
//outflowin rad energy flux (18)
if(utcon[1]>0.)
profiles[16][ix]+=(-Rrt)*dx[1]*dx[2]*geomBL.gdet;
//jet rad energy flux (19)
if(isjet==1)
profiles[17][ix]+=(-Rrt)*dx[1]*dx[2]*geomBL.gdet;
#endif
//outflowin mass flux (20)
if(utcon[1]>0.)
profiles[18][ix]+=(-rhouconr)*dx[1]*dx[2]*geomBL.gdet;
//opt. thin mass flux (27)
if(tautot<1.)
profiles[25][ix]+=(-rhouconr)*dx[1]*dx[2]*geomBL.gdet;
//jet mass flux (21)
if(isjet==1)
profiles[19][ix]+=(-rhouconr)*dx[1]*dx[2]*geomBL.gdet;
//rho-weighted minus radial velocity (4)
profiles[2][ix]+=-rhouconr*dxph[1];
//energy-averaged radial transport velocity (53)
if(Be<0.)
profiles[51][ix]+=endenuconr*dxph[1];
//energy-averaged vertical transport velocity (54)
if(Be<0.)
profiles[52][ix]+=my_sign(geomBL.xxvec[2]-M_PI/2.)*endenuconth*dxph[1];
//rho-weighted minus radial velocity in the inflow (24)
if(utcon[1]<0.)
profiles[22][ix]+=-rhouconr*dxph[1];
#if(PROBLEM==87)
ldouble angmomR = ucov[3];
ldouble epsR =-(1.+ucov[0]);
ldouble eccR = 2.*angmomR*angmomR*epsR;
if(eccR > -1.)
{
profiles[34][ix]+= rho*dxph[1]*sqrt(1. - 2.*ucov[3]*ucov[3]*(1.+ucov[0]));
profiles[21][ix]+= rho*dxph[1];
}
#else
//surface density in the inflow (23)
if(utcon[1]<0.)
profiles[21][ix]+=rho*dxph[1];
//rho-weighted minus radial velocity in the outflow (36)
if(utcon[1]>0.)
profiles[34][ix]+=rhouconr*dxph[1];
#endif
//abs optical depth (7)
profiles[5][ix]=tauabs;
//tot optical depth (8)
profiles[6][ix]=tautot;
for(iv=0;iv<NV+NAVGVARS;iv++)
avgsums[iv][ix]+=get_uavg(pavg,iv,ix,iy,iz)*dxph[1];
//summing up 3d angular momentum
ldouble Jx,Jy,Jz,th,ph,r;
ldouble xxveccar[4],velvec[3],posvec[3],jvec[3];
r=geomBL.xx;
th=geomBL.yy;
ph=geomBL.zz;
coco_N(geomBL.xxvec,xxveccar,BLCOORDS,MINKCOORDS);
posvec[0]=xxveccar[1];
posvec[1]=xxveccar[2];
posvec[2]=xxveccar[3];
velvec[0]=sin(th)*cos(ph)*rho*utcon[1]
+ cos(th)*cos(ph)*rho*utcon[2]
- sin(ph)*rho*utcon[3];
velvec[1] = sin(th)*sin(ph)*rho*utcon[1]
+ cos(th)*sin(ph)*rho*utcon[2]
+ cos(ph)*rho*utcon[3];
velvec[1]*=r;
velvec[2] = cos(th)*rho*utcon[1]
- sin(th)*rho*utcon[2];
velvec[2]*=r*sin(th);
jvec[0]=posvec[1]*velvec[2]-posvec[2]*velvec[1];
jvec[1]=-(posvec[0]*velvec[2]-posvec[2]*velvec[0]);
jvec[2]=posvec[0]*velvec[1]-posvec[1]*velvec[0];
Jvec[0]+=jvec[0];
Jvec[1]+=jvec[1];
Jvec[2]+=jvec[2];
//u_phi everywhere (5)
//if(utcon[1]<0.)
{
if(doingavg)
profiles[3][ix]+=get_uavg(pavg,AVGRHOUCOV(3),ix,iy,iz)*dxph[1];
else
profiles[3][ix]+=rho*ucov[3]*dxph[1];
}
//in the outflow (51)
if(utcon[1]>0.)
{
if(doingavg)
profiles[49][ix]+=get_uavg(pavg,AVGRHOUCOV(3),ix,iy,iz)*dxph[1];
else
profiles[49][ix]+=rho*ucov[3]*dxph[1];
}
// special quantities for problem 134//139
if (PROBLEM == 134 || PROBLEM == 139)
{
if(xxBL[2]<thetamax_134 && xxBL[2]>thetamin_134)
{
normalize[ix] += dx[1] * dx[2] * geomBL.gdet;
rho134[ix] += rho * dx[1] * dx[2] * geomBL.gdet;
ldouble pgass = uint * (GAMMA - 1.);
pgas134[ix] += pgass * dx[1] * dx[2] * geomBL.gdet;
bfield134[ix] += sqrt(bsq) * dx[1] * dx[2] * geomBL.gdet;
uconphi134[ix] += utcon[3] * dx[1] * dx[2] * geomBL.gdet;
ptot134[ix] += (pgass + (bsq/2.)) * dx[1] * dx[2] * geomBL.gdet;
betainv134[ix] += (0.5 * bsq / pgass) * dx[1] * dx[2] * geomBL.gdet;
}
}
} // end for(iy=0;iy<NY;iy++)
} // end for(iz=0;iz<NZ;iz++)
//calculating angle between the total angular momentum vector at this radius and the axis
ldouble angle = acos( (Jvec[2])/(sqrt(Jvec[0]*Jvec[0]+Jvec[1]*Jvec[1]+Jvec[2]*Jvec[2])));
profiles[53][ix]=angle;
//normalizing by sigma
ldouble sigmaout=profiles[0][ix]-profiles[21][ix];
ldouble sigmain=profiles[21][ix];
profiles[2][ix]/=profiles[0][ix]; //total
profiles[51][ix]/=profiles[39][ix];
profiles[52][ix]/=profiles[39][ix];
profiles[49][ix]/=sigmaout; //normalized by surface density in the outlfow
profiles[22][ix]/=profiles[21][ix]; //sigma in
#if(PROBLEM==87)
profiles[34][ix]/=profiles[21][ix];
#else
profiles[34][ix]/=sigmaout;
#endif
profiles[26][ix]/=profiles[0][ix];
profiles[49][ix]/=(profiles[0][ix]-profiles[21][ix]); //normalized by surface density in the outlfow
profiles[45][ix]/=profiles[0][ix];
profiles[27][ix]/=profiles[0][ix];
profiles[48][ix]/=profiles[0][ix];
profiles[44][ix]/=profiles[0][ix];
profiles[57][ix]/=profiles[0][ix];
#ifndef CALCHRONTHEGO
profiles[29][ix]/=profiles[0][ix];
profiles[29][ix]=sqrt(profiles[29][ix]); //scale height
#else
profiles[29][ix]=scaleth_otg[ix]; //scale height
#endif
profiles[30][ix]/=profiles[0][ix];
profiles[31][ix]/=profiles[0][ix];
profiles[32][ix]/=profiles[0][ix];
profiles[40][ix]/=jetsigma;
Bangle1/=profiles[0][ix];
Bangle2/=profiles[0][ix];
//rho-weighted magn.field angle -<sqrt(grr gphph)b^r b^ph> / <bsq> (30)
profiles[28][ix]=-Bangle1/Bangle2;
//normalizing by <(rho+u+bsq/2)u^r>
profiles[3][ix]/=profiles[0][ix];
//Keplerian u_phi (6)
ldouble r=xxBL[1];
profiles[4][ix]=((r*r-2.*BHSPIN*sqrt(r)+BHSPIN*BHSPIN)/(sqrt(r*(r*r-3.*r+2.*BHSPIN*sqrt(r)))));
//net accretion rate at given radius (9)
profiles[7][ix]=fabs(calc_mdot(xxBL[1],0));
//inflow accretion rate at given radius (10)
profiles[8][ix]=fabs(calc_mdot(xxBL[1],1));
//outflow accretion rate at given radius (11)
profiles[9][ix]=fabs(calc_mdot(xxBL[1],2));
//luminosity at given radius (12) -- outside photosphere
ldouble radlum,totallum;
calc_lum(xxBL[1],0,&radlum,&totallum);
profiles[10][ix]=radlum;
//luminosity at given radius (22) -- everywhere
calc_lum(xxBL[1],1,&radlum,&totallum);
profiles[20][ix]=radlum;
//location of the photosphere (13)
profiles[11][ix]=calc_photloc(ix);
// special quantities for problem 134/139
if (PROBLEM == 134 || PROBLEM == 139)
{
profiles[7][ix] = rho134[ix] / normalize[ix];
profiles[8][ix] = pgas134[ix] / normalize[ix];
profiles[12][ix] = bfield134[ix] / normalize[ix];
profiles[13][ix] = uconphi134[ix] / normalize[ix];
profiles[17][ix] = ptot134[ix] / normalize[ix];
profiles[18][ix] = betainv134[ix] / normalize[ix];
profiles[29][ix] = scaleheight134[ix] / sigmagdet[ix];
profiles[27][ix] = rholambda134[ix] / sigmagdet[ix];
}
// TOP jet profiles
ldouble Ajet = profiles[64][ix];
if (Ajet==0.) Ajet=1.;
profiles[59][ix] /= Ajet;
profiles[60][ix] /= Ajet;
profiles[61][ix] -= (profiles[59][ix]*profiles[59][ix]*Ajet);
profiles[62][ix] -= (profiles[60][ix]*profiles[60][ix]*Ajet);
profiles[63][ix] -= (profiles[59][ix]*profiles[60][ix]*Ajet);
} // end for(ix=0;ix<NX;ix++)
return 0;
}
/*********************************************/
/* calculates theta profiles */
//total energy flux (2) (column)
/*********************************************/
int calc_thetaprofiles(ldouble profiles[][NY])
{
//adjust NTHPROFILES in problem.h
ldouble rho,uint,bsq,bcon[4],bcov[4],utcon[4],ucov[4],rhouconr,rhoucont,rhouconrucovt;
ldouble Tij[4][4],Tij22[4][4],Rij[4][4],Trt,Trtkin,Rrt,Ehat,Rviscij[4][4],Rviscrt,Rtt,Ttt;
ldouble pp[NV];
//choose radius where to extract from
int ix,i,j,iv,iz;
//search for appropriate radial index
ldouble xx[4],xxBL[4];
ldouble radius=1.e3;
#ifdef THPROFRADIUS
radius=THPROFRADIUS;
#endif
for(ix=0;ix<NX;ix++)
{
get_xx(ix,0,0,xx);
#ifdef PRECOMPUTE_MY2OUT
get_xxout(ix, 0, 0, xxBL);
#else
coco_N(xx,xxBL,MYCOORDS,OUTCOORDS);
#endif
if(xxBL[1]>radius) break;
}
int iy;
#pragma omp parallel for private(iy)
for(iy=0;iy<NY;iy++)
{
for(iv=0;iv<NTHPROFILES;iv++)
profiles[iv][iy]=0.;
if(NZ==1) //phi-symmetry
{
iz=0;
struct geometry geomBL;
fill_geometry_arb(ix,iy,iz,&geomBL,OUTCOORDS);
struct geometry geom;
fill_geometry_arb(ix,iy,iz,&geom,MYCOORDS);
//primitives at the cell - either averaged or original, in BL or MYCOORDS
for(iv=0;iv<NV;iv++)
pp[iv]=get_u(p,iv,ix,iy,iz);
//to BL, res-files and primitives in avg in MYCOORDS
#ifdef PRECOMPUTE_MY2OUT
trans_pall_coco_my2out(pp,pp,&geom,&geomBL);
#else
trans_pall_coco(pp, pp, MYCOORDS,OUTCOORDS, xx,&geom,&geomBL);