コード例 #1
0
ファイル: test_mobse.py プロジェクト: stevemcmillan/amuse
 def test4(self):
     print "Test large number of particles..."
     number_of_particles = 2000
     instance = MOBSEInterface()
     status = instance.initialize(0.02, 0.5, 0.0, 0.5, 1.0, 0.1, 0, 1, 0, 1, 1, 3, 1, 3.0,
         29769, 0.05, 0.01, 0.02, 265.0, 7.0, 1.0/8.0, 1.0, 3.0/2.0, 0.001, 1.0, -1.0)
     masses1 = [1.0 + ((x / 1.0*number_of_particles) * 10.0) for x in range(1,number_of_particles+1)]
     masses2 = [2.0 + ((x / 1.0*number_of_particles) * 5.0) for x in range(1,number_of_particles+1)]
     orbital_periods = [100.0 + ((x / 1.0*number_of_particles) * 900.0) for x in range(1,number_of_particles+1)]
     eccentricities = [0.5 + ((x / 1.0*number_of_particles) * 0.4) for x in range(1,number_of_particles+1)]
     
     types1 = types2 = [1 for x in range(1,number_of_particles+1)]
     radii1 = luminosity1 = core_mass1 = core_radius1 =  envelope_mass1 =\
     envelope_radius1 =  spin1 = epoch1 = t_ms1 =\
     radii2 = luminosity2 = core_mass2 = core_radius2 =  envelope_mass2 =\
     envelope_radius2 =  spin2 = epoch2 = t_ms2 =\
     bse_age = [0.0 for x in range(1,number_of_particles+1)]
     end_time = [1.0 for x in range(1,number_of_particles+1)]
     init_mass1 = masses1
     init_mass2 = masses2
     
     result = instance.evolve_binary(
         types1, types2, init_mass1, init_mass2,
         masses1, masses2, radii1, radii2,
         luminosity1, luminosity2, core_mass1, core_mass2,
         core_radius1, core_radius2, envelope_mass1, envelope_mass2,
         envelope_radius1, envelope_radius2, spin1, spin2,
         epoch1, epoch2, t_ms1, t_ms2, 
         bse_age, orbital_periods, eccentricities, end_time
     )
     self.assertEquals(len(result['mass1']), number_of_particles)
     instance.stop()
コード例 #2
0
ファイル: test_mobse.py プロジェクト: stevemcmillan/amuse
    def test3(self):
        print "Test whether the interface can handle arrays..."
        instance = MOBSEInterface()
        status = instance.initialize(0.02, 0.5, 0.0, 0.5, 1.0, 0.1, 0, 1, 0, 1, 1, 3, 1, 3.0,
            29769, 0.05, 0.01, 0.02, 265.0, 7.0, 1.0/8.0, 1.0, 3.0/2.0, 0.001, 1.0, -1.0)
        masses1 = [10.0,5.0,4.0,40.0,130.0]
        masses2 = [1.0,1.0,1.0,10.0,60.0]
        types1 = types2 = [1,1,1,1,1]
        orbital_periods = [100.0,200.0,300.0,500.0,600.0]
        eccentricities = [0.5,0.6,0.7,0.3,0.2]

        radii1 = luminosity1 = core_mass1 = core_radius1 =  envelope_mass1 =\
        envelope_radius1 = spin1 = epoch1 = t_ms1 = [0.0,0.0,0.0,0.0,0.0]
        radii2 = luminosity2 = core_mass2 = core_radius2 =  envelope_mass2 =\
        envelope_radius2 = spin2 = epoch2 = t_ms2 = [0.0,0.0,0.0,0.0,0.0]
        init_mass1 = masses1
        init_mass2 = masses2
        bse_age = [0.0,0.0,0.0,0.0,0.0]
        end_time = [10.0, 10.0, 10.0, 10.0, 10.0]
        result = instance.evolve_binary(
            types1, types2, init_mass1, init_mass2,
            masses1, masses2, radii1, radii2,
            luminosity1, luminosity2, core_mass1, core_mass2,
            core_radius1, core_radius2, envelope_mass1, envelope_mass2,
            envelope_radius1, envelope_radius2, spin1, spin2,
            epoch1, epoch2, t_ms1, t_ms2, 
            bse_age, orbital_periods, eccentricities, end_time
        )
        self.assertAlmostEqual(result['mass1'][0], 9.99356, 2)
        self.assertAlmostEqual(result['mass1'][1], 4.99956, 2)
        self.assertAlmostEqual(result['mass1'][2], 3.99992, 2)
        self.assertAlmostEqual(result['mass1'][3], 3.07374, 2)
        self.assertAlmostEqual(result['mass1'][4], 13.61644, 2)
        instance.stop()
コード例 #3
0
ファイル: test_mobse.py プロジェクト: rjfarmer/amuse
 def test4(self):
     print("Test large number of particles...")
     number_of_particles = 2000
     instance = MOBSEInterface()
     status = instance.initialize(0.02, 0.5, 0.0, 0.5, 1.0, 0.1, 0, 1, 0, 1, 1, 3, 1, 3.0,
         29769, 0.05, 0.01, 0.02, 265.0, 7.0, 1.0/8.0, 1.0, 3.0/2.0, 0.001, 1.0, -1.0)
     masses1 = [1.0 + ((x / 1.0*number_of_particles) * 10.0) for x in range(1,number_of_particles+1)]
     masses2 = [2.0 + ((x / 1.0*number_of_particles) * 5.0) for x in range(1,number_of_particles+1)]
     orbital_periods = [100.0 + ((x / 1.0*number_of_particles) * 900.0) for x in range(1,number_of_particles+1)]
     eccentricities = [0.5 + ((x / 1.0*number_of_particles) * 0.4) for x in range(1,number_of_particles+1)]
     
     types1 = types2 = [1 for x in range(1,number_of_particles+1)]
     radii1 = luminosity1 = core_mass1 = core_radius1 =  envelope_mass1 =\
     envelope_radius1 =  spin1 = epoch1 = t_ms1 =\
     radii2 = luminosity2 = core_mass2 = core_radius2 =  envelope_mass2 =\
     envelope_radius2 =  spin2 = epoch2 = t_ms2 =\
     bse_age = [0.0 for x in range(1,number_of_particles+1)]
     end_time = [1.0 for x in range(1,number_of_particles+1)]
     init_mass1 = masses1
     init_mass2 = masses2
     
     result = instance.evolve_binary(
         types1, types2, init_mass1, init_mass2,
         masses1, masses2, radii1, radii2,
         luminosity1, luminosity2, core_mass1, core_mass2,
         core_radius1, core_radius2, envelope_mass1, envelope_mass2,
         envelope_radius1, envelope_radius2, spin1, spin2,
         epoch1, epoch2, t_ms1, t_ms2, 
         bse_age, orbital_periods, eccentricities, end_time
     )
     self.assertEqual(len(result['mass1']), number_of_particles)
     instance.stop()
コード例 #4
0
ファイル: test_mobse.py プロジェクト: rjfarmer/amuse
    def test3(self):
        print("Test whether the interface can handle arrays...")
        instance = MOBSEInterface()
        status = instance.initialize(0.02, 0.5, 0.0, 0.5, 1.0, 0.1, 0, 1, 0, 1, 1, 3, 1, 3.0,
            29769, 0.05, 0.01, 0.02, 265.0, 7.0, 1.0/8.0, 1.0, 3.0/2.0, 0.001, 1.0, -1.0)
        masses1 = [10.0,5.0,4.0,40.0,130.0]
        masses2 = [1.0,1.0,1.0,10.0,60.0]
        types1 = types2 = [1,1,1,1,1]
        orbital_periods = [100.0,200.0,300.0,500.0,600.0]
        eccentricities = [0.5,0.6,0.7,0.3,0.2]

        radii1 = luminosity1 = core_mass1 = core_radius1 =  envelope_mass1 =\
        envelope_radius1 = spin1 = epoch1 = t_ms1 = [0.0,0.0,0.0,0.0,0.0]
        radii2 = luminosity2 = core_mass2 = core_radius2 =  envelope_mass2 =\
        envelope_radius2 = spin2 = epoch2 = t_ms2 = [0.0,0.0,0.0,0.0,0.0]
        init_mass1 = masses1
        init_mass2 = masses2
        bse_age = [0.0,0.0,0.0,0.0,0.0]
        end_time = [10.0, 10.0, 10.0, 10.0, 10.0]
        result = instance.evolve_binary(
            types1, types2, init_mass1, init_mass2,
            masses1, masses2, radii1, radii2,
            luminosity1, luminosity2, core_mass1, core_mass2,
            core_radius1, core_radius2, envelope_mass1, envelope_mass2,
            envelope_radius1, envelope_radius2, spin1, spin2,
            epoch1, epoch2, t_ms1, t_ms2, 
            bse_age, orbital_periods, eccentricities, end_time
        )
        self.assertAlmostEqual(result['mass1'][0], 9.99356, 2)
        self.assertAlmostEqual(result['mass1'][1], 4.99956, 2)
        self.assertAlmostEqual(result['mass1'][2], 3.99992, 2)
        self.assertAlmostEqual(result['mass1'][3], 3.07374, 2)
        self.assertAlmostEqual(result['mass1'][4], 13.61644, 2)
        instance.stop()
コード例 #5
0
ファイル: test_mobse.py プロジェクト: rjfarmer/amuse
    def test1(self):
        print("Test initialization...")
        instance = MOBSEInterface()
        metallicity = 0.02
        neta = 0.5
        bwind =  0.0
        hewind =  0.5
        alpha1 = 1.0
        CElambda = 0.1
        ceflag = 0
        tflag = 1
        ifflag = 0
        wdflag =  1
        bhflag =  1 
        nsflag =  3
        piflag =  1
        mxns =  3.0
        idum = 29769
        pts1 = 0.05
        pts2 = 0.01
        pts3 = 0.02
        sigma1 =  265.0
        sigma2 =  7.0
        beta = 1.0/8.0
        xi = 1.0
        acc2 = 3.0/2.0
        epsnov = 0.001
        eddfac = 1.0
        gamma = -1.0

        status = instance.initialize(metallicity,
            neta, bwind, hewind, alpha1, CElambda,
            ceflag, tflag, ifflag, wdflag, bhflag,
            nsflag, piflag, mxns, idum, pts1, pts2, pts3,
            sigma1,sigma2,beta,xi,acc2,epsnov,eddfac,gamma)
        self.assertEqual(status,0)
        instance.stop()
コード例 #6
0
ファイル: test_mobse.py プロジェクト: stevemcmillan/amuse
    def test1(self):
        print "Test initialization..."
        instance = MOBSEInterface()
        metallicity = 0.02
        neta = 0.5
        bwind =  0.0
        hewind =  0.5
        alpha1 = 1.0
        CElambda = 0.1
        ceflag = 0
        tflag = 1
        ifflag = 0
        wdflag =  1
        bhflag =  1 
        nsflag =  3
        piflag =  1
        mxns =  3.0
        idum = 29769
        pts1 = 0.05
        pts2 = 0.01
        pts3 = 0.02
        sigma1 =  265.0
        sigma2 =  7.0
        beta = 1.0/8.0
        xi = 1.0
        acc2 = 3.0/2.0
        epsnov = 0.001
        eddfac = 1.0
        gamma = -1.0

        status = instance.initialize(metallicity,
            neta, bwind, hewind, alpha1, CElambda,
            ceflag, tflag, ifflag, wdflag, bhflag,
            nsflag, piflag, mxns, idum, pts1, pts2, pts3,
            sigma1,sigma2,beta,xi,acc2,epsnov,eddfac,gamma)
        self.assertEqual(status,0)
        instance.stop()
コード例 #7
0
ファイル: test_mobse.py プロジェクト: rjfarmer/amuse
    def test2(self):
        print("Test basic operations (legacy functions evolve & get_time_step)...")
        instance = MOBSEInterface()
        status = instance.initialize(0.02, 0.5, 0.0, 0.5, 1.0, 0.1, 0, 1, 0, 1, 1, 3, 1, 3.0,
            29769, 0.05, 0.01, 0.02, 265.0, 7.0, 1.0/8.0, 1.0, 3.0/2.0, 0.001, 1.0, -1.0)
        
        new_state = self.state()
        new_state.mass1 = 3.0
        new_state.mass2 = 1.0
        new_state.initial_mass1 = 3.0
        new_state.initial_mass2 = 1.0
        new_state.type1 = 1.0
        new_state.type2 = 1.0
        new_state.end_time = 1e-06
        new_state.orbital_period = 200.0
        new_state.eccentricity = 0.5
        
        result = instance.evolve_binary(
            new_state.type1,new_state.type2,new_state.initial_mass1,new_state.initial_mass2,
            new_state.mass1, new_state.mass2, new_state.radius1, new_state.radius2, 
            new_state.luminosity1, new_state.luminosity2, new_state.core_mass1, 
            new_state.core_mass2, new_state.core_radius1, new_state.core_radius2,
            new_state.envelope_mass1, new_state.envelope_mass2, new_state.envelope_radius1,
            new_state.envelope_radius2, new_state.spin1, new_state.spin2, new_state.epoch1,
            new_state.epoch2, new_state.t_ms1, new_state.t_ms2, new_state.bse_age,
            new_state.orbital_period, new_state.eccentricity, new_state.end_time
        )
        
        updated_state = self.state()
        (updated_state.type1,updated_state.type2,updated_state.initial_mass1,updated_state.initial_mass2,
            updated_state.mass1, updated_state.mass2, updated_state.radius1, updated_state.radius2, 
            updated_state.luminosity1, updated_state.luminosity2, updated_state.core_mass1,
            updated_state.core_mass2, updated_state.core_radius1, updated_state.core_radius2,
            updated_state.envelope_mass1,updated_state.envelope_mass2,updated_state.envelope_radius1,
            updated_state.envelope_radius2, updated_state.spin1, updated_state.spin2,
            updated_state.epoch1, updated_state.epoch2, updated_state.t_ms1, updated_state.t_ms2,
            updated_state.bse_age, updated_state.orbital_period,
            updated_state.eccentricity, updated_state.end_time) = result        
         
        expected = {
            'radius2' : '0x1.c6c8a1c793bcep-1',
            'luminosity2' : '0x1.653b1b2d0333bp-1',
            'core_mass2' : '0x0.0p+0',
            'bse_age' : '0x1.0c6f7a0b5ed8dp-20',
            'end_time' : '0x1.0c6f7a0b5ed8dp-20',
            'envelope_mass2' : '0x1.0d6fc100ab510p-5',
            'mass2' : '0x1.0000000000000p+0',
            'initial_mass2' : '0x1.0000000000000p+0',
            'envelope_radius2' : '0x1.db27631ba0e5ap-3',
            'core_radius2' : '0x0.0p+0',
            'epoch2' : '0x0.0p+0',
            't_ms2' : '0x1.57d90abe54643p+13',
            'spin2' : '0x1.07413b0522dabp+10',
        };    

        for x in expected:
            print("'%s' : '%s'," % (x, getattr(updated_state, x).hex()))
            self.assertAlmostRelativeEqual(float.fromhex(expected[x]),getattr(updated_state, x))
            
        self.assertEqual(updated_state.end_time, 1e-06)
        dt = instance.get_time_step(updated_state.type1, updated_state.type2,
            updated_state.initial_mass1, updated_state.initial_mass2, updated_state.mass1,
            updated_state.mass2, updated_state.t_ms1, updated_state.t_ms2,
            updated_state.epoch1, updated_state.epoch2, updated_state.bse_age)
        self.assertAlmostEqual(dt, 18.8768, 3)
        instance.stop()
