Skip to content
New issue

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

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

Already on GitHub? # to your account

Updates to SeBa #1128

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion src/amuse/community/seba/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ def new_option_parser():
result = OptionParser()
result.add_option(
"--seba-version",
default='2d8088ad03a4323514780e19e5895fbcac42e0ec',
#default='2d8088ad03a4323514780e19e5895fbcac42e0ec',
#default='9fb5af99199b369f58be9a18a1d023e960d923d4',
default='a6f4b64f852249a0b66d52aa6f276be517dccb64',

dest="seba_version",
help="SeBa commit hash to download",
type="string"
Expand Down
17 changes: 14 additions & 3 deletions src/amuse/community/seba/interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ local void addbinary(

id = bi->get_index();

// cerr << "Adding binary to "<< id << " at time = "
// << stellar_time << endl;
cerr << "Adding binary to "<< id << " at time = "
<< stellar_time << endl;

double_star* new_double
= new_double_star(bi, sma, ecc, stellar_time, id, type);
Expand All @@ -53,7 +53,8 @@ local void addbinary(
// Give the new binary the old star_story.

new_double->set_star_story(old_story);

// Assure that SeBa prints zero-age binary parameters (SPZ+FK Febr2025).
new_double->dump("SeBa.data", true);

}
else {
Expand Down Expand Up @@ -458,6 +459,7 @@ int new_particle(int * index_of_the_star, double mass){
}

addstar(new_node, seba_time, start_type, seba_metallicity, 0, false, start_type, mass, mass, 0, 0, 0);

new_node->get_starbase()->set_time_offset(seba_time);
*index_of_the_star = next_seba_id;

Expand Down Expand Up @@ -919,6 +921,15 @@ int new_binary(
child2->set_elder_sister(child1);
child1->set_parent(new_node);
child2->set_parent(new_node);
// We cannot access the stellar parameters from here, because the starbase class is in between.
// SPZ*FK Febr.2025
//cerr << "Set stelar id in new binary interface."<<endl;
//cerr << "Current interface "<< child1->get_star_id()<<"and "<< child1->get_star_id()<<endl;
//child2->set_star_id(1);
// set stellar id's
//child1->set_star_id(0);
//child2->set_star_id(1);


addbinary(new_node, seba_time, binary_start_type, semi_major_axis, eccentricity);

Expand Down
62 changes: 56 additions & 6 deletions src/amuse/test/suite/codes_tests/test_seba.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ def test5(self):
print(mass)
self.assertEqual(error, 0)
self.assertAlmostRelativeEqual(mass[0], 1.0, 6)
self.assertAlmostRelativeEqual(mass[1], 0.62973, 4)
self.assertAlmostRelativeEqual(mass[2], 0.75012, 4)
self.assertAlmostRelativeEqual(mass[1], 0.6306, 4)
self.assertAlmostRelativeEqual(mass[2], 0.7408, 4)

instance.stop()

Expand All @@ -155,7 +155,7 @@ def test6(self):
mass, error = instance.get_mass(index)
print(mass)
self.assertEqual(error, 0)
self.assertAlmostRelativeEqual(mass, [1.0, 0.62973, 0.75072], 4)
self.assertAlmostRelativeEqual(mass, [1.0, 0.6306, 0.7408], 4)

instance.stop()

Expand Down Expand Up @@ -284,7 +284,7 @@ def test9(self):
self.assertEqual(error, 0)
mass, error = instance.get_mass(1)
self.assertEqual(error, 0)
self.assertAlmostRelativeEqual(mass, 2.98777, 4)
self.assertAlmostRelativeEqual(mass, 2.9887, 4)
mass, error = instance.get_mass(2)
self.assertEqual(error, 0)
self.assertAlmostRelativeEqual(mass, 0.29999, 4)
Expand All @@ -293,7 +293,7 @@ def test9(self):
self.assertEqual(error, 0)
mass, error = instance.get_mass(1)
self.assertEqual(error, 0)
self.assertAlmostRelativeEqual(mass, 0.902743, 4)
self.assertAlmostRelativeEqual(mass, 0.9019, 4)
mass, error = instance.get_mass(2)
self.assertEqual(error, 0)
self.assertAlmostRelativeEqual(mass, 0.3, 4)
Expand Down Expand Up @@ -420,7 +420,7 @@ def test_evolution_of_close_binary_system(self):
3.0000 | units.MSun,
3.0000 | units.MSun,
2.9983 | units.MSun,
2.9741 | units.MSun,
2.9797 | units.MSun,
0.6710 | units.MSun,
0.6596 | units.MSun,
)
Expand Down Expand Up @@ -683,3 +683,53 @@ def test_supernova_stopping_condition_with_multiple_stars_of_equal_mass(self):
self.assertAlmostRelativeEqual(instance.particles[0].mass, 1.2507 | units.MSun, 4)
self.assertAlmostRelativeEqual(instance.particles[1].mass, 1.2507 | units.MSun, 4)
self.assertAlmostRelativeEqual(instance.particles[2].mass, 0.5 | units.MSun, 4)

def test_restart_for_different_stellar_type(self):
""" Test restart SeBa for different stellar types. """
instance = self.new_instance_of_an_optional_code(SeBa)

#a very specific case, which went wrong in Torch
stars = Particles(2)
stars.mass = [69.08994562, 69.40049406] | units.MSun
stars.relative_mass = [69.44820097, 69.40049406] | units.MSun
stars.age = [3.2865, 3.2865] | units.Myr
stars.relative_age = [3.68045615, 3.63104588] | units.Myr
stars.stellar_type = [2, 1] | units.stellar_type
stars.core_mass = [29.90683271, 0.] | units.MSun
stars.radius = [944.70734099, 94.874201] | units.RSun
stars.luminosity = [1517964.62534381, 1468414.68887237] | units.LSun

instance.particles.add_particles(stars)
instance.evolve_model(0.1 | units.day)

self.assertAlmostRelativeEqual(instance.particles[0].age, 0 | units.Myr, 4)
self.assertAlmostRelativeEqual(instance.particles[1].age, 0 | units.Myr, 4)
self.assertAlmostRelativeEqual(instance.particles[0].relative_age, 3.68045615 | units.Myr, 4)
self.assertAlmostRelativeEqual(instance.particles[1].relative_age, 3.63104588 | units.Myr, 4)
self.assertAlmostRelativeEqual(instance.particles[0].radius, 944.70734099 | units.RSun, 4)
self.assertAlmostRelativeEqual(instance.particles[1].radius, 94.874201 | units.RSun, 4)
self.assertAlmostRelativeEqual(instance.particles[0].core_mass, 29.90683275 | units.MSun, 4)
self.assertAlmostRelativeEqual(instance.particles[1].core_mass, 0 | units.MSun, 4)
self.assertAlmostRelativeEqual(instance.particles[0].luminosity, 1517964.62534381 | units.LSun, 4)
self.assertAlmostRelativeEqual(instance.particles[1].luminosity, 1468414.68887237 | units.LSun, 4)


def test_adding_zero_age_star_and_recover_with_channel(self):
""" Test restart SeBa for different stellar types. """
instance = self.new_instance_of_an_optional_code(SeBa)

#a very specific case, which went wrong in Torch

stars = Particles(1)
stars.mass = 20|units.MSun
stars.radius = 10|units.RSun

instance.particles.add_particle(stars[0])
instance.evolve_model(1|units.yr)

channel = stars.new_channel_to(instance.particles)
channel.copy()

self.assertAlmostRelativeEqual(instance.particles[0].mass, 19.9999999903 | units.MSun, 4)
self.assertAlmostRelativeEqual(instance.particles[0].radius, 5.99895518242 | units.RSun, 4)

Loading