Ejemplo n.º 1
0
def coreradius(mass,x,y,z):
  hop=Hop()
  ids,err=hop.new_particle(mass,x,y,z)
  hop.set_density_method(2)
  hop.set_nDens(7)
  hop.calculate_densities()
  dens,err=hop.get_density(ids)


  tdens=numpy.sum(dens)
  x_core=numpy.sum(dens*x)/tdens
  y_core=numpy.sum(dens*y)/tdens
  z_core=numpy.sum(dens*z)/tdens

  rc=numpy.sqrt(
      numpy.sum(dens**2*((x-x_core)**2+(y-y_core)**2+(z-z_core)**2))/numpy.sum(dens**2))
  return x_core,y_core,z_core,rc
Ejemplo n.º 2
0
def coreradius(mass,x,y,z):
  hop=Hop()
  ids,err=hop.new_particle(mass,x,y,z)
  hop.set_density_method(2)
  hop.set_nDens(7)
  hop.calculate_densities()
  dens,err=hop.get_density(ids)


  tdens=numpy.sum(dens)
  x_core=numpy.sum(dens*x)/tdens
  y_core=numpy.sum(dens*y)/tdens
  z_core=numpy.sum(dens*z)/tdens

  rc=numpy.sqrt(
      numpy.sum(dens**2*((x-x_core)**2+(y-y_core)**2+(z-z_core)**2))/numpy.sum(dens**2))
  return x_core,y_core,z_core,rc
Ejemplo n.º 3
0
    def test3(self):

        random.seed(1001)

        print "Third test: densest neighbors and groups."

        hop = HopInterface()
        hop.initialize_code()

        particles1 = new_plummer_model(10)
        particles2 = new_plummer_model(10)
        particles3 = new_plummer_model(10)

        particles2.position += (10, 0, 0) | nbody_system.length

        particles3.position += (0, 20, 0) | nbody_system.length

        ids1, errors = hop.new_particle(
            particles1.mass.value_in(nbody_system.mass),
            particles1.x.value_in(nbody_system.length),
            particles1.y.value_in(nbody_system.length),
            particles1.z.value_in(nbody_system.length))

        ids2, errors = hop.new_particle(
            particles2.mass.value_in(nbody_system.mass),
            particles2.x.value_in(nbody_system.length),
            particles2.y.value_in(nbody_system.length),
            particles2.z.value_in(nbody_system.length))

        ids3, errors = hop.new_particle(
            particles3.mass.value_in(nbody_system.mass),
            particles3.x.value_in(nbody_system.length),
            particles3.y.value_in(nbody_system.length),
            particles3.z.value_in(nbody_system.length))

        hop.set_nDens(5)
        hop.calculate_densities()
        hop.do_hop()

        n, err = hop.get_group_id(ids1)
        self.assertEquals(n, 2)
        self.assertEquals(err, 0)
        n, err = hop.get_group_id(ids2)
        self.assertEquals(err, 0)
        n, err = hop.get_group_id(ids3)
        self.assertEquals(err, 0)

        n, err = hop.get_densest_particle_in_group(2)
        self.assertEquals(n, 7)
        for i in range(3):
            n, err = hop.get_number_of_particles_in_group(0)
            self.assertEquals(err, 0)
            self.assertEquals(n, 10)

        n, err = hop.get_number_of_groups()
        self.assertEquals(n, 3)

        n, err = hop.get_densest_neighbor(ids1)
        self.assertEquals(n, [7, 7, 12, 0, 7, 7, 7, 7, 12, 7])
        hop.stop()
Ejemplo n.º 4
0
    def test2(self):
        random.seed(1001)

        hop = HopInterface()
        hop.initialize_code()

        particles = new_plummer_model(1000)
        ids, errors = hop.new_particle(
            particles.mass.value_in(nbody_system.mass),
            particles.x.value_in(nbody_system.length),
            particles.y.value_in(nbody_system.length),
            particles.z.value_in(nbody_system.length))

        n, err = hop.get_number_of_particles()
        self.assertEquals(n, 1000)
        self.assertEquals(err, 0)

        #distance_to_center = (particles.position - particles.center_of_mass()).lengths()

        #print distance_to_center
        ds = {0: 0.482308834791, 1: 0.4885137677192688, 2: 0.27442726492881775}
        for method in [0, 1, 2]:
            hop.set_nDens(7)
            hop.set_density_method(method)
            hop.calculate_densities()

            d, err = hop.get_density(0)
            self.assertAlmostRelativeEquals(d, ds[method], 5)
        hop.stop()
Ejemplo n.º 5
0
    def test4(self):
        hop = HopInterface()
        hop.initialize_code()
        value, error = hop.get_nDens()
        self.assertEquals(error, 0)
        self.assertEquals(value, 64)
        error = hop.set_nDens(7)
        self.assertEquals(error, 0)
        value, error = hop.get_nDens()
        self.assertEquals(value, 7)

        value, error = hop.get_nHop()
        self.assertEquals(error, 0)
        self.assertEquals(value, -1)
        error = hop.set_nHop(7)
        self.assertEquals(error, 0)
        value, error = hop.get_nHop()
        self.assertEquals(value, 7)

        value, error = hop.get_nBucket()
        self.assertEquals(error, 0)
        self.assertEquals(value, 16)
        error = hop.set_nHop(7)
        self.assertEquals(error, 0)
        value, error = hop.get_nHop()
        self.assertEquals(value, 7)
        hop.stop()
Ejemplo n.º 6
0
    def test1(self):
        print "First test: adding particles, setting and getting."
        hop = HopInterface()
        hop.initialize_code()
        n, err = hop.get_number_of_particles()
        self.assertEquals(n, 0)
        self.assertEquals(err, 0)

        for i in range(6):
            id, err = hop.new_particle(0, i * i, 0, 0)
            n, err = hop.get_number_of_particles()
            self.assertEquals(n, i + 1)
            self.assertEquals(err, 0)

        for i in range(6):
            x, y, z, err = hop.get_position(i)
            self.assertEquals(x, i * i)
            self.assertEquals(y, 0)
            self.assertEquals(z, 0)
            self.assertEquals(err, 0)

            hop.set_position(i, x, i * i, 0)

        for i in range(6):
            x, y, z, err = hop.get_position(i)
            self.assertEquals(x, y)
            self.assertEquals(z, 0)
            self.assertEquals(err, 0)

        hop.stop()
Ejemplo n.º 7
0
def hopfromnb(nb,ids):
  m,r,x,y,z,vx,vy,vz,err=nb.get_state(ids)
  hop=Hop()
  ids2,err=hop.new_particle(x,y,z)    
  return hop,ids2
Ejemplo n.º 8
0
 def test3(self): 
 
     random.seed(1001)
     
     print "Third test: densest neighbors and groups."
             
     hop = HopInterface()
     hop.initialize_code()
     
     particles1 = new_plummer_model(10)
     particles2 = new_plummer_model(10)
     particles3 = new_plummer_model(10)
     
     particles2.position += (10,0,0) | nbody_system.length
     
     particles3.position += (0,20,0) | nbody_system.length
     
     ids1, errors = hop.new_particle(
         particles1.mass.value_in(nbody_system.mass),
         particles1.x.value_in(nbody_system.length),
         particles1.y.value_in(nbody_system.length),
         particles1.z.value_in(nbody_system.length)
     )
     
     ids2, errors = hop.new_particle(
         particles2.mass.value_in(nbody_system.mass),
         particles2.x.value_in(nbody_system.length),
         particles2.y.value_in(nbody_system.length),
         particles2.z.value_in(nbody_system.length)
     )
     
     ids3, errors = hop.new_particle(
         particles3.mass.value_in(nbody_system.mass),
         particles3.x.value_in(nbody_system.length),
         particles3.y.value_in(nbody_system.length),
         particles3.z.value_in(nbody_system.length)
     )
     
     
     hop.set_nDens(5)
     hop.calculate_densities()
     hop.do_hop()
     
     n, err = hop.get_group_id(ids1)
     self.assertEquals(n, 2)
     self.assertEquals(err, 0)
     n, err = hop.get_group_id(ids2)
     self.assertEquals(err, 0)
     n, err = hop.get_group_id(ids3)
     self.assertEquals(err, 0)
     
     n, err = hop.get_densest_particle_in_group(2)
     self.assertEquals(n, 7)
     for i in range(3):
         n, err = hop.get_number_of_particles_in_group(0)
         self.assertEquals(err, 0)
         self.assertEquals(n, 10)
         
     n, err = hop.get_number_of_groups()
     self.assertEquals(n, 3)
     
     n, err = hop.get_densest_neighbor(ids1)
     self.assertEquals(n, [7,7,12,0,7,7,7,7,12,7])
     hop.stop()
Ejemplo n.º 9
0
 def test2(self):
     random.seed(1001)
     
     hop = HopInterface()
     hop.initialize_code()
     
     particles = new_plummer_model(1000)
     ids, errors = hop.new_particle(
         particles.mass.value_in(nbody_system.mass),
         particles.x.value_in(nbody_system.length),
         particles.y.value_in(nbody_system.length),
         particles.z.value_in(nbody_system.length)
     )
     
     n, err = hop.get_number_of_particles()
     self.assertEquals(n, 1000)
     self.assertEquals(err, 0)
     
     #distance_to_center = (particles.position - particles.center_of_mass()).lengths()
     
     #print distance_to_center
     ds = {0: 0.482308834791, 1:0.4885137677192688, 2:0.27442726492881775}
     for method in [0,1,2]:
         hop.set_nDens(7)
         hop.set_density_method(method)
         hop.calculate_densities()
         
         d, err = hop.get_density(0)
         self.assertAlmostRelativeEquals(d,ds[method], 5)
     hop.stop()
Ejemplo n.º 10
0
 def test4(self):
     hop = HopInterface()
     hop.initialize_code()
     value, error = hop.get_nDens()
     self.assertEquals(error,0)
     self.assertEquals(value,64)
     error = hop.set_nDens(7)
     self.assertEquals(error,0)
     value, error = hop.get_nDens()
     self.assertEquals(value,7)
     
     value, error = hop.get_nHop()
     self.assertEquals(error,0)
     self.assertEquals(value, -1)
     error = hop.set_nHop(7)
     self.assertEquals(error,0)
     value, error = hop.get_nHop()
     self.assertEquals(value,7)
     
     value, error = hop.get_nBucket()
     self.assertEquals(error,0)
     self.assertEquals(value, 16)
     error = hop.set_nHop(7)
     self.assertEquals(error,0)
     value, error = hop.get_nHop()
     self.assertEquals(value,7)
     hop.stop()
Ejemplo n.º 11
0
 def test1(self):
     print "First test: adding particles, setting and getting."
     hop = HopInterface()
     hop.initialize_code()
     n, err = hop.get_number_of_particles()
     self.assertEquals(n, 0)
     self.assertEquals(err, 0)
     
     for i in range(6):
         id, err = hop.new_particle(0, i*i, 0, 0)
         n, err = hop.get_number_of_particles()
         self.assertEquals(n, i+1)
         self.assertEquals(err, 0)
     
     for i in range(6):
         x, y, z, err = hop.get_position(i)
         self.assertEquals(x, i*i)
         self.assertEquals(y, 0)
         self.assertEquals(z, 0)
         self.assertEquals(err, 0)
         
         hop.set_position(i, x, i*i, 0)
     
     for i in range(6):
         x, y, z, err  = hop.get_position(i)
         self.assertEquals(x, y)
         self.assertEquals(z, 0)
         self.assertEquals(err, 0)
     
     hop.stop()
Ejemplo n.º 12
0
def hopfromnb(nb,ids):
  m,r,x,y,z,vx,vy,vz,err=nb.get_state(ids)
  hop=Hop()
  ids2,err=hop.new_particle(x,y,z)    
  return hop,ids2