コード例 #8
0
ファイル: test_mobse.py プロジェクト: stevemcmillan/amuse
    def test2(self):
        print "Test basic operations (legacy functions evolve & get_time_step)..."
        instance = MOBSEInterface()
        status = instance.initialize(0.02, 0.5, 0.0, 0.5, 1.0, 0.1, 0, 1, 0, 1, 1, 3, 1, 3.0,
            29769, 0.05, 0.01, 0.02, 265.0, 7.0, 1.0/8.0, 1.0, 3.0/2.0, 0.001, 1.0, -1.0)
        
        new_state = self.state()
        new_state.mass1 = 3.0
        new_state.mass2 = 1.0
        new_state.initial_mass1 = 3.0
        new_state.initial_mass2 = 1.0
        new_state.type1 = 1.0
        new_state.type2 = 1.0
        new_state.end_time = 1e-06
        new_state.orbital_period = 200.0
        new_state.eccentricity = 0.5
        
        result = instance.evolve_binary(
            new_state.type1,new_state.type2,new_state.initial_mass1,new_state.initial_mass2,
            new_state.mass1, new_state.mass2, new_state.radius1, new_state.radius2, 
            new_state.luminosity1, new_state.luminosity2, new_state.core_mass1, 
            new_state.core_mass2, new_state.core_radius1, new_state.core_radius2,
            new_state.envelope_mass1, new_state.envelope_mass2, new_state.envelope_radius1,
            new_state.envelope_radius2, new_state.spin1, new_state.spin2, new_state.epoch1,
            new_state.epoch2, new_state.t_ms1, new_state.t_ms2, new_state.bse_age,
            new_state.orbital_period, new_state.eccentricity, new_state.end_time
        )
        
        updated_state = self.state()
        (updated_state.type1,updated_state.type2,updated_state.initial_mass1,updated_state.initial_mass2,
            updated_state.mass1, updated_state.mass2, updated_state.radius1, updated_state.radius2, 
            updated_state.luminosity1, updated_state.luminosity2, updated_state.core_mass1,
            updated_state.core_mass2, updated_state.core_radius1, updated_state.core_radius2,
            updated_state.envelope_mass1,updated_state.envelope_mass2,updated_state.envelope_radius1,
            updated_state.envelope_radius2, updated_state.spin1, updated_state.spin2,
            updated_state.epoch1, updated_state.epoch2, updated_state.t_ms1, updated_state.t_ms2,
            updated_state.bse_age, updated_state.orbital_period,
            updated_state.eccentricity, updated_state.end_time) = result        
         
        expected = {
            'radius2' : '0x1.c6c8a1c793bcep-1',
            'luminosity2' : '0x1.653b1b2d0333bp-1',
            'core_mass2' : '0x0.0p+0',
            'bse_age' : '0x1.0c6f7a0b5ed8dp-20',
            'end_time' : '0x1.0c6f7a0b5ed8dp-20',
            'envelope_mass2' : '0x1.0d6fc100ab510p-5',
            'mass2' : '0x1.0000000000000p+0',
            'initial_mass2' : '0x1.0000000000000p+0',
            'envelope_radius2' : '0x1.db27631ba0e5ap-3',
            'core_radius2' : '0x0.0p+0',
            'epoch2' : '0x0.0p+0',
            't_ms2' : '0x1.57d90abe54643p+13',
            'spin2' : '0x1.07413b0522dabp+10',
        };    

        for x in expected:
            print "'%s' : '%s'," % (x, getattr(updated_state, x).hex())
            self.assertAlmostRelativeEqual(float.fromhex(expected[x]),getattr(updated_state, x))
            
        self.assertEquals(updated_state.end_time, 1e-06)
        dt = instance.get_time_step(updated_state.type1, updated_state.type2,
            updated_state.initial_mass1, updated_state.initial_mass2, updated_state.mass1,
            updated_state.mass2, updated_state.t_ms1, updated_state.t_ms2,
            updated_state.epoch1, updated_state.epoch2, updated_state.bse_age)
        self.assertAlmostEqual(dt, 18.8768, 3)
        instance.stop()