cfs-energy / cfspopcon

POPCONs (Plasma OPerating CONtours)
https://cfspopcon.readthedocs.io/en/latest/
MIT License
22 stars 14 forks source link

Update radas to v1 #31

Closed tbody-cfs closed 5 months ago

tbody-cfs commented 5 months ago

Removes the radas submodule and replaces it with a pip-installed version.

tbody-cfs commented 5 months ago
from cfspopcon.read_atomic_data import AtomicData, AtomicSpecies
atomic_data = AtomicData()

from cfspopcon.atomic_data import read_atomic_data
atomic_data_2 = read_atomic_data()

for species in [
    "Helium",
    "Lithium",
    "Beryllium",
    "Carbon",
    "Nitrogen",
    "Oxygen",
    "Neon",
    "Argon",
    "Krypton",
    "Xenon",
    "Tungsten",
]:
    kind = AtomicData.CoronalLz

    dataset = atomic_data[species]

    Ne = np.logspace(np.log10(dataset.dim_electron_density.min()), np.log10(dataset.dim_electron_density.max()), num=1000, endpoint=False)
    Te = np.logspace(np.log10(dataset.dim_electron_temp.min()), np.log10(dataset.dim_electron_temp.max()), num=1000, endpoint=False)
    atomic_data.eval_interpolator(Ne, Te, kind=kind, species=species, allow_extrapolation=True).sel(dim_electron_density=1e20, method="nearest").plot(xscale="log", yscale="log", label="new")

    interpolator_2 = atomic_data_2[AtomicSpecies[species]].coronal_Lz_interpolator

    xr.DataArray(np.power(10, interpolator_2(np.log10(Te), np.log10(Ne), grid=True)), coords=dict(dim_electron_temp=Te, dim_electron_density=Ne)).sel(dim_electron_density=1e20, method="nearest").plot(xscale="log", yscale="log", label="original", linestyle="--")

    plt.title(f"{species} Lz ")
    plt.legend()

    plt.savefig(f"{species}_Lz.png")
    plt.close()

Tungsten_Z Xenon_Z Krypton_Z Argon_Z Neon_Z Oxygen_Z Nitrogen_Z Carbon_Z Beryllium_Z Lithium_Z Helium_Z Tungsten_Lz Xenon_Lz Krypton_Lz Argon_Lz Neon_Lz Oxygen_Lz Nitrogen_Lz Carbon_Lz Beryllium_Lz Lithium_Lz Helium_Lz

tbody-cfs commented 5 months ago

Seems to be slower than the previous version. Why is this? Might want to try evaluate for the entire ne, Te grid at once. Alternatively, pick a single ne value (weak dependence for rates) and just use this single reference value.

tbody-cfs commented 5 months ago

Seems to be slower than the previous version. Why is this? Might want to try evaluate for the entire ne, Te grid at once. Alternatively, pick a single ne value (weak dependence for rates) and just use this single reference value.

Fixed this in latest commit. Seems to be significantly faster to precompute as much as possible.

python -m cProfile cfspopcon/cli.py example_cases/SPARC_PRD > profile.txt

profile.txt

tbody-cfs commented 5 months ago

Checking the comparison of the Krypton data, was getting an issue where the Lz curve was going to zero at a particular temperature. Have now added logic to drop invalid rows and columns from the atomic data.

Raw data

atomic_data[AtomicSpecies.Krypton].sel(dim_electron_density=1e20, method="nearest").coronal_Lz.plot(xscale="log", yscale="log")
plt.title("Krypton")

image

New output of interpolator, dropping invalid values

Krypton_Lz