Skip to content

Add ThermalCXLine model#386

Merged
jacklovell merged 27 commits into
cherab:developmentfrom
vsnever:feature/thermal_cx_line
Jul 31, 2024
Merged

Add ThermalCXLine model#386
jacklovell merged 27 commits into
cherab:developmentfrom
vsnever:feature/thermal_cx_line

Conversation

@vsnever
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread cherab/core/model/plasma/impact_excitation.pyx Outdated
Comment thread cherab/core/model/plasma/recombination.pyx Outdated
Comment thread cherab/core/model/plasma/thermal_cx.pyx
Comment thread cherab/openadas/rates/pec.pyx Outdated
Comment thread cherab/openadas/rates/pec.pyx Outdated
Comment thread cherab/openadas/rates/pec.pyx Outdated
Comment thread cherab/openadas/repository/pec.py Outdated
Comment thread cherab/openadas/repository/pec.py Outdated
Comment thread cherab/openadas/repository/pec.py Outdated
Comment thread cherab/core/model/plasma/thermal_cx.pyx
@vsnever
Copy link
Copy Markdown
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
Copy Markdown
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!

Comment thread cherab/core/tests/test_line_emission.py Outdated
Comment thread cherab/core/tests/test_line_emission.py Outdated
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
Copy Markdown
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
Copy Markdown
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.

Comment thread cherab/core/tests/test_line_emission.py Outdated
Comment thread cherab/core/tests/test_line_emission.py Outdated
Comment thread cherab/openadas/rates/pec.pyx Outdated
from cherab.core.utility.conversion import PhotonToJ


DEF ZERO_THRESHOLD = 1.e-300
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread cherab/openadas/repository/pec.py Outdated
integration_step = 0.0025
beam_transform = translate(-0.5, 0.0, 0) * rotate_basis(Vector3D(1, 0, 0), Vector3D(0, 0, 1))
beam_energy = 50000 # keV
beam_energy = 50000 # eV
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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().

Comment thread cherab/openadas/repository/create.py
Copy link
Copy Markdown
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.

Comment thread cherab/core/model/plasma/thermal_cx.pyx
Comment thread cherab/core/model/plasma/thermal_cx.pyx
@jacklovell jacklovell merged commit d8a0b8c into cherab:development Jul 31, 2024
@vsnever vsnever deleted the feature/thermal_cx_line branch August 30, 2024 16:26
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