Skip to content

Instantly share code, notes, and snippets.

@anandxkumar
Created June 14, 2021 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anandxkumar/cbe12f47170e1d71a82f4b246bd01dcc to your computer and use it in GitHub Desktop.
Save anandxkumar/cbe12f47170e1d71a82f4b246bd01dcc to your computer and use it in GitHub Desktop.
Legacy Benchmark_OH_CO
from radis import plot_diff, SpectrumFactory
import numpy as np
import math
# Finds complement of the lines to drop
def find_missing(lst, N):
start = 0
end = N-1
return sorted(set(range(start, end + 1)).difference(lst))
# Finds average
def Average(lst):
return sum(lst) / len(lst)
# Computation parameters
wmin = 2000
wmax = 10000
wstep = 0.005
T = 3000.0 #K
p = 0.1 #bar
broadening_max_width=10
Total_Calc_TIME = {}
Total_Voigt_Broadening_TIME = {}
N_lines = {}
#%% Calculate CO, 25000+ lines
sf = SpectrumFactory(wavenum_min=wmin, wavenum_max=wmax,
pressure=p,
wstep=wstep,
broadening_max_width=broadening_max_width,
molecule="CO",
cutoff=0, # 1e-27,
verbose=0,
)
sf.load_databank('HITEMP-CO')
Ntarget = 25000
rows = np.arange(0,len(sf.df0),max(1,int(len(sf.df0)//Ntarget)))
# Complements the array
rows = find_missing(rows,len(sf.df0))
rows = sf.df0.index[rows]
# Drops the array to use
sf.df0.drop(rows, inplace=True)
N = len(sf.df0)
sf.params['optimization'] = None
sf.params['broadening_method'] = 'voigt'
#%% compute Spectrum 100 times
total_time = []
total_voigt_broadening = []
for i in range(1,101):
print("ITERATION -",i)
s_co = sf.eq_spectrum(T)
total_time.append(s_co.get_conditions()['calculation_time'])
total_voigt_broadening.append(s_co.get_conditions()['Legacy_Voigt_Broadening'])
Total_Calc_TIME[s_co.get_conditions()['molecule']] = Average(total_time)
Total_Voigt_Broadening_TIME[s_co.get_conditions()['molecule']] = Average(total_voigt_broadening)
N_lines[s_co.get_conditions()['molecule']] = N
spectral_range = s_co.conditions['wavenum_max_calc'] - s_co.conditions['wavenum_min_calc']
# LEGACY_SCALE
Legacy_Scale = broadening_max_width * spectral_range/math.pow(wstep,2) * N
#%% Calculate OH 25000+ lines
sf1 = SpectrumFactory(wavenum_min=0, wavenum_max=38000,
pressure=p,
wstep=wstep,
broadening_max_width=broadening_max_width,
molecule="OH",
cutoff=0, # 1e-27,
verbose=0,
)
sf1.load_databank('HITEMP-OH')
Ntarget = 25000
rows = np.arange(0,len(sf1.df0),max(1,int(len(sf1.df0)//Ntarget)))
# Complements the array
rows = find_missing(rows,len(sf1.df0))
rows = sf1.df0.index[rows]
# Drops the array to use
sf1.df0.drop(rows, inplace=True)
N = len(sf1.df0)
sf1.params['optimization'] = None
sf1.params['broadening_method'] = 'voigt'
#%% compute Spectrum 100 times
total_time1 = []
total_voigt_broadening1 = []
for i in range(1,101):
print("ITERATION -",i)
s_co1 = sf1.eq_spectrum(T)
total_time1.append(s_co1.get_conditions()['calculation_time'])
total_voigt_broadening1.append(s_co1.get_conditions()['Legacy_Voigt_Broadening'])
Total_Calc_TIME[s_co1.get_conditions()['molecule']] = Average(total_time1)
Total_Voigt_Broadening_TIME[s_co1.get_conditions()['molecule']] = Average(total_voigt_broadening1)
N_lines[s_co1.get_conditions()['molecule']] = N
spectral_range1 = s_co1.conditions['wavenum_max_calc'] - s_co1.conditions['wavenum_min_calc']
# LEGACY_SCALE
Legacy_Scale1 = broadening_max_width * spectral_range1/math.pow(wstep,2) * N
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment