Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to limit number of BF estimators #47

Merged
merged 43 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
043b13d
commit
jpollin98 Dec 1, 2023
7ef653a
Update radfield.cc
jpollin98 Dec 1, 2023
eb2daad
Update radfield.cc
jpollin98 Dec 1, 2023
ec842e9
Update radfield.cc
jpollin98 Dec 1, 2023
4a812ff
Update radfield.cc
jpollin98 Dec 1, 2023
b363337
Update radfield.cc
jpollin98 Dec 1, 2023
fc7986c
Update radfield.cc
jpollin98 Dec 1, 2023
ec31b59
Update input.cc
jpollin98 Dec 1, 2023
03f4466
Moved Assertions to inside the bf estimator if clause
jpollin98 Dec 2, 2023
a7918b4
bf estimator changes
jpollin98 Feb 21, 2024
576c83a
moved is_bfest
jpollin98 Feb 21, 2024
6181afe
Merge remote-tracking branch 'origin/main' into bfestimator
jpollin98 Feb 21, 2024
a63b6c8
Update radfield.cc
jpollin98 Feb 21, 2024
89d130d
Resolved Conflicts
jpollin98 Feb 21, 2024
6855d99
moved is_bfest
jpollin98 Feb 21, 2024
73e30be
updated other artis options
jpollin98 Feb 21, 2024
1128af1
Merge branch 'bfestimator' of https://github.com/artis-mcrt/artis int…
jpollin98 Feb 21, 2024
4b8253b
bfest changes
jpollin98 Feb 21, 2024
7f5ac10
clang format
jpollin98 Feb 21, 2024
75d19b1
bfest
jpollin98 Feb 21, 2024
c6d69e3
changed nltepop_reset to reset last nlte level as well
jpollin98 Feb 23, 2024
f272196
Merge branch 'main' into bfestimator
lukeshingles Mar 22, 2024
9d73e3d
Refactor artisoptions for LEVEL_HAS_BFEST
lukeshingles Mar 25, 2024
1ce1678
Add test nebularonezone_1d_3dgrid_limitbfest
lukeshingles Mar 25, 2024
38c6096
Update artisoptions_nltenebular.h
lukeshingles Mar 25, 2024
cfc3053
Add junk md5
lukeshingles Mar 25, 2024
644b4b5
Update setup_nebularonezone_1d_3dgrid_limitbfest.sh
lukeshingles Mar 25, 2024
b845e50
Update checksums for limitbfest
lukeshingles Mar 25, 2024
02db793
Break bflimit by switching off all bfestimators
lukeshingles Mar 25, 2024
0c32ab9
Revert "Break bflimit by switching off all bfestimators"
lukeshingles Mar 25, 2024
fc21939
Replace bool has_bf_estimator with int bfestimindex
lukeshingles Mar 25, 2024
f3eb03b
Remove is_bfest() duplicate of LEVEL_HAS_BFEST()
lukeshingles Mar 25, 2024
f372543
Use globals::bfestimcount
lukeshingles Mar 25, 2024
48fe56f
Update ci-checks.yml
lukeshingles Mar 25, 2024
e554dbb
Update results_md5_final.txt
lukeshingles Mar 25, 2024
ee34a39
Revert "Update results_md5_final.txt"
lukeshingles Mar 25, 2024
7a8cc6e
Run clang-format 18
lukeshingles Mar 25, 2024
93b5aba
Update .pre-commit-config.yaml
lukeshingles Mar 25, 2024
34a16f9
Update results_md5_final.txt
lukeshingles Mar 25, 2024
b9364d8
Update ratecoeff.cc
lukeshingles Mar 25, 2024
c3638bf
Revert "Update ratecoeff.cc"
lukeshingles Mar 25, 2024
f0e3a26
Shrink prev_bfrate_normed array from nonemptymgi * nbfcontinua to non…
lukeshingles Mar 25, 2024
8864a6f
Use more ptrdiff_t
lukeshingles Mar 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions artisoptions_christinenonthermal.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ constexpr bool DETAILED_BF_ESTIMATORS_ON = true;

constexpr int DETAILED_BF_ESTIMATORS_USEFROMTIMESTEP = 13;

constexpr bool LEVEL_HAS_BFEST(int element_z, int ionstage, int level) {
bool custom_bf_estimator = false;
if (custom_bf_estimator == true) {
if (element_z == 26 && ionstage == 2) {
return (level <= 197);
}
return (level <= 80);
} else {
return true; // Always treat (element, ion, level) with bf estimator
}
}

lukeshingles marked this conversation as resolved.
Show resolved Hide resolved
constexpr bool USE_LUT_PHOTOION = false;

