Skip to content

Conversation

@goodfeli
Copy link
Contributor

@goodfeli goodfeli commented Dec 5, 2025

This commit addresses issue #529 by integrating ICRH minority species with the plasma composition system, ensuring physical consistency across all plasma calculations.

Changes:

  • Add optional 'minority_species' parameter to IonCyclotronSourceConfig that allows specifying which species in plasma_composition to use as the ICRH minority (e.g., 'He3', 'D', 'T')
  • Add _get_minority_concentration_from_composition() helper function that extracts minority concentration from plasma composition, supporting:
    • Minority species in main ions (for hydrogenic species)
    • Minority species in impurities (for helium species)
    • All three impurity modes: fractions, n_e_ratios, n_e_ratios_Z_eff
  • Update icrh_model_func() to read minority concentration from plasma_composition when minority_species is set
  • Maintain backward compatibility: existing configs using minority_concentration parameter continue to work

Testing:

  • Add test_source_with_minority_species_from_composition() to verify new functionality with He3 minority in impurities
  • All existing ICRH tests pass (backward compatibility confirmed)
  • All 651 source tests pass (no regressions)

This implementation completes the first task in issue #529: "Map ICRH minority to either main-ion (if hydrogenic) or impurity (if He)"

This commit addresses issue google-deepmind#529 by integrating ICRH minority species
with the plasma composition system, ensuring physical consistency across
all plasma calculations.

Changes:
- Add optional 'minority_species' parameter to IonCyclotronSourceConfig
  that allows specifying which species in plasma_composition to use as
  the ICRH minority (e.g., 'He3', 'D', 'T')
- Add _get_minority_concentration_from_composition() helper function that
  extracts minority concentration from plasma composition, supporting:
  * Minority species in main ions (for hydrogenic species)
  * Minority species in impurities (for helium species)
  * All three impurity modes: fractions, n_e_ratios, n_e_ratios_Z_eff
- Update icrh_model_func() to read minority concentration from
  plasma_composition when minority_species is set
- Maintain backward compatibility: existing configs using
  minority_concentration parameter continue to work

Testing:
- Add test_source_with_minority_species_from_composition() to verify
  new functionality with He3 minority in impurities
- All existing ICRH tests pass (backward compatibility confirmed)
- All 651 source tests pass (no regressions)

This implementation completes the first task in issue google-deepmind#529:
"Map ICRH minority to either main-ion (if hydrogenic) or impurity (if He)"
@google-cla
Copy link

google-cla bot commented Dec 5, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@goodfeli
Copy link
Contributor Author

goodfeli commented Dec 5, 2025

I've signed the CLA for this github account before but re-signed it for the e-mail used on this commit. Not sure how to retrigger the CLA check after re-signing.

@theo-brown
Copy link
Collaborator

Manually triggered it for you, CLA check pass fine now!

Copy link
Collaborator

@jcitrin jcitrin left a comment

Choose a reason for hiding this comment

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

Thanks for this contribution, and sorry that it fell between the cracks leading to a delayed review!

minority_concentration_profile, geo
)
else:
# Use legacy parameter (backward compatibility)
Copy link
Collaborator

Choose a reason for hiding this comment

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

add a TODO to remove the backwards incompatibility in V2

minority_concentration: torax_pydantic.TimeVaryingScalar = (
torax_pydantic.ValidatedDefault(0.03)
)
minority_species: Annotated[str | None, torax_pydantic.JAX_STATIC] = None
Copy link
Collaborator

Choose a reason for hiding this comment

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

At the moment, the TORIC-NN being used is only valid for He3 minority. A Pydantic validation can assure that only He3 is a valid input.

elif minority_species in plasma_comp.impurity_names:
# For impurities, need to get the species-specific density
# The impurity concentration depends on the impurity mode
if isinstance(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This internal branching adversely impacts readability. Maybe use a match case pattern for the 3 cases?

)

else:
raise ValueError(
Copy link
Collaborator

Choose a reason for hiding this comment

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

could check for this in the beginning of the function, and avoid this extra else

Comment on lines +374 to +378
else:
raise ValueError(
f'Minority species {minority_species} not found in'
' impurity_fractions.'
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

can remove this if checking for minority species not being in main_ions or impurities in the beginning of the function

Comment on lines +390 to +394
else:
raise ValueError(
f'Minority species {minority_species} not found in'
' impurity_fractions.'
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

can remove this if checking for minority species not being in main_ions or impurities in the beginning of the function

species_fraction = core_profiles.impurity_fractions[
minority_species
]
return total_impurity_concentration * species_fraction
Copy link
Collaborator

Choose a reason for hiding this comment

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

this does not provide the true ne_ratio of the impurity, due to . We also need to multiply by the impurity_density_scaling.

See here:

impurity_density_scaling = (

With the explanation why here:

# The impurity density must be scaled to account for the true total impurity

core_profiles.n_impurity.value / core_profiles.n_e.value
)
species_fraction = core_profiles.impurity_fractions[minority_species]
return total_impurity_concentration * species_fraction
Copy link
Collaborator

Choose a reason for hiding this comment

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

as above, this does not provide the true ne_ratio of the impurity, due to . We also need to multiply by the impurity_density_scaling.

@jcitrin
Copy link
Collaborator

jcitrin commented Jan 8, 2026

No further action needed from your side. The comments are minor and we can take care of them in internal review. Thanks again for this contribution

@jcitrin jcitrin added the copybara:import-manual Set when ready for copybara manual import label Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copybara:import-manual Set when ready for copybara manual import

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants