tardis.plasma.equilibrium.thermal_balance module

class tardis.plasma.equilibrium.thermal_balance.ElectronThermalBalanceSolver(evaluator: PlasmaEquilibriumEvaluator, radiation_temperature: ndarray[tuple[Any, ...], dtype[float64]], level_initial_guess: DataFrame, maximum_electron_density: ndarray[tuple[Any, ...], dtype[float64]])[source]

Bases: object

Solve electron density and temperature balance across plasma shells.

Initialize a solve from one frozen plasma-equilibrium snapshot.

Parameters:
evaluatorPlasmaEquilibriumEvaluator

Fixed equilibrium evaluator for the outer thermal solve.

radiation_temperaturenumpy.ndarray

Radiation temperature in each shell [K].

level_initial_guesspandas.DataFrame

Frozen normalized level populations used during optimization.

maximum_electron_densitynumpy.ndarray

Maximum electron number density in each shell [cm^-3].

static calculate_electron_and_thermal_residuals(evaluation: PlasmaEquilibriumEvaluation) → ndarray[tuple[Any, ...], dtype[float64]][source]

Interleave the electron and heating residuals of each shell.

Parameters:
evaluationtardis.plasma.equilibrium.evaluator.PlasmaEquilibriumEvaluation

Equilibrium state at a candidate.

Returns:
numpy.ndarray

Interleaved normalized electron-density change (n_e,solved - n_e,trial)/n_e,trial and fractional heating (H - C)/C for each shell.

calculate_residual(candidate: ndarray[tuple[Any, ...], dtype[float64]]) → ndarray[tuple[Any, ...], dtype[float64]][source]

Calculate charge and heating residuals for all shells.

Parameters:
candidatenumpy.ndarray

Interleaved electron-density fractions and electron-to-radiation temperature ratios for each shell.

Returns:
numpy.ndarray

Interleaved normalized electron-density and fractional-heating residuals for each shell.

calculate_row_scale(candidate: ndarray[tuple[Any, ...], dtype[float64]], residual: ndarray[tuple[Any, ...], dtype[float64]], upper_bound: ndarray[tuple[Any, ...], dtype[float64]]) → ndarray[tuple[Any, ...], dtype[float64]][source]

Calculate the inverse Jacobian diagonal of each residual row.

Dividing each row by its own derivative puts the electron and heating rows of every shell in candidate units. In inner shells the heating row is otherwise ~100 times less sensitive than the electron row, and the trust-region solve stalls in their curved valley. Shells are independent, so one forward difference per candidate variable, taken in every shell at once, gives the whole diagonal.

Parameters:
candidatenumpy.ndarray

Interleaved electron-density fractions and electron-to-radiation temperature ratios for each shell.

residualnumpy.ndarray

Interleaved electron and heating residuals at candidate.

upper_boundnumpy.ndarray

Upper bounds for each value in candidate. A step that would cross a bound is taken backward instead.

Returns:
numpy.ndarray

1 / |d residual_i / d candidate_i| for each residual row, or 1 where that derivative is zero or not finite.

evaluate_candidate(candidate: ndarray[tuple[Any, ...], dtype[float64]]) → PlasmaEquilibriumEvaluation[source]

Rebuild the terminal equilibrium state for a candidate.

Parameters:
candidatenumpy.ndarray

Interleaved electron-density fractions and temperature ratios for each shell.

Returns:
tardis.plasma.equilibrium.evaluator.PlasmaEquilibriumEvaluation

Equilibrium state rebuilt using the candidate’s converged level populations as the terminal seed.

static find_converged_shells(residuals: ndarray[tuple[Any, ...], dtype[float64]]) → ndarray[tuple[Any, ...], dtype[bool]][source]

Find the shells within ELECTRON_AND_THERMAL_RESIDUAL_LIMITS.

Parameters:
residualsnumpy.ndarray

Interleaved electron and heating residuals for each shell.

Returns:
numpy.ndarray

True for each shell with both residuals within their limits. Nonfinite residuals are not converged.

least_squares_settings = {'ftol': 1e-12, 'gtol': 1e-14, 'max_nfev': 100, 'x_scale': 'jac', 'xtol': 1e-14}
solve(initial_guess: ndarray[tuple[Any, ...], dtype[float64]], lower_bound: ndarray[tuple[Any, ...], dtype[float64]], upper_bound: ndarray[tuple[Any, ...], dtype[float64]]) → tuple[ndarray[tuple[Any, ...], dtype[float64]], PlasmaEquilibriumEvaluation][source]

Solve all shells jointly and validate the accepted state.

Shells outside ELECTRON_AND_THERMAL_RESIDUAL_LIMITS after the joint solve are reported by a warning, and the run goes on; the next iteration starts its thermal solve from the accepted state.

Parameters:
initial_guessnumpy.ndarray

Initial interleaved electron-density fractions and temperature ratios for each shell.

