Stellar Evolution Simulation Script

This script appears to be used for simulating stellar evolution using Python with the PYSEP library. It imports various modules for setting up the stellar model environment, customizing physics and control parameters, handling file types related to pre-main-sequence files, and dealing with opacity tables. The core function defined in the script, sethighresolution, is designed to adjust model parameters for high-resolution simulations. The script then proceeds to parse elemental abundance files, customize the control parameters based on these abundances, and execute multiple stellar evolution models with varying parameters. This could be particularly useful for astrophysicists or researchers studying stellar properties and evolution.

from pysep.dsep import stellarModel as sm
from pysep.io.nml.control.defaults import controlLow
from pysep.io.nml.physics.defaults import phys1Low
from pysep.dm.filetypes import premsf_file
from pysep.opac.opal.defaults import GS98hz
 
from pysep.opac.tops import open_and_parse
 
 
FDEF="""def set_high_resolution(pnml):
    hr_pnml = pnml.copy()
    hr_pnml['lenvg'] = True
    hr_pnml['atmstp'] = 0.002
    hr_pnml['envstp'] = 0.002
    hr_pnml['tridt'] = 1.0e-4
    hr_pnml['tridl'] = 8.0e-3
    hr_pnml['atmerr'] = 3.0e-5
    hr_pnml['atmmax'] = 0.05
    hr_pnml['atmmin'] = 0.015
    hr_pnml['atmbeg'] = 0.015
    hr_pnml['enverr'] = 3.0e-5
    hr_pnml['envmax'] = 0.05
    hr_pnml['envmin'] = 0.015
    hr_pnml['envbeg'] = 0.015
    hr_pnml['htoler'][0][0] = 6.0e-7
    hr_pnml['htoler'][0][1] = 4.5e-7
    hr_pnml['htoler'][0][2] = 3.0e-7
    hr_pnml['htoler'][0][3] = 9.0e-7
    hr_pnml['htoler'][0][4] = 3.0e-7
    hr_pnml['htoler'][1][4] = 2.5e-8
    hr_pnml['shelltol'][1] = 0.0575
    hr_pnml['shelltol'][7] = 0.01
    hr_pnml['shelltol'][8] = 0.01
    hr_pnml['shelltol'][9] = 0.01
    hr_pnml['shelltol'][10] = 0.01
    hr_pnml['niter2'] = 40
    return hr_pnml"""
 
def comment_after_line(linen):
    lines = FDEF.split('\n')
    newlines = list()
    for lineID, line in enumerate(lines):
        if lineID == 0 or lineID == 1 or lineID == 27:
            newlines.append(line)
        elif lineID <= 2+linen:
            newlines.append(line)
    return '\n'.join(newlines)
 
parsed = open_and_parse("../../inputs/abun/GS98.abun")
prems = premsf_file("../../inputs/prems/GS98_fixedLum/m0302GS98.prems")
useCTL = controlLow.copy()
useCTL[0]['rsclx'] = parsed['AbundanceRatio']['X']
useCTL[0]['rsclz'] = parsed['AbundanceRatio']['Z']
useCTL[1]['nmodls'] = 5
checkRange = range(19, 25)
 
flines = FDEF.split('\n')
for disableNum in checkRange:
    print(f"WORKING ON {flines[2+disableNum]}")
    func2eval = comment_after_line(disableNum)
    exec(func2eval)
    usePHY = set_high_resolution(phys1Low)
    model = sm(".", useCTL, usePHY, GS98hz, prems)
    model.evolve()