24 const std::string& id_)
33 const std::string& id_)
49 bool x_changed = (
m_xlast != xnow);
56 }
else if (xnow == 1) {
67 if (x_changed ||
m_tlast != tnow) {
70 double rrt = 1.0 /
RT();
73 for (
size_t k = 0; k <
m_kk; k++) {
83 throw CanteraError(
"BinarySolutionTabulatedThermo::addSpecies",
84 "No. of species should be equal to 2");
97 "No. of species should be equal to 2 in phase '{}'!",
name());
102 "Species '{}' is not in phase '{}'",
106 vector_fp x = table[
"mole-fractions"].asVector<
double>();
113 if (table.
hasKey(
"molar-volume")) {
116 for(
size_t i = 0; i < N; i++) {
123 std::vector<std::pair<double,double>> x_h(N), x_s(N), x_vmol(N);
124 for(
size_t i = 0; i < N; i++) {
125 x_h[i] = {x[i], h[i]};
126 x_s[i] = {x[i], s[i]};
127 x_vmol[i] = {x[i], vmol[i]};
129 std::sort(x_h.begin(), x_h.end());
130 std::sort(x_s.begin(), x_s.end());
131 std::sort(x_vmol.begin(), x_vmol.end());
135 m_enthalpy_tab.resize(N);
136 m_entropy_tab.resize(N);
137 m_molar_volume_tab.resize(N);
138 m_derived_molar_volume_tab.resize(N);
139 m_partial_molar_volume_1_tab.resize(N);
140 m_partial_molar_volume_2_tab.resize(N);
142 for (
size_t i = 0; i < N; i++) {
144 m_enthalpy_tab[i] = x_h[i].second;
145 m_entropy_tab[i] = x_s[i].second;
146 m_molar_volume_tab[i] = x_vmol[i].second;
149 diff(m_molar_volume_tab, m_derived_molar_volume_tab);
151 for (
size_t i = 0; i < N; i++) {
152 m_partial_molar_volume_1_tab[i] = m_molar_volume_tab[i] +
154 m_partial_molar_volume_2_tab[i] = m_molar_volume_tab[i] -
172 tabThermo[
"enthalpy"].setQuantity(m_enthalpy_tab,
"J/kmol");
173 tabThermo[
"entropy"].setQuantity(m_entropy_tab,
"J/kmol/K");
174 phaseNode[
"tabulated-thermo"] = std::move(tabThermo);
180 std::vector<std::pair<double,double>> x_h_temp, x_s_temp, x_vmol_temp;
182 if (id_.size() > 0) {
183 if (phaseNode.
id() != id_) {
184 throw CanteraError(
"BinarySolutionTabulatedThermo::initThermoXML",
185 "phasenode and Id are incompatible");
189 throw CanteraError(
"BinarySolutionTabulatedThermo::initThermoXML",
190 "No. of species should be equal to 2!");
194 std::string mString = thermoNode[
"model"];
196 throw CanteraError(
"BinarySolutionTabulatedThermo::initThermoXML",
197 "Unknown thermo model: " + mString);
199 if (thermoNode.
hasChild(
"tabulatedSpecies")) {
200 XML_Node& speciesNode = thermoNode.
child(
"tabulatedSpecies");
201 std::string tabulated_species_name = speciesNode[
"name"];
204 throw CanteraError(
"BinarySolutionTabulatedThermo::initThermoXML",
205 "Species " + tabulated_species_name +
" not found.");
208 if (thermoNode.
hasChild(
"tabulatedThermo")) {
213 vmol.resize(x.size());
214 for(
size_t i=0; i<vmol.size(); i++) {
219 if ((x.size() != h.size()) || (x.size() != s.size()) ||
220 (x.size() != vmol.size())) {
221 throw CanteraError(
"BinarySolutionTabulatedThermo::initThermoXML",
222 "Species tabulated thermo data has different lengths.");
225 for(
size_t i = 0; i < x.size(); i++){
226 x_h_temp.push_back(std::make_pair(x[i],h[i]));
227 x_s_temp.push_back(std::make_pair(x[i],s[i]));
228 x_vmol_temp.push_back(std::make_pair(x[i],vmol[i]));
230 std::sort(x_h_temp.begin(), x_h_temp.end());
231 std::sort(x_s_temp.begin(), x_s_temp.end());
232 std::sort(x_vmol_temp.begin(), x_vmol_temp.end());
236 m_enthalpy_tab.resize(x_h_temp.size());
237 m_entropy_tab.resize(x_h_temp.size());
238 m_molar_volume_tab.resize(x_h_temp.size());
239 m_derived_molar_volume_tab.resize(x_h_temp.size());
240 m_partial_molar_volume_1_tab.resize(x_h_temp.size());
241 m_partial_molar_volume_2_tab.resize(x_h_temp.size());
243 for (
size_t i = 0; i < x_h_temp.size(); i++) {
245 m_enthalpy_tab[i] = x_h_temp[i].second;
246 m_entropy_tab[i] = x_s_temp[i].second;
247 m_molar_volume_tab[i] = x_vmol_temp[i].second;
250 diff(m_molar_volume_tab, m_derived_molar_volume_tab);
252 for (
size_t i = 0; i < x_h_temp.size(); i++) {
253 m_partial_molar_volume_1_tab[i] = m_molar_volume_tab[i] +
255 m_partial_molar_volume_2_tab[i] = m_molar_volume_tab[i] -
259 throw CanteraError(
"BinarySolutionTabulatedThermo::initThermoXML",
260 "Unspecified tabulated species or thermo");
263 throw CanteraError(
"BinarySolutionTabulatedThermo::initThermoXML",
264 "Unspecified thermo model");
274 if (phaseNode.
hasChild(
"standardConc")) {
278 throw CanteraError(
"BinarySolutionTabulatedThermo::initThermoXML",
279 "Unspecified standardConc model");
292 c = inputData.back();
296 c = inputData.front();
301 c = inputData[i-1] + (inputData[i] - inputData[i-1])
309 if (inputData.size() > 1) {
310 derivedData[0] = (inputData[1] - inputData[0]) /
312 derivedData.back() = (inputData.back() - inputData[inputData.size()-2]) /
315 if (inputData.size() > 2) {
316 for (
size_t i = 1; i < inputData.size()-1; i++) {
317 derivedData[i] = (inputData[i+1] - inputData[i-1]) /
322 derivedData.front() = 0;
330 m_partial_molar_volume_2_tab);
Header file for an binary solution model with tabulated standard state thermodynamic data (see Thermo...
Header for a general species thermodynamic property manager for a phase (see MultiSpeciesThermo).
Declarations for the virtual base class PDSS (pressure dependent standard state) which handles calcul...
Header for factory functions to build instances of classes that manage the standard-state thermodynam...
Declaration for class Cantera::Species.
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
A map of string keys to values whose type can vary at runtime.
size_t size() const
Returns the number of elements in this map.
vector_fp convertVector(const std::string &key, const std::string &units, size_t nMin=npos, size_t nMax=npos) const
Convert a vector of dimensional values.
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
double m_xlast
Current tabulated species mole fraction.
virtual bool addSpecies(shared_ptr< Species > spec)
virtual void getParameters(AnyMap &phaseNode) const
Store the parameters of a ThermoPhase object such that an identical one could be reconstructed using ...
void diff(const vector_fp &inputData, vector_fp &derivedData) const
Numerical derivative of the molar volume table.
double m_s0_tab
Tabulated contribution to s0[m_kk_tab] at the current composition.
vector_fp m_molefrac_tab
Vector for storing tabulated thermo.
size_t m_kk_tab
Current tabulated species index.
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
virtual void getPartialMolarVolumes(double *vbar) const
returns an array of partial molar volumes of the species in the solution.
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id_)
Import and initialize a ThermoPhase object using an XML tree.
double m_h0_tab
Tabulated contribution to h0[m_kk_tab] at the current composition.
virtual void compositionChanged()
If the compositions have changed, update the tabulated thermo lookup.
double interpolate(const double x, const vector_fp &inputData) const
Species thermodynamics linear interpolation function.
virtual void _updateThermo() const
This function gets called for every call to functions in this class.
virtual bool ready() const
Returns a bool indicating whether the object is ready for use.
BinarySolutionTabulatedThermo(const std::string &infile="", const std::string &id="")
Construct and initialize an BinarySolutionTabulatedThermo ThermoPhase object directly from an input f...
virtual void calcDensity()
Overloads the calcDensity() method of IdealSolidSoln to also consider non-ideal behavior.
Base class for exceptions thrown by Cantera classes.
vector_fp m_g0_RT
Vector containing the species reference Gibbs functions at T = m_tlast.
vector_fp m_cp0_R
Vector containing the species reference constant pressure heat capacities at T = m_tlast.
virtual bool addSpecies(shared_ptr< Species > spec)
virtual void getParameters(AnyMap &phaseNode) const
Store the parameters of a ThermoPhase object such that an identical one could be reconstructed using ...
vector_fp m_h0_RT
Vector containing the species reference enthalpies at T = m_tlast.
vector_fp m_s0_R
Vector containing the species reference entropies at T = m_tlast.
vector_fp m_speciesMolarVolume
Vector of molar volumes for each species in the solution.
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
virtual doublereal standardConcentration(size_t k) const
The standard concentration used to normalize the generalized concentration.
virtual void compositionChanged()
Apply changes to the state which are needed after the composition changes.
void setStandardConcentrationModel(const std::string &model)
Set the form for the standard and generalized concentrations.
virtual void update(doublereal T, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Compute the reference-state properties for all species.
void assignDensity(const double density_)
Set the internally stored constant density (kg/m^3) of the phase.
std::string name() const
Return the name of the phase.
size_t nSpecies() const
Returns the number of species in the phase.
size_t m_kk
Number of species in the phase.
std::string speciesName(size_t k) const
Name of the species with index k.
doublereal meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
double moleFraction(size_t k) const
Return the mole fraction of a single species.
doublereal temperature() const
Temperature (K).
size_t speciesIndex(const std::string &name) const
Returns the index of a species named 'name' within the Phase object.
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
doublereal m_tlast
last value of the temperature processed by reference state
void initThermoFile(const std::string &inputFile, const std::string &id)
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
MultiSpeciesThermo m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
AnyMap m_input
Data supplied via setParameters.
Class XML_Node is a tree-based representation of the contents of an XML file.
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
std::string id() const
Return the id attribute, if present.
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data.
void importPhase(XML_Node &phase, ThermoPhase *th)
Import a phase information into an empty ThermoPhase object.
Namespace for the Cantera kernel.
const size_t npos
index returned by functions to indicate "no position"
const double Faraday
Faraday constant [C/kmol].
bool caseInsensitiveEquals(const std::string &input, const std::string &test)
Case insensitive equality predicate.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
const double GasConstant
Universal Gas Constant [J/kmol/K].
size_t getFloatArray(const XML_Node &node, vector_fp &v, const bool convert=true, const std::string &unitsString="", const std::string &nodeName="floatArray")
This function reads the current node or a child node of the current node with the default name,...
const double BigNumber
largest number to compare to inf.
Contains declarations for string manipulation functions within Cantera.