def test_that_two_level_analytic_pop_dens_ratios_are_computed_correctly(): # # load the two level species data # species_data = DataLoader().load('two_level_1') n_c = 1e6 * u.meter ** -3 t_rad = 1000.0 * u.Kelvin # # for each value in the temperature range # - compute the population density ration numerically # - compute the population density analytically # # plot the comaprision # ratio_numeric_vs_t_kin = [] ratio_analytic_vs_t_kin = [] t_kin_range = numpy.logspace(1.0, 10.0, 50) * u.Kelvin for t_kin in t_kin_range: pop_dens_eq_numeric = population_density_at_steady_state( species_data, t_kin, t_rad, n_c) pop_dens_eq_ratio_numeric = pop_dens_eq_numeric[1] / pop_dens_eq_numeric[0] ratio_numeric_vs_t_kin.append(pop_dens_eq_ratio_numeric) pop_dens_eq_ratio_analytic = analytic.population_density_ratio_two_level( species_data.energy_levels.data['g'], species_data.energy_levels.data['E'], species_data.k_dex_matrix_interpolator(t_kin)[1, 0], species_data.a_matrix[1, 0], n_c, t_kin, t_rad ) ratio_analytic_vs_t_kin.append(pop_dens_eq_ratio_analytic) print(t_kin) ratio_numeric_vs_t_kin = numpy.array(ratio_numeric_vs_t_kin).flatten() ratio_analytic_vs_t_kin = numpy.array(ratio_analytic_vs_t_kin).flatten() relative_error = numpy.abs( 1.0 - numpy.array(ratio_numeric_vs_t_kin) / numpy.array( ratio_analytic_vs_t_kin) ) assert relative_error.max() < 1.2e-15 assert relative_error.std() < 5.0e-16
def test_that_the_lipovka_cooling_function_is_computed_correctly(): t_rad = 0.0 * u.K nc_h = 1e6 * u.m**-3 species_data = DataLoader().load('HD_lipovka') t_array = u.Quantity([100.0, 500.0, 1000.0, 1500.0, 2000.0]) * u.K cooling_rate_expected = u.Quantity([ 2.239044e-25, # T=100K 2.861033e-24, # T=500K 6.783145e-24, # T=1000K 1.108309e-23, # T=1500K 1.570218e-23 # T=2000K ]) * u.erg / u.s cooling_rate_for_t_array = u.Quantity([ cooling_rate_at_steady_state(species_data, t, t_rad, nc_h) for t in t_array ]) assert_allclose(cooling_rate_for_t_array.cgs.value, cooling_rate_expected.cgs.value, rtol=1e-6, atol=0.0)
def test_that_the_lique_cooling_function_is_computed_correctly(): t_rad = 0.0 * u.K nc_h = 1e6 * u.m**-3 species_data = DataLoader().load('H2_lique') t_array = u.Quantity([100.0, 500.0, 1000.0, 2000.0, 5000.0]) * u.K cooling_rate_expected = u.Quantity([ 1.09526153e-28, # T=100K 2.67540424e-26, # T=500K 6.64684189e-25, # T=1000K 8.35387575e-24, # T=2000K 1.00510330e-22 # T=5000K ]) * u.erg / u.s cooling_rate_for_t_array = u.Quantity([ cooling_rate_at_steady_state(species_data, t, t_rad, nc_h) for t in t_array ]) assert_allclose(cooling_rate_for_t_array.cgs.value, cooling_rate_expected.cgs.value, rtol=2e-6, atol=0.0)
import matplotlib.pyplot as plt import numpy from astropy import units as u from frigus.cooling_function.fits import fit_glover from frigus.population import (cooling_rate_at_steady_state, population_density_at_steady_state) from frigus.readers.dataset import DataLoader import matplotlib from matplotlib.ticker import ScalarFormatter from decimal import Decimal species_data = DataLoader().load('H2_lique') species_data_wrathmall = DataLoader().load('H2_wrathmall') plt.ion() #fig, axs = plt.subplots(figsize=(8, 8)) # density of the colliding species, in m^3 nc_h_rng = [1.e6, 1.e7, 1.e8, 1.e9, 1.e10, 1.e11, 1.e12, 1.e13, 1.e14 ] * u.meter**-3 t_rad = 0.0 * u.Kelvin t_rng = numpy.logspace(2, 3.6, 10) * u.Kelvin # T_rng = species_data.raw_data.collision_rates_T_range plot_markers = [(2 + i // 2, 1 + i % 2, 0) for i in range(16)]
<seealso> </seealso> """ from __future__ import print_function import numpy from astropy import units as u import matplotlib.pyplot as plt from frigus.readers.dataset import DataLoader from frigus.population import population_density_at_steady_state from frigus.solvers import analytic # # load the two level species data # species_data = DataLoader().load('two_level_1') n_c = 1e6 * u.meter ** -3 t_kin = 100000.0 * u.Kelvin t_rad = 100.0 * u.Kelvin # # for each value in the temperature range # - compute the population density ration numerically # - compute the population density analytically # # plot the comaprision # ratio_numeric_vs_t_kin = [] ratio_analytic_vs_t_kin = [] t_kin_range = numpy.logspace(1.0, 10.0, 50) * u.Kelvin
<seealso> </seealso> """ from __future__ import print_function import numpy from astropy import units as u import matplotlib.pyplot as plt from scipy.integrate import ode from frigus.population import (population_density_at_steady_state, compute_transition_rate_matrix) from frigus.readers.dataset import DataLoader # load the species data species_data = DataLoader().load('HD_lipovka') # time range and timestep t_0 = 0.0 t_f = 1e10 dt = 1e5 # the environment parameters nc_h = 1e8 * u.meter**-3 t_kin = 2000.0 * u.Kelvin t_rad = 2.73 * u.Kelvin # the rates matrix (that is fixed if the environemnt params above are fixed) # so it is computed once m_matrix = compute_transition_rate_matrix(species_data, t_kin, t_rad, nc_h)
.. warning:: this results in negative population densities. fix it. """ from __future__ import print_function import matplotlib.pyplot as plt import numpy from astropy import units as u from frigus.cooling_function.fits import fit_glover from frigus.population import (cooling_rate_at_steady_state, population_density_at_steady_state) from frigus.readers.dataset import DataLoader species_data = DataLoader().load('H2_wrathmall') # density of the colliding species, in m^3 nc_h = 1e6 * u.meter ** -3 t_rad = 0.0 * u.Kelvin lambda_vs_t_kin = [] pop_dens_vs_t_kin = [] t_rng = species_data.raw_data.collision_rates_t_range for i, t_kin in enumerate(t_rng): #print(t_kin) pop_dens_vs_t_kin += [ population_density_at_steady_state(species_data, t_kin, t_rad, nc_h)
""" compute the cooling function as a function of kinetic temperature and gas density and plot them in 3D """ from __future__ import print_function import numpy as np from astropy import units as u from frigus.readers.dataset import DataLoader from frigus.cooling_function.grid import CoolingFunctionGrid grid = CoolingFunctionGrid() grid.set_species(DataLoader().load('HD_lipovka')) grid.set_density(np.logspace(6, 14, 10) * u.m**-3) grid.set_t_kin(np.logspace(2, 3.2, 10) * u.Kelvin) grid.set_t_rad(0.0 * u.Kelvin) grid.plot_3d(x='n', y='t_kin', show=True) print('done')
from numpy import fabs, logspace, array from astropy import units as u from frigus.solvers.analytic import population_denisty_ratio_two_level_no_radiation from frigus.population import population_density_at_steady_state from frigus.readers.dataset import DataLoader # density of the colliding species, in m^3 nc = 1e14 * u.meter**-3 # the kinetic temperature of the gas t_kin = 3000.0 * u.Kelvin t_rad = 30.0 * u.Kelvin species_data = DataLoader().load('two_level_1') t_kin_range = logspace(2.0, 6.0, 100) * u.K x_exact = array([ population_denisty_ratio_two_level_no_radiation(species_data, T_kin, nc) for T_kin in t_kin_range ], 'f8') x_numerical = array([ population_density_at_steady_state(species_data, T_kin, 0.0, nc) for T_kin in t_kin_range ], 'f8')[:, :, 0] # plot the relative population densities as a function of temperatures pylab.figure()
# -*- coding: utf-8 -*- """ Calculate equilibrium population of species and the cooling function using the Lipovka data """ from __future__ import print_function import numpy as np import matplotlib.pyplot as plt from astropy import units as u from frigus.cooling_function.fits import fit_lipovka from frigus.population import cooling_rate_at_steady_state from frigus.readers.dataset import DataLoader species_data = DataLoader().load('HeH2') plt.ion() fig, axs = plt.subplots(figsize=(8, 8)) # density of the colliding species, in m^3 nc_h_rng = [1.e6, 1.e7, 1.e8, 1.e9, 1.e10, 1.e11, 1.e12, 1.e13, 1.e14 ] * u.meter**-3 t_rad = 0.0 * u.Kelvin t_rng = np.logspace(2, 3.2, 10) * u.Kelvin # T_rng = species_data.raw_data.collision_rates_T_range plot_markers = [(2 + i // 2, 1 + i % 2, 0) for i in range(16)] for nc_index, nc_h in enumerate(nc_h_rng):
# -*- coding: utf-8 -*- """ Calculate equilibrium population of species and the cooling function using the Lipovka data """ from __future__ import print_function import numpy as np import matplotlib.pyplot as plt from astropy import units as u from frigus.cooling_function.fits import fit_coppola from frigus.population import cooling_rate_at_steady_state from frigus.readers.dataset import DataLoader species_data = DataLoader().load('H2_lique') plt.ion() fig, axs = plt.subplots(figsize=(8, 8)) # density of the colliding species, in m^3 nc_h_rng = [ 1.e6, 1.e7, 1.e8, 1.e9, 1.e10, 1.e11, 1.e12, 1.e13, 1.e14 ] * u.meter ** -3 t_rad = 0.0 * u.Kelvin t_rng = np.logspace(2, 3.2, 10) * u.Kelvin # T_rng = species_data.raw_data.collision_rates_T_range plot_markers = [(2 + i//2, 1 + i % 2, 0) for i in range(16)]
Calculate equilibrium population of species and the cooling function using the Lique data. """ from __future__ import print_function import matplotlib.pyplot as plt import numpy from astropy import units as u from frigus.cooling_function.fits import fit_glover from frigus.population import (cooling_rate_at_steady_state, population_density_at_steady_state) from frigus.readers.dataset import DataLoader species_data = DataLoader().load('H2_low_energy_levels') # density of the colliding species, in m^3 nc_h = 1e6 * u.meter**-3 t_rad = 0.0 * u.Kelvin lambda_vs_t_kin = [] pop_dens_vs_t_kin = [] t_rng = species_data.raw_data.collision_rates_t_range for t_kin in t_rng: print(t_kin) pop_dens_vs_t_kin += [ population_density_at_steady_state(species_data, t_kin, t_rad, nc_h)
# -*- coding: utf-8 -*- """ Calculate equilibrium population of species and the cooling function using the data by Benjamin Desrorreaux et al 2018 """ from __future__ import print_function import numpy as np import matplotlib.pyplot as plt from astropy import units as u from frigus.cooling_function.fits import fit_lipovka, fit_flower from frigus.population import cooling_rate_at_steady_state from frigus.readers.dataset import DataLoader species_data = DataLoader().load('HD_galileo_project') # density of the colliding species, in m^3 #nc_h_rng = [ # 1.e6, 1.e7, 1.e8, 1.e9, 1.e10, 1.e11, 1.e12, 1.e13, 1.e14 # ] * u.meter ** -3 nc_h_rng = [1.e6] * u.meter**-3 t_rad = 0.0 * u.Kelvin t_rng = np.logspace(1, 3.1, 30) * u.Kelvin #T_rng = species_data.raw_data.collision_rates_T_range #T_rng_old = species_data_old.raw_data.collision_rates_T_range plot_markers = [(2 + i // 2, 1 + i % 2, 0) for i in range(16)] fig, axs = plt.subplots(figsize=(10, 10))