moved some methods to State.cpp

This commit is contained in:
Dave Goodwin 2003-07-29 22:37:30 +00:00
parent 6e5eae4dd6
commit 03e175c01f

View File

@ -10,7 +10,7 @@
* $Date$
* $Revision$
*
* Copyright 2001 California Institute of Technology
* Copyright 2001-2003 California Institute of Technology
* See file License.txt for licensing information
*
*/
@ -19,10 +19,8 @@
#ifndef CT_STATE2_H
#define CT_STATE2_H
//#include "config.h"
//#include "ct_defs.h"
#include "utilities.h"
#include "updaters.h"
//#include "updaters.h"
#include "ctexceptions.h"
namespace Cantera {
@ -47,14 +45,13 @@ namespace Cantera {
/**
* Constructor.
*/
State() : m_kk(0), m_temp(0.0), m_dens(0.001), m_mmw(0.0) {
}
State();
/**
* Destructor. Since no memory is allocated by methods of this
* class, the destructor does nothing.
*/
virtual ~State() {}
virtual ~State();
/**
@ -73,15 +70,7 @@ namespace Cantera {
}
/// The mole fraction of species k.
doublereal moleFraction(int k) const {
if (k >= 0 && k < m_kk) {
return m_ym[k] * m_mmw;
}
else {
throw CanteraError("State:moleFraction",
"illegal species index number");
}
}
doublereal moleFraction(int k) const;
/**
* Set the mole fractions to the specified values, and then
@ -90,33 +79,13 @@ namespace Cantera {
* Must have a length greater than or equal to the number of
* species.
*/
void setMoleFractions(const doublereal* x) {
int k;
doublereal sum = 0.0, norm = 0.0;
sum = dot(x, x + m_kk, m_molwts.begin());
for (k = 0; k != m_kk; ++k) {
m_ym[k] = x[k] / sum;
m_y[k] = m_molwts[k]*m_ym[k];
norm += x[k];
}
m_mmw = sum/norm;
m_C_updater.need_update();
}
void setMoleFractions(const doublereal* x);
/**
* Set the mole fractions to the specified values without
* normalizing.
*/
void setMoleFractions_NoNorm(const doublereal* x) {
int k;
m_mmw = dot(x, x + m_kk, m_molwts.begin());
doublereal rmmw = 1.0/m_mmw;
for (k = 0; k != m_kk; ++k) {
m_ym[k] = x[k]*rmmw;
m_y[k] = m_ym[k] * m_molwts[k];
}
m_C_updater.need_update();
}
void setMoleFractions_NoNorm(const doublereal* x);
void getMassFractions(size_t leny, doublereal* y) const {
copy(m_y.begin(), m_y.end(), y);
@ -132,15 +101,8 @@ namespace Cantera {
}
/// Mass fraction of species k.
doublereal massFraction(int k) const {
if (k >= 0 && k < m_kk) {
return m_y[k];
}
else {
throw CanteraError("State:massFraction",
"illegal species index number");
}
}
doublereal massFraction(int k) const;
/**
* Set the mole fractions to the specified values, and then
@ -149,37 +111,13 @@ namespace Cantera {
* Must have a length greater than or equal to the number of
* species.
*/
void setMassFractions(const doublereal* y) {
doublereal norm = 0.0, sum = 0.0;
int k;
for (k = 0; k != m_kk; ++k) {
norm += y[k];
}
scale(y, y + m_kk, m_y.begin(), 1.0/norm);
for (k = 0; k != m_kk; ++k) {
m_ym[k] = m_y[k] * m_rmolwts[k];
sum += m_ym[k];
}
m_mmw = 1.0/sum;
m_C_updater.need_update();
}
void setMassFractions(const doublereal* y);
/**
* Set the mass fractions to the specified values without
* normalizing.
*/
void setMassFractions_NoNorm(const doublereal* y) {
int k;
doublereal sum = 0.0;
for (k = 0; k != m_kk; ++k) {
m_y[k] = y[k];
m_ym[k] = m_y[k] * m_rmolwts[k];
sum += m_ym[k];
}
m_mmw = 1.0/sum;
//copy(y, y + m_kk, m_y.begin());
m_C_updater.need_update();
}
void setMassFractions_NoNorm(const doublereal* y);
/**
* Get the species concentrations (kmol/m^3). @param c On return, c
@ -220,14 +158,10 @@ namespace Cantera {
}
/// Evaluate \f$ \sum_k X_k \log X_k \f$.
doublereal sum_xlogx() const {
return m_mmw*_sum_xlogx(m_ym.begin(), m_ym.end()) + log(m_mmw);
}
doublereal sum_xlogx() const;
/// Evaluate \f$ \sum_k X_k \log Q_k \f$.
doublereal sum_xlogQ(doublereal* Q) const {
return m_mmw * _sum_xlogQ(m_ym.begin(), m_ym.end(), Q);
}
doublereal sum_xlogQ(doublereal* Q) const;
/// Temperature. Units: K.
doublereal temperature() const { return m_temp; }
@ -244,41 +178,26 @@ namespace Cantera {
void setDensity(doublereal rho) {
if (rho != m_dens) {
m_dens = rho;
m_C_updater.need_update();
//m_C_updater.need_update();
}
}
/// Set the molar density to value n (kmol/m^3).
void setMolarDensity(doublereal n) {
m_dens = n*meanMolecularWeight();
m_C_updater.need_update();
//m_C_updater.need_update();
}
/// Set the temperature to value temp (K).
void setTemperature(doublereal temp) {
if (temp != m_temp) {
m_temp = temp;
m_T_updater.need_update();
//m_T_updater.need_update();
}
}
/// set the concentrations to the specified values
void setConcentrations(const doublereal* c) {
int k;
doublereal sum = 0.0, norm = 0.0;
for (k = 0; k != m_kk; ++k) {
sum += c[k]*m_molwts[k];
norm += c[k];
}
m_mmw = sum/norm;
setDensity(sum);
doublereal rsum = 1.0/sum;
for (k = 0; k != m_kk; ++k) {
m_ym[k] = c[k] * rsum;
m_y[k] = m_ym[k] * m_molwts[k];
}
m_C_updater.need_update();
}
void setConcentrations(const doublereal* c);
const doublereal* massFractions() const { return m_y.begin(); }
@ -287,8 +206,8 @@ namespace Cantera {
protected:
PropertyUpdater& updater_T() { return m_T_updater; }
PropertyUpdater& updater_C() { return m_C_updater; }
//PropertyUpdater& updater_T() { return m_T_updater; }
//PropertyUpdater& updater_C() { return m_C_updater; }
/**
* @internal
@ -298,22 +217,17 @@ namespace Cantera {
* State has about the species is their molecular weights.
*
*/
void init(const array_fp& mw) {
m_kk = mw.size();
m_molwts.resize(m_kk);
m_rmolwts.resize(m_kk);
m_y.resize(m_kk, 0.0);
m_ym.resize(m_kk, 0.0);
copy(mw.begin(), mw.end(), m_molwts.begin());
for (int k = 0; k < m_kk; k++)
m_rmolwts[k] = 1.0/m_molwts[k];
}
void init(const array_fp& mw); //, density_is_independent = true);
/**
* m_kk is the number of species in the mixture
*/
int m_kk;
private:
doublereal m_temp, m_dens;
/**
* Temperature. This is an independent variable
* units = Kelvin
@ -333,6 +247,7 @@ namespace Cantera {
* m_mmw is the mean molecular weight of the mixture
* (kg kmol-1)
*/
doublereal m_mmw;
/**
@ -357,13 +272,6 @@ namespace Cantera {
*/
array_fp m_rmolwts;
// property updaters
mutable PropertyUpdater m_T_updater;
mutable PropertyUpdater m_C_updater;
private:
};
}