Skip to content

Commit aea5b55

Browse files
cournoyercloutiercspzwartrieder
authored
Updates to SeBa (#1128)
* added two tests to test_seba.py to check earlier seba interface problems. And relaired test_seba: should now work as expected. * assure that new bug-corrected version of SeBa is downloaded (see SeBa issue a6f4), and make SeBa interface print zero-age binary parameters. * Update download.py * Update download.py --------- Co-authored-by: Simon Portegies Zwart <spz@strw.leidenuniv.nl> Co-authored-by: Steven Rieder <steven+github@rieder.nl>
1 parent 2fcce97 commit aea5b55

3 files changed

Lines changed: 71 additions & 10 deletions

File tree

src/amuse/community/seba/download.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def new_option_parser():
9393
result = OptionParser()
9494
result.add_option(
9595
"--seba-version",
96-
default='2d8088ad03a4323514780e19e5895fbcac42e0ec',
96+
default='a6f4b64f852249a0b66d52aa6f276be517dccb64',
9797
dest="seba_version",
9898
help="SeBa commit hash to download",
9999
type="string"

src/amuse/community/seba/interface.cc

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ local void addbinary(
4242

4343
id = bi->get_index();
4444

45-
// cerr << "Adding binary to "<< id << " at time = "
46-
// << stellar_time << endl;
45+
cerr << "Adding binary to "<< id << " at time = "
46+
<< stellar_time << endl;
4747

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

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

5859
}
5960
else {
@@ -458,6 +459,7 @@ int new_particle(int * index_of_the_star, double mass){
458459
}
459460

460461
addstar(new_node, seba_time, start_type, seba_metallicity, 0, false, start_type, mass, mass, 0, 0, 0);
462+
461463
new_node->get_starbase()->set_time_offset(seba_time);
462464
*index_of_the_star = next_seba_id;
463465

@@ -919,6 +921,15 @@ int new_binary(
919921
child2->set_elder_sister(child1);
920922
child1->set_parent(new_node);
921923
child2->set_parent(new_node);
924+
// We cannot access the stellar parameters from here, because the starbase class is in between.
925+
// SPZ*FK Febr.2025
926+
//cerr << "Set stelar id in new binary interface."<<endl;
927+
//cerr << "Current interface "<< child1->get_star_id()<<"and "<< child1->get_star_id()<<endl;
928+
//child2->set_star_id(1);
929+
// set stellar id's
930+
//child1->set_star_id(0);
931+
//child2->set_star_id(1);
932+
922933

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

src/amuse/test/suite/codes_tests/test_seba.py

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ def test5(self):
134134
print(mass)
135135
self.assertEqual(error, 0)
136136
self.assertAlmostRelativeEqual(mass[0], 1.0, 6)
137-
self.assertAlmostRelativeEqual(mass[1], 0.62973, 4)
138-
self.assertAlmostRelativeEqual(mass[2], 0.75012, 4)
137+
self.assertAlmostRelativeEqual(mass[1], 0.6306, 4)
138+
self.assertAlmostRelativeEqual(mass[2], 0.7408, 4)
139139

140140
instance.stop()
141141

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

160160
instance.stop()
161161

@@ -284,7 +284,7 @@ def test9(self):
284284
self.assertEqual(error, 0)
285285
mass, error = instance.get_mass(1)
286286
self.assertEqual(error, 0)
287-
self.assertAlmostRelativeEqual(mass, 2.98777, 4)
287+
self.assertAlmostRelativeEqual(mass, 2.9887, 4)
288288
mass, error = instance.get_mass(2)
289289
self.assertEqual(error, 0)
290290
self.assertAlmostRelativeEqual(mass, 0.29999, 4)
@@ -293,7 +293,7 @@ def test9(self):
293293
self.assertEqual(error, 0)
294294
mass, error = instance.get_mass(1)
295295
self.assertEqual(error, 0)
296-
self.assertAlmostRelativeEqual(mass, 0.902743, 4)
296+
self.assertAlmostRelativeEqual(mass, 0.9019, 4)
297297
mass, error = instance.get_mass(2)
298298
self.assertEqual(error, 0)
299299
self.assertAlmostRelativeEqual(mass, 0.3, 4)
@@ -420,7 +420,7 @@ def test_evolution_of_close_binary_system(self):
420420
3.0000 | units.MSun,
421421
3.0000 | units.MSun,
422422
2.9983 | units.MSun,
423-
2.9741 | units.MSun,
423+
2.9797 | units.MSun,
424424
0.6710 | units.MSun,
425425
0.6596 | units.MSun,
426426
)
@@ -683,3 +683,53 @@ def test_supernova_stopping_condition_with_multiple_stars_of_equal_mass(self):
683683
self.assertAlmostRelativeEqual(instance.particles[0].mass, 1.2507 | units.MSun, 4)
684684
self.assertAlmostRelativeEqual(instance.particles[1].mass, 1.2507 | units.MSun, 4)
685685
self.assertAlmostRelativeEqual(instance.particles[2].mass, 0.5 | units.MSun, 4)
686+
687+
def test_restart_for_different_stellar_type(self):
688+
""" Test restart SeBa for different stellar types. """
689+
instance = self.new_instance_of_an_optional_code(SeBa)
690+
691+
#a very specific case, which went wrong in Torch
692+
stars = Particles(2)
693+
stars.mass = [69.08994562, 69.40049406] | units.MSun
694+
stars.relative_mass = [69.44820097, 69.40049406] | units.MSun
695+
stars.age = [3.2865, 3.2865] | units.Myr
696+
stars.relative_age = [3.68045615, 3.63104588] | units.Myr
697+
stars.stellar_type = [2, 1] | units.stellar_type
698+
stars.core_mass = [29.90683271, 0.] | units.MSun
699+
stars.radius = [944.70734099, 94.874201] | units.RSun
700+
stars.luminosity = [1517964.62534381, 1468414.68887237] | units.LSun
701+
702+
instance.particles.add_particles(stars)
703+
instance.evolve_model(0.1 | units.day)
704+
705+
self.assertAlmostRelativeEqual(instance.particles[0].age, 0 | units.Myr, 4)
706+
self.assertAlmostRelativeEqual(instance.particles[1].age, 0 | units.Myr, 4)
707+
self.assertAlmostRelativeEqual(instance.particles[0].relative_age, 3.68045615 | units.Myr, 4)
708+
self.assertAlmostRelativeEqual(instance.particles[1].relative_age, 3.63104588 | units.Myr, 4)
709+
self.assertAlmostRelativeEqual(instance.particles[0].radius, 944.70734099 | units.RSun, 4)
710+
self.assertAlmostRelativeEqual(instance.particles[1].radius, 94.874201 | units.RSun, 4)
711+
self.assertAlmostRelativeEqual(instance.particles[0].core_mass, 29.90683275 | units.MSun, 4)
712+
self.assertAlmostRelativeEqual(instance.particles[1].core_mass, 0 | units.MSun, 4)
713+
self.assertAlmostRelativeEqual(instance.particles[0].luminosity, 1517964.62534381 | units.LSun, 4)
714+
self.assertAlmostRelativeEqual(instance.particles[1].luminosity, 1468414.68887237 | units.LSun, 4)
715+
716+
717+
def test_adding_zero_age_star_and_recover_with_channel(self):
718+
""" Test restart SeBa for different stellar types. """
719+
instance = self.new_instance_of_an_optional_code(SeBa)
720+
721+
#a very specific case, which went wrong in Torch
722+
723+
stars = Particles(1)
724+
stars.mass = 20|units.MSun
725+
stars.radius = 10|units.RSun
726+
727+
instance.particles.add_particle(stars[0])
728+
instance.evolve_model(1|units.yr)
729+
730+
channel = stars.new_channel_to(instance.particles)
731+
channel.copy()
732+
733+
self.assertAlmostRelativeEqual(instance.particles[0].mass, 19.9999999903 | units.MSun, 4)
734+
self.assertAlmostRelativeEqual(instance.particles[0].radius, 5.99895518242 | units.RSun, 4)
735+

0 commit comments

Comments
 (0)