コード例 #1
0
    def p2p_self(self):
        """calculates the potential on all particle inside a cell due to particles in the same cell
        """
        ############## Task 5.1 begins ################

        #create particle index list for cell
        list_index = [i for i in range(len(self.particle_list))]

        #iterate through all particles
        for idx_self in range(len(self.particle_list)):

            #calculate dist. between other particles and accumulate potential to particle.phi

            # loop for particles before current
            for idx_others in list_index[:idx_self]:
                distance = self.particle_list[idx_self].distance(
                    self.particle_list[idx_others])
                self.particle_list[idx_self].phi += utils.lj_potential(
                    distance)

            # loop for particles after current
            for idx_others in list_index[idx_self + 1:]:
                distance = self.particle_list[idx_self].distance(
                    self.particle_list[idx_others])
                self.particle_list[idx_self].phi += utils.lj_potential(
                    distance)
コード例 #2
0
    def p2p_neigbor_cells(self, list_particles, list_cells):
        """calculates the potential on all particle inside a cell due to particles in the neighor cells
        
        Parameters
        ----------
        list_particles: list
            List of all "Particle" objects
        list_cells: list
            List of all cells
        """
        ############## Task 3.2 begins ################
        for particle_idx in self.particle_index:  ## Loop through particles in current cell
            particle = list_particles[particle_idx]  ## Current Particle

            for neighbor_idx in self.neighbor_cell_index:  ## Loop through neighbor cell
                neighbor_cell = list_cells[neighbor_idx]  ## Current Neighbor

                for other_idx in neighbor_cell.particle_index:  ## Looop through particles in neighbor cell
                    other_particle = list_particles[
                        other_idx]  ## Other Particle

                    distance = particle.distance(other_particle)
                    if (distance == 0):
                        continue
                    particle.phi += utils.lj_potential(
                        distance)  ## Add potential
コード例 #3
0
def direct_potential_one_particle(idx, list_particles):
    p1 = list_particles[idx]
    potential = 0.
    for p2 in list_particles:
        distance = p1.distance(p2)
        if distance > 1e-10:
            potential += utils.lj_potential(distance)
    return potential
コード例 #4
0
def direct_interaction_one_particle_v2(particle, list_cells):
    potential = 0
    for cell in list_cells:
        for p in cell.particle_list:
            distance = particle.distance(p)
            if distance > 1e-10:
                potential += utils.lj_potential(distance)
    return potential
コード例 #5
0
 def p2p_self(self):
     """calculates the potential on all particle inside a cell due to particles in the same cell
     """
     ############## Task 5.1 begins ################
     for particle in self.particle_list:
         for other_particle in self.particle_list:                
                 distance = particle.distance(other_particle)  # Calculate distance between the particles in the same cell
                 if(distance == 0):  # Ignore if it's the same particle
                 	continue
                 particle.phi += utils.lj_potential(distance)  # Add potentials
コード例 #6
0
 def p2p_self(self):
     """calculates the potential on all particle inside a cell due to particles in the same cell
     """
     ############## Task 5.1 begins ################
     # Iterate over all particles in the cell_local particle list
     for particle_id, particle in enumerate(self.particle_list):
         for neighbor_id, neighbor in enumerate(self.particle_list):
             # Only calculate the potential with other particles and not the
             # current particle since this would result in a zero distance
             # and hence division by zero
             if particle_id != neighbor_id:
                 distance = particle.distance(neighbor)
                 particle.phi += utils.lj_potential(distance)
コード例 #7
0
 def p2p_self(self, list_particles):
     """calculates the potential on all particle inside a cell due to particles in the same cell
     
     Parameters
     ----------
     list_particles: list
         List of all "Particle" objects
     """
     ############## Task 3.1 begins ################
     for i, particle_i in enumerate(self.particle_index):
         for particle_j in self.particle_index[i+1:]:
             distance = list_particles[particle_i].distance(list_particles[particle_j])
             potential = utils.lj_potential(distance)
             list_particles[particle_i].phi += potential
             list_particles[particle_j].phi += potential
コード例 #8
0
 def p2p_neigbor_cells(self, list_cells):
     """calculates the potential on all particle inside a cell due to particles in the neighor cells
     
     Parameters
     ----------
     list_cells: list
         List of all cells
     """
     ############## Task 5.2 begins ################
     for particle in self.particle_list:
         for neighbor_cell_id in self.neighbor_cell_index:
             for neighor_particle in list_cells[neighbor_cell_id].particle_list:  # Consider the particles in each neighbor cell
                 distance = particle.distance(neighor_particle)  # Calculate distance to the particles in the neighbor cell
                 if(distance == 0):
                 	continue
                 particle.phi += utils.lj_potential(distance) 
コード例 #9
0
 def p2p_neigbor_cells(self, list_particles, list_cells):
     """calculates the potential on all particle inside a cell due to particles in the neighor cells
     
     Parameters
     ----------
     list_particles: list
         List of all "Particle" objects
     list_cells: list
         List of all cells
     """
     ############## Task 3.2 begins ################
     for p_index in self.particle_index:
         for nc_index in self.neighbor_cell_index:
             for nc_particle_index in list_cells[nc_index].particle_index:
                 distance = list_particles[p_index].distance(list_particles[nc_particle_index])
                 potential = utils.lj_potential(distance)
                 list_particles[p_index].phi += potential
コード例 #10
0
 def p2p_neigbor_cells(self, list_cells):
     """calculates the potential on all particle inside a cell due to particles in the neighor cells
     
     Parameters
     ----------
     list_cells: list
         List of all cells
     """
     ############## Task 5.2 begins ################
     # Iterate over all particles in the current cell
     for particle in self.particle_list:
         # Iterate over all neighboring cells
         for neighbor_cell_id in self.neighbor_cell_index:
             # Iterate over all particles in a neighbor cell
             for neighbor_particle in list_cells[
                     neighbor_cell_id].particle_list:
                 distance = particle.distance(neighbor_particle)
                 particle.phi += utils.lj_potential(distance)
コード例 #11
0
    def p2p_self(self, list_particles):
        """calculates the potential on all particle inside a cell due to particles in the same cell
        
        Parameters
        ----------
        list_particles: list
            List of all "Particle" objects
        """
        ############## Task 3.1 begins ################
        for particle_idx in self.particle_index:  ## For every particle in current cell which we get from particle index.
            particle = list_particles[particle_idx]  ##Current Particle in Cell

            for other_idx in self.particle_index:  ## For every particle in current cell which we get from particle index.
                other_particle = list_particles[
                    other_idx]  ## Other Particle in same Cell

                if (particle_idx !=
                        other_idx):  ## If two particles aren't same particle
                    distance = particle.distance(other_particle)
                    particle.phi += utils.lj_potential(
                        distance)  ## Add potential
コード例 #12
0
    def p2p_neighbor_cells(self, list_cells):
        """calculates the potential on all particle inside a cell due to particles in the neighor cells
        
        Parameters
        ----------
        list_cells: list
            List of all cells
        """
        ############## Task 5.2 begins ################

        #iterate through particle in current cell and calculate potential with particles from other cells
        for particle_self in self.particle_list:

            for neighbor_cell_index in self.neighbor_cell_index:
                particle_list = list_cells[neighbor_cell_index].particle_list

                for particle in particle_list:
                    distance = particle.distance(particle_self)

                    #accumulate potential to particle.phi
                    particle_self.phi += utils.lj_potential(distance)
コード例 #13
0
 def p2p_neigbor_cells(self, list_particles, list_cells):
     """calculates the potential on all particle inside a cell due to particles in the neighor cells
     
     Parameters
     ----------
     list_particles: list
         List of all "Particle" objects
     list_cells: list
         List of all cells
     """
     ############## Task 3.2 begins ################
     # Over all particles inside the current cell
     for particle_id in self.particle_index:
         # Over all cells that are neighbors of the current cell
         for neighbor_cell_id in self.neighbor_cell_index:
             # Over all particles in the neighboring cell
             for neighbor_particle_id in list_cells[
                     neighbor_cell_id].particle_index:
                 distance = list_particles[particle_id].distance(
                     list_particles[neighbor_particle_id])
                 list_particles[particle_id].phi +=\
                     utils.lj_potential(distance)
コード例 #14
0
    def p2p_self(self, list_particles):
        """calculates the potential on all particle inside a cell due to particles in the same cell
        
        Parameters
        ----------
        list_particles: list
            List of all "Particle" objects
        """
        ############## Task 3.1 begins ################
        # Implements the slow O(n^2) affinity based calculation
        # TODO: Use Newton's 3rd law

        # Over all particles in the current cell
        for particle_id in self.particle_index:
            # Over all particles in the current cell
            for neighbor_id in self.particle_index:
                # Ignore the potential between the particle and itself -> leads
                # to division by zero in the potential
                if particle_id != neighbor_id:
                    distance = list_particles[particle_id].distance(
                        list_particles[neighbor_id])
                    list_particles[particle_id].phi +=\
                        utils.lj_potential(distance)