예제 #1
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()
예제 #2
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()