Exemple #1
0
    def calculate(self, phi, partition_function, number_density):
        n_e_convergence_threshold = 0.05
        n_electron = number_density.sum(axis=0)
        n_electron_iterations = 0

        while True:
            ion_number_density = self.calculate_with_n_electron(
                phi, partition_function, number_density, n_electron)
            if hasattr(self.plasma_parent, 'plasma_properties_dict'):
                if 'HeliumNLTE' in \
                    self.plasma_parent.plasma_properties_dict.keys():
                    ion_number_density = \
                        self.update_helium_nlte(ion_number_density,
                        number_density)
            ion_numbers = ion_number_density.index.get_level_values(1).values
            ion_numbers = ion_numbers.reshape((ion_numbers.shape[0], 1))
            new_n_electron = (ion_number_density.values *
                              ion_numbers).sum(axis=0)
            if np.any(np.isnan(new_n_electron)):
                raise PlasmaIonizationError('n_electron just turned "nan" -'
                                            ' aborting')
            n_electron_iterations += 1
            if n_electron_iterations > 100:
                logger.warn('n_electron iterations above 100 ({0}) -'
                            ' something is probably wrong'.format(
                                n_electron_iterations))
            if np.all(
                    np.abs(new_n_electron - n_electron) /
                    n_electron < n_e_convergence_threshold):
                break
            n_electron = 0.5 * (new_n_electron + n_electron)
        return ion_number_density, n_electron
Exemple #2
0
 def calculate(self, phi, partition_function, number_density,
               helium_population):
     n_e_convergence_threshold = 0.05
     n_electron = number_density.sum(axis=0)
     n_electron_iterations = 0
     while True:
         ion_number_density, self.block_ids = \
             IonNumberDensity.calculate_with_n_electron(
             phi, partition_function, number_density, n_electron,
                 self.block_ids, self.ion_zero_threshold)
         helium_population_updated = self.update_he_population(
             helium_population, n_electron, number_density)
         ion_number_density.ix[2].ix[0].update(helium_population_updated.ix[
                                                   0].sum(axis=0))
         ion_number_density.ix[2].ix[1].update(helium_population_updated.ix[
                                                   1].sum(axis=0))
         ion_number_density.ix[2].ix[2].update(helium_population_updated.ix[
                                                   2].ix[0])
         ion_numbers = ion_number_density.index.get_level_values(1).values
         ion_numbers = ion_numbers.reshape((ion_numbers.shape[0], 1))
         new_n_electron = (ion_number_density.values * ion_numbers).sum(
             axis=0)
         if np.any(np.isnan(new_n_electron)):
             raise PlasmaIonizationError('n_electron just turned "nan" -'
                                         ' aborting')
         n_electron_iterations += 1
         if n_electron_iterations > 100:
             logger.warn('n_electron iterations above 100 ({0}) -'
                         ' something is probably wrong'.format(
                 n_electron_iterations))
         if np.all(np.abs(new_n_electron - n_electron)
                           / n_electron < n_e_convergence_threshold):
             break
         n_electron = 0.5 * (new_n_electron + n_electron)
     return ion_number_density, n_electron, helium_population_updated
    def calculate(self, phi, partition_function, number_density):
        if self._electron_densities is None:
            n_e_convergence_threshold = 0.05
            n_electron = number_density.sum(axis=0)
            n_electron_iterations = 0

            while True:
                (
                    ion_number_density,
                    self.block_ids,
                ) = self.calculate_with_n_electron(
                    phi,
                    partition_function,
                    number_density,
                    n_electron,
                    self.block_ids,
                    self.ion_zero_threshold,
                )
                ion_numbers = ion_number_density.index.get_level_values(
                    1
                ).values
                ion_numbers = ion_numbers.reshape((ion_numbers.shape[0], 1))
                new_n_electron = (ion_number_density.values * ion_numbers).sum(
                    axis=0
                )
                if np.any(np.isnan(new_n_electron)):
                    raise PlasmaIonizationError(
                        'n_electron just turned "nan" -' " aborting"
                    )
                n_electron_iterations += 1
                if n_electron_iterations > 100:
                    logger.warn(
                        f"n_electron iterations above 100 ({n_electron_iterations}) -"
                        f" something is probably wrong"
                    )
                if np.all(
                    np.abs(new_n_electron - n_electron) / n_electron
                    < n_e_convergence_threshold
                ):
                    break
                n_electron = 0.5 * (new_n_electron + n_electron)
        else:
            n_electron = self._electron_densities
            ion_number_density, self.block_ids = self.calculate_with_n_electron(
                phi,
                partition_function,
                number_density,
                n_electron,
                self.block_ids,
                self.ion_zero_threshold,
            )

        return ion_number_density, n_electron