[SpeciesThermo] assign nCoeffs in C++ layer
This commit is contained in:
parent
5ab15e15ce
commit
cf8d2efa09
11 changed files with 61 additions and 8 deletions
|
|
@ -86,6 +86,9 @@ public:
|
||||||
void updatePropertiesTemp(const doublereal temp,
|
void updatePropertiesTemp(const doublereal temp,
|
||||||
doublereal* cp_R, doublereal* h_RT,
|
doublereal* cp_R, doublereal* h_RT,
|
||||||
doublereal* s_R) const;
|
doublereal* s_R) const;
|
||||||
|
|
||||||
|
size_t nCoeffs() const { return 4; }
|
||||||
|
|
||||||
void reportParameters(size_t& n, int& type,
|
void reportParameters(size_t& n, int& type,
|
||||||
doublereal& tlow, doublereal& thigh,
|
doublereal& tlow, doublereal& thigh,
|
||||||
doublereal& pref,
|
doublereal& pref,
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,9 @@ public:
|
||||||
doublereal* cp_R,
|
doublereal* cp_R,
|
||||||
doublereal* h_RT,
|
doublereal* h_RT,
|
||||||
doublereal* s_R) const;
|
doublereal* s_R) const;
|
||||||
|
|
||||||
|
virtual size_t nCoeffs() const;
|
||||||
|
|
||||||
virtual void reportParameters(size_t& n, int& type,
|
virtual void reportParameters(size_t& n, int& type,
|
||||||
doublereal& tlow, doublereal& thigh,
|
doublereal& tlow, doublereal& thigh,
|
||||||
doublereal& pref,
|
doublereal& pref,
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,8 @@ public:
|
||||||
doublereal* cp_R, doublereal* h_RT,
|
doublereal* cp_R, doublereal* h_RT,
|
||||||
doublereal* s_R) const;
|
doublereal* s_R) const;
|
||||||
|
|
||||||
|
virtual size_t nCoeffs() const;
|
||||||
|
|
||||||
//! This utility function reports back the type of parameterization and all
|
//! This utility function reports back the type of parameterization and all
|
||||||
//! of the parameters for the species, index.
|
//! of the parameters for the species, index.
|
||||||
/*!
|
/*!
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,8 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t nCoeffs() const { return 15; }
|
||||||
|
|
||||||
void reportParameters(size_t& n, int& type,
|
void reportParameters(size_t& n, int& type,
|
||||||
doublereal& tlow, doublereal& thigh,
|
doublereal& tlow, doublereal& thigh,
|
||||||
doublereal& pref,
|
doublereal& pref,
|
||||||
|
|
|
||||||
|
|
@ -306,6 +306,8 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual size_t nCoeffs() const { return 15; }
|
||||||
|
|
||||||
virtual void reportParameters(size_t& n, int& type,
|
virtual void reportParameters(size_t& n, int& type,
|
||||||
doublereal& tlow, doublereal& thigh,
|
doublereal& tlow, doublereal& thigh,
|
||||||
doublereal& pref,
|
doublereal& pref,
|
||||||
|
|
|
||||||
|
|
@ -206,6 +206,12 @@ public:
|
||||||
doublereal* h_RT,
|
doublereal* h_RT,
|
||||||
doublereal* s_R) const;
|
doublereal* s_R) const;
|
||||||
|
|
||||||
|
|
||||||
|
//! This utility function reports back the number of coefficients
|
||||||
|
//! for a given type of species parameterization
|
||||||
|
virtual size_t nCoeffs() const;
|
||||||
|
|
||||||
|
|
||||||
//! This utility function reports back the type of parameterization and all
|
//! This utility function reports back the type of parameterization and all
|
||||||
//! of the parameters for the species.
|
//! of the parameters for the species.
|
||||||
/*!
|
/*!
|
||||||
|
|
|
||||||
|
|
@ -96,6 +96,7 @@ cdef extern from "cantera/thermo/SpeciesThermoInterpType.h":
|
||||||
double maxTemp()
|
double maxTemp()
|
||||||
double refPressure()
|
double refPressure()
|
||||||
void reportParameters(size_t&, int&, double&, double&, double&, double* const) except +translate_exception
|
void reportParameters(size_t&, int&, double&, double&, double&, double* const) except +translate_exception
|
||||||
|
int nCoeffs() except +translate_exception
|
||||||
|
|
||||||
cdef extern from "cantera/thermo/SpeciesThermoFactory.h":
|
cdef extern from "cantera/thermo/SpeciesThermoFactory.h":
|
||||||
cdef CxxSpeciesThermo* CxxNewSpeciesThermo "Cantera::newSpeciesThermoInterpType"\
|
cdef CxxSpeciesThermo* CxxNewSpeciesThermo "Cantera::newSpeciesThermoInterpType"\
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ cdef class SpeciesThermo:
|
||||||
if not init:
|
if not init:
|
||||||
return
|
return
|
||||||
|
|
||||||
if len(coeffs) != self.n_coeffs:
|
if not self.check_n_coeffs(len(coeffs)):
|
||||||
raise ValueError("Coefficient array has incorrect length")
|
raise ValueError("Coefficient array has incorrect length")
|
||||||
cdef np.ndarray[np.double_t, ndim=1] data = np.ascontiguousarray(
|
cdef np.ndarray[np.double_t, ndim=1] data = np.ascontiguousarray(
|
||||||
coeffs, dtype=np.double)
|
coeffs, dtype=np.double)
|
||||||
|
|
@ -59,6 +59,11 @@ cdef class SpeciesThermo:
|
||||||
def __get__(self):
|
def __get__(self):
|
||||||
return self.spthermo.refPressure()
|
return self.spthermo.refPressure()
|
||||||
|
|
||||||
|
property n_coeffs:
|
||||||
|
""" Number of parameters for the parameterization."""
|
||||||
|
def __get__(self):
|
||||||
|
return self.spthermo.nCoeffs()
|
||||||
|
|
||||||
property coeffs:
|
property coeffs:
|
||||||
"""
|
"""
|
||||||
Array of coefficients for the parameterization. The length of this
|
Array of coefficients for the parameterization. The length of this
|
||||||
|
|
@ -74,6 +79,9 @@ cdef class SpeciesThermo:
|
||||||
T_high, P_ref, &data[0])
|
T_high, P_ref, &data[0])
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def check_n_coeffs(self, n):
|
||||||
|
raise NotImplementedError('Needs to be overloaded')
|
||||||
|
|
||||||
def cp(self, T):
|
def cp(self, T):
|
||||||
"""
|
"""
|
||||||
Molar heat capacity at constant pressure [J/kmol/K] at temperature *T*.
|
Molar heat capacity at constant pressure [J/kmol/K] at temperature *T*.
|
||||||
|
|
@ -109,13 +117,15 @@ cdef class ConstantCp(SpeciesThermo):
|
||||||
- `coeffs[3]` = :math:`c_p^o(T_0, p_{ref})` [J/kmol-K]
|
- `coeffs[3]` = :math:`c_p^o(T_0, p_{ref})` [J/kmol-K]
|
||||||
"""
|
"""
|
||||||
derived_type = SPECIES_THERMO_CONSTANT_CP
|
derived_type = SPECIES_THERMO_CONSTANT_CP
|
||||||
n_coeffs = 4
|
|
||||||
|
def check_n_coeffs(self, n):
|
||||||
|
return n == 4
|
||||||
|
|
||||||
|
|
||||||
cdef class Mu0Poly(SpeciesThermo):
|
cdef class Mu0Poly(SpeciesThermo):
|
||||||
"""
|
"""
|
||||||
Thermodynamic properties for a species which is parameterized using an
|
Thermodynamic properties for a species which is parameterized using an
|
||||||
interpolation of the Gibbs free energy based on a piecewise constant heat
|
interpolation of the Gibbs free energy based on a piecewise constant heat
|
||||||
capacity approximation. This is a wrapper for the C++ class :ct:`Mu0Poly`.
|
capacity approximation. This is a wrapper for the C++ class :ct:`Mu0Poly`.
|
||||||
|
|
||||||
:param coeffs:
|
:param coeffs:
|
||||||
|
|
@ -130,7 +140,9 @@ cdef class Mu0Poly(SpeciesThermo):
|
||||||
- ...
|
- ...
|
||||||
"""
|
"""
|
||||||
derived_type = SPECIES_THERMO_MU0_INTERP
|
derived_type = SPECIES_THERMO_MU0_INTERP
|
||||||
n_coeffs = 2
|
|
||||||
|
def check_n_coeffs(self, n):
|
||||||
|
return n > 3 and n % 2 == 0
|
||||||
|
|
||||||
|
|
||||||
cdef class NasaPoly2(SpeciesThermo):
|
cdef class NasaPoly2(SpeciesThermo):
|
||||||
|
|
@ -153,13 +165,15 @@ cdef class NasaPoly2(SpeciesThermo):
|
||||||
input files.
|
input files.
|
||||||
"""
|
"""
|
||||||
derived_type = SPECIES_THERMO_NASA2
|
derived_type = SPECIES_THERMO_NASA2
|
||||||
n_coeffs = 15
|
|
||||||
|
def check_n_coeffs(self, n):
|
||||||
|
return n == 15
|
||||||
|
|
||||||
|
|
||||||
cdef class Nasa9PolyMultiTempRegion(SpeciesThermo):
|
cdef class Nasa9PolyMultiTempRegion(SpeciesThermo):
|
||||||
"""
|
"""
|
||||||
Thermodynamic properties for a species which is parameterized using the
|
Thermodynamic properties for a species which is parameterized using the
|
||||||
9-coefficient NASA polynomial form encompassing multiple temperature ranges.
|
9-coefficient NASA polynomial form encompassing multiple temperature ranges.
|
||||||
This is a wrapper for the C++ class :ct:`Nasa9PolyMultiTempRegion`.
|
This is a wrapper for the C++ class :ct:`Nasa9PolyMultiTempRegion`.
|
||||||
|
|
||||||
:param coeffs:
|
:param coeffs:
|
||||||
|
|
@ -176,7 +190,9 @@ cdef class Nasa9PolyMultiTempRegion(SpeciesThermo):
|
||||||
as in the NIST Chemistry WebBook).
|
as in the NIST Chemistry WebBook).
|
||||||
"""
|
"""
|
||||||
derived_type = SPECIES_THERMO_NASA9MULTITEMP
|
derived_type = SPECIES_THERMO_NASA9MULTITEMP
|
||||||
n_coeffs = 11
|
|
||||||
|
def check_n_coeffs(self, n):
|
||||||
|
return n > 11 and ((n - 1) % 11) == 0
|
||||||
|
|
||||||
|
|
||||||
cdef class ShomatePoly2(SpeciesThermo):
|
cdef class ShomatePoly2(SpeciesThermo):
|
||||||
|
|
@ -200,7 +216,9 @@ cdef class ShomatePoly2(SpeciesThermo):
|
||||||
as in the NIST Chemistry WebBook).
|
as in the NIST Chemistry WebBook).
|
||||||
"""
|
"""
|
||||||
derived_type = SPECIES_THERMO_SHOMATE2
|
derived_type = SPECIES_THERMO_SHOMATE2
|
||||||
n_coeffs = 15
|
|
||||||
|
def check_n_coeffs(self, n):
|
||||||
|
return n == 15
|
||||||
|
|
||||||
|
|
||||||
cdef wrapSpeciesThermo(shared_ptr[CxxSpeciesThermo] spthermo):
|
cdef wrapSpeciesThermo(shared_ptr[CxxSpeciesThermo] spthermo):
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,11 @@ void Mu0Poly::updatePropertiesTemp(const doublereal T,
|
||||||
updateProperties(&T, cp_R, h_RT, s_R);
|
updateProperties(&T, cp_R, h_RT, s_R);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t Mu0Poly::nCoeffs() const
|
||||||
|
{
|
||||||
|
return 2*m_numIntervals + 2;
|
||||||
|
}
|
||||||
|
|
||||||
void Mu0Poly::reportParameters(size_t& n, int& type,
|
void Mu0Poly::reportParameters(size_t& n, int& type,
|
||||||
doublereal& tlow, doublereal& thigh,
|
doublereal& tlow, doublereal& thigh,
|
||||||
doublereal& pref,
|
doublereal& pref,
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,11 @@ void Nasa9PolyMultiTempRegion::updatePropertiesTemp(const doublereal temp,
|
||||||
m_regionPts[m_currRegion]->updatePropertiesTemp(temp, cp_R, h_RT, s_R);
|
m_regionPts[m_currRegion]->updatePropertiesTemp(temp, cp_R, h_RT, s_R);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t Nasa9PolyMultiTempRegion::nCoeffs() const
|
||||||
|
{
|
||||||
|
return 11*m_regionPts.size() + 1;
|
||||||
|
}
|
||||||
|
|
||||||
void Nasa9PolyMultiTempRegion::reportParameters(size_t& n, int& type,
|
void Nasa9PolyMultiTempRegion::reportParameters(size_t& n, int& type,
|
||||||
doublereal& tlow, doublereal& thigh,
|
doublereal& tlow, doublereal& thigh,
|
||||||
doublereal& pref,
|
doublereal& pref,
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,12 @@ void SpeciesThermoInterpType::updatePropertiesTemp(const double temp,
|
||||||
"Not implemented");
|
"Not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t SpeciesThermoInterpType::nCoeffs() const
|
||||||
|
{
|
||||||
|
throw CanteraError("SpeciesThermoInterpType::nCoeffs",
|
||||||
|
"Not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
void SpeciesThermoInterpType::reportParameters(size_t& index, int& type,
|
void SpeciesThermoInterpType::reportParameters(size_t& index, int& type,
|
||||||
double& minTemp, double& maxTemp, double& refPressure,
|
double& minTemp, double& maxTemp, double& refPressure,
|
||||||
double* const coeffs) const
|
double* const coeffs) const
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue