-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisc_model.c
executable file
·326 lines (295 loc) · 14.3 KB
/
disc_model.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
/*
* model.c
* LIME, The versatile 3D line modeling tool
*
* Created by Christian Brinch on 11/05/07.
* Copyright 2006-2011, Christian Brinch,
* Sterrewacht Leiden,
* Leiden University.
* All rights reserved.
*
*/
#include "lime.h"
//#include "disk.h"
//#include "rho_disk_reduced2.h"
#include "vel.h"
#include "CO.h" //create this header file witht he fits2header.py script froma chemistry fits file
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h> //no idea which of these are need from example so just including them all
#define elements 20971520
#define file 3 //ugly ugly hack, for some reason cant open a file and save its int here or manage to extern it from main, but as it's the only file im opening it *SEEMS* to always be 3 when i open it from main.c so I'll run with it, should ask dan how to do this propperly.
//int file=open("disk.bdat",O_RDONLY);
// double *disk_arr;
// disk_arr= (double*)mmap(0, elements*sizeof(double), PROT_READ, MAP_SHARED,file,0);
// if (disk_arr == MAP_FAILED) {
// close(file);
// perror("Error mmapping the file");
// exit(EXIT_FAILURE);
// } //open and memmap the binary disk array
/******************************************************************************/
void
input(inputPars *par, image *img){
/*
* Basic parameters. See cheat sheet for details.
*/
par->radius = 95*AU;
par->minScale = 2*AU;
par->pIntensity = 30000;
par->sinkPoints = 8000;
par->sampling = 0;
par->dust = "jena_thick_e6.tab";
par->moldatfile[0] = "co.dat"; //replace this with relevent LAMDA file
par->outputfile = "populations.pop";
// par->pregrid = "pregrid.dat";
par->gridfile = "grid.vtk";
//
//Definitions for image #0. Add blocks for additional images.
//
img[0].nchan = 251; // Number of channels
img[0].velres = 75.; // Channel resolution in m/s
img[0].trans = 0; // zero-indexed J quantum number
// img[0].freq = 75.0e9; //central freqency
// img[0].bandwidth = 1500e6;
img[0].pxls = 201; // Pixels per dimension
img[0].imgres = 0.05; // Resolution in arc seconds
img[0].theta = 0.0; // 0: face-on, pi/2: edge-on
img[0].distance = 12.5*PC; // source distance in m
img[0].source_vel = 0; // source velocity in m/s
img[0].unit = 0; // 0:Kelvin 1:Jansky/pixel 2:SI 3:Lsun/pixel 4:tau
img[0].filename = "imageCO_1-0F.fits"; // Output filename
img[1].nchan = 251; // Number of channels
img[1].velres = 75.; // Channel resolution in m/s
img[1].trans = 0; // zero-indexed J quantum number
// img[1].freq = 75.0e9; //central freqency
// img[1].bandwidth = 1500e6;
img[1].pxls = 201; // Pixels per dimension
img[1].imgres = 0.05; // Resolution in arc seconds
img[1].theta = PI/2; // 0: face-on, pi/2: edge-on
img[1].distance = 12.5*PC; // source distance in m
img[1].source_vel = 0; // source velocity in m/s
img[1].unit = 0; // 0:Kelvin 1:Jansky/pixel 2:SI 3:Lsun/pixel 4:tau
img[1].filename = "imageCO_1-0E.fits"; // Output filename
img[2].nchan = 251; // Number of channels
img[2].velres = 75.; // Channel resolution in m/s
img[2].trans = 2; // zero-indexed J quantum number
// img[2].freq = 75.0e9; //central freqency
// img[2].bandwidth = 1500e6;
img[2].pxls = 201; // Pixels per dimension
img[2].imgres = 0.05; // Resolution in arc seconds
img[2].theta = 0.0; // 0: face-on, pi/2: edge-on
img[2].distance = 12.5*PC; // source distance in m
img[2].source_vel = 0; // source velocity in m/s
img[2].unit = 0; // 0:Kelvin 1:Jansky/pixel 2:SI 3:Lsun/pixel 4:tau
img[2].filename = "imageCO_3-2F.fits"; // Output filename
img[3].nchan = 251; // Number of channels
img[3].velres = 75.; // Channel resolution in m/s
img[3].trans = 2; // zero-indexed J quantum number
// img[3].freq = 75.0e9; //central freqency
// img[3].bandwidth = 1500e6;
img[3].pxls = 201; // Pixels per dimension
img[3].imgres = 0.05; // Resolution in arc seconds
img[3].theta = PI/2; // 0: face-on, pi/2: edge-on
img[3].distance = 12.5*PC; // source distance in m
img[3].source_vel = 0; // source velocity in m/s
img[3].unit = 0; // 0:Kelvin 1:Jansky/pixel 2:SI 3:Lsun/pixel 4:tau
img[3].filename = "imageCO_3-2E.fits"; // Output filename
img[4].nchan = 251; // Number of channels
img[4].velres = 75.; // Channel resolution in m/s
img[4].trans = 4; // zero-indexed J quantum number
// img[4].freq = 75.0e9; //central freqency
// img[4].bandwidth = 1500e6;
img[4].pxls = 201; // Pixels per dimension
img[4].imgres = 0.05; // Resolution in arc seconds
img[4].theta = 0.0; // 0: face-on, pi/2: edge-on
img[4].distance = 12.5*PC; // source distance in m
img[4].source_vel = 0; // source velocity in m/s
img[4].unit = 0; // 0:Kelvin 1:Jansky/pixel 2:SI 3:Lsun/pixel 4:tau
img[4].filename = "imageCO_5-4F.fits"; // Output filename
img[5].nchan = 251; // Number of channels
img[5].velres = 75.; // Channel resolution in m/s
img[5].trans = 4; // zero-indexed J quantum number
// img[5].freq = 75.0e9; //central freqency
// img[5].bandwidth = 1500e6;
img[5].pxls = 201; // Pixels per dimension
img[5].imgres = 0.05; // Resolution in arc seconds
img[5].theta = PI/2; // 0: face-on, pi/2: edge-on
img[5].distance = 12.5*PC; // source distance in m
img[5].source_vel = 0; // source velocity in m/s
img[5].unit = 0; // 0:Kelvin 1:Jansky/pixel 2:SI 3:Lsun/pixel 4:tau
img[5].filename = "imageCO_5-4E.fits"; // Output filename
img[6].nchan = 251; // Number of channels
img[6].velres = 75.; // Channel resolution in m/s
img[6].trans = 8; // zero-indexed J quantum number
// img[6].freq = 75.0e9; //central freqency
// img[6].bandwidth = 1500e6;
img[6].pxls = 201; // Pixels per dimension
img[6].imgres = 0.05; // Resolution in arc seconds
img[6].theta = PI/2; // 0: face-on, pi/2: edge-on
img[6].distance = 12.5*PC; // source distance in m
img[6].source_vel = 0; // source velocity in m/s
img[6].unit = 0; // 0:Kelvin 1:Jansky/pixel 2:SI 3:Lsun/pixel 4:tau
img[6].filename = "imageCO_9-8E.fits"; // Output filename
img[7].nchan = 251; // Number of channels
img[7].velres = 75.; // Channel resolution in m/s
img[7].trans = 6; // zero-indexed J quantum number
// img[7].freq = 75.0e9; //central freqency
// img[7].bandwidth = 1500e6;
img[7].pxls = 201; // Pixels per dimension
img[7].imgres = 0.05; // Resolution in arc seconds
img[7].theta = PI/2; // 0: face-on, pi/2: edge-on
img[7].distance = 12.5*PC; // source distance in m
img[7].source_vel = 0; // source velocity in m/s
img[7].unit = 0; // 0:Kelvin 1:Jansky/pixel 2:SI 3:Lsun/pixel 4:tau
img[7].filename = "imageCO_7-6E.fits"; // Output filename
/*
img[3].nchan = 150; // Number of channels
img[3].velres = 50.; // Channel resolution in m/s
img[3].trans = 8; // zero-indexed J quantum number
// img[1].freq = 75.0e9; //central freqency
// img[1].bandwidth = 1500e6;
img[3].pxls = 151; // Pixels per dimension
img[3].imgres = 0.05; // Resolution in arc seconds
img[3].theta = PI/2; // 0: face-on, pi/2: edge-on
img[3].distance = 12.5*PC; // source distance in m
img[3].source_vel = 0; // source velocity in m/s
img[3].unit = 0; // 0:Kelvin 1:Jansky/pixel 2:SI 3:Lsun/pixel 4:tau
img[3].filename = "imageCO_8Ex100v.fits"; // Output filename
img[4].nchan = 150; // Number of channels
img[4].velres = 50.; // Channel resolution in m/s
img[4].trans = 9; // zero-indexed J quantum number
// img[0].freq = 75.0e9; //central freqency
// img[0].bandwidth = 1500e6;
img[4].pxls = 151; // Pixels per dimension
img[4].imgres = 0.05; // Resolution in arc seconds
img[4].theta = 0.0; // 0: face-on, pi/2: edge-on
img[4].distance = 12.5*PC; // source distance in m
img[4].source_vel = 0; // source velocity in m/s
img[4].unit = 0; // 0:Kelvin 1:Jansky/pixel 2:SI 3:Lsun/pixel 4:tau
img[4].filename = "imageCO_9Fx100v.fits"; // Output filename
img[5].nchan = 150; // Number of channels
img[5].velres = 50.; // Channel resolution in m/s
img[5].trans = 9; // zero-indexed J quantum number
// img[1].freq = 75.0e9; //central freqency
// img[1].bandwidth = 1500e6;
img[5].pxls = 151; // Pixels per dimension
img[5].imgres = 0.05; // Resolution in arc seconds
img[5].theta = PI/2; // 0: face-on, pi/2: edge-on
img[5].distance = 12.5*PC; // source distance in m
img[5].source_vel = 0; // source velocity in m/s
img[5].unit = 0; // 0:Kelvin 1:Jansky/pixel 2:SI 3:Lsun/pixel 4:tau
img[5].filename = "imageCO_9Ex100v.fits"; // Output filename
img[6].nchan = 150; // Number of channels
img[6].velres = 50.; // Channel resolution in m/s
img[6].trans = 9; // zero-indexed J quantum number
// img[1].freq = 75.0e9; //central freqency
// img[1].bandwidth = 1500e6;
img[6].pxls = 151; // Pixels per dimension
img[6].imgres = 0.05; // Resolution in arc seconds
img[6].theta = PI/2; // 0: face-on, pi/2: edge-on
img[6].distance = 12.5*PC; // source distance in m
img[6].source_vel = 0; // source velocity in m/s
img[6].unit = 4; // 0:Kelvin 1:Jansky/pixel 2:SI 3:Lsun/pixel 4:tau
img[6].filename = "imageCO_9E_Taux100v.fits"; // Output filename
img[7].nchan = 150; // Number of channels
img[7].velres = 50.; // Channel resolution in m/s
img[7].trans = 7; // zero-indexed J quantum number
// img[7].freq = 75.0e9; //central freqency
// img[7].bandwidth = 1500e6;
img[7].pxls = 151; // Pixels per dimension
img[7].imgres = 0.05; // Resolution in arc seconds
img[7].theta = PI/2; // 0: face-on, pi/2: edge-on
img[7].distance = 12.5*PC; // source distance in m
img[7].source_vel = 0; // source velocity in m/s
img[7].unit = 4; // 0:Kelvin 1:Jansky/pixel 2:SI 3:Lsun/pixel 4:tau
img[7].filename = "imageCO_7E_Taux100v.fits"; // Output filename
*/
}
/******************************************************************************/
void density(double x, double y, double z, double *density){
int X=x/AU*2+128.1, Y=y/AU*2+128.1, Z=z/AU*2+32.1; //convert co-ords to AU, then to cell number, offset to 0,0,0 at -x_max,-y_max,-z_max
double *disk_arr;
disk_arr= (double*)mmap(0, elements*sizeof(double), PROT_READ, MAP_SHARED,file,0);
if (disk_arr == MAP_FAILED) {
close(file);
perror("Error mmapping the file");
exit(EXIT_FAILURE);
} //open and memmap the binary disk array
if (X>255) X=255;
else if (X<0) X=0;
if (Y>255) Y=255;
else if (Y<0) Y=0;
if (Z>63) Z=63;
else if (Z<0) Z=0;
int n=X*256*64+Y*64+Z; // grid-ref to arr pos
// fprintf(stderr, "D: %.3e %.3e %.3e : %.3e\n",x,y,z,disk_arr[n*5+1]);
density[0] = disk_arr[n*5+1];
munmap(disk_arr,elements*sizeof(double));
//density[0] = 1.0e6;
}
/******************************************************************************/
void temperature(double x, double y, double z, double *temperature){
int X=x/AU*2+127.1, Y=y/AU*2+127.1, Z=z/AU*2+31.1; //convert co-ords to AU, then to cell number, offset to 0,0,0 at -x_max,-y_max,-z_max
double *disk_arr;
disk_arr= (double*)mmap(0, elements*sizeof(double), PROT_READ, MAP_SHARED,file,0);
if (disk_arr == MAP_FAILED) {
close(file);
perror("Error mmapping the file");
exit(EXIT_FAILURE);
} //open and memmap the binary disk array
if (X>255) X=255;
else if (X<0) X=0;
if (Y>255) Y=255;
else if (Y<0) Y=0;
if (Z>63) Z=63;
else if (Z<0) Z=0;
int n=X*256*64+Y*64+Z; // grid-ref to arr pos
// fprintf(stderr, "T: %.3e %.3e %.3e : %.3e\n",x,y,z,disk_arr[n*5+0]);
temperature[0]=disk_arr[n*5+0];
munmap(disk_arr, elements*sizeof(double));
// temperature[0]=50.;
}
/******************************************************************************/
void abundance(double x, double y, double z, double *abundance){
int X=x/AU/002.1764+25.1, Y=y/AU/002.1764+25.1, Z=z/AU/0.218214+25.1; //convert co-ords to AU, then to cell number, offset to 0,0,0 at -x_max,-y_max,-z_max
if (X>50) X=50;
else if (X<0) X=0;
if (Y>50) Y=50;
else if (Y<0) Y=0;
if (Z>50) Z=50;
else if (Z<0) Z=0;
int n=X*51*51+Y*51+Z;
double ans =chem_arr[n];
if (ans>=-0.001) ans=-30.0;
// fprintf(stderr, "A: %.3e %.3e %.3e : %.3e\n",x,y,z,pow(10,ans));
abundance[0] = pow(10,ans);
// abundance[0] = 1.e-11;
}
/******************************************************************************/
void doppler(double x, double y, double z, double *doppler){
*doppler = 100.;
}
/******************************************************************************/
void velocity(double x, double y, double z, double *velocity){
int X=2*x/AU+128.01, Y=2*y/AU+128.01, Z=2*z/AU+32.01;
if (X<0) X=0;
else if (X>255) X=255;
if (Y<0) Y=0;
else if (Y>255) Y=255;
if (Z<0) Z=0;
else if (Z>63) Z=63;
// fprintf(stderr,"%.3d %.3d %.2e %.2e\n",X-128,Y-128,vel_arr[X][Y][Z][0],vel_arr[X][Y][Z][1]);
velocity[0]=vel_arr[X][Y][Z][0];
velocity[1]=vel_arr[X][Y][Z][1];
velocity[2]=vel_arr[X][Y][Z][2];
/* double r =sqrt(x*x+y*y), p=10000/sqrt(r/AU), phi=atan2(y,x);
velocity[0]=p*sin(phi);
velocity[1]=p*cos(phi);
velocity[2]=-1000/(z/AU);*/
}
/******************************************************************************/