constexpr bool USE_LUT_BFHEATING = false;
Expand Down
12 changes: 12 additions & 0 deletions artisoptions_classic.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ constexpr bool DETAILED_LINE_ESTIMATORS_ON = false;

constexpr bool DETAILED_BF_ESTIMATORS_ON = false;

constexpr bool LEVEL_HAS_BFEST(int element_z, int ionstage, int level) {
bool custom_bf_estimator = false;
if (custom_bf_estimator == true) {
if (element_z == 26 && ionstage == 2) {
return (level <= 197);
}
return (level <= 80);
} else {
return true; // Always treat (element, ion, level) with bf estimator
}
}

lukeshingles marked this conversation as resolved.
Show resolved Hide resolved
constexpr int DETAILED_BF_ESTIMATORS_USEFROMTIMESTEP = 13;

constexpr bool USE_LUT_PHOTOION = true;
Expand Down
12 changes: 12 additions & 0 deletions artisoptions_kilonova_lte.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ constexpr bool DETAILED_LINE_ESTIMATORS_ON = false;

constexpr bool DETAILED_BF_ESTIMATORS_ON = false;

constexpr bool LEVEL_HAS_BFEST(int element_z, int ionstage, int level) {
bool custom_bf_estimator = false;
if (custom_bf_estimator == true) {
if (element_z == 26 && ionstage == 2) {
return (level <= 197);
}
return (level <= 80);
} else {
return true;
}
}

constexpr int DETAILED_BF_ESTIMATORS_USEFROMTIMESTEP = 13;

constexpr bool USE_LUT_PHOTOION = true;
Expand Down
16 changes: 14 additions & 2 deletions artisoptions_nltenebular.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "constants.h"

constexpr int MPKTS = 1000000;
constexpr int MPKTS = 750000;
lukeshingles marked this conversation as resolved.
Show resolved Hide resolved

constexpr int GRID_TYPE = GRID_CARTESIAN3D;
constexpr int CUBOID_NCOORDGRID_X = 50;
Expand Down Expand Up @@ -82,6 +82,18 @@ constexpr bool DETAILED_LINE_ESTIMATORS_ON = false;

constexpr bool DETAILED_BF_ESTIMATORS_ON = true;

constexpr bool LEVEL_HAS_BFEST(int element_z, int ionstage, int level) {
bool custom_bf_estimator = false;
if (custom_bf_estimator == true) {
if (element_z == 26 && ionstage == 2) {
return (level <= 197);
}
return (level <= 80);
} else {
return true;
}
}

lukeshingles marked this conversation as resolved.
Show resolved Hide resolved
constexpr int DETAILED_BF_ESTIMATORS_USEFROMTIMESTEP = 13;

constexpr bool USE_LUT_PHOTOION = false;
Expand Down Expand Up @@ -146,4 +158,4 @@ constexpr bool KEEP_ALL_RESTART_FILES = false;
constexpr bool BFCOOLING_USELEVELPOPNOTIONPOP = false;

// NOLINTEND(modernize*,misc-unused-parameters)
#endif // ARTISOPTIONS_H
#endif // ARTISOPTIONS_H
12 changes: 12 additions & 0 deletions artisoptions_nltewithoutnonthermal.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ constexpr bool DETAILED_LINE_ESTIMATORS_ON = false;

constexpr bool DETAILED_BF_ESTIMATORS_ON = true;

constexpr bool LEVEL_HAS_BFEST(int element_z, int ionstage, int level) {
bool custom_bf_estimator = false;
if (custom_bf_estimator == true) {
if (element_z == 26 && ionstage == 2) {
return (level <= 197);
}
return (level <= 80);
} else {
return true; // Always treat (element, ion, level) with bf estimator
}
}

lukeshingles marked this conversation as resolved.
Show resolved Hide resolved
constexpr int DETAILED_BF_ESTIMATORS_USEFROMTIMESTEP = 13;

constexpr bool USE_LUT_PHOTOION = false;
Expand Down
2 changes: 2 additions & 0 deletions globals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ std::unique_ptr<struct time[]> timesteps = nullptr;

double *rpkt_emiss = nullptr; /// Volume estimator for the rpkt emissivity

int BFCounter;
lukeshingles marked this conversation as resolved.
Show resolved Hide resolved

// for USE_LUT_PHOTOION = true
double *corrphotoionrenorm = nullptr;
double *gammaestimator = nullptr;
Expand Down
3 changes: 3 additions & 0 deletions globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ struct fullphixslist {
float *photoion_xs;
double probability;
int index_in_groundphixslist;
bool has_bf_estimator;
lukeshingles marked this conversation as resolved.
Show resolved Hide resolved
};

struct groundphixslist {
Expand Down Expand Up @@ -209,6 +210,8 @@ extern std::unique_ptr<struct time[]> timesteps;

extern double *rpkt_emiss;

extern int BFCounter;

// for USE_LUT_PHOTOION = true
extern double *corrphotoionrenorm;
extern double *gammaestimator;
Expand Down
26 changes: 25 additions & 1 deletion input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,13 @@ static void write_bflist_file(int includedphotoiontransitions) {
}
}

auto is_bfest(const int element, const int ion, const int level) -> bool
// Returns true if (element,ion,level) is to be treated with a bf estimator.
{
return LEVEL_HAS_BFEST(get_atomicnumber(element), get_ionstage(element, ion),
level); // defined in artisoptions.h
}

lukeshingles marked this conversation as resolved.
Show resolved Hide resolved
static void setup_phixs_list() {
// set up the photoionisation transition lists
// and temporary gamma/kappa lists for each thread
Expand Down Expand Up @@ -1456,6 +1463,8 @@ static void setup_phixs_list() {
globals::nbfcontinua * (sizeof(fullphixslist)) / 1024. / 1024.);
size_t nbftables = 0;
int allcontindex = 0;
int bound_free_levels_counter = 0;
int nonbound_free_levels_counter = 0;
for (int element = 0; element < get_nelements(); element++) {
const int nions = get_nions(element);
for (int ion = 0; ion < nions - 1; ion++) {
Expand All @@ -1482,6 +1491,15 @@ static void setup_phixs_list() {
nonconstallcont[allcontindex].probability = get_phixsprobability(element, ion, level, phixstargetindex);
nonconstallcont[allcontindex].upperlevel = get_phixsupperlevel(element, ion, level, phixstargetindex);

if (is_bfest(element, ion, level)) {
nonconstallcont[allcontindex].has_bf_estimator = true;
bound_free_levels_counter += 1;

} else {
nonconstallcont[allcontindex].has_bf_estimator = false;
nonbound_free_levels_counter += 1;
}

if constexpr (USE_LUT_PHOTOION || USE_LUT_BFHEATING) {
int index_in_groundlevelcontestimator = 0;
nonconstallcont[allcontindex].index_in_groundphixslist =
Expand All @@ -1495,6 +1513,12 @@ static void setup_phixs_list() {
}
}
}
int total_bound_free = nonbound_free_levels_counter + bound_free_levels_counter;
printout("[info] Bf estimator flag passed through: \t%d\n", total_bound_free);
printout("[info] Bf estimator flag activated for: \t%d\n", bound_free_levels_counter);
printout("[info] Bf estimator flag not activated for: \t%d\n", nonbound_free_levels_counter);
globals::BFCounter = bound_free_levels_counter;
printout("[info] Set the BFCounter to:\t%d\n", bound_free_levels_counter);

assert_always(allcontindex == globals::nbfcontinua);
assert_always(globals::nbfcontinua >= 0); // was initialised as -1 before startup
Expand Down Expand Up @@ -2189,4 +2213,4 @@ void write_timestep_file() {
globals::timesteps[n].width / DAY);
}
fclose(timestepfile);
}
}
1 change: 1 addition & 0 deletions input.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ void update_parameterfile(int nts);
void time_init();
void write_timestep_file();
auto get_noncommentline(std::fstream &input, std::string &line) -> bool;
auto is_bfest(int element, int ion, int level) -> bool;

static inline auto lineiscommentonly(const std::string &line) -> bool
// return true for whitepace-only lines, and lines that are exclusively whitepace up to a '#' character
Expand Down
47 changes: 39 additions & 8 deletions radfield.cc
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,10 @@ void init(int my_rank, int ndo_nonempty)
printout("[info] mem_usage: detailed bf estimators for non-empty cells occupy %.3f MB (node shared memory)\n",
nonempty_npts_model * globals::nbfcontinua * sizeof(float) / 1024. / 1024.);

bfrate_raw = static_cast<double *>(malloc(nonempty_npts_model * globals::nbfcontinua * sizeof(double)));
bfrate_raw = static_cast<double *>(malloc(nonempty_npts_model * globals::BFCounter * sizeof(double)));

printout("[info] mem_usage: detailed bf estimator acculumators for non-empty cells occupy %.3f MB\n",
nonempty_npts_model * globals::nbfcontinua * sizeof(double) / 1024. / 1024.);
nonempty_npts_model * globals::BFCounter * sizeof(double) / 1024. / 1024.);
}

for (int modelgridindex = 0; modelgridindex < grid::get_npts_model(); modelgridindex++) {
Expand Down Expand Up @@ -655,8 +655,8 @@ void zero_estimators(int modelgridindex)
if constexpr (DETAILED_BF_ESTIMATORS_ON) {
assert_always(bfrate_raw != nullptr);
if (grid::get_numassociatedcells(modelgridindex) > 0) {
for (int i = 0; i < globals::nbfcontinua; i++) {
bfrate_raw[nonemptymgi * globals::nbfcontinua + i] = 0.;
for (int i = 0; i < globals::BFCounter; i++) {
bfrate_raw[nonemptymgi * globals::BFCounter + i] = 0.;
}
}
}
Expand Down Expand Up @@ -703,18 +703,42 @@ static void update_bfestimators(const int nonemptymgi, const double distance_e_c
const int tid = get_thread_num();
const double distance_e_cmf_over_nu =
distance_e_cmf / nu_cmf * dopplerfactor; // TODO: Luke: why did I put a doppler factor here?
int detailed_counter = 0;
for (int allcontindex = 0; allcontindex < nbfcontinua; allcontindex++) {
const double nu_edge = globals::allcont_nu_edge[allcontindex];
const double nu_max_phixs = nu_edge * last_phixs_nuovernuedge; // nu of the uppermost point in the phixs table

if (nu_cmf >= nu_edge && nu_cmf <= nu_max_phixs) {
safeadd(bfrate_raw[nonemptymgi * nbfcontinua + allcontindex],
globals::phixslist[tid].gamma_contr[allcontindex] * distance_e_cmf_over_nu);
if (globals::allcont[allcontindex].has_bf_estimator == true) {
if (detailed_counter == globals::BFCounter) {
printout("detailed_counter %d\n", detailed_counter);
printout("globals::BFCounter \n", globals::BFCounter);
printout("allcontindex %d\n", allcontindex);
}
assert_always(detailed_counter < globals::BFCounter);

if (nonemptymgi * globals::BFCounter + detailed_counter >=
grid::get_nonempty_npts_model() * globals::BFCounter) {
printout("detailed_counter %d\n", detailed_counter);
printout("globals::BFCounter %d\n", globals::BFCounter);
printout("grid::get_nonempty_npts_model() %d\n", grid::get_nonempty_npts_model());
printout("nonemptymgi %d\n", nonemptymgi);
}
assert_always(nonemptymgi * globals::BFCounter + detailed_counter <
grid::get_nonempty_npts_model() * globals::BFCounter)

safeadd(bfrate_raw[nonemptymgi * globals::BFCounter + detailed_counter],
globals::phixslist[tid].gamma_contr[allcontindex] * distance_e_cmf_over_nu);
}

} else if (nu_cmf < nu_edge) {
// list is sorted by nu_edge, so all remaining will have nu_cmf < nu_edge
break;
}

if (globals::allcont[allcontindex].has_bf_estimator == true) {
detailed_counter += 1;
}
}
}

Expand Down Expand Up @@ -1161,9 +1185,16 @@ void normalise_bf_estimators(const int modelgridindex, const double estimator_no
printout("normalise_bf_estimators for cell %d with factor %g\n", modelgridindex, estimator_normfactor_over_H);
const int nonemptymgi = grid::get_modelcell_nonemptymgi(modelgridindex);
assert_always(nonemptymgi >= 0);
int detailed_counter = 0;
for (int i = 0; i < globals::nbfcontinua; i++) {
const int mgibfindex = nonemptymgi * globals::nbfcontinua + i;
prev_bfrate_normed[mgibfindex] = bfrate_raw[mgibfindex] * estimator_normfactor_over_H;
const int detailed_mgibfindex = nonemptymgi * globals::BFCounter + detailed_counter;
if (globals::allcont[i].has_bf_estimator == true) {
prev_bfrate_normed[mgibfindex] = bfrate_raw[detailed_mgibfindex] * estimator_normfactor_over_H;
detailed_counter += 1;
} else if (globals::allcont[i].has_bf_estimator == false) {
prev_bfrate_normed[mgibfindex] = 0;
}
}
}
}
Expand Down Expand Up @@ -1257,7 +1288,7 @@ void reduce_estimators()
MPI_Allreduce(MPI_IN_PLACE, nuJ.data(), nonempty_npts_model, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);

if constexpr (DETAILED_BF_ESTIMATORS_ON) {
MPI_Allreduce(MPI_IN_PLACE, bfrate_raw, nonempty_npts_model * globals::nbfcontinua, MPI_DOUBLE, MPI_SUM,
MPI_Allreduce(MPI_IN_PLACE, bfrate_raw, grid::get_nonempty_npts_model() * globals::BFCounter, MPI_DOUBLE, MPI_SUM,
MPI_COMM_WORLD);
}

Expand Down
Loading