Cantera 4.0.0#
Under development
Breaking Changes#
As a new major version, Cantera 4.0 includes a number of backwards-incompatible changes which may require updates to user code. These changes are summarized here, along with some guidance on how to migrate existing code.
C++: Transition to std::span for array arguments#
Methods operating on arrays have been modified to take std::span arguments instead of
pointers to unsized arrays or references to std::vector. This approach provides the
opportunity to ensure array sizes are correct while providing compatibility with
different data containers. For example, Phase::getMoleFractions(double* x) has been
replaced with Phase::getMoleFractions(span<double> x).
The following code demonstrates how to use different container types with Cantera’s
methods that take span arguments:
using namespace Cantera;
auto soln = newSolution("mech.yaml");
auto phase = soln->thermo();
vector<double> x1(phase->nSpecies());
Eigen::ArrayXd x2 = Eigen::ArrayXd::Zero(phase->nSpecies());
// custom user container for multiple states
MyVector x3(4 * phase->nSpecies());
size_t offset = 2 * phase->nSpecies();
// Old call signatures (Cantera 3.2 and older)
phase->getMoleFractions(x1.data());
phase->getMoleFractions(x2.data());
phase->getMoleFractions(&x3[offset]);
// New call signatures (Cantera 4.0 and newer)
phase->getMoleFractions(x1);
phase->getMoleFractions(asSpan(x2)); // Eigen 3.4.0
phase->getMoleFractions(x2); // Eigen 5.0
phase->getMoleFractions(span<const double>(&x3[offset], phase->nSpecies()));
For methods that had an extra argument specifying array sizes, this argument has
been removed. For example,
PlasmaPhase::setElectronEnergyLevels(const double* levels, size_t length) is now just
PlasmaPhase::setElectronEnergyLevels(span<const double> levels).
Additionally, a number of methods which previously returned references to std::vector
have been updated to return std::span instead. For example,
const std::vector<double> Phase::molecularWeights() has been replaced with
span<const double> Phase::molecularWeights().