cherab / core

The core source repository for the Cherab project.
https://www.cherab.info
Other
44 stars 24 forks source link

BeamCXPEC interface class is missing the donor_metastable attribute used in BeamCXLine #411

Closed vsnever closed 1 month ago

vsnever commented 1 year ago

The BeamCXLine model uses the donor_metastable attribute of the BeamCXPEC. https://github.com/cherab/core/blob/9ae5a3e5493632c0d4cc8deef3aa838bb0085275/cherab/core/model/beam/charge_exchange.pyx#L309-L312 However, the interface class of the BeamCXPEC does not have this attribute. https://github.com/cherab/core/blob/9ae5a3e5493632c0d4cc8deef3aa838bb0085275/cherab/core/atomic/rates.pxd#L53-L55 The attribute is added only in the openadas implementation of the BeamCXPEC. https://github.com/cherab/core/blob/9ae5a3e5493632c0d4cc8deef3aa838bb0085275/cherab/openadas/rates/cx.pxd#L23-L29

First, models should not use any attributes/methods that are not in the interface classes of atomic rates.

Second, because NullBeamCXPEC does not have a donor_metastable attribute, running code with missing CX PECs for some species will raise an AttributeError if atomic data is configured with missing_rates_return_null = True.

There are two possible solutions. The first is to add the donor_metastable attribute to the BeamCXPEC interface class, and the second is to update the AtomicData.beam_cx_pec() method to return a list of (donor_metastable, rate) pairs instead of a list of rates. I think the first solution is less invasive and will have less impact on user code.

@jacklovell, @Mateasek, which solution do you like better?

vsnever commented 1 month ago

Fixed in #444.