-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit_iharm2dv3_data.c
159 lines (129 loc) · 3.62 KB
/
init_iharm2dv3_data.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
#include "decs.h"
/*
get iharm3d_v3 simulation data from fname
checks for consistency of coordinates in data file with
values of coordinate parameters
Uses standard iharm3d_v3 data file format
CFG 29 apr 16
*/
extern double ***bcon;
extern double ***bcov;
extern double ***ucon;
extern double ***ucov;
extern double ***p;
extern double **ne;
extern double **thetae;
extern double **b;
void init_harm_data(char *fname)
{
FILE *fp;
double x[4];
int i, j, k ;
/* header variables not used except locally */
double t,tf,cour,DTd,DTl,DTi,dt ;
int nstep,DTr,dump_cnt,image_cnt,rdump_cnt;
double divb,vmin,vmax,gdet ;
double J ;
double dMact, Ladv ;
fp = fopen(fname, "r");
if (fp == NULL) {
fprintf(stderr, "can't open sim data file\n");
exit(1);
} else {
fprintf(stderr,
"successfully opened %s\n",fname);
}
/* get standard HARM header */
fscanf(fp, "%lf ", &t) ;
fscanf(fp, "%d ", &N1) ;
fscanf(fp, "%d ", &N2) ;
fscanf(fp, "%lf ", &startx[1]) ;
fscanf(fp, "%lf ", &startx[2]) ;
fscanf(fp, "%lf ", &dx[1]) ;
fscanf(fp, "%lf ", &dx[2]) ;
fscanf(fp, "%lf ", &tf) ;
fscanf(fp, "%d ", &nstep) ;
fscanf(fp, "%lf ", &gam) ;
fscanf(fp, "%lf ", &cour) ;
fscanf(fp, "%lf ", &DTd) ;
fscanf(fp, "%lf ", &DTl) ;
fscanf(fp, "%lf ", &DTi) ;
fscanf(fp, "%d ", &DTr) ;
fscanf(fp, "%d ", &dump_cnt) ;
fscanf(fp, "%d ", &image_cnt) ;
fscanf(fp, "%d ", &rdump_cnt) ;
fscanf(fp, "%lf ", &dt) ;
double dum;
for(i=0;i<21;i++) fscanf(fp, "%lf",&dum);
/* not set automatically */
a = 0.9375;
Rin = 0.98 * (1. + sqrt(1. - a*a)) ;
Rout = 40.;
hslope = 0.3;
R0 = 0.0;
fprintf(stderr,"coordinate parameters: Rin,Rout,hslope,R0,dx[1],dx[2]: %g %g %g %g %g %g\n",
Rin,Rout,hslope,R0,dx[1],dx[2]) ;
/* nominal non-zero values for axisymmetric simulations */
startx[0] = 0.;
startx[3] = 0.;
stopx[0] = 1. ;
stopx[1] = startx[1] + N1*dx[1] ;
stopx[2] = startx[2] + N2*dx[2] ;
stopx[3] = 2.*M_PI ;
dx[0] = 1. ;
dx[3] = 2.*M_PI;
/* Allocate storage for all model size dependent variables */
init_storage();
dMact = 0. ;
Ladv = 0. ;
for(k = 0 ; k < N1*N2 ; k++) {
j = k%N2 ;
i = (k - j)/N2 ;
fscanf(fp, "%lf %lf ", &x[1], &x[2]);
fscanf(fp, "%lf %lf %lf %lf %lf %lf %lf %lf",
&p[i][j][KRHO],
&p[i][j][UU],
&p[i][j][U1],
&p[i][j][U2],
&p[i][j][U3],
&p[i][j][B1],
&p[i][j][B2],
&p[i][j][B3]);
fscanf(fp, "%lf", &divb);
fscanf(fp, "%lf %lf %lf %lf",
&ucon[i][j][0], &ucon[i][j][1],
&ucon[i][j][2], &ucon[i][j][3]);
fscanf(fp, "%lf %lf %lf %lf", &ucov[i][j][0],
&ucov[i][j][1], &ucov[i][j][2],
&ucov[i][j][3]);
fscanf(fp, "%lf %lf %lf %lf", &bcon[i][j][0],
&bcon[i][j][1], &bcon[i][j][2],
&bcon[i][j][3]);
fscanf(fp, "%lf %lf %lf %lf", &bcov[i][j][0],
&bcov[i][j][1], &bcov[i][j][2],
&bcov[i][j][3]);
fscanf(fp, "%lf ", &vmin);
fscanf(fp, "%lf ", &vmax);
fscanf(fp, "%lf ", &vmin);
fscanf(fp, "%lf ", &vmax);
fscanf(fp, "%lf ", &gdet);
/* additional stuff: current */
fscanf(fp, "%lf ", &J) ;
fscanf(fp, "%lf ", &J) ;
fscanf(fp, "%lf ", &J) ;
fscanf(fp, "%lf ", &J) ;
fscanf(fp, "%lf ", &J) ;
fscanf(fp, "%lf ", &J) ;
fscanf(fp, "%lf ", &J) ;
fscanf(fp, "%lf\n", &J) ;
/* check accretion rate */
if(i <= 20) dMact += gdet * p[i][j][KRHO] * ucon[i][j][1] ;
if(i >= 20 && i < 40) Ladv += gdet * p[i][j][UU] * ucon[i][j][1] * ucov[i][j][0] ;
}
dMact *= dx[3]*dx[2] ;
dMact /= 21. ;
Ladv *= dx[3]*dx[2] ;
Ladv /= 21. ;
fprintf(stderr,"dMact: %g, Ladv: %g\n",dMact,Ladv) ;
/* done! */
}