Skip to content

Improve testing of thermodynamic consistency #114

@speth

Description

@speth

Abstract

Rather than ad hoc testing that ThermoPhase objects satisfy basic thermodynamic relations, consolidating all of these tests into a single test suite that operates over all thermo models would automatically provide comprehensive coverage and allow us to remove a number of other isolated tests.

Motivation

Cantera ThermoPhase objects calculate a large number of different quantities, some of which can be computed from other available quantities but which in practice are calculated directly for the sake of computational efficiency. While the test suite contains some tests addressing such identities, a full set of tests is not done for every thermo model.

The lack of these tests has repeatedly resulted in implementation errors (e.g. Cantera/cantera#998 and Cantera/cantera#1080).

Consolidating such testing would all but eliminate the need for a good portion of some model-specific test suites, e.g. BinarySolutionTabulatedThermo_Test.cpp, MaskellSolidSolnPhase_Test.cpp, PengRobinson_Test.cpp, etc.). It would also provide a quick starting point for testing new thermo model implementations.

Possible Solutions

Add a new GTest test class which includes specific tests for various identities. The main ones that come to mind are:

  • dot product of partial molar properties and mole fractions equals the mixture properties with
    • getPartialMolarEnthalpies and enthalpy_mole
    • getPartialMolarEntropies and entropy_mole
    • getPartialMolarIntEnergies and intEnergy_mole
    • getChemPotentials and gibbs_mole
    • getPartialMolarCp and cp_mole
    • getPartialMolarVolumes and molarVolume
  • Thermodynamic relations at the current state, for both the mixture properties and the partial molar properties:
    • h = u + P*v
    • g = h - T*s
  • Thermodynamic derivatives that can be compared to finite difference calculations
  • cp = dh/dT at constant P,N_i
  • cv = du/dT at constant V,N_i
  • isothermalCompressibility = -1/v * dv/dP at constant T,N_i
  • thermalExpansionCoeff = 1/v * dv/dT at constant P,N_i
  • Relationships among activities / activity coefficients
  • Relationships among the standard / reference / non-dimensionalized properties

The test would then be parameterized to use different input files and mixture states. We would also want a way to disable specific tests for certain models, for example those that don't implement specific methods.

We could also use this structure for doing regression tests on known/assumed good output values for different models, where the test values were stored in a YAML file. This file could look something like:

- input-file: whatever.yaml # group by phase definitions
  phase-name: PR_CO2
  - state: {T: 330, P: 100 bar, X: {CO2: 0.9, H2O: 0.1} # loop over different states
    - enthalpy_mass: 1.234e5 # values to check for this state
    - partial_molar_entropies: [1.2, 3.4, ...] # array over all species
    - ... # additional properties to check
  - state: # more states where some properties have values to check
- input-file: # Next input file / phase name
  ...

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions