Skip to content

Commit

Permalink
Use more anon namespaces instead of static
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeshingles committed Mar 27, 2024
1 parent c76bf33 commit 9a9075d
Show file tree
Hide file tree
Showing 10 changed files with 368 additions and 330 deletions.
10 changes: 7 additions & 3 deletions decay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@

namespace decay {

static constexpr std::array<const std::string_view, 119> elsymbols{
namespace {

constexpr std::array<const std::string_view, 119> elsymbols{
"n", "H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", "Na", "Mg", "Al", "Si", "P", "S",
"Cl", "Ar", "K", "Ca", "Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As",
"Se", "Br", "Kr", "Rb", "Sr", "Y", "Zr", "Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag", "Cd", "In", "Sn",
"Sb", "Te", "I", "Xe", "Cs", "Ba", "La", "Ce", "Pr", "Nd", "Pm", "Sm", "Eu", "Gd", "Tb", "Dy", "Ho",
"Er", "Tm", "Yb", "Lu", "Hf", "Ta", "W", "Re", "Os", "Ir", "Pt", "Au", "Hg", "Tl", "Pb", "Bi", "Po",
"At", "Rn", "Fr", "Ra", "Ac", "Th", "Pa", "U", "Np", "Pu", "Am", "Cm", "Bk", "Cf", "Es", "Fm", "Md",
"No", "Lr", "Rf", "Db", "Sg", "Bh", "Hs", "Mt", "Ds", "Rg", "Cn", "Uut", "Fl", "Uup", "Lv", "Uus", "Uuo"};
static constexpr int Z_MAX = elsymbols.size() - 1;
constexpr int Z_MAX = elsymbols.size() - 1;

struct Nuclide {
int z{-1}; // atomic number
Expand All @@ -59,7 +61,9 @@ struct Nuclide {
std::array<double, decaytypes::DECAYTYPE_COUNT> branchprobs = {0.}; // branch probability of each decay type
};

static std::vector<Nuclide> nuclides;
std::vector<Nuclide> nuclides;

} // anonymous namespace

constexpr auto decay_daughter_z(const int z_parent, const int /*a_parent*/, const int decaytype) -> int
// check if (z_parent, a_parent) is a parent of (z, a)
Expand Down
8 changes: 6 additions & 2 deletions exspec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ std::mt19937 stdrng{std::random_device{}()};

std::ofstream output_file;

static void do_angle_bin(const int a, Packet *pkts, bool load_allrank_packets, Spectra &rpkt_spectra, Spectra &stokes_i,
Spectra &stokes_q, Spectra &stokes_u, Spectra &gamma_spectra) {
namespace {

void do_angle_bin(const int a, Packet *pkts, bool load_allrank_packets, Spectra &rpkt_spectra, Spectra &stokes_i,
Spectra &stokes_q, Spectra &stokes_u, Spectra &gamma_spectra) {
std::vector<double> rpkt_light_curve_lum(globals::ntimesteps, 0.);
std::vector<double> rpkt_light_curve_lumcmf(globals::ntimesteps, 0.);
std::vector<double> gamma_light_curve_lum(globals::ntimesteps, 0.);
Expand Down Expand Up @@ -158,6 +160,8 @@ static void do_angle_bin(const int a, Packet *pkts, bool load_allrank_packets, S
}
}

} // anonymous namespace

auto main(int argc, char *argv[]) -> int { // NOLINT(misc-unused-parameters)
const auto sys_time_start = std::time(nullptr);

Expand Down
49 changes: 26 additions & 23 deletions input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@
#include "sn3d.h"
#include "vpkt.h"

static const int groundstate_index_in = 1; // starting level index in the input files
static int phixs_file_version = -1;
namespace {

const int groundstate_index_in = 1; // starting level index in the input files
int phixs_file_version = -1;

struct Transitions {
int *to;
Expand Down Expand Up @@ -82,11 +84,11 @@ constexpr std::array<std::string_view, 24> inputlinecomments = {
"23: kpktdiffusion_timescale n_kpktdiffusion_timesteps: kpkts diffuse x of a time step's length for the first y "
"time steps"};

static CellCachePhixsTargets *chphixstargetsblock = nullptr;
CellCachePhixsTargets *chphixstargetsblock = nullptr;

static void read_phixs_data_table(std::fstream &phixsfile, const int nphixspoints_inputtable, const int element,
const int lowerion, const int lowerlevel, const int upperion, int upperlevel_in,
size_t *mem_usage_phixs) {
void read_phixs_data_table(std::fstream &phixsfile, const int nphixspoints_inputtable, const int element,
const int lowerion, const int lowerlevel, const int upperion, int upperlevel_in,
size_t *mem_usage_phixs) {
if (upperlevel_in >= 0) // file gives photoionisation to a single target state only
{
int upperlevel = upperlevel_in - groundstate_index_in;
Expand Down Expand Up @@ -240,7 +242,7 @@ static void read_phixs_data_table(std::fstream &phixsfile, const int nphixspoint
}
}

static void read_phixs_data(const int phixs_file_version) {
void read_phixs_data(const int phixs_file_version) {
size_t mem_usage_phixs = 0;

printout("readin phixs data from %s\n", phixsdata_filenames[phixs_file_version]);
Expand Down Expand Up @@ -344,8 +346,8 @@ static void read_phixs_data(const int phixs_file_version) {
printout("[info] mem_usage: photoionisation tables occupy %.3f MB\n", mem_usage_phixs / 1024. / 1024.);
}

static void read_ion_levels(std::fstream &adata, const int element, const int ion, const int nions, const int nlevels,
int nlevelsmax, const double energyoffset, const double ionpot, Transitions *transitions) {
void read_ion_levels(std::fstream &adata, const int element, const int ion, const int nions, const int nlevels,
int nlevelsmax, const double energyoffset, const double ionpot, Transitions *transitions) {
const ptrdiff_t nlevels_used = std::min(nlevels, nlevelsmax);
// each level contains 0..level elements. seriess sum of 1 + 2 + 3 + 4 + ... + nlevels_used is used here
const ptrdiff_t transitblocksize = nlevels_used * (nlevels_used + 1) / 2;
Expand Down Expand Up @@ -398,9 +400,9 @@ static void read_ion_levels(std::fstream &adata, const int element, const int io
}
}

static void read_ion_transitions(std::fstream &ftransitiondata, const int tottransitions_in_file, int *tottransitions,
std::vector<Transition> &transitiontable, const int nlevels_requiretransitions,
const int nlevels_requiretransitions_upperlevels) {
void read_ion_transitions(std::fstream &ftransitiondata, const int tottransitions_in_file, int *tottransitions,
std::vector<Transition> &transitiontable, const int nlevels_requiretransitions,
const int nlevels_requiretransitions_upperlevels) {
transitiontable.reserve(*tottransitions);
transitiontable.clear();

Expand Down Expand Up @@ -487,10 +489,9 @@ static void read_ion_transitions(std::fstream &ftransitiondata, const int tottra
}
}

static void add_transitions_to_unsorted_linelist(const int element, const int ion, const int nlevelsmax,
const std::vector<Transition> &transitiontable,
Transitions *transitions, int *lineindex,
std::vector<TransitionLine> &temp_linelist) {
void add_transitions_to_unsorted_linelist(const int element, const int ion, const int nlevelsmax,
const std::vector<Transition> &transitiontable, Transitions *transitions,
int *lineindex, std::vector<TransitionLine> &temp_linelist) {
const int lineindex_initial = *lineindex;
size_t totupdowntrans = 0;
// pass 0 to get transition counts of each level
Expand Down Expand Up @@ -652,7 +653,7 @@ static void add_transitions_to_unsorted_linelist(const int element, const int io
#endif
}

static auto calculate_nlevels_groundterm(int element, int ion) -> int {
auto calculate_nlevels_groundterm(int element, int ion) -> int {
const int nlevels = get_nlevels(element, ion);
if (nlevels == 1) {
return 1;
Expand Down Expand Up @@ -693,7 +694,7 @@ static auto calculate_nlevels_groundterm(int element, int ion) -> int {
return nlevels_groundterm;
}

static void read_atomicdata_files() {
void read_atomicdata_files() {
int totaluptrans = 0;
int totaldowntrans = 0;

Expand Down Expand Up @@ -1121,7 +1122,7 @@ static void read_atomicdata_files() {
update_includedionslevels_maxnions();
}

static auto search_groundphixslist(double nu_edge, int el, int in, int ll) -> int
auto search_groundphixslist(double nu_edge, int el, int in, int ll) -> int
/// Return the closest ground level continuum index to the given edge
/// frequency. If the given edge frequency is redder than the reddest
/// continuum return -1.
Expand Down Expand Up @@ -1179,7 +1180,7 @@ static auto search_groundphixslist(double nu_edge, int el, int in, int ll) -> in
return index;
}

static void setup_cellcache() {
void setup_cellcache() {
globals::mutex_cellcachemacroatom.resize(get_includedlevels());

// const int num_cellcache_slots = get_max_threads();
Expand Down Expand Up @@ -1297,7 +1298,7 @@ static void setup_cellcache() {
}
}

static void write_bflist_file() {
void write_bflist_file() {
globals::bflist.resize(globals::nbfcontinua);

FILE *bflist_file = nullptr;
Expand Down Expand Up @@ -1341,7 +1342,7 @@ static void write_bflist_file() {
}
}

static void setup_phixs_list() {
void setup_phixs_list() {
// set up the photoionisation transition lists
// and temporary gamma/kappa lists for each thread

Expand Down Expand Up @@ -1513,7 +1514,7 @@ static void setup_phixs_list() {
setup_photoion_luts();
}

static void read_atomicdata() {
void read_atomicdata() {
read_atomicdata_files();

/// INITIALISE THE ABSORPTION/EMISSION COUNTERS ARRAYS
Expand Down Expand Up @@ -1618,6 +1619,8 @@ static void read_atomicdata() {
printout("[input] Total NLTE levels: %d, of which %d are superlevels\n", globals::total_nlte_levels, n_super_levels);
}

} // anonymous namespace

void input(int rank)
/// To govern the input. For now hardwire everything.
{
Expand Down
16 changes: 10 additions & 6 deletions kpkt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

namespace kpkt {

namespace {

enum coolingtype {
COOLINGTYPE_FF = 0,
COOLINGTYPE_FB = 1,
Expand All @@ -37,15 +39,15 @@ struct CellCachecoolinglist {
int upperlevel;
};

static CellCachecoolinglist *coolinglist;
CellCachecoolinglist *coolinglist;

static int n_kpktdiffusion_timesteps{0};
static float kpktdiffusion_timescale{0.};
int n_kpktdiffusion_timesteps{0};
float kpktdiffusion_timescale{0.};

template <bool update_cooling_contrib_list>
static auto calculate_cooling_rates_ion(const int modelgridindex, const int element, const int ion,
const int indexionstart, const int cellcacheslotid, double *C_ff, double *C_fb,
double *C_exc, double *C_ionization) -> double
auto calculate_cooling_rates_ion(const int modelgridindex, const int element, const int ion, const int indexionstart,
const int cellcacheslotid, double *C_ff, double *C_fb, double *C_exc,
double *C_ionization) -> double
// calculate the cooling contribution list of individual levels/processes for an ion
// oldcoolingsum is the sum of lower ion (of same element or all ions of lower elements) cooling contributions
{
Expand Down Expand Up @@ -173,6 +175,8 @@ static auto calculate_cooling_rates_ion(const int modelgridindex, const int elem
return C_ion;
}

} // anonymous namespace

void calculate_cooling_rates(const int modelgridindex, HeatingCoolingRates *heatingcoolingrates)
// Calculate the cooling rates for a given cell and store them for each ion
// optionally store components (ff, bf, collisional) in heatingcoolingrates struct
Expand Down
10 changes: 7 additions & 3 deletions ltepop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
#include "rpkt.h"
#include "sn3d.h"

namespace {

struct nne_solution_paras {
int modelgridindex;
bool force_lte;
};

static auto interpolate_ions_spontrecombcoeff(const int element, const int ion, const double T) -> double {
auto interpolate_ions_spontrecombcoeff(const int element, const int ion, const double T) -> double {
assert_testmodeonly(element < get_nelements());
assert_testmodeonly(ion < get_nions(element));
assert_always(T >= MINTEMP);
Expand All @@ -44,7 +46,7 @@ static auto interpolate_ions_spontrecombcoeff(const int element, const int ion,
return globals::elements[element].ions[ion].Alpha_sp[TABLESIZE - 1];
}

static auto phi_lte(const int element, const int ion, const int modelgridindex) -> double {
auto phi_lte(const int element, const int ion, const int modelgridindex) -> double {
// use Saha equation for LTE ionization balance
auto partfunc_ion = grid::modelgrid[modelgridindex].composition[element].partfunct[ion];
auto partfunc_upperion = grid::modelgrid[modelgridindex].composition[element].partfunct[ion + 1];
Expand All @@ -55,7 +57,7 @@ static auto phi_lte(const int element, const int ion, const int modelgridindex)
return partfunct_ratio * SAHACONST * pow(T_e, -1.5) * exp(ionpot / KB / T_e);
}

static auto phi_ion_equilib(const int element, const int ion, const int modelgridindex, const int nonemptymgi) -> double
auto phi_ion_equilib(const int element, const int ion, const int modelgridindex, const int nonemptymgi) -> double
/// Calculates population ratio (a saha factor) of two consecutive ionisation stages
/// in nebular approximation phi_j,k* = N_j,k*/(N_j+1,k* * nne)
{
Expand Down Expand Up @@ -119,6 +121,8 @@ static auto phi_ion_equilib(const int element, const int ion, const int modelgri
return phi;
}

} // anonymous namespace

[[nodiscard]] auto calculate_ionfractions(const int element, const int modelgridindex, const double nne,
const bool use_phi_lte) -> std::vector<double>
// Calculate the fractions of an element's population in each ionization stage based on Saha LTE or ionisation
Expand Down
Loading

0 comments on commit 9a9075d

Please sign in to comment.