Skip to content

Commit

Permalink
Replace level transition pointers with indicies (#123)
Browse files Browse the repository at this point in the history
sim2010 classic mode 2-120 days 2e7pkt 960 core JUWELS runtime decreased from 1.18k core hrs (v2024.09) to 1.13k core hours (4.5% faster).
  • Loading branch information
lukeshingles committed Sep 11, 2024
1 parent ec46b73 commit d59dcb5
Show file tree
Hide file tree
Showing 19 changed files with 337 additions and 326 deletions.
23 changes: 20 additions & 3 deletions atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ inline auto get_nphixstargets(const int element, const int ion, const int level)
assert_testmodeonly(phixstargetindex >= 0);
assert_testmodeonly(phixstargetindex < get_nphixstargets(element, ion, level));

return globals::elements[element].ions[ion].levels[level].phixstargets[phixstargetindex].levelindex;
return globals::allphixstargets[globals::elements[element].ions[ion].levels[level].phixstargetstart +
phixstargetindex]
.levelindex;
}

// Return the probability of a target state for photoionization of (element,ion,level).
Expand All @@ -106,7 +108,9 @@ inline auto get_nphixstargets(const int element, const int ion, const int level)
assert_testmodeonly(phixstargetindex >= 0);
assert_testmodeonly(phixstargetindex < get_nphixstargets(element, ion, level));

return globals::elements[element].ions[ion].levels[level].phixstargets[phixstargetindex].probability;
return globals::allphixstargets[globals::elements[element].ions[ion].levels[level].phixstargetstart +
phixstargetindex]
.probability;
}

// Return the statistical weight of (element,ion,level).
Expand Down Expand Up @@ -360,6 +364,10 @@ inline auto get_includedlevels() -> int { return includedlevels; }
return globals::elements[element].ions[ion].levels[level].ndowntrans;
}

[[nodiscard]] inline auto get_downtranslist(const int element, const int ion, const int level) -> LevelTransition * {
return globals::alltrans + globals::elements[element].ions[ion].levels[level].alltrans_startdown;
}

// the number of upward bound-bound transitions from the specified level
[[nodiscard]] inline auto get_nuptrans(const int element, const int ion, const int level) -> int {
assert_testmodeonly(element < get_nelements());
Expand All @@ -368,6 +376,15 @@ inline auto get_includedlevels() -> int { return includedlevels; }
return globals::elements[element].ions[ion].levels[level].nuptrans;
}

[[nodiscard]] inline auto get_uptranslist(const int element, const int ion, const int level) -> LevelTransition * {
const auto &levelref = globals::elements[element].ions[ion].levels[level];
return globals::alltrans + levelref.alltrans_startdown + levelref.ndowntrans;
}

[[nodiscard]] inline auto get_uptransspan(const int element, const int ion, const int level) {
return std::span(get_uptranslist(element, ion, level), get_nuptrans(element, ion, level));
}

// the number of downward bound-bound transitions from the specified level
inline void set_ndowntrans(const int element, const int ion, const int level, const int ndowntrans) {
assert_testmodeonly(element < get_nelements());
Expand Down Expand Up @@ -404,7 +421,7 @@ inline void set_nuptrans(const int element, const int ion, const int level, cons
[[nodiscard]] inline auto get_emtype_continuum(const int element, const int ion, const int level,
const int upperionlevel) -> int {
const int phixstargetindex = get_phixtargetindex(element, ion, level, upperionlevel);
return globals::elements[element].ions[ion].levels[level].cont_index - phixstargetindex;
return -1 - globals::elements[element].ions[ion].levels[level].cont_index - phixstargetindex;
}

// Returns the energy of (element,ion,level).
Expand Down
39 changes: 20 additions & 19 deletions globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct FullPhotoionTransition {
int level;
int phixstargetindex;
int upperlevel;
float *photoion_xs;
const float *photoion_xs;
double probability;
int index_in_groundphixslist;
int bfestimindex;
Expand All @@ -66,11 +66,6 @@ struct GroundPhotoion {
int ion;
};

struct PhotoionTarget {
double probability; // fraction of phixs cross section leading to this final level
int levelindex; // index of upper ion level after photoionisation
};

struct LevelTransition {
int lineindex;
int targetlevelindex;
Expand All @@ -80,18 +75,23 @@ struct LevelTransition {
bool forbidden;
};

struct PhotoionTarget {
double probability; // fraction of phixs cross section leading to this final level
int levelindex; // index of upper ion level after photoionisation
};

struct EnergyLevel {
double epsilon{-1}; // Excitation energy of this level relative to the neutral ground level.
LevelTransition *uptrans{}; // Allowed upward transitions from this level
LevelTransition *downtrans{}; // Allowed downward transitions from this level
int nuptrans{0};
int ndowntrans{0};
PhotoionTarget *phixstargets{}; // pointer to table of target states and probabilities
int phixsstart{-1}; // index to start of photoionisation cross-sections table in global::allphixs
int nphixstargets{0}; // length of phixstargets array:
float stat_weight{0.}; // Statistical weight of this level.

int cont_index{-1}; // Index of the continuum associated to this level. Negative number.
double epsilon{-1}; // Excitation energy of this level relative to the neutral ground level.
int alltrans_startdown{}; // index into globals::alltrans for first down transition from this level
int ndowntrans{0}; // Number of down transitions from this level
int nuptrans{0}; // Number of up transitions to this level
int phixsstart{-1}; // index to start of photoionisation cross-sections table in global::allphixs
int nphixstargets{0}; // number of target levels for photoionisation
float stat_weight{0.}; // statistical weight of this level
int phixstargetstart{}; // index into globals::allphixstargets
int cont_index{-1}; // index of the bound-free continuum (for first target) sorted by
// element/ion/level/phixstargetindex
// (not an index into the nu_edge-sorted allcont list!)
int closestgroundlevelcont{-1};
};

Expand All @@ -109,7 +109,6 @@ struct Ion {
int uniquelevelindexstart;
int groundcontindex;
double ionpot; // Ionisation threshold to the next ionstage
LevelTransition *alltransitions;
};

struct Element {
Expand All @@ -134,7 +133,7 @@ struct TransitionLine {
struct GSLIntegrationParas {
double nu_edge;
float T;
float *photoion_xs;
const float *photoion_xs;
};

template <bool separatestimrecomb>
Expand Down Expand Up @@ -258,6 +257,8 @@ inline int opacity_case{}; // 0 grey, 1 for Fe-grp dependence.
inline std::vector<float> ion_alpha_sp; // alpha_sp for each ion and temperature table value

inline float *allphixs{};
inline LevelTransition *alltrans;
inline std::vector<PhotoionTarget> allphixstargets;

inline std::vector<Element> elements;

Expand Down
Loading

0 comments on commit d59dcb5

Please sign in to comment.