Skip to content

Thermodynamic properties for a 2-temperature plasma#2101

Open
pag1pag wants to merge 57 commits intoCantera:mainfrom
pag1pag:fix_thermo_maxwellian_two_temperatures_plasma
Open

Thermodynamic properties for a 2-temperature plasma#2101
pag1pag wants to merge 57 commits intoCantera:mainfrom
pag1pag:fix_thermo_maxwellian_two_temperatures_plasma

Conversation

@pag1pag
Copy link
Copy Markdown

@pag1pag pag1pag commented Mar 20, 2026

Note that the following assumes that a temperature can be defined for all species. While this may be true for all heavy species, electrons may not be characterized by an electron temperature (for instance, if the electron energy distribution function (EEDF) is far away from a Maxwellian). It is therefore assumed that the implementation below holds if, for instance, the EEDF is Maxwellian (which may be seen as a strong approximation in plasma).

The partial pressure is defined as: $P_k = R T_k X_k \rho_m$ (with $\rho_m$ the mixture molar density).
The total pressure is the sum of all partial pressure: $P = \sum_k P_k = R \rho_m \sum_k X_k T_k$
Introducing a mean temperature, defined by $\overline{T}=\sum_k X_k T_k$, the total pressure is rewritten $P = R \rho_m \overline{T}$.

The standard concentration (standardConcentration) uses this mean temperature: $c^°=\frac{P}{R \overline{T}}$.
The standard volume (getStandardVolumes and getPartialMolarVolumes) is $v_k = \frac{R T_k}{P}$.

Changes proposed in this pull request

  • Define or Redefine for a 2-temperature system:
    • Molar Thermodynamic Properties: enthalpy_mole, entropy_mole, gibbs_mole, intEnergy_mole
    • Mechanical Equation of State: meanTemperature, pressure, setPressure, electronPressure
    • Chemical Potentials and Activities: standardConcentration
    • Partial Molar Properties: getChemPotentials, getPartialMolarEnthalpies, getPartialMolarIntEnergies, getPartialMolarVolumes
    • Properties of the Standard State of the Species: getStandardChemPotentials, getStandardVolumes
    • Thermodynamic Values for the Species Reference: getGibbs_ref, getStandardVolumes_ref
  • Update the setState method to account for additional electron temperature. Also introduce setState_TgTeP and setState_TgTeD to set electron temperature along with other quantities.
  • Looking now at consistency tests, all of them pass when the electron temperature is equal to gas temperature. New cases were added with different electron and gas temperatures. The skipped tests are due to temperature differential, which are hard to define when there are multiple temperature (When $T_e \neq T_g$, $c_p=\frac{dh}{dT}$ may not be correct: is $dT$ equal to $dT_h$ or $dT_e$ ?). Some Python tests required to update the electron temperature after setting TPX, and doing that gives the expected value.
  • Refactor and document plasma thermo files by regrouping related method in the same section (no change of code, just move some parts for better lisibility)

If applicable, fill in the issue number this pull request is fixing

Closes #1872

If applicable, provide an example illustrating new features this pull request is introducing

import cantera as ct

# Create the plasma object using a default YAML file.
plasma = ct.Solution(
    "example_data/oxygen-plasma-itikawa.yaml",
    "isotropic-electron-energy-plasma",
    transport_model=None,
)

# Initialize the plasma object with a temperature, pressure, and composition.
plasma.TDX = 300, 0.6415, {"O2": 0.5, "E": 0.5}
# Also initialize the electron temperature, at the same temperature as the heavy particles.
plasma.Te = 300.0

print(
    "Initializing the plasma object:\n"
    + f"T = {plasma.T} K\n"  # >>> 300 K, ok
    + f"rho = {plasma.density} kg/m^3\n"  # >>> 0.6415 kg/m^3, ok
    + f"X = {plasma.X}\n"  # >>> [0.5 0.  0.5 0.  0.  0. ], ok
    + f"Te = {plasma.Te} K\n"  # >>> 300 K, ok
)

print(f"Computed pressure = {plasma.P} Pa")
# >>> 100011.93190795329 Pa, ok
print(f"Computed (electron) pressure = {plasma.Pe} Pa")
# >>> 50005.96595397664 Pa, ok

print("==========================")

# Now, changing the electron temperature.
plasma.Te = 30_000.0

print(
    f"Changing the electron temperature to T_e={plasma.Te} K:\n"
    + f"T = {plasma.T} K\n"  # >>> 300 K, ok
    + f"rho = {plasma.density} kg/m^3\n"  # >>> 0.6415 kg/m^3, ok
    + f"X = {plasma.X}\n"  # >>> [0.5 0.  0.5 0.  0.  0. ], ok
    + f"Te = {plasma.Te} K\n"  # >>> 30000 K, ok
)
print(f"Computed (total) pressure = {plasma.P} Pa")
# >>> 5050602.561351642 Pa, ok
print(f"Computed (electron) pressure = {plasma.Pe} Pa")
# >>> 5000596.595397665, ok
# The total pressure is now dominated by the electron pressure, as expected.

AI Statement (required)

  • No generative AI was used. This contribution was written entirely without AI
    assistance.

Checklist

  • The pull request includes a clear description of this code change
  • Commit messages have short titles and reference relevant issues
  • Build passes (scons build & scons test) and unit tests address code coverage
  • Style & formatting of contributed code follows contributing guidelines
  • AI Statement is included
  • The pull request is ready for review

Updated and standardized comments throughout PlasmaPhase.cpp for clarity and consistency. Minor clarifications were made to comment phrasing to better describe the logic and intent of code blocks. No functional code changes were introduced.
Moved the comment about updating electron Gibbs functions inside the loop to accurately reflect where the update occurs.
Implemented cp_mole, cp_mole_e, cp_mass_e, cv_mole_e, cv_mass_e, cp_mole_h, cp_mass_h, cv_mole_h, and cv_mass_h methods in PlasmaPhase to separately compute specific heat capacities for electrons and heavy species. Updated the header and source files with method definitions and detailed documentation for each new function.
Introduced meanTemperature() to compute the mole-fraction-weighted average temperature of electrons and heavy species in the plasma phase. Overrode pressure() to use the mean temperature in pressure calculations, and updated setPressure() to set density based on the mean temperature.
Reorganizes and documents the PlasmaPhase class. Improves Doxygen comments, groups related methods, and adds stubs for unimplemented thermodynamic properties. No new codes, only reorganization and minor updates on comments.
Add full stop at the end of some comment, and change from parenthesis to bracket
Grouped and reordered method declarations in PlasmaPhase.h for partial molar, standard state, and reference state properties. Added and commented out several method overrides, that comes from the IdealGasPhase.
Reorganizes the PlasmaPhase class implementation by grouping related methods into clearly marked sections, improving code readability and maintainability. Moves and consolidates overridden methods, adds section comments. No functional changes are introduced.
Clarified the documentation for overridden methods in PlasmaPhase, specifying that methods are overridden from IdealGasPhase or ThermoPhase and adding a Doxygen group marker.
Added Doxygen-style comments and grouping for electron species information methods in PlasmaPhase.h to improve code documentation and organization.
Added detailed documentation for getStandardChemPotentials and getGibbs_ref in PlasmaPhase, clarifying their behavior for heavy species and electrons.

Updated getStandardChemPotentials implementation to:
- correctly evaluate getGibbs_ref using the electron temperature.
- use total pressure instead of electron pressure.
There is no need to subtract the electron pressure instead of the total pressure (cf. previous commit, where the pressure has been defined including the electron temperature)
The getPartialMolarEntropies method in PlasmaPhase.cpp has been commented out. No need to correct for electron pressure.
Updated Doxygen comments in PlasmaPhase.h to use consistent notation (\overline{T} instead of \bar{T}), clarified units for variables in equations, and improved descriptions for several methods.
Also commented out the getPartialMolarEntropies method override (cf. previous commit).
Replaced calls to the m_Me() function with the m_Me member variable in cp_mass_e() and cv_mass_e() methods to ensure correct calculation of electron-specific heat capacities.
Commented out the entropy_mole, gibbs_mole, and intEnergy_mole overrides in PlasmaPhase, removing their NotImplementedError stubs. Now that pressure is defined, it should work as expected
Introduced new properties to ThermoPhase for accessing electron and heavy species heat capacities (cp/cv, mole/mass) and mean plasma temperature. These properties are only available when plasma mode is enabled and provide more detailed thermodynamic information for plasma phases.
Changed the setState_TD method in the Phase class to be virtual, allowing derived classes to override this method for custom behavior.
Introduces new methods to set the thermodynamic state of PlasmaPhase, including setState_TP, setState_TgTeP, setState_TD, and setState_TgTeD, supporting both gas and electron temperatures. Also adds explicit NotImplementedError exceptions for unsupported state-setting methods and improves documentation and member variable comments for clarity.
Changed the plasma test phase from 'discretized-electron-energy-plasma' to 'isotropic-electron-energy-plasma'. Updated known failures to only include unsupported 'setState_SV' in PlasmaPhase and added a note clarifying the assumption that electron temperature equals gas temperature in test cases.
Updates the test setup to assume electron temperature (Te) equals the bulk temperature (T) in all test cases. For plasma phases, explicitly sets Te and resets the state to ensure consistency.
Before, the electron temperature was not set?
Implements PlasmaPhase::setState to allow setting the phase state from an AnyMap with flexible property keys and units. This method supports various synonyms for gas temperature, electron temperature, pressure, density, and composition, improving usability and integration with input files.
Simplifies the pressure() method in PlasmaPhase to use the multi-temperature ideal gas law with mean temperature and density, removing the previous adjustment for electron temperature and concentration.
Introduced a new plasma test case in consistency-cases.yaml where the electron temperature (Te) is set to a value different from the gas temperature (T) to test handling of non-equilibrium conditions.
Now, tests are not passing.
Added implementations for standardConcentration, getPartialMolarVolumes, and getStandardVolumes in PlasmaPhase to properly handle multi-temperature plasma phases. Also added stubs for thermalExpansionCoeff and soundSpeed with NotImplementedError, and updated documentation to clarify temperature usage in these calculations.
Listed additional known failures in the plasma test cases for differential methods that are not yet implemented for two-temperature systems. This clarifies current test expectations and documents unimplemented features.
Update consistency tests to correctly handle two-temperature plasma models by distinguishing between electron and heavy species temperatures in relevant thermodynamic relations. Adjust tests for Gibbs energy, enthalpy, entropy, and heat capacity to account for electron temperature where appropriate.
All consistency tests passed.
Introduced TgTeP and TgTeD properties to the ThermoPhase class for getting and setting gas temperature, electron temperature, and pressure or density, respectively. Updated the Cython interface to expose setState_TgTeP and setState_TgTeD methods. Added corresponding tests to verify correct behavior.
pag1pag added 22 commits March 19, 2026 13:21
Replace raw pointer + size calls with vector-based overloads for saving/restoring partial state in PlasmaPhase (savePartialState/restorePartialState) and for retrieving partial molar entropies in the thermo consistency test. This simplifies calls, uses safer STL containers, and matches updated API signatures. Changes applied in src/thermo/PlasmaPhase.cpp and test/thermo_consistency/consistency.cpp.
Update docstrings for getPartialMolarEnthalpies, getPartialMolarVolumes, getPartialMolarEntropies, and getPartialMolarCp. The last two are not overriden, since there is no need for it.
Also add a comment for 5 methods, for why we don't need to override them.
Without `.resolve()` on Windows, it can lead to error.
Check that cp and h are correctly computed, even if the electron temperature is not the same as the gas temperature
Some tests are failing for 2-temperature systems, when Te!=Tg
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 22, 2026

Codecov Report

❌ Patch coverage is 63.63636% with 108 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.54%. Comparing base (3ee92b6) to head (2caaef7).

Files with missing lines Patch % Lines
src/thermo/PlasmaPhase.cpp 66.39% 39 Missing and 42 partials ⚠️
include/cantera/thermo/PlasmaPhase.h 34.14% 27 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2101      +/-   ##
==========================================
- Coverage   77.62%   77.54%   -0.09%     
==========================================
  Files         451      451              
  Lines       53045    53173     +128     
  Branches     8853     8871      +18     
==========================================
+ Hits        41177    41231      +54     
- Misses       8891     8946      +55     
- Partials     2977     2996      +19     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

pag1pag added 5 commits March 23, 2026 09:22
Remove numerous setState_XY overloads from PlasmaPhase.h that previously threw NotImplementedError (e.g., setState_HP, setState_UV, setState_SV, etc.).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cantera does not compute a multi-temperature ideal gas law for now

1 participant