Cantera / enhancements

Repository for proposed and ongoing enhancements to Cantera
11 stars 5 forks source link

Improve testing of thermodynamic consistency #114

Closed speth closed 2 years ago

speth commented 3 years ago

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:

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