Ejemplo n.º 1
0
    def test3(self):
        print "Testing get/set for metallicity..."
        instance = EVtwinInterface()
        error = instance.initialize_code()
        self.assertEquals(0, error)
        error = instance.set_ev_path(instance.get_data_directory())
        self.assertEquals(0, error)
        (metallicity, error) = instance.get_metallicity()
        self.assertEquals(0, error)
        self.assertEquals(0.02, metallicity)

        # Z > 0.04 is not allowed
        error = instance.set_metallicity(0.0401)
        self.assertEquals(0, error)
        error = instance.commit_parameters()
        self.assertEquals(-2, error)

        # 0.0 <= Z <= 0.04 is allowed
        any_allowed_Z = numpy.random.random() * 0.04
        error = instance.set_metallicity(any_allowed_Z)
        self.assertEquals(0, error)
        (metallicity, error) = instance.get_metallicity()
        self.assertEquals(0, error)
        self.assertEquals(any_allowed_Z, metallicity)
        error = instance.commit_parameters()
        self.assertEquals(0, error)
        error = instance.cleanup_code()
        self.assertEquals(0, error)
        instance.stop()
Ejemplo n.º 2
0
    def test6(self):
        print "Testing EVtwin stop conditions..."
        instance = EVtwinInterface()
        error = instance.initialize_code()
        self.assertEquals(0, error)
        error = instance.set_ev_path(instance.get_data_directory())
        self.assertEquals(0, error)

        (value, error) = instance.get_max_age_stop_condition()
        self.assertEquals(0, error)
        self.assertEquals(2.0e12, value)
        for x in range(10,14):
            error = instance.set_max_age_stop_condition(10 ** x)
            self.assertEquals(0, error)
            (value, error) = instance.get_max_age_stop_condition()
            self.assertEquals(0, error)
            self.assertEquals(10 ** x, value)

        (value, error) = instance.get_min_timestep_stop_condition()
        self.assertEquals(0, error)
        self.assertAlmostEqual(1.0e6, value, 5)
        for x in range(-3,2):
            error = instance.set_min_timestep_stop_condition(10 ** x)
            self.assertEquals(0, error)
            (value, error) = instance.get_min_timestep_stop_condition()
            self.assertEquals(0, error)
            self.assertEquals(10 ** x, value)

        instance.stop()
Ejemplo n.º 3
0
 def test2(self):
     instance = EVtwinInterface()
     error = instance.initialize_code()
     self.assertEquals(0, error)
     error = instance.set_ev_path(instance.get_data_directory())
     self.assertEquals(0, error)
     error = instance.cleanup_code()
     self.assertEquals(0, error)
     instance.stop()
Ejemplo n.º 4
0
    def test5(self):
        print "Testing basic operations (new_particle_method, evolve_one_step etc.)..."
        instance = EVtwinInterface()
        error = instance.initialize_code()
        self.assertEquals(0, error)
        error = instance.set_ev_path(instance.get_data_directory())
        self.assertEquals(0, error)
        error = instance.commit_parameters()
        self.assertEquals(0, error)

        (index_of_the_star, error) = instance.new_particle_method(1.05)
        self.assertEquals(0, error)
        self.assertTrue(index_of_the_star >= 0)
        error = instance.commit_particles()
        self.assertEquals(0, error)
        error = instance.set_wind_multiplier(index_of_the_star, 1.0)
        self.assertEquals(0, error)

        (mass, error) = instance.get_mass(index_of_the_star)
        self.assertEquals(0, error)
        self.assertEquals(1.05, mass)

        for i in range(3):
            error = instance.evolve_one_step(index_of_the_star)
            self.assertEquals(0, error)

        (mass, error) = instance.get_mass(index_of_the_star)
        self.assertEquals(0, error)
        self.assertTrue(mass <= 1.05)

        (age, error) = instance.get_age(index_of_the_star)
        self.assertEquals(0, error)
        self.assertTrue(age > 0)

        (x, error) = instance.get_wind_mass_loss_rate(index_of_the_star)
        self.assertEquals(0, error)
        self.assertTrue(x < 1e-13, "mass loss should be less than 1e-13, it is {0}".format(x))
        self.assertTrue(x > 0, "mass loss rate should be more than 0, it is {0}".format(x))

        error = instance.cleanup_code()
        self.assertEquals(0, error)
        instance.stop()
