forked from planetarymike/3D_planetary_RT_model
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_source_function.cpp
More file actions
executable file
·328 lines (280 loc) · 10.9 KB
/
Copy pathgenerate_source_function.cpp
File metadata and controls
executable file
·328 lines (280 loc) · 10.9 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
//generate_source_function.cpp -- program to generate a source
//function for comparison with analytic solutions and other models
#include "Real.hpp"
#include "cuda_compatibility.hpp"
#include "atm/temperature.hpp"
#include "atm/chamb_diff_1d.hpp"
#include "grid_plane_parallel.hpp"
#include "grid_spherical_azimuthally_symmetric.hpp"
#include "RT_grid.hpp"
#include "emission/singlet_CFR.hpp"
#include "emission/O_1026.hpp"
#include "emission/H_lyman_multiplet_test.hpp"
#include "emission/H_lyman_multiplet.hpp"
//#define GENERATE_O_1026
//#define H_LYMAN_MULTIPLET_TEST
//#define H_LYMAN_SINGLET_TEST
//#define NO_SIM_BRIGHTNESS
int main(__attribute__((unused)) int argc, __attribute__((unused)) char* argv[]) {
// read input if provided
Real input_exobase_density, input_exobase_temp;
if (argc == 1) {
#ifdef GENERATE_O_1026
input_exobase_density = 2e7;// cm-3
#else
input_exobase_density = 5e5;// cm-3
#endif
input_exobase_temp = 200;//K
} else {
input_exobase_density = atof(argv[1]);
input_exobase_temp = atof(argv[2]);
}
//define the physical atmosphere
Real exobase_temp = input_exobase_temp;//K
krasnopolsky_temperature temp(exobase_temp);
Real species_exobase_density = input_exobase_density;//cm-3
Real CO2_exobase_density = 2e8;//cm-3
#ifdef GENERATE_O_1026
oxygen_density_parameters species_thermosphere;
Real min_exosphere_density = 10;
Real rmin = rMars+100e5;
int method = thermosphere_exosphere::method_nspmin_nCO2exo;
// // to specify max altitude instead of min density:
// Real rmax = rMars+1500e5;
// int method = thermosphere_exosphere::method_rmax_nCO2rmin;
// min_exosphere_density = rmax;
#else
hydrogen_density_parameters species_thermosphere;
Real min_exosphere_density = 10;
Real rmin = rMars+80e5;
int method = thermosphere_exosphere::method_nspmin_nCO2exo;
#endif
chamb_diff_1d atm(/* rmin = */ rmin,
/* rexo = */ rMars+200e5,
/* rmaxx_or_nspmin = */ min_exosphere_density,
/* rmindifussion = */ rmin,
species_exobase_density,
CO2_exobase_density,
&temp,
&species_thermosphere,
method);
// // fix temperature to the exobase temp, eliminate CO2 absorption to compare with JY
// atm.temp_dependent_sH=false;
// atm.constant_temp_sH=exobase_temp;
// atm.no_CO2_absorption = true;
#if defined(GENERATE_O_1026)
atm.save("test/test_atmosphere_O_1026.dat");
#elif defined(H_LYMAN_MULTIPLET_TEST)
atm.save("test/test_atmosphere_H_multiplet.dat");
#elif defined(H_LYMAN_SINGLET_TEST)
atm.save("test/test_atmosphere_H_singlet.dat");
#else
atm.save("test/test_atmosphere.dat");
#endif
// define the geometry of the grid
//#define PLANE_PARALLEL
#ifdef PLANE_PARALLEL
static const int n_radial_boundaries = 40;
static const int n_rays_theta = 6;
typedef plane_parallel_grid<n_radial_boundaries,
n_rays_theta> grid_type;
atm.spherical = false;
grid_type grid;
grid.rmethod = grid.rmethod_log_n_species;
#else
static const int n_radial_boundaries = 40;
static const int n_sza_boundaries = 20;/*20 for 10 deg increments with szamethod_uniform*/
static const int n_rays_theta = 7;
static const int n_rays_phi = 12;
typedef spherical_azimuthally_symmetric_grid<n_radial_boundaries,
n_sza_boundaries,
n_rays_theta,
n_rays_phi> grid_type;
grid_type grid;
//grid.rmethod = grid.rmethod_altitude;
grid.rmethod = grid.rmethod_log_n_species;
//grid.rmethod = grid.rmethod_log_n_species_tau_absorber;
//grid.szamethod = grid.szamethod_uniform; //requires CONEABS = 1e-2 in Real.hpp
grid.szamethod = grid.szamethod_uniform_cos;
grid.raymethod_theta = grid.raymethod_theta_uniform;
#endif
grid.setup_voxels(atm);
grid.setup_rays();
//define the emissions to be solved for
#if defined(GENERATE_O_1026)
static const int n_emissions = 1;
//solve for O 1026
typedef O_1026_emission<grid_type::n_voxels> emission_type;
emission_type oxygen_1026;
oxygen_1026.define("O_1026",
atm,
&chamb_diff_1d::n_species_voxel_avg,
&chamb_diff_1d::Temp_voxel_avg,
&chamb_diff_1d::n_absorber_voxel_avg,
grid.voxels);
oxygen_1026.set_solar_brightness(1.69e-3); /* ph/cm2/s/Hz,
solar line center brightness at Lyman beta,
solar minimum */
emission_type *emissions[n_emissions] = {&oxygen_1026};
#elif defined(H_LYMAN_MULTIPLET_TEST)
static const int n_emissions = 1;
// true doublets for Lyman alpha and beta
typedef H_lyman_multiplet<grid_type::n_voxels> emission_type;
emission_type lyman_emission;
if (atm.no_CO2_absorption)
lyman_emission.set_CO2_absorption_off();
if (not atm.temp_dependent_sH)
lyman_emission.set_constant_temp_RT(exobase_temp);
lyman_emission.define("H Lyman alpha and beta",
atm,
&chamb_diff_1d::n_species_voxel_avg,
&chamb_diff_1d::Temp_voxel_avg,
&chamb_diff_1d::n_absorber_voxel_avg,
grid.voxels);
lyman_emission.set_solar_brightness(lyman_alpha_flux_Mars_typical, /* ph/cm2/s/Hz, solar brightness */
lyman_beta_flux_Mars_typical);
emission_type *emissions[n_emissions] = {&lyman_emission};
#elif defined(H_LYMAN_SINGLET_TEST)
static const int n_emissions = 1;
// singlet treatment in standard multiplet code
typedef H_lyman_singlet<grid_type::n_voxels> emission_type;
emission_type lyman_emission;
if (atm.no_CO2_absorption)
lyman_emission.set_CO2_absorption_off();
if (not atm.temp_dependent_sH)
lyman_emission.set_constant_temp_RT(exobase_temp);
lyman_emission.define("H Lyman alpha and beta",
atm,
&chamb_diff_1d::n_species_voxel_avg,
&chamb_diff_1d::Temp_voxel_avg,
&chamb_diff_1d::n_absorber_voxel_avg,
grid.voxels);
lyman_emission.set_solar_brightness(lyman_alpha_flux_Mars_typical, /* ph/cm2/s/Hz, solar brightness */
lyman_beta_flux_Mars_typical);
emission_type *emissions[n_emissions] = {&lyman_emission};
#else
// normal singlet CFR treatment
//static const int n_emissions = 1;
static const int n_emissions = 2;
//solve for H lyman alpha
typedef singlet_CFR<grid_type::n_voxels> emission_type;
emission_type lyman_alpha;
lyman_alpha.define("H Lyman alpha",
/*emission branching ratio = */1.0,
exobase_temp, atm.sH_lya(exobase_temp),
atm,
&chamb_diff_1d::n_species_voxel_avg, &chamb_diff_1d::Temp_voxel_avg,
&chamb_diff_1d::n_absorber_voxel_avg, &chamb_diff_1d::sCO2_lya,
grid.voxels);
//solve for H lyman beta
emission_type lyman_beta;
lyman_beta.define("H Lyman beta",
/*emission branching ratio = */lyman_beta_branching_ratio,
exobase_temp, atm.sH_lyb(exobase_temp),
atm,
&chamb_diff_1d::n_species_voxel_avg, &chamb_diff_1d::Temp_voxel_avg,
&chamb_diff_1d::n_absorber_voxel_avg, &chamb_diff_1d::sCO2_lyb,
grid.voxels);
//emission_type *emissions[n_emissions] = {&lyman_alpha};
emission_type *emissions[n_emissions] = {&lyman_alpha, &lyman_beta};
#endif
// now set up the RT object
RT_grid<emission_type, n_emissions, grid_type> RT(grid, emissions);
std::cout << "size of RT grid: " << sizeof(RT) << "\n";
//solve for the source function
#ifndef __CUDACC__
RT.generate_S();
#else
//RT.generate_S();
RT.generate_S_gpu();
RT.generate_S_gpu();
#endif
//now print out the output
#if defined(GENERATE_O_1026)
string sfn_name_tag = "_O_1026";
#elif defined(H_LYMAN_MULTIPLET_TEST)
string sfn_name_tag = "_H_multiplet";
#elif defined(H_LYMAN_SINGLET_TEST)
string sfn_name_tag = "_H_singlet";
#else
string sfn_name_tag = "";
#endif
RT.save_S("test/test_source_function"+sfn_name_tag+".dat");
string sfn_name_tag_dims = sfn_name_tag+"_";
sfn_name_tag_dims += std::to_string(n_radial_boundaries) + "x";
#ifndef PLANE_PARALLEL
sfn_name_tag_dims += std::to_string(n_sza_boundaries) + "x";
#endif
sfn_name_tag_dims += std::to_string(n_rays_theta);
#ifndef PLANE_PARALLEL
sfn_name_tag_dims += "x";
sfn_name_tag_dims += std::to_string(n_rays_phi);
#endif
RT.save_S("test/test_source_function"+sfn_name_tag_dims+".dat");
RT.save_influence("test/influence_matrix"+sfn_name_tag+".dat");
RT.save_influence("test/influence_matrix"+sfn_name_tag_dims+".dat");
#if !defined(NO_SIM_BRIGHTNESS) && !defined(PLANE_PARALLEL)
//simulate a fake observation
observation<emission_type, n_emissions> obs(emissions);
observation<emission_type, n_emissions> obs_nointerp(emissions);
Real dist = 30*rMars;
#ifdef GENERATE_O_1026
Real angle = grid.rmax / dist * 180/pi;
Vector3 loc = {0.,-1.,0.};
#else
Real angle = 30;
Vector3 loc = {0.,-1.0,0.};
#endif
#if !defined(GENERATE_O_1026) && !defined(H_LYMAN_MULTIPLET_TEST) && !defined(H_LYMAN_SINGLET_TEST)
lyman_alpha.set_emission_g_factor(lyman_alpha_typical_g_factor);
lyman_beta.set_emission_g_factor(lyman_beta_typical_g_factor);
std::cout << "lyman alpha solar brightness is: " << lyman_alpha_flux_Mars_typical << " ph/cm2/s/Hz" <<std::endl;
std::cout << "lyman alpha g factor is: " << lyman_alpha_typical_g_factor << std::endl;
std::cout << "lyman alpha line center cross section coef is: "
<< lyman_alpha_line_center_cross_section_coef << std::endl;
std::cout << "lyman alpha tau=1 brightness at " << exobase_temp << " K : "
<< (lyman_alpha_typical_g_factor/
(lyman_alpha_line_center_cross_section_coef/std::sqrt(exobase_temp))
/1e9)
<< " kR" << std::endl;
std::cout << "lyman beta solar brightness is: " << lyman_beta_flux_Mars_typical << " ph/cm2/s/Hz" <<std::endl;
std::cout << "lyman beta g factor is: " << lyman_beta_typical_g_factor << std::endl;
std::cout << "lyman beta line center cross section coef is: "
<< lyman_beta_line_center_cross_section_coef << std::endl;
std::cout << "lyman beta tau=1 brightness at " << exobase_temp << " K : "
<< (lyman_beta_typical_g_factor/
(lyman_beta_line_center_cross_section_coef/std::sqrt(exobase_temp))
/1e6)
<< " R" << std::endl;
std::cout << std::endl;
#endif
#ifndef __CUDACC__
//CPU-only code
int size = 600;
obs.fake(dist, angle, size, loc);
obs_nointerp.fake(dist, angle, size, loc);
std::cout << "Performing brightness calculation without interpolation...\n";
RT.brightness_nointerp(obs_nointerp);
obs_nointerp.save_brightness("test/test_brightness"+sfn_name_tag+"_nointerp.dat");
std::cout << "Performing interpolated brightness calculation...\n";
RT.brightness(obs);
obs.save_brightness("test/test_brightness"+sfn_name_tag+".dat");
#else
//GPU code
vector<int> sizes = {10,100,300,600/*,1200,2400*/};
for (auto&& size: sizes) {
std::cout << "simulating image size "<< size << "x" << size << ":" << std::endl;
obs.fake(dist,angle,size,loc);
RT.brightness_gpu(obs);
my_clock save_clk;
save_clk.start();
string fname = "test/test_brightness_gpu" + sfn_name_tag + "_"+ std::to_string(size) + "x" + std::to_string(size) + ".dat";
obs.save_brightness(fname);
save_clk.stop();
save_clk.print_elapsed("saving file takes ");
std::cout << std::endl;
}
#endif
#endif
return 0;
}