From 7c6d29f93cf1149083f3a60f7bad1438583e027a Mon Sep 17 00:00:00 2001 From: Kong You Liow <53225674+kyliow@users.noreply.github.com> Date: Wed, 27 Oct 2021 18:32:02 +0100 Subject: [PATCH 1/2] Included failsafe and edited break condition --- src/amuse/ext/masc/cluster.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/amuse/ext/masc/cluster.py b/src/amuse/ext/masc/cluster.py index be28829..7907008 100644 --- a/src/amuse/ext/masc/cluster.py +++ b/src/amuse/ext/masc/cluster.py @@ -80,8 +80,9 @@ def new_fixed_mass_distribution( mass = mass[mass.cumsum() < stellar_mass] additional_mass = [] | units.MSun - while True: - if previous_number_of_stars + len(additional_mass) > len(mass): + count_failsafe = 0 + while count_failsafe > 10: + if len(mass) > number_of_stars: break # We don't have enough stars yet, or at least not tested this additional_mass = initial_mass_function( @@ -102,6 +103,7 @@ def new_fixed_mass_distribution( mass.sum() + additional_mass.cumsum() < stellar_mass ] mass.append(additional_mass) + count_failsafe += 1 number_of_stars = len(mass) else: # Give stars their mass From b57c132b8ac8f458a1995d425cd69da514fa2ea0 Mon Sep 17 00:00:00 2001 From: Kong You Liow <53225674+kyliow@users.noreply.github.com> Date: Thu, 28 Oct 2021 11:00:08 +0100 Subject: [PATCH 2/2] Flatten new_masses So that the returned AMUSE vector always has shape (N,). It wasn't the case previously if mass array before the `stellar_mass` if statement is empty. --- src/amuse/ext/masc/cluster.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/amuse/ext/masc/cluster.py b/src/amuse/ext/masc/cluster.py index 7907008..eef9450 100644 --- a/src/amuse/ext/masc/cluster.py +++ b/src/amuse/ext/masc/cluster.py @@ -113,6 +113,7 @@ def new_fixed_mass_distribution( mass_max=upper_mass_limit, ) + mass = mass.flatten() return mass