keflavich / imf

Simple tools to work with the Initial Mass Function
MIT License
44 stars 17 forks source link

nsamp may be 0 or negative in the function make_cluster #3

Closed xinglunju closed 6 years ago

xinglunju commented 6 years ago

Hi Adam, I am trying to use your code to generate cluster masses, but sometimes it falls into an infinite loop, because nsamp happens to be intialized as 0, or has an error like "ValueError: negative dimensions are not allowed", because nsamp is intialized as a negative number. This could happen if mtot is very close to mcluster, or mtot > mcluster but mtot < mcluster + tolerance. I tried the following parameters and about 5 in 10 times the above issue occurs: imf.make_cluster(400.,tolerance = 5., verbose = True, stop_criterion='nearest', mmax = 150.)

keflavich commented 6 years ago

Good catch. There was a missing 'tolerance' value. I had never set the tolerance to be nonzero before, apparently

keflavich commented 6 years ago

I used hub to turn this issue into a pull request, so now it looks like I wrote the issue, but it was actually submitted by Xing Lu.... unfortunately it also erased his username...