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

Uninitialised gas SFR threshold #79

Closed
rtobar opened this issue May 26, 2021 · 8 comments
Closed

Uninitialised gas SFR threshold #79

rtobar opened this issue May 26, 2021 · 8 comments
Labels
bug Something isn't working

Comments

@rtobar
Copy link

rtobar commented May 26, 2021

While reading the code I found that Option.gas_sft_threshold is never initialised: it doesn't have a default value (so it cannot be assumed it takes a fixed value at startup), and there's no place in the code that writes into it (either from the command line, configuration file, or input data files). On the other hand the value is used in a few places in the code, particularly in few of the functions in substructureproperties.cxx.

$> grep -RIn gas_sfr_threshold src/
src/substructureproperties.cxx:616:                if (SFR>opt.gas_sfr_threshold) pdata[i].M_gas_sf+=mval;
src/substructureproperties.cxx:641:                if (SFR>opt.gas_sfr_threshold) {
src/substructureproperties.cxx:693:                if (SFR>opt.gas_sfr_threshold) {
src/substructureproperties.cxx:871:                    if (SFR>opt.gas_sfr_threshold){
src/substructureproperties.cxx:1473:                if (SFR>opt.gas_sfr_threshold) pdata[i].M_gas_sf+=mval;
src/substructureproperties.cxx:1546:                if (SFR > opt.gas_sfr_threshold) {
src/substructureproperties.cxx:1754:                    if (SFR>opt.gas_sfr_threshold) {
src/substructureproperties.cxx:1809:            if (SFR>opt.gas_sfr_threshold) {
src/substructureproperties.cxx:5637:            if (SFR>opt.gas_sfr_threshold) {
src/substructureproperties.cxx:5841:            if (SFR>opt.gas_sfr_threshold) EncMassGasSF+=mass;
src/substructureproperties.cxx:5891:            if (SFR>opt.gas_sfr_threshold) oldrc_gas_sf=rc;
src/substructureproperties.cxx:5993:                if (SFR>opt.gas_sfr_threshold) {
src/substructureproperties.cxx:6071:                if (SFR>opt.gas_sfr_threshold) EncMassGasSF+=mass;
src/substructureproperties.cxx:6116:                if (SFR>opt.gas_sfr_threshold) oldrc_gas_sf=rc;
src/substructureproperties.cxx:6202:        if (Pval->GetSFR()>opt.gas_sfr_threshold)
src/substructureproperties.cxx:6238:        if (sfrval>opt.gas_sfr_threshold)
src/substructureproperties.cxx:6274:        if (Pval->GetSFR()>opt.gas_sfr_threshold)
src/substructureproperties.cxx:6311:        if (sfrval>opt.gas_sfr_threshold)
src/allvars.h:775:    Double_t gas_sfr_threshold;

Given the variable is uninitialised, this potentially means some results (basically whatever happens within those ifs) cannot be guaranteed to be consistent across different compilations/settings/platforms/etc.

The fix should be easy: firstly, make sure the variable has a default value, and secondly, we'll probably need a way to assign arbitrary values for this threshold.

@MatthieuSchaller, I have two questions about this:

@MatthieuSchaller
Copy link

Interesting. Might be related to / leading to #75.

Now, unfortunately, I don't know what that variable ought to be doing...
My guess is that it is used to select gas with a star formation rate above a given user-defined threshold. Not sure why one would want to do this for a non-zero threshold. I suppose the only natural value is 0 to select between star-forming and non-star-forming gas.

Definitely needs to be initialised. Whether it needs to be a parameter I don't know. For EAGLE-related applications that will always be zero anyway.

@rtobar
Copy link
Author

rtobar commented May 26, 2021

OK, I'll add a default value of 0 for now. @pelahi, when you have a time: do you have any insights as to the purpose of this setting, and whether this should be controlled via the configuration file?

rtobar added a commit that referenced this issue May 26, 2021
This variable was not being initialised, and is never written to, and
thus code reading it cannot assume any consistent value, even between
two different runs.

This was reported in #79. Additionally we might want to add a new option
in the configuration file to allow users provide an arbitrary value for
this setting.

Signed-off-by: Rodrigo Tobar <rtobar@icrar.org>
@rtobar
Copy link
Author

rtobar commented May 26, 2021

The change is now on the master branch. I'll wait for Pascal's guidance to decide whether we need a new setting or not.

@rtobar rtobar added the bug Something isn't working label May 26, 2021
@pelahi
Copy link
Collaborator

pelahi commented May 26, 2021

Hi @rtobar @MatthieuSchaller it is the variable that is used to split star forming gas from non-star forming gas so 0 is a good default value. I've just pushed a branch with a fix (default is 0 and has configuration option). Did you want to try
https://github.com/pelahi/VELOCIraptor-STF/tree/bugfix/gas_sfr
I can also create a pull request if desired.

@rtobar
Copy link
Author

rtobar commented May 26, 2021

Thanks @pelahi for the very prompt reply! I'll cherry-pick the main bit from pelahi@875a60d to allow users to provide the setting.

@rtobar
Copy link
Author

rtobar commented May 26, 2021

The option is now defaulted to 0 and a new Gas_star_forming_rate_threshold setting in the configuration file allows users to specify a different value if required. Thanks again @MatthieuSchaller and @pelahi for your help!

@rtobar rtobar closed this as completed May 26, 2021
@MatthieuSchaller
Copy link

Thanks! Just to be extra clear, do we now need to update our config files?

@rtobar
Copy link
Author

rtobar commented May 26, 2021

@MatthieuSchaller no, it shouldn't be necessary as the default value of 0 should kick in.

rtobar added a commit that referenced this issue May 31, 2021
The Options class' members were all first declared, then initialised in
the body of the default constructor. This is firstly against the idea of
initialising members in the member initialisation list, but moreover it
required having to keep two lists of members in the code: the one
declaring them, and the one initialising them.

This commit brings together member declaration and initialisation, which
has been available since C++11. While doing so I found a few members
that were:

 * Not initialised (see #79 for example).
 * Initialised later on deep within VR (so probably shouldn't belong in
   this class in the first place).
 * Uninitialised and later on only written to (and never read).
 * Not used at all.

I've removed the latter two sets of members, and added initialisation
for the first two.

I've also taken the opportunity to remove all the rest of the member
functions, including the constructor, as they were unnecessary.

Signed-off-by: Rodrigo Tobar <rtobar@icrar.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants