Beispiel #1
0
 def output(self):
     """
     Print the verlet list 
     """
     Log.Output("\nVerletList object: algo={}, rcutoff={}".format(
         self.algo, self.rcutoff))
     for a in range(self.n_atoms()):
         na = self.data[0, a]
         Log.Output('{} {}'.format(a, self.data[0:na + 1, a]))
 def compute_interactions(self,zero_accelerations=True,verbose=False,n_iterations=1, verlet_list=None, verlet_linear=True):
     """
     Compute the interactions as specified by self.verlet_list.
     returns the cputime taken in the fortran subprogram
     """
     if verbose:
         Log.Output("ParticleContainer.compute_interactions - computing interactions ...")
         
     if zero_accelerations:
         self.zero_accelerations()
     
     if verlet_list:
         vll = verlet_list
     else:
         vll = self.verlet_list
     
     if verlet_linear:
         if vll.linear is None:
             vll.linearize()
         if use_md=='F90':
             cputime = pyMDFortran.compute_interactions_verlet_linear \
                                     ( self.rx, self.ry, self.rz
                                     , self.ax, self.ay, self.az, vll.linear
                                     , n_iterations
                                     )
         elif use_md in md_implementations_[1:]:
             n_atoms = self.ax.shape[0]
             vln,vlj = verlet_list_linear_to_nj(vll.linear,n_atoms)
             if use_md=='Vc':
                 cputime = pyMDCppVc.compute_interactions_verlet_list \
                                     ( self.rx, self.ry, self.rz
                                     , self.ax, self.ay, self.az, vln, vlj
                                     , n_iterations
                                     )
             elif use_md=='boost.simd':
                 cputime = pyMDCppBS.compute_interactions_verlet_list \
                                     ( self.rx, self.ry, self.rz
                                     , self.ax, self.ay, self.az, vln, vlj
                                     , n_iterations
                                     )
     else:
         cputime = pyMDFortran.compute_interactions_verlet \
                                     ( self.rx, self.ry, self.rz
                                     , self.ax, self.ay, self.az, vll.data
                                     , n_iterations
                                     )
     if verbose:
         Log.Output("{} x ParticleContainer.compute_interactions_verlet done in {}s".format(n_iterations,cputime))
     return cputime
Beispiel #3
0
def FCC(n, offset=[0, 0, 0], a=1, verbose=False):
    """
    Generate n points on a FCC lattice with a cubic lattice vector a.
    """
    # coordinate arrays
    x = np.zeros((n, ))
    y = np.zeros((n, ))
    z = np.zeros((n, ))
    # translation vector
    b = np.zeros((3, ))
    # xyz coordinates of i-th point
    r = np.zeros((3, ))
    # number of unit cells that is repeated in each direction
    nb = int(math.ceil((float(n) / 4)**(1. / 3)))
    i = 0
    for iz in range(nb):
        if i == n:
            break
        b[2] = iz + offset[2]
        for iy in range(nb):
            if i == n:
                break
            b[1] = iy + offset[1]
            for ix in range(nb):
                if i == n:
                    break
                b[0] = ix + offset[0]
                for j in range(4):
                    if i == n:
                        break
                    r = a * (b + A[j])
                    x[i] = r[0]
                    y[i] = r[1]
                    z[i] = r[2]

                    i += 1

    if verbose:
        Log.Output('FCC:')
        Log.Output('  number of points generated:' + str(n))
        Log.Output('  lattice constant a        :' + str(a))
        Log.Output('  offset                    :' + str(offset))
        Log.Output('  maximum number of cells in each direction:' + str(nb))
        Log.Output('  x :' + str(x))
        Log.Output('  y :' + str(y))
        Log.Output('  z :' + str(z))
        Log.Output('(call fcc with verbose=False to suppress this output)')
    return x, y, z, nb
Beispiel #4
0

