def test_set_of_sites_addition(self): sites1 = [1, 2, 3, 4] sites2 = [5, 6, 7, 8] set_of_sites_1 = Set_of_Sites(sites1) set_of_sites_2 = Set_of_Sites(sites2) combined_set_of_sites = set_of_sites_1 + set_of_sites_2 self.assertEqual(combined_set_of_sites.sites, sites1 + sites2)
def mole_fractions(self): """Calculate the mole fractions (probability of defects occupation) for each site on the subgrid for each species. The output is stored as a Calculation attribute. Calculation.mf (dict): A dictionary of the defect species mole fractions for each site on the subgrid for each site species. Args: None """ mole_fractions = {} for label in self.site_labels: name = '{}'.format(label) mole_fractions[name] = Set_of_Sites( self.subgrids[name].set_of_sites).calculate_probabilities( self.grid, self.phi, self.temp) self.mf = mole_fractions
def mole_fractions(self): """ Calculates the mole fractions (probability of defects occupation ) for each site on the subgrid for each species. Returns: mf( dict ): A dictionary of the defect species mole fractions for each site on the subgrid for each site species. """ mole_fractions = {} for label in self.site_labels: name = '{}'.format(label) mole_fractions[name] = Set_of_Sites( self.subgrids[name].set_of_sites).calculate_probabilities( self.grid, self.phi, self.temp) self.mf = mole_fractions
def create_subregion_sites(self, grid, min_cut_off, max_cut_off): """ Creates a Set_of_Sites object for a defined region of the grid. Args: grid (object): Grid object - contains properties of the grid including the x coordinates and the volumes. Used to access the x coordinates. min_cut_off (float): Minimum x coordinate value defining the calculation region. max_cut_off (float): Maximum x coordinate value defining the calculation region. Returns: sites (object): Set of Sites object for a given subregion of the grid. """ sites = [] for site in grid.set_of_sites: if site.x > min_cut_off and site.x < max_cut_off: sites.append(site) sites = Set_of_Sites(sites) return sites
def calculate_mobile_defect_conductivities(self, pos_or_neg_scr, scr_limit, species, mobility_scaling=False): """Calculate the conductivity ratio between the space charge region and the bulk both perpendicular and parallel to the grain boundary. A `Set_of_Sites` object is created for the sites in the space charge region, and the defect distributions calculated. The width of the space charge region is calculated and a bulk region of the same width is defined. A Set_of_Sites object for the bulk region is created and the defect distributions calculated. Taking each site as a resistor in series or parallel respectively, the conductivity is calculated and the ratio between the space charge region and the bulk is taken. Args: pos_or_neg_scr (str): 'positive' - for a positive space charge potential. 'negative' - for a negative space charge potential. scr_limit (float): The minimum electrostatic potential that the electrostatic potential must exceed to be included in the space charge region. species (str): The species for which the conductivity is being calculated. mobility_scaling (bool): For particles on a lattice which only interact through volume exclusion, the mobility exhibits a blocking term. True if the blocking term is to be included, False if the blocking term is not to be included. Default = False. Returns: float: The perpendicular conductivity ratio. The conductivity ratio between the bulk and the space charge region perpendicular to the grain boundary. float: The parallel conductivity ratio. The conductivity ratio between the bulk and the space charge region parallel to the grain boundary. """ space_charge_region = self.create_space_charge_region( self.subgrids[species], pos_or_neg_scr, scr_limit) space_charge_region_limits = self.calculate_offset( self.subgrids[species], np.min(space_charge_region), np.max(space_charge_region)) space_charge_region_sites = self.create_subregion_sites( self.subgrids[species], np.min(space_charge_region), np.max(space_charge_region)) for site in space_charge_region_sites: charge = site.defects[0].valence mobilities = site.defects[0].mobility space_charge_region_grid = Grid.grid_from_set_of_sites( space_charge_region_sites, space_charge_region_limits, space_charge_region_limits, self.grid.b, self.grid.c) space_charge_region_width = space_charge_region_grid.x[ -1] - space_charge_region_grid.x[0] mobile_defect_density = Set_of_Sites( self.subgrids[species].set_of_sites ).subgrid_calculate_defect_density(self.subgrids[species], self.grid, self.phi, self.temp) space_charge_region_mobile_defect_mf = space_charge_region_sites.calculate_probabilities( space_charge_region_grid, self.phi, self.temp) space_charge_region_mobile_defect_density = space_charge_region_sites.subgrid_calculate_defect_density( space_charge_region_grid, self.grid, self.phi, self.temp) if mobility_scaling: mobile_defect_conductivity = space_charge_region_mobile_defect_density * ( 1 - space_charge_region_mobile_defect_mf) * charge * mobilities else: mobile_defect_conductivity = space_charge_region_mobile_defect_density * charge * mobilities bulk_x_max = self.bulk_x_min + space_charge_region_width min_bulk_index, max_bulk_index = self.find_index( self.subgrids[species], self.bulk_x_min, bulk_x_max) self.bulk_limits = self.calculate_offset(self.subgrids[species], self.bulk_x_min, bulk_x_max) bulk_mobile_defect_sites = self.create_subregion_sites( self.subgrids[species], self.bulk_x_min, bulk_x_max) bulk_mobile_defect_grid = Grid.grid_from_set_of_sites( bulk_mobile_defect_sites, self.bulk_limits, self.bulk_limits, self.grid.b, self.grid.c) bulk_mobile_defect_density = Set_of_Sites( bulk_mobile_defect_grid.set_of_sites ).subgrid_calculate_defect_density(bulk_mobile_defect_grid, self.grid, self.phi, self.temp) bulk_region_mobile_defect_mf = bulk_mobile_defect_sites.calculate_probabilities( bulk_mobile_defect_grid, self.phi, self.temp) if mobility_scaling: bulk_mobile_defect_conductivity = bulk_mobile_defect_density * charge * mobilities else: bulk_mobile_defect_conductivity = bulk_mobile_defect_density * charge * mobilities * ( 1 - bulk_region_mobile_defect_mf) space_charge_array = np.column_stack( (mobile_defect_conductivity, space_charge_region_grid.x)) bulk_array = np.column_stack( (bulk_mobile_defect_conductivity, bulk_mobile_defect_grid.x)) if mobilities != 0.0: space_charge_perpendicular = sum(space_charge_region_grid.delta_x / mobile_defect_conductivity) self.average_bulk_mobile_defect_density = sum( bulk_mobile_defect_grid.delta_x * bulk_mobile_defect_density) / sum( bulk_mobile_defect_grid.delta_x) bulk_perpendicular = sum(bulk_mobile_defect_conductivity / bulk_mobile_defect_grid.delta_x) space_charge_parallel = sum(mobile_defect_conductivity / space_charge_region_grid.delta_x) bulk_parallel = sum(bulk_mobile_defect_grid.delta_x / bulk_mobile_defect_conductivity) perpendicular_conductivity_ratio = 1 / ( space_charge_perpendicular * bulk_perpendicular) parallel_conductivity_ratio = space_charge_parallel * bulk_parallel else: perpendicular_conductivity_ratio = 0.0 parallel_conductivity_ratio = 0.0 # self.depletion_factor = 1 - ( mobile_defect_density / average_bulk ) return perpendicular_conductivity_ratio, parallel_conductivity_ratio
def test_set_of_sites_is_initialised(self): sites = [1, 2, 3, 4] set_of_sites = Set_of_Sites(sites) self.assertEqual(set_of_sites.sites, sites)