Ejemplo n.º 5
0
    def test9(self):
        print "Testing adding and removing particles from stellar evolution code..."
        instance = EVtwinInterface()
        self.assertEquals(0, instance.initialize_code())
        self.assertEquals(0, instance.set_ev_path(instance.get_data_directory()))
        self.assertEquals(0, instance.commit_parameters())

        (indices, errors) = instance.new_particle_method([1.0, 1.0])
        self.assertEquals(errors, [0, 0])
        self.assertEquals(indices, [1, 2])

        self.assertEquals(0, instance.commit_particles())


        for index in indices:
            self.assertEquals(0, instance.evolve_one_step(index))
            (age_after_evolve, error) = instance.get_age(index)
            self.assertEquals(0, error)
            self.assertAlmostEqual(age_after_evolve, 3000000.0, 5)

        self.assertEquals(0, instance.delete_star(1))
        self.assertEquals(instance.get_number_of_particles()['number_of_particles'], 1)
        (age, error) = instance.get_age(1)
        self.assertEquals(error, -1)

        (indices, errors) = instance.new_particle_method([1.0, 1.0])
        self.assertEquals(errors, [0, 0])
        self.assertEquals(indices, [1, 3])
        self.assertEquals(instance.get_number_of_particles()['number_of_particles'], 3)

        for index in indices:
            (age, error) = instance.get_age(index)
            self.assertEquals(0, error)
            print age, age_after_evolve
            self.assertTrue(age < age_after_evolve)
            self.assertEquals(0, instance.evolve_one_step(index))
            (age, error) = instance.get_age(index)
            self.assertEquals(0, error)
            self.assertAlmostEqual(age, age_after_evolve)

        instance.stop()
Ejemplo n.º 6
0
    def test4(self):
        print "Testing get/set for maximum number of stars..."
        instance = EVtwinInterface()
        error = instance.initialize_code()
        self.assertEquals(0, error)
        error = instance.set_ev_path(instance.get_data_directory())
        self.assertEquals(0, error)
        (value, error) = instance.get_maximum_number_of_stars()
        self.assertEquals(0, error)
        self.assertEquals(10, value)

        error = instance.set_maximum_number_of_stars(10000)
        self.assertEquals(0, error)

        (value, error) = instance.get_maximum_number_of_stars()
        self.assertEquals(0, error)
        self.assertEquals(10000, value)

        error = instance.commit_parameters()
        self.assertEquals(0, error)
        error = instance.cleanup_code()
        self.assertEquals(0, error)
        instance.stop()
Ejemplo n.º 7
0
    def test7(self):
        print "Testing EVtwin parameters..."
        instance = EVtwinInterface()
        error = instance.initialize_code()
        self.assertEquals(0, error)
        error = instance.set_ev_path(instance.get_data_directory())
        self.assertEquals(0, error)
        error = instance.commit_parameters()
        self.assertEquals(0, error)

        (value, error) = instance.get_number_of_ionization_elements()
        self.assertEquals(0, error)
        self.assertEquals(5, value)
        for x in range(1,10):
            error = instance.set_number_of_ionization_elements(x)
            self.assertEquals(0, error)
            (value, error) = instance.get_number_of_ionization_elements()
            self.assertEquals(0, error)
            self.assertEquals(x, value)

        (value, error) = instance.get_convective_overshoot_parameter()
        self.assertEquals(0, error)
        self.assertEquals(0.12, value)
        for x in [0.0, 0.1, 0.12, 0.15]:
            error = instance.set_convective_overshoot_parameter(x)
            self.assertEquals(0, error)
            (value, error) = instance.get_convective_overshoot_parameter()
            self.assertEquals(0, error)
            self.assertEquals(x, value)

        (value, error) = instance.get_mixing_length_ratio()
        self.assertEquals(0, error)
        self.assertEquals(2.0, value)
        for x in [0.1, 1.0, 3.0]:
            error = instance.set_mixing_length_ratio(x)
            self.assertEquals(0, error)
            (value, error) = instance.get_mixing_length_ratio()
            self.assertEquals(0, error)
            self.assertEquals(x, value)

        (value, error) = instance.get_semi_convection_efficiency()
        self.assertEquals(0, error)
        self.assertEquals(0.04, value)
        for x in [0.0, 0.1]:
            error = instance.set_semi_convection_efficiency(x)
            self.assertEquals(0, error)
            (value, error) = instance.get_semi_convection_efficiency()
            self.assertEquals(0, error)
            self.assertEquals(x, value)

        (value, error) = instance.get_thermohaline_efficiency()
        self.assertEquals(0, error)
        self.assertEquals(1.0, value)
        for x in [0.0, 0.5, 1.5]:
            error = instance.set_thermohaline_efficiency(x)
            self.assertEquals(0, error)
            (value, error) = instance.get_thermohaline_efficiency()
            self.assertEquals(0, error)
            self.assertEquals(x, value)

        instance.stop()