def test_index_of_grid_at_x(self): coordinates = np.array([-2.0, -1.0, 0.0, 1.0, 2.0]) with patch('pyscses.grid.closest_index') as mock_closest_index: mock_closest_index.side_effect = [0, 2, 3] self.assertEqual( index_of_grid_at_x(coordinates=coordinates, x=-1.5), 0) self.assertEqual( index_of_grid_at_x(coordinates=coordinates, x=0.1), 2) self.assertEqual( index_of_grid_at_x(coordinates=coordinates, x=1.5), 3)
def calculate_energies_on_grid( self, grid, phi ): """ Returns an array of energies at their points on a one-dimensional grid. Args: grid (object): Grid object - contains properties of the grid including the x coordinates and the volumes. Used to access the x coordinates. phi (array): electrostatic potential on a one-dimensional grid. Returns: array: energies at their grid points """ energies_on_grid = np.zeros_like( grid ) for site in self.sites: energies_on_grid[index_of_grid_at_x( grid.x, site.x )] =+ energy_at_x( site.defect_energies, grid.x, site.x ) return energies_on_grid
def calculate_probabilities( self, grid, phi, temp ): """ Calculates the probability of a site being occupied by its corresponding defect. Args: grid (object): Grid object - contains properties of the grid including the x coordinates and the volumes. Used to access the x coordinates. phi (array): electrostatic potential on a one-dimensional grid. temp (float): Absolute temperature. Returns: array: probabilities of defects occupying each site using their grid points """ probability = np.zeros_like( grid.x ) for site in self.sites: probability[index_of_grid_at_x( grid.x, site.x )] = np.asarray( site.probabilities( phi_at_x( phi, grid.x, site.x ), temp ) ) return probability
def calculate_defect_density( self, grid, phi, temp ): """ Calculates the defect density at each site. Args: grid (object): Grid object - contains properties of the grid including the x coordinates and the volumes. Used to access the x coordinates. phi (array): electrostatic potential on a one-dimensional grid. temp (float): Absolute temperature. Returns: array: defect density for each site using their grid points """ defect_density = np.zeros_like( grid.x ) for site in self.sites: i = index_of_grid_at_x( grid.x, site.x ) defect_density[ i ] += np.asarray( site.probabilities( phi_at_x( phi, grid.x, site.x ), temp ) ) / grid.volumes[ i ] return defect_density
def subgrid_calculate_defect_density(self, sub_grid: Grid, full_grid: Grid, phi: np.ndarray, temp: float) -> np.ndarray: """ Calculates the defect density at each site for a given subset of sites. Args: subgrid (Grid): Grid object - contains properties of the grid including the x coordinates and the volumes. Used to access the x coordinates. For a given subset of sites. full_grid (Grid): Grid object - contains properties of the grid including the x coordinates and the volumes. Used to access the x coordinates. For all sites. phi (array): electrostatic potential on a one-dimensional grid. temp (float): Absolute temperature. Returns: array: defect density for each site using their grid points """ defect_density = np.zeros_like( sub_grid.x ) for site in self.sites: i = index_of_grid_at_x( sub_grid.x, site.x ) defect_density[ i ] += np.asarray( site.probabilities_as_list( phi_at_x( phi, full_grid.x, site.x ), temp ) ) / sub_grid.volumes[ i ] return defect_density