@@ -1377,3 +1377,93 @@ def test25(self):
13771377 )
13781378 self .assertAlmostEqual (composition [:, - 1 ], [0.75 , 0 , 0 , 0 , 0 , 0 , 0 , 0.25 ])
13791379 instance .stop ()
1380+
1381+ def test26 (self ):
1382+ print ("Testing basic operations: evolve..." )
1383+ instance = self .new_instance_of_an_optional_code (MESAInterface )
1384+ if instance is None :
1385+ print ("MESA was not built. Skipping test." )
1386+ return
1387+ set_mesa_paths_instance (instance )
1388+ instance .initialize_code ()
1389+ (index_of_the_star , error ) = instance .new_particle (1.0 )
1390+ self .assertEqual (0 , error )
1391+ self .assertEqual (index_of_the_star , 1 )
1392+ self .assertEqual (0 , instance .commit_particles ())
1393+
1394+
1395+ # Subsequent calls to evolve function (the updated function is evolve_until in mesa_interface.f90)
1396+ # To check that the timestep can increase
1397+ # In the previous version it would be prevented from increasing when the evolve function was called
1398+ # multiple times in a row
1399+
1400+ for i in range (10 ):
1401+ self .assertEqual (0 ,instance .evolve_for (index_of_the_star , 1.0e6 ))
1402+
1403+ # With the update, it increases freely up to the maximum allowed value, i.e. the value given as argument
1404+ # to evolve_for. In this example, evolve_for is called several time in a row with value 1 Myr
1405+ # After a few (6) calls to evolve_for, the MESA timestep has reached the maximum value it can, i.e. 1 Myr
1406+ # After the last call, the next timestep should be 1.2*previous_timestep, i.e. 1.2 Myr, if the timestep can
1407+ # increase freely. With the previous version of evolve_until, next_timestep would not be 1.2 Myr.
1408+
1409+ desired_next_timestep_yr = 1.2e6 #value in yr
1410+ desired_next_timestep_second = desired_next_timestep_yr * 365.25 * 24 * 3600 #value in seconds
1411+
1412+ obtained_next_time_step = instance .get_time_step (index_of_the_star ).values ()[0 ]
1413+
1414+ #check desired_next_timestep has the intended value (1.2 Myr)
1415+ self .assertEqual (desired_next_timestep_second , obtained_next_time_step )
1416+
1417+ instance .stop ()
1418+
1419+ def test27 (self ):
1420+ print ("Testing basic operations: evolve..." )
1421+ instance = self .new_instance_of_an_optional_code (MESAInterface )
1422+ if instance is None :
1423+ print ("MESA was not built. Skipping test." )
1424+ return
1425+ set_mesa_paths_instance (instance )
1426+ instance .initialize_code ()
1427+ (index_of_the_star , error ) = instance .new_particle (1.0 )
1428+ self .assertEqual (0 , error )
1429+ self .assertEqual (index_of_the_star , 1 )
1430+ self .assertEqual (0 , instance .commit_particles ())
1431+
1432+ initial_dt = 1.0e5
1433+
1434+ instance .set_time_step (index_of_the_star , initial_dt )
1435+ self .assertEqual ([initial_dt , 0 ], list (instance .get_time_step (index_of_the_star ).values ()))
1436+
1437+ self .assertEqual (0 , instance .evolve_for (index_of_the_star , initial_dt ))
1438+ self .assertEqual (
1439+ [initial_dt , 0 ],
1440+ list (instance .get_age (index_of_the_star ).values ())
1441+ )
1442+
1443+ target_end_time = 3.0e5 # (years)
1444+ self .assertEqual (
1445+ 0 , instance .evolve_for (
1446+ index_of_the_star , target_end_time - initial_dt
1447+ )
1448+ )
1449+
1450+ self .assertTrue (
1451+ instance .get_age (index_of_the_star )['age' ] >= target_end_time
1452+ )
1453+ #Tests the functionality of new getters
1454+ (ML_of_the_star , error ) = instance .get_wind_mass_loss_rate (index_of_the_star )
1455+ self .assertEqual (0 , error )
1456+ self .assertAlmostEqual (ML_of_the_star , 0 , - 4 )
1457+ (gyr_of_the_star , error ) = instance .get_gyration_radius (index_of_the_star )
1458+ self .assertEqual (0 , error )
1459+ self .assertAlmostEqual (gyr_of_the_star , 0.3 , 1 )
1460+ (k2_of_the_star , error ) = instance .get_apsidal_motion_constant (index_of_the_star )
1461+ self .assertEqual (0 , error )
1462+ self .assertAlmostEqual (k2_of_the_star , 0.024 , 2 )
1463+ (Renv_of_the_star , error ) = instance .get_convective_envelope_radius (index_of_the_star )
1464+ self .assertEqual (0 , error )
1465+ self .assertAlmostEqual (Renv_of_the_star , 0.12 , 2 )
1466+ (Menv_of_the_star , error ) = instance .get_convective_envelope_mass (index_of_the_star )
1467+ self .assertEqual (0 , error )
1468+ self .assertAlmostEqual (Menv_of_the_star , 0.08 , 2 )
1469+ instance .stop ()
0 commit comments