def setup(nb, case, reserve=200, verify=False, force_construct=False):
    # nb = number of unit_cells in each direction
    n_atoms = 4 * nb**3  # fcc has 4 atoms per unit cell
    OK = False
    atoms_filename = 'atoms(nb={},case={}).pickled'.format(nb, case)

    if os.path.exists(atoms_filename) and not force_construct:
        #read the atoms from a file
        f = open(atoms_filename, 'rb')
        atoms = pickle.load(f)

        if atoms.size() == n_atoms:
            OK = True
            Log.Output('read from file:', atoms_filename)
            Log.Output("    nb =", atoms.extra['fcc_nb'])
            Log.Output("natoms =", atoms.size())
            Log.Output("  rmin =", atoms.extra['rmin'])
            Log.Output("     a =", atoms.extra['fcc_a'])
            Log.Output("cutoff =", atoms.extra['rcutoff'])
            Log.Output("     w =", atoms.extra['rcutoff'])
            Log.Output(
                "nb*a/w =", atoms.extra['fcc_nb'] * atoms.extra['fcc_a'] /
                atoms.extra['rcutoff'])

    if not OK:
        #construct atoms and save to file
        # lattice constant
        rmin = math.pow(2, 1 / 6)
        a = math.sqrt(2) * rmin
    def build_verlet_list_hilbert(self,cell_width,rcutoff,reserve,verbose,spatial_sort=True):
        """
        1. perform a hilbert sort
        2. construct hilbert list
        3. construct verlet list
        """
        print("spatial sort={}".format(spatial_sort))        
        with Log('ParticleContainer.build_verlet_list_hilbert: w={}, rc={}'.format(cell_width,rcutoff)):
                        
            # 1. indirect sort of the hilbert indices
            with Log("ParticleContainer.build_verlet_list - spatial sort"):
                if spatial_sort:
                    self.spatial_sort()
                    h = self.h
                    I = None
                else:
                    Log.Output('Spatial sort skipped on request.')
                    self.compute_h(self.cell_width)
                    Iint = np.argsort(self.h)
                    h = self.h[Iint]
                    I = Iint.astype(np.int32)
#                     Log.Output('h',h)
#                     Log.Output('I',I)

            # now h is sorted array of hilbert indices
            # and I is the indirection array if the particles are not spatially sorted, otherwise I = None
            n_atoms = self.size()
            hend = np.max(h)+1
            # 2. construct hilbert list
            with Log("ParticleContainer.build_verlet_list - building hilbert list") as logger:
                self.hilbert_list = np.empty((hend,2),dtype=np.int32)
                #   hilbert_list[0,h] is the index of the first atom in the cell with hilbert index h, 
                #   hilbert_list[1,h] is the number of atoms in that cell
                ia = 0
                for ih in range(hend):
                    self.hilbert_list[ih,0] = ia
                    n_atoms_in_h = 0
                    while ia<n_atoms and h[ia]==ih:
                        n_atoms_in_h += 1
                        ia += 1
                    self.hilbert_list[ih,1] = n_atoms_in_h
                                    
            # 3. construct verlet list
            if verbose:
                progressBar = ProgressBar()
            else:
                progressBar = None
            with Log("ParticleContainer.build_verlet_list - building verlet list", progressBar=progressBar) as logger:
                rcutoff2 = rcutoff**2
                self.verlet_list = VerletList( self.size(), algo='hilbert(cw={}, rc={})'.format(cell_width,rcutoff), reserve=reserve,rcutoff=rcutoff)
                if use_cpp:
                    logger.output('(executing C++ version)')
                    if I is None:
                        I = np.empty((0,),dtype=np.int32)

                    hilbert.build_verlet_list( self.verlet_list.data
                                             , self.hilbert_list
                                             , self.rx, self.ry, self.rz
                                             , I
                                             , rcutoff2
                                             )
                else:
                    logger.output('(executing Python version)')
                    #loop over all cells
                    ijk00 = np.empty((3,),dtype=np.int32)
                    for h00 in range(hend):
                        Log.Show_progress(h00/hend)
                        
                        hilbert.h2ijk_1(h00,ijk00)
                        h0 = h00
                        ijk0 = ijk00.copy()
                        # intra-cell
                        self.verlet_list_add_cell_(h0, rcutoff2,I)
                                
                        # loop over neighbouring cells
                        nb0 = [0,7,10,12,13]
                        for inb0 in range(4):
                            ijk0 = ijk00 + E[nb0[inb0],0,:]
                            h0 = hilbert.ijk2h_1(ijk0)
    #                         logger.print("h0={}:{}".format(h0,ijk0))
                            if -1<h0<hend:
                                for nb in range(nb0[inb0],nb0[inb0+1]):
    #                                 print(nb)
                                    ijk1 = ijk00 + E[nb,1,:]
                                    h1 = hilbert.ijk2h_1(ijk1)
        #                             logger.print("h1={}:{}".format(h1,ijk1))
                                    if -1<h1<hend:
        #                                 logger.print('{}:{}-{}:{}'.format(h0,ijk0,h1,ijk1))
                                        self.verlet_list_add_cell_cell_(h0,h1,rcutoff2,I)
                self.verlet_list.linearize()
        return self.verlet_list