-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathspectrum_lightcurve.h
More file actions
103 lines (83 loc) · 3.56 KB
/
spectrum_lightcurve.h
File metadata and controls
103 lines (83 loc) · 3.56 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
#ifndef SPECTRUM_H
#define SPECTRUM_H
#include <array>
#include <cstddef>
#include <span>
#include <string>
#pragma clang unsafe_buffer_usage begin
#include <mpi.h>
#pragma clang unsafe_buffer_usage end
#include "exspec.h"
#include "globals.h"
#include "packet.h"
struct Spectra {
double nu_min = -1.;
double nu_max = -1.;
std::array<float, MNUBINS> lower_freq{};
std::array<float, MNUBINS> delta_freq{};
std::span<double> fluxalltimesteps;
MPI_Win win_fluxalltimesteps{MPI_WIN_NULL};
std::span<double> absorptionalltimesteps;
MPI_Win win_absorptionalltimesteps{MPI_WIN_NULL};
std::span<double> emissionalltimesteps;
MPI_Win win_emissionalltimesteps{MPI_WIN_NULL};
std::span<double> trueemissionalltimesteps;
MPI_Win win_trueemissionalltimesteps{MPI_WIN_NULL};
bool do_emission_absorption = false;
[[nodiscard]] auto mem_usage_bytes() const -> size_t {
auto mem_usage = sizeof(Spectra);
mem_usage += sizeof(float) * (lower_freq.size() + delta_freq.size());
mem_usage += sizeof(double) * (fluxalltimesteps.size() + absorptionalltimesteps.size() +
emissionalltimesteps.size() + trueemissionalltimesteps.size());
// Note: Allocator overhead is not included in this calculation.
return mem_usage;
}
auto operator=(Spectra&&) -> Spectra& = delete;
auto operator=(const Spectra&) -> Spectra& = delete;
Spectra(Spectra&&) = delete;
Spectra(const Spectra&) = delete;
// constructor to allocate MPI windows
Spectra() = default;
// destructor to free MPI windows
~Spectra() {
if (globals::mpi_finalized) {
return; // do not free MPI windows after MPI_Finalize
}
if (win_fluxalltimesteps != MPI_WIN_NULL) {
fluxalltimesteps = {};
MPI_Win_free(&win_fluxalltimesteps);
win_fluxalltimesteps = MPI_WIN_NULL;
}
if (win_absorptionalltimesteps != MPI_WIN_NULL) {
absorptionalltimesteps = {};
MPI_Win_free(&win_absorptionalltimesteps);
win_absorptionalltimesteps = MPI_WIN_NULL;
}
if (win_emissionalltimesteps != MPI_WIN_NULL) {
emissionalltimesteps = {};
MPI_Win_free(&win_emissionalltimesteps);
win_emissionalltimesteps = MPI_WIN_NULL;
}
if (win_trueemissionalltimesteps != MPI_WIN_NULL) {
trueemissionalltimesteps = {};
MPI_Win_free(&win_trueemissionalltimesteps);
win_trueemissionalltimesteps = MPI_WIN_NULL;
}
}
};
void write_spectra(const std::string& spec_filename, const std::string& emission_filename,
const std::string& trueemission_filename, const std::string& absorption_filename,
const Spectra& spectra, int numtimesteps);
void write_specpol(const std::string& specpol_filename, const std::string& emission_filename,
const std::string& absorption_filename, const Spectra* stokes_i, const Spectra* stokes_q,
const Spectra* stokes_u);
void add_to_spec_res(const Packet& pkt, int dirbin, Spectra& spectra, Spectra* stokes_i, Spectra* stokes_q,
Spectra* stokes_u);
void init_spectra(Spectra& spectra, double nu_min, double nu_max, bool do_emission_absorption);
void init_spectrum_trace();
void write_partial_lightcurve_spectra(int nts, std::span<const Packet> pkts);
void add_to_lc_res(const Packet& pkt, int dirbin, std::span<double> light_curve_lum,
std::span<double> light_curve_lumcmf);
void write_light_curve(const std::string& lc_filename, std::span<const double> light_curve_lum,
std::span<const double> light_curve_lumcmf, int numtimesteps);
#endif // SPECTRUM_H