lower_boundnumpy.ndarray

Lower bounds for each value in initial_guess.

upper_boundnumpy.ndarray

Upper bounds for each value in initial_guess.

Returns:
accepted_candidatenumpy.ndarray

Interleaved electron-density fractions and temperature ratios of the accepted state.

evaluationtardis.plasma.equilibrium.evaluator.PlasmaEquilibriumEvaluation

Validated terminal equilibrium state for accepted_candidate.

Raises:
RuntimeError

If the populations or the level and charge closure are invalid.

solve_multiple_shells(initial_guess: ndarray[tuple[Any, ...], dtype[float64]], lower_bound: ndarray[tuple[Any, ...], dtype[float64]], upper_bound: ndarray[tuple[Any, ...], dtype[float64]]) → OptimizeResult[source]

Solve charge and heating balance for all shells jointly.

Each residual row is divided by its Jacobian diagonal at the initial guess (see calculate_row_scale). The scaling leaves the roots unchanged.

Parameters:
initial_guessnumpy.ndarray

Initial interleaved electron-density fractions and temperature ratios for each shell.

lower_boundnumpy.ndarray

Lower bounds for each value in initial_guess.

upper_boundnumpy.ndarray

Upper bounds for each value in initial_guess.

Returns:
scipy.optimize.OptimizeResult

Result of the joint nonlinear least-squares solve. Its fun holds the row-scaled residuals.

static validate_evaluation(evaluation: PlasmaEquilibriumEvaluation) → None[source]

Validate the populations and the level and charge closure.

The electron and heating residuals are not checked here: shells that miss ELECTRON_AND_THERMAL_RESIDUAL_LIMITS are reported by warn_failed_shells instead.

Parameters:
evaluationtardis.plasma.equilibrium.evaluator.PlasmaEquilibriumEvaluation

Terminal equilibrium state to validate.

Raises:
RuntimeError

If populations or derived states are invalid, or if a level or charge residual exceeds its limit in THERMAL_BALANCE_RESIDUAL_LIMITS.

warn_failed_shells(evaluation: PlasmaEquilibriumEvaluation) → None[source]

Warn about shells outside their electron and heating limits.

Parameters:
evaluationtardis.plasma.equilibrium.evaluator.PlasmaEquilibriumEvaluation

Terminal equilibrium state.

class tardis.plasma.equilibrium.thermal_balance.ThermalBalanceSolver(bound_free_solver: BoundFreeThermalRates, free_free_solver: FreeFreeThermalRates, collisional_ionization_solver: CollisionalIonizationThermalRates, collisional_bound_solver: CollisionalBoundThermalRates)[source]

Bases: object

Class to solve the thermal balance equation using all available

heating and cooling processes. See section 6.4 in Lucy 03, especially equations 55-57.

Initialize the thermal balance solver with individual solver components.

Parameters:
bound_free_solver

Solver for bound-free heating and free-bound cooling processes.

free_free_solver

Solver for free-free heating and cooling processes.

collisional_ionization_solver

Solver for collisional ionization heating and cooling processes.

collisional_bound_solver

Solver for collisional bound-bound heating and cooling processes.

solve(thermal_electron_distribution: ThermalElectronEnergyDistribution, level_population: DataFrame, ion_population: DataFrame, collisional_ionization_rate_coefficient: DataFrame, collisional_deexcitation_rate_coefficient: DataFrame, collisional_excitation_rate_coefficient: DataFrame, free_free_heating_estimator: DataFrame, level_population_ratio: DataFrame, radiation_field: DilutePlanckianRadiationField | None = None, bound_free_heating_estimator: DataFrame | None = None, stimulated_recombination_estimator: DataFrame | None = None) → tuple[Series, Series][source]

Compute the current heating rate and the fractional heating

rate using all available processes. See section 6.4 in Lucy 03.

Parameters:
thermal_electron_distributionThermalElectronEnergyDistribution

Electron energy, temperature, and density.

level_populationpd.DataFrame

Level number density.

ion_populationpd.DataFrame

Ion number density.

collisional_ionization_rate_coefficientpd.DataFrame

Collisional ionization rate coefficient.

collisional_deexcitation_rate_coefficientpd.DataFrame

Collisional deexcitation rate coefficient.

collisional_excitation_rate_coefficientpd.DataFrame

Collisional excitation rate coefficient.

free_free_heating_estimatorpd.DataFrame

Montecarlo estimator for free-free heating.

level_population_ratiopd.DataFrame

Level population to ion population ratio. Lucy 03, equation 14.

radiation_fieldRadiationField, optional

Radiation field for mean intensity calculation.

bound_free_heating_estimatorpd.DataFrame, optional

Bound-free heating estimator.

stimulated_recombination_estimatorpd.DataFrame, optional

Stimulated recombination estimator.

Returns:
tuple[pd.Series, pd.Series]

Total heating rate and fractional heating rate for each cell.