Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ThermalCXLine model #386

Open
wants to merge 25 commits into
base: development
Choose a base branch
from

Conversation

vsnever
Copy link
Member

@vsnever vsnever commented Nov 18, 2022

This draft PR fixes #57 by adding ThermalCXLine model and implementing ThermalCXPEC.

ThermalCXPEC is implemented as a function of 3 variables: electron density, electron temperature and donor temperature assuming Maxwellian distribution of both receiver and donor.

PR currently misses:

  • documentation,
  • tests,
  • demos.

@jacklovell jacklovell added this to the 1.5 milestone Dec 22, 2022
@jacklovell jacklovell linked an issue Dec 22, 2022 that may be closed by this pull request
@vsnever
Copy link
Member Author

vsnever commented Dec 5, 2023

I've added tests, demos and documentation, so I think this PR is ready for review.

@vsnever vsnever marked this pull request as ready for review December 5, 2023 14:57
Copy link
Member

@Mateasek Mateasek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @vsnever,

I'm sorry I was delaying this. I don't want to be delaying the review any further, so I'm posting this review without thesting the actual loading of the ADAS file, but I guess if there were any problems you would discover them. I have some questions and suggestions to consider which could improve the code. In any case, thanks for adding the thermal cx rate.

cherab/core/model/plasma/impact_excitation.pyx Outdated Show resolved Hide resolved
cherab/core/model/plasma/recombination.pyx Outdated Show resolved Hide resolved
cherab/core/model/plasma/thermal_cx.pyx Show resolved Hide resolved
cherab/openadas/rates/pec.pyx Outdated Show resolved Hide resolved
cherab/openadas/rates/pec.pyx Outdated Show resolved Hide resolved
cherab/openadas/rates/pec.pyx Outdated Show resolved Hide resolved
cherab/openadas/repository/pec.py Outdated Show resolved Hide resolved
cherab/openadas/repository/pec.py Outdated Show resolved Hide resolved
cherab/openadas/repository/pec.py Outdated Show resolved Hide resolved
cherab/core/model/plasma/thermal_cx.pyx Show resolved Hide resolved
@vsnever
Copy link
Member Author

vsnever commented May 12, 2024

Thanks a lot for the review, @Mateasek. I agree with all your suggestions. They are implemented in the latest commits.

Copy link
Member

@jacklovell jacklovell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, couple of suggestions.

I appreciate the additional test coverage of all the line emission models. In the other PR we did request that ImpactExcitation and Recombination docstrings were moved to a separate PR: in principle the same applies here. But I've no qualms with accepting this PR as is: any increase in test coverage is to be welcomed!

cherab/core/tests/test_line_emission.py Outdated Show resolved Hide resolved
Comment on lines 93 to 102
world = World()

atomic_data = TestAtomicData()

plasma_species = [(carbon, 5, 2.e18, 800., Vector3D(0, 0, 0))]
slab_length = 1.2
plasma = build_constant_slab_plasma(length=slab_length, width=1, height=1, electron_density=1e19, electron_temperature=1000.,
plasma_species=plasma_species, b_field=Vector3D(0, 10., 0))
plasma.atomic_data = atomic_data
plasma.parent = world
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be put into a TestExcitationLine.setUp method, to ensure the plasma state is consistent before each test and there is no retained state after each test. See https://docs.python.org/3/library/unittest.html#organizing-test-code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently the tests do not change the plasma state, but you are right, it is better to move this to the setUp() method to avoid possible problems in the future. For all other tests I will do this in a separate PR.

cherab/core/tests/test_line_emission.py Outdated Show resolved Hide resolved
cherab/core/tests/test_line_emission.py Outdated Show resolved Hide resolved
from cherab.core.utility.conversion import PhotonToJ


DEF ZERO_THRESHOLD = 1.e-300
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be >0?

Also, prefer cdef ZERO_THRESHOLD to DEF: https://cython.readthedocs.io/en/latest/src/userguide/migrating_to_cy30.html#deprecation-of-def-if. Or just type the value out manually: it's only used in 3 places within the same function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially I introduced this threshold when we switched to Raysect interpolators and moved to log-log interpolation for atomic rates. The idea was to not override the extrapolation settings of the interpolators by forcibly returning zero when extrapolation is disabled. However, if we decided to return zero rate for zero plasma parameters, it is safe to remove the threshold and just check if parameters are <= 0.

cherab/openadas/repository/pec.py Outdated Show resolved Hide resolved
beam_energy = 50000 # keV
beam_energy = 50000 # eV
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOL, good catch.

Comment on lines 19 to 20
# Install PECs for CVI spectral lines
install_adf15(carbon, 5, 'adf15/pec96#c/pec96#c_pju#c5.dat', download=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel a bit uncomfortable about a demo modifying the users' atomic data repository. Should we in fact add this file to repository.populate()? It's unclear why we don't have more carbon lines in there by default, given they parse fine with the existing parser? @Mateasek any thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I think user database shouldn't be changed from a demo. It could lead to errors or worse, for example due to filesystem rights restrictions. If the file is provided by Open ADAS, I agree it should be rather added to the repository.populate(). If it is not available yet, I would say comment out the file installation and add an additional comment for the users that they have to install it this way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, I added this to populate().

@@ -147,6 +147,7 @@ def populate(download=True, repository_path=None, adas_path=None):
(carbon, 0, 'adf15/pec96#c/pec96#c_vsu#c0.dat'),
(carbon, 1, 'adf15/pec96#c/pec96#c_vsu#c1.dat'),
(carbon, 2, 'adf15/pec96#c/pec96#c_vsu#c2.dat'),
(carbon, 5, 'adf15/pec96#c/pec96#c_pju#c5.dat'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a note in the changelog that this carbon line is added to cherab.openadas.repository.populate, and therefore that users will need to rerun this function before running the demo?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, it's done.

Copy link
Member

@Mateasek Mateasek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @vsnever for implemeting the changes. Once you sort out @jacklovell's comments, the PR can be accepted.

cherab/core/model/plasma/thermal_cx.pyx Show resolved Hide resolved
cherab/core/model/plasma/thermal_cx.pyx Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement ThermalCX plasma emission model
3 participants