1 /*
2  * Copyright (c) 2016-2020, The OSKAR Developers.
3  * See the LICENSE file at the top-level directory of this distribution.
4  */
5 
6 #include <log/oskar_log.h>
7 #include <mem/oskar_mem.h>
8 #include <telescope/oskar_telescope.h>
9 #include <utility/oskar_timer.h>
10 #include <utility/oskar_thread.h>
11 
12 #include <fitsio.h>
13 #include <stdio.h>
14 #include <stddef.h>
15 #include <string.h>
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 /* Memory allocated per device. */
22 struct DeviceData
23 {
24     /* Host memory. */
25     /* Chunks have dimension max_chunk_size * num_active_stations. */
26     /* Cross power beams have dimension max_chunk_size. */
27     oskar_Mem* jones_data_cpu[2]; /* On host, for copy back & write. */
28 
29     /* Per test source Stokes type. */
30     oskar_Mem* auto_power_cpu[2][2]; /* On host, for copy back & write. */
31     oskar_Mem* auto_power_time_avg[2];
32     oskar_Mem* auto_power_channel_avg[2];
33     oskar_Mem* auto_power_channel_and_time_avg[2];
34     oskar_Mem* cross_power_cpu[2][2]; /* On host, for copy back & write. */
35     oskar_Mem* cross_power_time_avg[2];
36     oskar_Mem* cross_power_channel_avg[2];
37     oskar_Mem* cross_power_channel_and_time_avg[2];
38 
39     /* Device memory. */
40     int previous_chunk_index;
41     oskar_Telescope* tel;
42     oskar_StationWork* work;
43     oskar_Mem *x, *y, *z, *lon_rad, *lat_rad, *jones_data;
44     oskar_Mem *auto_power[2], *cross_power[2]; /* Per Stokes type. */
45 
46     /* Timers. */
47     oskar_Timer* tmr_compute;   /* Total time spent calculating pixels. */
48 };
49 typedef struct DeviceData DeviceData;
50 
51 struct DataProduct
52 {
53     int type;
54     int stokes_in; /* Source polarisation type. */
55     int stokes_out; /* Image polarisation type. */
56     int i_station;
57     int time_average;
58     int channel_average;
59     fitsfile* fits_file;
60     FILE* text_file;
61 };
62 typedef struct DataProduct DataProduct;
63 
64 struct oskar_BeamPattern
65 {
66     /* Settings. */
67     int prec, num_devices, num_gpus_avail, dev_loc, num_gpus, *gpu_ids;
68     int max_chunk_size;
69     int num_time_steps, num_channels, num_chunks;
70     int pol_mode, width, height, nside;
71     int num_active_stations, *station_ids;
72     int voltage_amp_txt, voltage_phase_txt, voltage_raw_txt;
73     int voltage_amp_fits, voltage_phase_fits;
74     int auto_power_txt;
75     int auto_power_fits, auto_power_phase_fits;
76     int auto_power_real_fits, auto_power_imag_fits;
77     int cross_power_amp_txt, cross_power_phase_txt, cross_power_raw_txt;
78     int cross_power_amp_fits, cross_power_phase_fits;
79     int cross_power_real_fits, cross_power_imag_fits;
80     int ixr_txt, ixr_fits;
81     int average_time_and_channel, separate_time_and_channel;
82     int set_cellsize;
83     int stokes[2]; /* Stokes I true/false, Stokes custom true/false. */
84     double test_source_stokes[4]; /* Custom Stokes parameters. */
85     double cellsize_rad, lon0, lat0, phase_centre_deg[2], fov_deg[2];
86     double time_start_mjd_utc, time_inc_sec, length_sec;
87     double freq_start_hz, freq_inc_hz;
88     char average_single_axis, coord_frame_type, coord_grid_type;
89     char *root_path, *sky_model_file;
90 
91     /* State. */
92     oskar_Mutex* mutex;
93     oskar_Barrier* barrier;
94     oskar_Log* log;
95     int i_global, status;
96 
97     /* Input data. */
98     int source_coord_type, num_pixels;
99     oskar_Mem *lon_rad, *lat_rad, *x, *y, *z;
100     oskar_Telescope* tel;
101 
102     /* Temporary arrays. */
103     oskar_Mem* pix; /* Real-valued pixel array to write to file. */
104     oskar_Mem* ctemp; /* Complex-valued array used for reordering. */
105 
106     /* Settings log data. */
107     char* settings_log;
108     size_t settings_log_length;
109 
110     /* Data product list. */
111     int num_data_products;
112     DataProduct* data_products;
113 
114     /* Timers. */
115     oskar_Timer *tmr_sim, *tmr_write;
116 
117     /* Array of DeviceData structures, one per compute device. */
118     DeviceData* d;
119 };
120 #ifndef OSKAR_BEAM_PATTERN_TYPEDEF_
121 #define OSKAR_BEAM_PATTERN_TYPEDEF_
122 typedef struct oskar_BeamPattern oskar_BeamPattern;
123 #endif
124 
125 enum OSKAR_BEAM_PATTERN_DATA_PRODUCT_TYPE
126 {
127     RAW_COMPLEX = 0,
128     AMP         = 1,
129     PHASE       = 2,
130     REAL        = 4,
131     IMAG        = 8,
132     AUTO_POWER  = 16,
133     CROSS_POWER = 32,
134     IXR         = 64,
135     AUTO_POWER_AMP          = AUTO_POWER  | AMP,
136     AUTO_POWER_PHASE        = AUTO_POWER  | PHASE,
137     AUTO_POWER_REAL         = AUTO_POWER  | REAL,
138     AUTO_POWER_IMAG         = AUTO_POWER  | IMAG,
139     CROSS_POWER_RAW_COMPLEX = CROSS_POWER | RAW_COMPLEX,
140     CROSS_POWER_AMP         = CROSS_POWER | AMP,
141     CROSS_POWER_PHASE       = CROSS_POWER | PHASE,
142     CROSS_POWER_REAL        = CROSS_POWER | REAL,
143     CROSS_POWER_IMAG        = CROSS_POWER | IMAG
144 };
145 
146 enum OSKAR_BEAM_DATA_TYPE
147 {
148     JONES_DATA,
149     AUTO_POWER_DATA,
150     CROSS_POWER_DATA
151 };
152 
153 enum OSKAR_STOKES
154 {
155     /* IQUV must be 0 to 3. */
156     I  = 0,
157     Q  = 1,
158     U  = 2,
159     V  = 3,
160     XX = 4,
161     XY = 5,
162     YX = 6,
163     YY = 7
164 };
165 
166 #ifdef __cplusplus
167 }
168 #endif
169